[Crossfire] LF instead of CRLF
This commit is contained in:
@@ -1,100 +1,100 @@
|
|||||||
local devices = { }
|
local devices = { }
|
||||||
local lineIndex = 1
|
local lineIndex = 1
|
||||||
local pageOffset = 0
|
local pageOffset = 0
|
||||||
|
|
||||||
local function createDevice(id, name)
|
local function createDevice(id, name)
|
||||||
local device = {
|
local device = {
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
timeout = 0
|
timeout = 0
|
||||||
}
|
}
|
||||||
return device
|
return device
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getDevice(name)
|
local function getDevice(name)
|
||||||
for i=1, #devices do
|
for i=1, #devices do
|
||||||
if devices[i].name == name then
|
if devices[i].name == name then
|
||||||
return devices[i]
|
return devices[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parseDeviceInfoMessage(data)
|
local function parseDeviceInfoMessage(data)
|
||||||
local id = data[2]
|
local id = data[2]
|
||||||
local name = ""
|
local name = ""
|
||||||
local i = 3
|
local i = 3
|
||||||
while data[i] ~= 0 do
|
while data[i] ~= 0 do
|
||||||
name = name .. string.char(data[i])
|
name = name .. string.char(data[i])
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
local device = getDevice(name)
|
local device = getDevice(name)
|
||||||
if device == nil then
|
if device == nil then
|
||||||
device = createDevice(id, name)
|
device = createDevice(id, name)
|
||||||
devices[#devices + 1] = device
|
devices[#devices + 1] = device
|
||||||
end
|
end
|
||||||
local time = getTime()
|
local time = getTime()
|
||||||
device.timeout = time + 3000 -- 30s
|
device.timeout = time + 3000 -- 30s
|
||||||
if lineIndex == 0 then
|
if lineIndex == 0 then
|
||||||
lineIndex = 1
|
lineIndex = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local devicesRefreshTimeout = 0
|
local devicesRefreshTimeout = 0
|
||||||
local function refreshNext()
|
local function refreshNext()
|
||||||
local command, data = crossfireTelemetryPop()
|
local command, data = crossfireTelemetryPop()
|
||||||
if command == nil then
|
if command == nil then
|
||||||
local time = getTime()
|
local time = getTime()
|
||||||
if time > devicesRefreshTimeout then
|
if time > devicesRefreshTimeout then
|
||||||
devicesRefreshTimeout = time + 100 -- 1s
|
devicesRefreshTimeout = time + 100 -- 1s
|
||||||
crossfireTelemetryPush(0x28, { 0x00, 0xEA })
|
crossfireTelemetryPush(0x28, { 0x00, 0xEA })
|
||||||
end
|
end
|
||||||
elseif command == 0x29 then
|
elseif command == 0x29 then
|
||||||
parseDeviceInfoMessage(data)
|
parseDeviceInfoMessage(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function selectDevice(step)
|
local function selectDevice(step)
|
||||||
lineIndex = 1 + ((lineIndex + step - 1 + #devices) % #devices)
|
lineIndex = 1 + ((lineIndex + step - 1 + #devices) % #devices)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Init
|
-- Init
|
||||||
local function init()
|
local function init()
|
||||||
lineIndex = 0
|
lineIndex = 0
|
||||||
pageOffset = 0
|
pageOffset = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Main
|
-- Main
|
||||||
local function run(event)
|
local function run(event)
|
||||||
if event == nil then
|
if event == nil then
|
||||||
error("Cannot be run as a model script!")
|
error("Cannot be run as a model script!")
|
||||||
return 2
|
return 2
|
||||||
elseif event == EVT_EXIT_BREAK then
|
elseif event == EVT_EXIT_BREAK then
|
||||||
return 2
|
return 2
|
||||||
elseif event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then
|
elseif event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then
|
||||||
selectDevice(1)
|
selectDevice(1)
|
||||||
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then
|
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then
|
||||||
selectDevice(-1)
|
selectDevice(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
lcd.clear()
|
lcd.clear()
|
||||||
lcd.drawScreenTitle("CROSSFIRE SETUP", 0, 0)
|
lcd.drawScreenTitle("CROSSFIRE SETUP", 0, 0)
|
||||||
if #devices == 0 then
|
if #devices == 0 then
|
||||||
lcd.drawText(24, 28, "Waiting for Crossfire devices...")
|
lcd.drawText(24, 28, "Waiting for Crossfire devices...")
|
||||||
else
|
else
|
||||||
for i=1, #devices do
|
for i=1, #devices do
|
||||||
local attr = (lineIndex == i and INVERS or 0)
|
local attr = (lineIndex == i and INVERS or 0)
|
||||||
if event == EVT_ENTER_BREAK and attr == INVERS then
|
if event == EVT_ENTER_BREAK and attr == INVERS then
|
||||||
crossfireTelemetryPush(0x28, { devices[i].id, 0xEA })
|
crossfireTelemetryPush(0x28, { devices[i].id, 0xEA })
|
||||||
return "device.lua"
|
return "device.lua"
|
||||||
end
|
end
|
||||||
lcd.drawText(0, i*8+9, devices[i].name, attr)
|
lcd.drawText(0, i*8+9, devices[i].name, attr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
refreshNext()
|
refreshNext()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return { init=init, run=run }
|
return { init=init, run=run }
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user