Right, in preparations for more tests with the Pi (Via a powered HuB) I’m scrolling through the forum to create a plugin. I’ll still need to test it with simple commands via LuaTest to see if it works - but my mind is wandering to the potential end state.
So I’ve started to look at creating a I_HDMIMatrix1.xml…
I’m assuming the protocol would be raw, compared to the others listed - but to quote the wiki - the explanation below does not sound too positive ?
raw - makes no modifications to outgoing data, and calls your incoming data callback for each byte received. This adds more overhead since the engine needs to call your Luup function for every character, and makes your code complex. So, generally avoid using ‘raw’ and let us add support for your protocol if you have a new one we don’t yet support.
<implementation>
<settings>
<protocol>raw</protocol>
</settings>
Next is the mapping table for the commands
local ipAddress
local mappingTable = {
["InputSelection1"] = {
["InputA1"] = "0232313103", -- Input A1
["InputA2"] = "0232313203", -- Input A2
["InputA3"] = "0232313303", -- Input A3
["InputA4"] = "0232313403", -- Input A4
["InputB1"] = "0232323103", -- Input B1
["InputB2"] = "0232323203", -- Input B2
["InputB3"] = "0232323303", -- Input B3
["InputB4"] = "0232323403", -- Input B4
},
["DiscretePower1"] = {
["Off"] = "0230303603", -- POWER OFF
["On"] = "0230303503", -- POWER ON
},
["MenuNavigation1"] = {
["LEDOn"] = "02303103303", -- LED ON
["LEDOff"] = "02303103403", -- LED OFF
["PortStatus"] = "02303103103", -- Port Status
},
}
Then the start up.
function doStartup(lul_device)
local PORT = 4001
ipAddress = luup.devices[lul_device].ip
if (ipAddress ~= "") then
luup.log("Running HDMI Matrix via a RaspBerry Pi plugin on " .. ipAddress)
luup.io.open(lul_device, ipAddress, PORT)
else
luup.log("Running Serial Attached to HDMI Matrix - THIS IS UNTESTED")
end
end[/code]
Then huge thanks to the Pioneer receiver plugin for helping me piece this. Sending the codes
[code]function sendCode(code)
local CR = string.char(13)
-- Wake up the HDMI if it is in standby mode.
luup.io.write(CR)
-- Send the code to the TV
if( false == luup.io.write(code .. CR)) then
luup.log("io.write error in action: " .. " code:" .. code, 1)
luup.set_failure(true)
return false
end
return true
end
function doAction(deviceType, actionName)
local code = mappingTable[deviceType][actionName];
-- Do we have a code?
if( code ~= "") then
sendCode(code)
else
luup.log("Unimplemented action: " .. deviceType .. "-" .. actionName, 1)
luup.set_failure(true)
return false
end
return true;
end
I’m not sure about this bit of code local CR = string.char(13) as the manual says it "Converts ASCII codes into their equivalent characters" but hopefully I’ll find more through testing the Luup.io.write commands for my switch
Next would be the Actions, one for each in the mapping table…
<actionList>
<action>
<serviceId>urn:micasaverde-com:serviceId:InputSelection1</serviceId>
<name>Input1</name>
<run>
doAction("InputSelection1", "InputA1")
</run>
</action>
</actionList>