|
| 1 | +sub Main() |
| 2 | + print "BrightScript CEC Example: Display On/Off" |
| 3 | + |
| 4 | + mp = createobject("roMessagePort") |
| 5 | + cec = CreateObject("roCecInterface", "HDMI-1") ' Modify this to be 'HDMI-1', 'HDMI-2', 'HDMI-3', or 'HDMI-4' as needed |
| 6 | + if cec = invalid then |
| 7 | + print "Failed to create roCecInterface object." |
| 8 | + return |
| 9 | + end if |
| 10 | + |
| 11 | + ' Create a HTML widget to display something on the screen |
| 12 | + r = CreateObject("roRectangle", 0, 0, 1920, 1080) |
| 13 | + config = { |
| 14 | + url: "file:///sd:/index.html", |
| 15 | + inspector_server: { |
| 16 | + port: 2999 |
| 17 | + } |
| 18 | + } |
| 19 | + htmlWidget = CreateObject("roHtmlWidget", r, config) |
| 20 | + htmlWidget.SetPort(mp) |
| 21 | + htmlWidget.Show() |
| 22 | + |
| 23 | + cec.SetPort(mp) |
| 24 | + |
| 25 | + ' Optionally enable debugging for CEC messages |
| 26 | + ' cec.EnableCecDebug("SD:/cec_debug.log") |
| 27 | + |
| 28 | + ' Send Image View On (4f0d) |
| 29 | + bufferImageViewOn = CreateObject("roByteArray") |
| 30 | + bufferImageViewOn.FromHexString("4f0d") |
| 31 | + cec.SendRawMessage(bufferImageViewOn) |
| 32 | + print "Sent Image View On: " + bufferImageViewOn.ToHexString() |
| 33 | + |
| 34 | + ' Wait 15 seconds, then send Standby |
| 35 | + sleep(15000) |
| 36 | + bufferStandby = CreateObject("roByteArray") |
| 37 | + bufferStandby.FromHexString("4f36") |
| 38 | + cec.SendRawMessage(bufferStandby) |
| 39 | + print "Sent Standby: " + bufferStandby.ToHexString() |
| 40 | + |
| 41 | + ' Optionally, uncomment the block below to repeat the cycle every 15 seconds |
| 42 | + ' while true |
| 43 | + ' sleep(15000) |
| 44 | + ' cec.SendRawMessage(bufferImageViewOn) |
| 45 | + ' print "Sent Image View On: " + bufferImageViewOn.ToHexString() |
| 46 | + |
| 47 | + ' sleep(15000) |
| 48 | + ' cec.SendRawMessage(bufferStandby) |
| 49 | + ' print "Sent Standby: " + bufferStandby.ToHexString() |
| 50 | + ' end while |
| 51 | + |
| 52 | + ' Message loop to handle any incoming messages (if needed) |
| 53 | + while true |
| 54 | + msg = wait(0, mp) |
| 55 | + if type(msg) = "roMessagePortEvent" |
| 56 | + ? "Message received: ";msg |
| 57 | + end if |
| 58 | + end while |
| 59 | +end sub |
0 commit comments