Object Creation
To create a cec object, load the @brightsign/cec module using the require()
method.
Code Block | ||
---|---|---|
| ||
var cecClass = require("@brightsign/cec"); var cec = new cecClass(); |
Cec
Event
ReceiveEvent
: The CEC reception path is implemented as a receive event. The receive message has two generic fields:type
: The event type "receive"data
: Array<byte> CEC frame
Method
send()
Code Block | ||
---|---|---|
| ||
Promise<void> send(Array<byte> data) |
Sends messages over cec.
data
Array<byte> : The CEC frame
port_name ()
Code Block | ||
---|---|---|
| ||
Promise<void> |
The parameters for this optional argument are:
default
: The default output for the platform, normallyHDMI-1
HDMI-X
: X is a number from 1 up to the number of HDMI® outputs on the platformeARC
: The default for the AU335
Note
As of BrightSignOS 8.2.55, the CEC implementation for AU series 5 products will reply to these messages with the correct data, without involving the script:
CEC_MSG_GET_CEC_VERSION
CEC_MSG_ABORT
CEC_MSG_GIVE_DEVICE_POWER_STATUS
CEC_MSG_GIVE_OSD_NAME
CEC_MSG_GIVE_DEVICE_VENDOR_ID
CEC_MSG_GIVE_FEATURES
CEC_MSG_GIVE_PHYSICAL_ADDR
CEC_MSG_USER_CONTROL_PRESSED
CEC_MSG_USER_CONTROL_RELEASED
CEC_MSG_REPORT_PHYSICAL_ADDR
Example
To send or receive CEC messages:
Code Block | ||
---|---|---|
| ||
const CecClass = require('@brightsign/cec'); const cec = new CecClass(); var initiatorAddress = 0x40; var opcodeGetVersion = 0x9f; var opcodeVersion = 0x9e; var version = ""; function onRxEvent(packet) { let frame = packet.data; let opcode = frame[1]; console.log("Frame Opcode: " + opcode); console.log(JSON.stringify(frame)); if (opcode == opcodeVersion) { version = frame[2].toString(16); console.log("Version: " + version); } } function cecVersion() { return new Promise(async (resolve) => { version = ""; let buffer =[]; buffer[0] = initiatorAddress; buffer[1] = opcodeGetVersion; cec.send(buffer) .then(async function() { await (async () => new Promise(resolve => setTimeout(resolve, 1000)))(); console.log("Version received: " + version); resolve(); }) .catch (function(error) { console.log("Ooops: " + error); resolve(); }); }); } async function runtest() { cec.addEventListener("receive", onRxEvent); await cecVersion(); } |