-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.lua
85 lines (74 loc) · 2.05 KB
/
driver.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--
-- Copyright 2018 Complete AV
-- driver.lua
--
-- Binding variables
SERIAL_BINDING = 1
-- Properties
SET_ID = "00"
-- Serial Commands
OSD_MENU = "F4 88 %s FD %s"
KEY_CODES = {
["MENU"] = "43",
["CANCEL"] = "50", -- Exit on the remote
["DOWN"] = "4B",
["UP"] = "47",
["LEFT"] = "57",
["RIGHT"] = "53",
["ENTER"] = "04",
["NUMBER_1"] = "1D",
["NUMBER_2"] = "1C",
["NUMBER_3"] = "46",
["NUMBER_4"] = "15",
["NUMBER_5"] = "15",
["NUMBER_6"] = "45",
["NUMBER_7"] = "00",
["NUMBER_8"] = "1F",
["NUMBER_9"] = "1B",
["NUMBER_0"] = "1E"
}
CMDS_SERIAL = {
--Power
["ON"] = "F5 88 00 FE FE 01",
["OFF"] = "F5 88 00 FE FE 00",
--Input Toggle
["DP"] = "F5 88 00 FE 01 01",
["HDMI"] = "F5 88 00 FE 01 02"
}
function ProcessCommand(strCommand)
local command = ""
if KEY_CODES[strCommand] ~= nil then
-- return concated keycode
command = string.format(OSD_MENU, SET_ID, KEY_CODES[strCommand])
C4:DebugLog("Key code found: " .. command)
elseif CMDS_SERIAL[strCommand] ~= nil then
-- return command from cmds
command = CMDS_SERIAL[strCommand]
C4:DebugLog("Serial command found: " .. command)
else
-- Command not supported
C4:DebugLog(strCommand .. " command not found for binding id: " .. SERIAL_BINDING)
end
return command
end
-- Manage Properties
function OnPropertyChanged(strName)
SET_ID = Properties[strName]
C4:DebugLog("SET_ID property changed to " .. Properties[strName])
end
-- C4 Stuff
function OnDriverInit()
SET_ID = Properties["Set ID"]
C4:DebugLog("SET_ID property set to " .. Properties[strName])
end
function ReceivedFromProxy(idBinding, strCommand, tParams)
local command = ProcessCommand(strCommand)
C4:SendToSerial(SERIAL_BINDING, tohex(command))
C4:DebugLog("Sending command " .. strCommand .. ": " .. command .. " to binding ID " .. SERIAL_BINDING)
end
function ReceivedFromSerial(idBinding, strData)
-- local serialData = hexdump(strData)
-- TODO Send this back to the proxy
hexdump(strData)
C4:DebugLog("Received from serial device: " .. strData)
end