Java Script Objects For Bright (5.0)
2014-10-15
: Brightsign Javascript Objects For Brightscript (5.0) JavaScript Objects for BrightScript (5.0) s
Open the PDF directly: View PDF .
Page Count: 25
Download | ![]() |
Open PDF In Browser | View PDF |
TECHNICAL NOTES Using JavaScript Objects for BrightScript (FW 5.0.x) BrightSign, LLC. 16795 Lark Ave., Suite 200 Los Gatos, CA 95032 408-852-9263 | www.brightsign.biz INTRODUCTION The BrightSign Webkit implementation exposes several JavaScript objects for BrightScript. These objects allow you to link many standard interactive events and hardware elements (serial, CEC, device info, etc.) to HTML5 pages. This tech note details the methods and parameters for each JavaScript object. For more information about the BrightScript objects that the JavaScript objects are linked to, see the BrightScript Object Reference Manual. Technical Notes – JavaScript Objects (FW ver. 5.0.x) 1 AVAILABLE OBJECTS BSControlPort ............................................................................. 3 BSDatagramSocket ..................................................................... 5 BSDeviceInfo ............................................................................... 7 BSIRReceiver ............................................................................... 9 BSIRTransmitter ........................................................................ 10 BSVideoMode ............................................................................ 11 BSCECTransmitter .................................................................... 13 BSCECReceiver ......................................................................... 14 BSSyncManager ........................................................................ 15 BSMessagePort ......................................................................... 18 BSSerialPort .............................................................................. 20 BSTicker ..................................................................................... 22 Technical Notes – JavaScript Objects (FW ver. 5.0.x) 2 BSControlPort For more information about available methods, refer to the entry on roControlPort. Object Creation BSControlPort(in DOMString PortName); Methods • boolean • boolean in in in • boolean in SetOutputValue(in unsigned long Param) SetOutputValues(in unsigned long Param1, unsigned long Param2, unsigned long Param3, unsigned long Param4) SetPinValue(in unsigned long Pin, unsigned long Param) Events The following events are available on the BSControlPort object. Each event can receive a ControlPortEvent event. • oncontroldown • oncontrolup • oncontrolevent ControlPortEvent – Attributes • readonly attribute unsigned long code Example The following JavaScript example causes the LEDs on a BP900 button board to twinkle: function myFunction() { var bp900_setup = new BSControlPort("TouchBoard-0-LED-SETUP"); bp900_setup.SetPinValue(0, 11) var bp900 = new BSControlPort("TouchBoard-0-LED"); bp900.SetPinValue(0, 0x07fe) bp900.SetPinValue(1, 0x07fd) bp900.SetPinValue(2, 0x07fb) bp900.SetPinValue(3, 0x07f7) bp900.SetPinValue(4, 0x07ef) bp900.SetPinValue(5, 0x07df) bp900.SetPinValue(6, 0x07bf) bp900.SetPinValue(7, 0x077f) bp900.SetPinValue(8, 0x06ff) bp900.SetPinValue(9, 0x05ff) bp900.SetPinValue(10, 0x03ff) Technical Notes – JavaScript Objects (FW ver. 5.0.x) 3 } var bp900_gpio = new BSControlPort("TouchBoard-0-GPIO"); bp900_gpio.oncontroldown = function(e) { console.log('###### oncontroldown' + e.code); } Technical Notes – JavaScript Objects (FW ver. 5.0.x) 4 BSDatagramSocket For more information about available methods, refer to the entry on roDatagramReceiver and roDatagramEvent. Methods • boolean BindLocalPort(in unsigned long portNumber) • byteArray GetBytes() Events The following event is available on the BSDatagramSocket object. It can receive an event of the type DatagramSocketEvent. • ondatagram DatagramSocketEvent – Attributes • readonly attribute DOMString remoteHost • readonly attribute int remotePort Example sock = new BSDatagramSocket(); // receiving sock.BindLocalPort(5000); sock.ondatagram = function(e) { $("#message").empty(); bytes = e.getBytes(); array = new Int8Array(bytes); console.log("the array:"+ array); console.log("Received from " + e.remoteHost + " port " + e.remotePort + " payload " + bytes + " " + array.length + " " + array[0]); var udpstring = [] $.each(array, function(i){ console.log(array[i]) var udpval = array[i] var udpconvert = String.fromCharCode(udpval) udpstring.push(udpconvert) }) var udpMessage = udpstring.join(""); switch(udpMessage){ case 'GE': $( "#message").append("UDP Message: "+udpMessage) $('#promo').css('background-image',"url(Giants_GE.png)") $("#scrollingText").show() break; case 'Morgan': $( "#message").append("UDP Message: "+udpMessage) $('#promo').css('background-image',"url(CaptainMorganLwrapNew.png)") $("#scrollingText").hide() break; Technical Notes – JavaScript Objects (FW ver. 5.0.x) 5 case 'Heinz': $( "#message").append("UDP Message: "+udpMessage) $('#promo').css('background-image',"url(Giants_Heinz.png)") $("#scrollingText").hide() break; } } Send UDP Technical Notes – JavaScript Objects (FW ver. 5.0.x) 10 BSVideoMode For more information about available methods, please refer to the entry on roVideoMode. If you’d like to change the video mode of the player, you will need to use BrightScript instead of this JavaScript class. Attributes • readonly • readonly • readonly • readonly • readonly • readonly • readonly attribute attribute attribute attribute attribute attribute attribute int resX int resY int safeX int safeY int safeWidth int safeHeight DOMString mode Methods • boolean IsAttached(in DOMString connector) • DOMString GetBestMode(in DOMString connector) • boolean SetBackgroundColour(in unsigned long rgb) • boolean SetBackgroundColour(in unsigned long r, in unsigned long g, in unsigned long b); • boolean HdmiAudioDisable(in boolean disable) Example The following JavaScript example illustrates how to retrieve information about the current video mode: function fillInVideoData() { var videomode_info = new BSVideoMode(); document.getElementById("resX").innerHTML = videomode_info.resX; document.getElementById("resY").innerHTML = videomode_info.resY; document.getElementById("safeX").innerHTML = videomode_info.safeX; document.getElementById("safeY").innerHTML = videomode_info.safeY; document.getElementById("safeWidth").innerHTML = videomode_info.safeWidth; document.getElementById("safeHeight").innerHTML = videomode_info.safeHeight; document.getElementById("videoMode").innerHTML = videomode_info.mode; document.getElementById("bestMode").innerHTML = videomode_info.GetBestMode("hdmi"); document.getElementById("connectedFlag").innerHTML = videomode_info.IsAttached("vga"); } Technical Notes – JavaScript Objects (FW ver. 5.0.x) 11 function changeBackground() { var videomode_info = new BSVideoMode(); videomode_info.SetBackgroundColour(0xFF0000); } Technical Notes – JavaScript Objects (FW ver. 5.0.x) 12 BSCECTransmitter For more information about available methods, refer to the entry on roCecInterface. Note that you can only use this JavaScript class to send CEC messages. Methods • boolean SendRawMessage(in ArrayBuffer data) • boolean SendRawMessage(in ArrayBufferView data) • boolean SendRawMessage(in DOMString data) Example The following JavaScript example shows how to send a set of CEC messages: function cecDisplayOn() { console.log("### cecDisplayOn ###"); var cec_control = new BSCECTransmitter(); var buffer = new Uint8Array(2); buffer[ 0 ] = 0x40; buffer[ 1 ] = 0x0D; cec_control.SendRawMessage(buffer); } function cecDisplayOff() { console.log("### cecDisplayOff ###"); var cec_control = new BSCECTransmitter(); var buffer = new Uint8Array(2); buffer[ 0 ] = 0x40; buffer[ 1 ] = 0x36; } cec_control.SendRawMessage(buffer); Technical Notes – JavaScript Objects (FW ver. 5.0.x) 13 BSCECReceiver For more information about available methods, refer to the documentation for roCecInterface. Note that you can only use this JavaScript class to receive CEC messages. Events The following events are available on the BSCECReceiver object. They can receive an event of the type CECReceiverEvent. • onececrxframe • oncectxcomplete CECReceiverEvent – Attributes • readonly attribute int status • readonly attribute DOMString data Example Technical Notes – JavaScript Objects (FW ver. 5.0.x) 14 BSSyncManager For more information about available methods, refer to the documentation for roSyncManager. Object Creation BSSyncManager(in DOMString domain, in DOMString multicast_address, in DOMString multicast_port); Methods • BSSyncManager(in DOMString domain, in DOMString multicast_address, in DOMString multicast_port) • void SetMaster(in boolean master_mode) raises(DOMException) • void Synchronize(in DOMString id, in unsigned long ms_delay) raises(DOMException) Events The following event is available on the BSSyncManager object. It can receive events of the type BSSyncManagerEvent. • onsyncevent HTML video tags have been extended to include a setSyncParams function. Calling this function causes a video to synchronize with the specified sync group. • setSyncParams(in DOMString domain, in DOMString id, in DOMString iso_timestamp) BSSyncManagerEvent – Attributes The following attributes are relevant to the onsyncevent event: • readonly attribute DOMString domain • readonly attribute DOMString id • readonly attribute DOMString iso_timestamp Example The following JavaScript example contains two videos being synchronized locally with BSSyncManager. If a Slave player is configured to be in the same PTP domain as the Master player and uses the Slave HTML script, then it will display the videos in sync with the Master player. This can be implemented on multiple Slave players. Master Script: Slave Script: