David Blume's GitList
Repositories
dxb_channel.git
Code
Commits
Branches
Tags
Search
Tree:
7bc7f5a
Branches
Tags
main
dxb_channel.git
components
mytask.brs
Display local time
dblume
commited
7bc7f5a
at 2024-04-10 00:00:43
mytask.brs
Blame
History
Raw
sub init() m.top.functionName = "executeTask" end sub function getDeviceInfo(deviceInfo as object, lastExit as String) as Object ' Try to get various info from an ECP call aa = {} ' Getting exit_code here may be a dupe of Launch Param LastExitOrTerminationReason am = CreateObject("roAppManager") if FindMemberFunction(am, "GetLastExitInfo") <> invalid: lastExitInfo = CreateObject("roAppManager").GetLastExitInfo() if lastExitInfo <> invalid and lastExitInfo.exit_code <> lastExit: aa["exit code"] = Mid(lastExitInfo.exit_code, 6) + " at " + Mid(lastExitInfo.timestamp, 12, 8) endif endif print "Client ID = " deviceInfo.GetChannelClientId() request = CreateObject("roUrlTransfer") request.SetUrl("http://localhost:8060/query/device-info") root = CreateObject("roXMLElement") if root.Parse(request.GetToString()) then elements = root.GetNamedElements("serial-number") if elements.Count() > 0 aa["serial number"] = elements[0].GetText() end if elements = root.GetNamedElements("device-id") if elements.Count() > 0 aa["device ID"] = elements[0].GetText() end if ' elements = root.GetNamedElements("model-number") ' if elements.Count() > 0 ' aa.["model"] = elements[0].GetText() ' end if elements = root.GetNamedElements("build-number") if elements.Count() > 0 fv = elements[0].GetText() elements = root.GetNamedElements("software-version") if elements.Count() > 0 aa.["firmware version"] = fv + " (" + elements[0].GetText() + " " + mid(fv, 9, 4) + ")" else aa.["firmware version"] = fv end if end if aa["friendly name"] = deviceInfo.GetFriendlyName() deets = deviceInfo.GetModelDetails() aa["model"] = deviceInfo.GetModel() + " (" + deets.VendorName + " " + deets.ModelNumber + ")" return aa end if ' That did not work, so make a custom one. deets = deviceInfo.GetModelDetails() aa.model = deviceInfo.GetModel() + " (" + deets.VendorName + " " + deets.ModelNumber + ")" mmrb = deviceInfo.GetOSVersion() ' major minor revision build aa["firmware version"] = mmrb.major+"."+mmrb.minor+"."+mmrb.revision+" build "+mmrb.build aa["friendly name"] = deviceInfo.GetFriendlyName() return aa end function function executeTask() as void am = CreateObject("roAppManager") aaRunParams = am.GetRunParams() for each key in aaRunParams.Keys() val = aaRunParams[key] m.top.updateText = key + " = " + val.ToStr() end for ' m.top.updateText = "devID " + CreateObject("roAppInfo").GetDevID() deviceInfo = CreateObject("roDeviceInfo") infoaa = getDeviceInfo(deviceInfo, aaRunParams.lastExitOrTerminationReason) if infoaa <> invalid: for each key in infoaa.Keys() val = infoaa[key] m.top.updateText = key + " = " + val.ToStr() end for else m.top.updateText = "(Could not get device info.)" end if port = CreateObject("roMessagePort") deviceInfo.SetMessagePort(port) input = CreateObject("roInput") input.SetMessagePort(port) cecstatus = CreateObject("roCECStatus") cecStatus.SetMessagePort(port) hdmistatus = CreateObject("roHDMIStatus") hdmistatus.SetMessagePort(port) success = deviceInfo.EnableLinkStatusEvent(true) if not success m.top.updateTextLower = "EnableLinkStatusEvent failure" mmrb = deviceInfo.GetOSVersion() ' major minor revision build if val(mmrb["major"], 10) < 12 or (val(mmrb["major"], 10) = 12 and mmrb["minor"] = "0") ' Not supported in 12.5. Might get fixed in 13 success = deviceInfo.EnableAudioDestinationEvent(true) if not success then m.top.updateTextLower = "EnableAudioDestinationEvent failure" end if success = deviceInfo.EnableAudioGuideChangedEvent(true) if not success then m.top.updateTextLower = "EnableAudioGuideChangedEvent failure" success = deviceInfo.EnableAppFocusEvent(true) if not success then m.top.updateTextLower = "EnableAppFocusEvent failure" success = deviceInfo.EnableCodecCapChangedEvent(true) if not success then m.top.updateTextLower = "EnableCodecCapChangedEvent failure" success = deviceInfo.EnableScreensaverExitedEvent(true) if not success then m.top.updateTextLower = "EnableScreensaverExitedEvent failure" success = deviceInfo.EnableInternetStatusEvent(true) if not success then m.top.updateTextLower = "EnableInternetStatusEvent failure" success = deviceInfo.EnableLowGeneralMemoryEvent(true) if not success then m.top.updateTextLower = "EnableLowGeneralMemoryEvent failure" if FindMemberFunction(deviceInfo, "EnableAudioOutputEvent") <> invalid: success = deviceInfo.EnableAudioOutputEvent(true, "all") if not success then m.top.updateTextLower = "EnableAudioOutputEvent failure" endif dt = CreateObject("roDateTime") while(true) msg = wait(0, port) msgType = type(msg) dt.Mark() dt.ToLocalTime() hms = Mid(dt.ToISOString(), 12, 8) if msgType = "roHdmiStatusEvent" aa = msg.GetInfo() plugged = aa.LookupCI("Plugged") portnum = aa.LookupCI("PortNumber") porttype = aa.LookupCI("PortType") s = hms + " HDMI " if porttype <> invalid then s = s + porttype + " " if portnum <> invalid then s = s + portnum.ToStr() + " " if plugged <> invalid then if plugged then s = s + "Plugged" else s = s + "Unplugged" end if m.top.updateTextLower = s elseif msgType = "roCECStatusEvent" aa = msg.GetInfo() v = aa.LookupCI("Active") if v <> invalid then m.top.updateTextLower = hms + " CEC Active " + v.toStr() elseif msgType = "roDeviceInfoEvent" aa = msg.GetInfo() v = aa.LookupCI("Mute") if v <> invalid then m.top.updateTextLower = hms + " Mute " + v.toStr() v = aa.LookupCI("Mode") if v <> invalid then m.top.updateTextLower = hms + " Caption Mode " + v.toStr() v = aa.LookupCI("linkStatus") if v <> invalid then m.top.updateTextLower = hms + " LinkStatus " + v.toStr() v = aa.LookupCI("audioGuideEnabled") if v <> invalid then m.top.updateTextLower = hms + " AudioGuide " + v.toStr() v = aa.LookupCI("appFocused") if v <> invalid then m.top.updateTextLower = hms + " AppFocused " + v.toStr() v = aa.LookupCI("audioCodecCapabilityChanged") if v <> invalid then m.top.updateTextLower = hms + " AudioCodecCapabilityChanged " + v.toStr() v = aa.LookupCI("videoCodecCapabilityChanged") if v <> invalid then m.top.updateTextLower = hms + " VideoCodecCapabilityChanged " + v.toStr() v = aa.LookupCI("exitedScreensaver") if v <> invalid then m.top.updateTextLower = hms + " ExitedScreensaver " + v.toStr() v = aa.LookupCI("appFocus") ' Need to verify it's actually appFocused above if v <> invalid then m.top.updateTextLower = hms + " AppFocus " + v.toStr() v = aa.LookupCI("generalMemoryLevel") if v <> invalid then m.top.updateTextLower = hms + " GeneralMemoryLevel " + v.toStr() v = aa.LookupCI("internetStatus") if v <> invalid then m.top.updateTextLower = hms + " InternetStatus " + v.toStr() v = aa.LookupCI("audioOutputEvent") if v <> invalid then m.top.updateTextLower = hms + " audioOutput " + v.toStr() vol = aa.LookupCI("volume") if vol <> invalid then m.top.updateTextLower = hms + " volume = " + vol.toStr() end if elseif msgType = "roInputEvent" info = msg.GetInfo() m.top.updateTextLower = hms + " Input " + FormatJSON(info) else m.top.updateTextLower = hms + " msgType " + msgType end if end while end function