2 local toolName
= "TNS|Multi LOLI RX config|TNE"
4 ---- #########################################################################
6 ---- # Copyright (C) OpenTX #
8 ---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
10 ---- # This program is free software; you can redistribute it and/or modify #
11 ---- # it under the terms of the GNU General Public License version 2 as #
12 ---- # published by the Free Software Foundation. #
14 ---- # This program is distributed in the hope that it will be useful #
15 ---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 ---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 ---- # GNU General Public License for more details. #
19 ---- #########################################################################
21 local loli_nok
= false
22 local channels
={ { 768, "PWM", 100, 102, "PPM", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH1
23 { 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH2
24 { -768, "Servo", 0, -2048, "Switch", -100 }, -- CH3
25 { -768, "Servo", 0, -2048, "Switch", -100 }, -- CH4
26 { 102, "SBUS", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH5
27 { -768, "Servo", 0, -2048, "Switch", -100 }, -- CH6
28 { 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH7
29 { -768, "Servo", 0, -2048, "Switch", -100 } } -- CH8
35 local BLINK_SPEED
= 15
37 local function drawScreenTitle(title
)
39 lcd
.drawFilledRectangle(0, 0, LCD_W
, 30, TITLE_BGCOLOR
)
40 lcd
.drawText(1, 5, title
, MENU_TITLE_COLOR
)
42 lcd
.drawScreenTitle(title
, 0, 0)
46 local function LOLI_Draw_LCD(event
)
54 drawScreenTitle("Multi - LOLI RX configuration tool")
67 --Multi Module detection
70 lcd
.drawText(10,50,"The LOLI protocol is not selected...", lcd_opt
)
73 lcd
.drawText(2,17,"LOLI protocol not selected...",SMLSIZE
)
78 --Display current config
81 lcd
.drawText(x_pos
, y_pos
+y_inc
*line
-2, "Channel", lcd_opt
)
82 lcd
.drawText(x_pos
+x_inc
, y_pos
+y_inc
*line
-2, "Function", lcd_opt
)
83 lcd
.drawRectangle(x_pos
-4, y_pos
+y_inc
*line
-4 , 2*x_inc
+2, 188)
84 lcd
.drawLine(x_pos
-4, y_pos
+y_inc
*line
+18, x_pos
-4 +2*x_inc
+1, y_pos
+y_inc
*line
+18, SOLID
, 0)
85 lcd
.drawLine(x_pos
+x_inc
-5, y_pos
+y_inc
*line
-4, x_pos
+x_inc
-5, y_pos
+y_inc
*line
-5 +188, SOLID
, 0)
91 out
= getValue("ch"..(i
+8))
92 lcd
.drawText(x_pos
, y_pos
+y_inc
*line
, "CH"..i
, lcd_opt
)
93 for j
= 1, #channels
[i
], 3 do
94 if out
> channels
[i
][j
] then
99 if blink
> BLINK_SPEED
then
101 if blink
> BLINK_SPEED
* 2 then
109 lcd
.drawText(x_pos
+x_inc
, y_pos
+y_inc
*line
, channels
[i
][j
+1], lcd_opt
+ invert
)
117 local function LOLI_Change_Value(dir
)
120 --look for the current position
121 out
= getValue("ch"..(sel
+8))
122 for j
= 1, #channels
[sel
], 3 do
123 if out
> channels
[sel
][j
] then
129 --decrement or increment
130 if dir
< 0 and pos
> 1 then
132 elseif dir
> 0 and pos
+ 3 < #channels
[sel
] then
138 --delete all mixers for the selected channel
139 local num_mix
= model
.getMixesCount(sel
-1 +8)
140 for i
= 1, num_mix
do
141 model
.deleteMix(sel
-1 +8, 0);
145 local source_max
= getFieldInfo("cyc1")
147 local val
= { name
= channels
[sel
][pos
+1],
148 source
= source_max
.id
- 1, -- MAX=100 on TX16S
149 weight
= channels
[sel
][pos
+2],
162 model
.insertMix(sel
-1 +8, 0, val
)
165 local function LOLI_Menu(event
)
166 if event
== EVT_VIRTUAL_NEXT
then
167 if edit
== false then
168 -- not changing a value
173 -- need to inc the value
176 elseif event
== EVT_VIRTUAL_PREV
then
177 if edit
== false then
178 -- not changing a value
183 -- need to dec the value
184 LOLI_Change_Value(-1)
186 elseif event
== EVT_VIRTUAL_ENTER
then
187 if edit
== false then
197 local function LOLI_Init()
198 local module_conf
= model
.getModule(0)
199 if module_conf
["Type"] ~= 6 or module_conf
["protocol"] ~= 82 then
200 module_conf
= model
.getModule(1)
201 if module_conf
["Type"] ~= 6 or module_conf
["protocol"] ~= 82 then
208 local function LOLI_Run(event
)
210 error("Cannot be run as a model script!")
212 elseif event
== EVT_VIRTUAL_EXIT
then
221 return { init
=LOLI_Init
, run
=LOLI_Run
}