tvcontroller
8 min
el objeto controlador de tv proporciona una interfaz de comunicación entre televisores y productos brightsign built in este objeto está disponible a partir de bos 9 0 168 múltiples instancias de tvcontroller pueden acceder al televisor desde múltiples dominios (aplicación de nodo de usuario, aplicación html de usuario, etc ), o puede usar múltiples instancias del objeto javascript todas acceden al mismo hardware del televisor y todas reciben una notificación con un evento cuando el televisor envía un mensaje idl de tvcontroller @brightsign/tvcontroller \[exposed=window] interface tvcontroller { promise\<void> send(array data); attribute eventhandler onreceive; }; \[exposed=window] interface receiveevent event { readonly attribute array data; }; creación de objetos para crear un objeto tvcontroller , cargue el módulo brightsign/tvcontroller usando el método require() y luego cree una instancia de tvcontroller let tv controller class = require("@brightsign/tvcontroller"); let tv controller = new tv controller class(); tvcontroller use esta interfaz para acceder a un televisor (por ejemplo, para enviar mensajes) send() promise\<void> send(array data) atributo onreceive \<font color="#6554c0">eventhandler\</font> receiveevent use esta interfaz para recibir una notificación con un evento cuando el televisor envía un mensaje atributo datos \<font color="#6554c0">array\</font> este es un atributo de solo lectura mensajes los mensajes se definen en formato protobuf el firmware de brightsign incluye los enlaces javascript de los mensajes del protocolo buffer en la imagen del firmware para cargar los mensajes, cargue el siguiente módulo let { messages } = require("messages pb"); se utiliza un único archivo protobuf tanto para los mensajes del televisor a brightsign built in como para los mensajes de brightsign built in al televisor, porque los mismos mensajes se utilizan tanto para las notificaciones de verificación como de actualización cuando brightsign actualiza un campo (por ejemplo, para configurar el volumen), el televisor envía de vuelta a brightsign el mismo mensaje indicando que el volumen se actualizó el volumen se puede actualizar con la interfaz de usuario del televisor, mediante control remoto brightsign también recibe eso como un evento del televisor hay algunas excepciones brightsign built in no envía mensajes de vuelta al televisor para confirmar el reconocimiento de recepción del mensaje de solicitud, solo envía la información solicitada ambos lados pueden enviarse el mensaje configuración de energía entre sí para evitar confusiones entre recibir un comando y un reconocimiento, tenemos los tipos de mensaje configuración de energía y powersettingsack powersettingsack se envía cuando el dispositivo recibe un mensaje configuración de energía y cambia al modo de energía solicitado este es el archivo proto para la interfaz de comunicación syntax = "proto3"; package messages; message whitebalance { int32 red gain = 1; // red channel gain (e g , 0 to 100) int32 green gain = 2; // green channel gain (e g , 0 to 100) int32 blue gain = 3; // blue channel gain (e g , 0 to 100) } // message to set the tv hdmi input message videooutputsettings { enum videooutputselection { hdmi 1 = 0; hdmi 2 = 1; // add more as needed } videooutputselection selected input = 1; } // there may be more powerstatus modes in the future enum powerstatus { standby = 0; on = 1; fast tv start = 2; } // message to set the power status message powersettings { powerstatus status = 1; } // powersettingsack message is an acknowledge to power status // change request // sender should wait for ack after changing powersettings // via powersettings message, or via gpio when waking device // up message powersettingsack { powerstatus status = 1; } // whatever this value is set to, the tv must store it on their side // and then when the tv goes into standby using an ir command, the tv // must send that value to the brightsign player // // powersettingsupdate message is mainly to be used as a trigger // to enable/disable "fast tv start" // message powersettingsupdate { powerstatus status = 1; } // message to set the power lock status message powerlocksettings { enum powerlockstatus { disabled = 0; enabled = 1; } powerlockstatus status = 1; } // message to set or get the usb device connection message usbconnectionsettings { enum usbconnection { connected to tv = 0; connected to set top box = 1; } usbconnection connection = 1; } // message to forward the ir commands received by the tv message ircommandmessage { uint32 code = 1; string encoding = 2; } enum request { device info = 0; video output settings = 1; power settings ack = 2; usb connection settings = 3; volume = 4; gamma = 5; brightness = 6; contrast = 7; white balance = 8; idle standby timeout seconds = 9; power settings = 10; power settings update = 11; power lock settings = 12; } message wifiinfo { string mac address = 1; // "xx\ xx\ xx\ xx\ xx\ xx" } message deviceinfo { string mac address = 1; // "xx\ xx\ xx\ xx\ xx\ xx" string serial no = 2; string os version = 3; // "x x x x" int32 hw revision = 4; // wifiinfo wifi info = 5; } message firmwareupdate { string file path = 1; } message firmwareupdatecomplete { enum firmwareupdatestatus { success = 0; fail = 1; } firmwareupdatestatus status = 1; string reason = 2; } // command message that will be sent from the set top box to the tv message tvcommand { oneof command { videooutputsettings video output settings = 1; powersettings power settings = 2; powersettingsack power settings ack = 3; usbconnectionsettings usb connection settings = 4; ircommandmessage ir command = 5; int32 volume = 6; float gamma = 7; int32 brightness = 8; int32 contrast = 9; whitebalance white balance = 10; request request = 11; deviceinfo device info = 12; int32 idle standby timeout seconds = 13; firmwareupdate firmware update = 14; firmwareupdatecomplete firmware update complete = 15; powersettingsupdate power settings update = 16; powerlocksettings power lock settings = 17; } } ejemplos de uso configurar el valor gamma del televisor en esta comunicación unidireccional, brightsign realiza la solicitud y el televisor actualiza y devuelve el valor gamma enviar toma un array de javascript, pero codificar devuelve uint8array uint8array debe convertirse a matriz usando array from() antes de llamar a enviar decodificar también espera un uint8array , pero el evento recibir devuelve matriz matriz debe convertirse a uint8array antes de llamar a decodificar usando uint8array from() let tv controller class = require("@brightsign/tvcontroller"); let tv controller = new tv controller class(); let { messages } = require("messages pb"); tv controller addeventlistener("receive", (event) => { // decode the binary data let tv = messages tvcommand decode(uint8array from(event detail)); switch (tv command) { case 'gamma' let gamma = tv gamma; console log("gamma value is updated to " + gamma); break; default console log("unknown command type " + tv command); break; } }); const tvcommand = { gamma 2 3 }; // encode the data const bytes = messages tvcommand encode(tvcommand) finish(); // send it as an array tv controller send(array from(bytes)); enviar información del dispositivo brightsign en el siguiente ejemplo, tv controller está configurado para enviar información del dispositivo cuando el televisor la solicite la aplicación configura un receptor de eventos receive y espera un evento de solicitud solo hay una solicitud disponible actualmente, device info , (cualquier otra producirá un error) una solicitud device info completa los campos requeridos y envía un mensaje de vuelta let tv controller class = require("@brightsign/tvcontroller"); let tv controller = new tv controller class(); let { messages } = require("messages pb"); tv controller addeventlistener("receive", (event)=>{ // decode the binary data let tv = messages tvcommand decode(uint8array from(event detail)); switch (tv command) { case 'request' // we only have device info request for now if (tv request != messages request device info) { throw new error("request is not device info"); } const tvcommand = { deviceinfo { serialno "1234567890", osversion "1 2 3 4", hwrevision 1, macaddress "xx\ xx\ xx\ xx\ xx\ xx", wifiinfo { macaddress "xx\ xx\ xx\ xx\ xx\ xx" } } }; const bytes = messages tvcommand encode(tvcommand) finish(); tv controller send(array from(bytes)); break; default console log("unknown command type " + tv command); break; } });