1 ---- #########################################################################
3 ---- # Copyright (C) OpenTX #
5 ---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
7 ---- # This program is free software; you can redistribute it and/or modify #
8 ---- # it under the terms of the GNU General Public License version 2 as #
9 ---- # published by the Free Software Foundation. #
11 ---- # This program is distributed in the hope that it will be useful #
12 ---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 ---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 ---- # GNU General Public License for more details. #
16 ---- #########################################################################
21 local function createDevice(id
, name
)
30 local function getDevice(name
)
32 if devices
[i
].name
== name
then
39 local function parseDeviceInfoMessage(data
)
44 name
= name
.. string.char(data
[i
])
47 local device
= getDevice(name
)
49 device
= createDevice(id
, name
)
50 devices
[#devices
+ 1] = device
52 local time
= getTime()
53 device
.timeout
= time
+ 3000 -- 30s
54 if lineIndex
== 0 then
59 local devicesRefreshTimeout
= 0
60 local function refreshNext()
61 local command
, data
= crossfireTelemetryPop()
62 if command
== nil then
63 local time
= getTime()
64 if time
> devicesRefreshTimeout
then
65 devicesRefreshTimeout
= time
+ 100 -- 1s
66 crossfireTelemetryPush(0x28, { 0x00, 0xEA })
68 elseif command
== 0x29 then
69 parseDeviceInfoMessage(data
)
73 local function selectDevice(step
)
74 lineIndex
= 1 + ((lineIndex
+ step
- 1 + #devices
) % #devices
)
83 NoCross
= { 110, LCD_H
- 28, "Waiting for Crossfire devices...", TEXT_COLOR
+ INVERS
+ BLINK
}
86 local function run(event
)
88 error("Cannot be run as a model script!")
90 elseif event
== EVT_EXIT_BREAK
then
92 elseif event
== EVT_ROT_LEFT
then
94 elseif event
== EVT_ROT_RIGHT
then
99 lcd
.drawFilledRectangle(0, 0, LCD_W
, 30, TITLE_BGCOLOR
)
100 lcd
.drawText(1, 5,"CROSSFIRE SETUP", MENU_TITLE_COLOR
)
103 if #devices
== 0 then
104 lcd
.drawText(NoCross
[1],NoCross
[2],NoCross
[3],NoCross
[4])
107 local attr
= (lineIndex
== i
and INVERS
or 0)
108 if event
== EVT_ROT_BREAK
and attr
== INVERS
then
109 crossfireTelemetryPush(0x28, { devices
[i
].id
, 0xEA })
112 lcd
.drawText(5, i
*22+10, devices
[i
].name
, attr
)
121 return { init
=init
, run
=run
}