1 rem -- Change ExpressLRS parameters
3 rem -- License https://www.gnu.org/licenses/gpl-3.0.en.html
5 rem -- basic script for radios running ErskTx R223A6 or later, based roughly on ELRS.lua
7 rem -- Original author: spinorkit
9 rem -- See https://openrcforums.com/forum/viewtopic.php?f=7&t=4676&sid=25e7416b867f2c94a6382fbff922d082
10 rem -- Description of the ErskyTx Basic dialect: https://openrcforums.com/forum/viewtopic.php?t=10325
11 rem -- N.B. ErskyTx Basic uses 0 based indexing into arrays in contrast to lua's 1 based indexing
13 rem -- Note: ErskyTx uses 400000 baud to talk to crossfire modules, and therefore ELRS.
14 rem -- If you have a 2018 R9M module (with the ACCST logo on the back), you need the
15 rem -- resistor mod for reliable communuication:
16 rem -- https://github.com/AlessandroAU/ExpressLRS/wiki/Inverter-Mod-for-R9M-2018
19 array
byte transmitBuffer
[64]
20 array
byte commitSha
[8]
21 array
byte intToHex
[17]
23 array
byte paramNames
[96]
28 array validAirRates127
[8]
29 array validAirRates128
[8]
30 array validAirRates
[8]
33 const kAirRateParamIdx
0
34 const kTLMintervalParamIdx
1
35 const kMaxPowerParamIdx
2
36 const kRFfreqParamIdx
3
37 const kWifiUpdateParamIdx
4
44 const kReceivedParams
1
45 const kWaitForUpdate
2
47 rem -- max param name len is 11 = 10 + null
48 const kMaxParamNameLen
11
49 const kMinCommandInterval10ms
100
50 const PARAMETER_WRITE
0x2D
51 const kQuestionMark
63
56 strtoarray(intToHex
,"0123456789abcdef")
58 rem -- try to detect e.g. Taranis style Tx
59 isTaranisStyle
= sysflags() & 0x20
61 eventLeft
= EVT_LEFT_FIRST
62 eventRight
= EVT_RIGHT_FIRST
63 eventUp
= EVT_UP_FIRST
64 eventDown
= EVT_DOWN_FIRST
66 eventLeftRept
= EVT_LEFT_REPT
67 eventRightRept
= EVT_RIGHT_REPT
68 eventUpRept
= EVT_UP_REPT
69 eventDownRept
= EVT_DOWN_REPT
71 activateBtn
= EVT_MENU_BREAK
74 eventLeft
= EVT_UP_FIRST
75 eventRight
= EVT_DOWN_FIRST
76 eventUp
= EVT_MENU_BREAK
77 eventDown
= EVT_LEFT_FIRST
79 eventLeftRept
= EVT_UP_REPT
80 eventRightRept
= EVT_DOWN_REPT
82 eventDownRept
= eventDown
84 activateBtn
= EVT_BTN_BREAK
92 lastChangeTime
= gettime()
94 rem -- Note: list indexes must match to param handling in tx_main!
95 rem -- list = {AirRate, TLMinterval, MaxPower, RFfreq, Bind, WebServer},
97 strtoarray(commitSha
,"??????")
99 strtoarray(paramNames
,"Pkt Rate:\0\0TLM Ratio:\0Power:\0\0\0\0\0RF freq:")
101 paramMins
[kAirRateParamIdx
] = 0
102 paramMaxs
[kAirRateParamIdx
] = 3
103 paramMins
[kTLMintervalParamIdx
] = 0
104 paramMaxs
[kTLMintervalParamIdx
] = 7
105 paramMins
[kMaxPowerParamIdx
] = 0
106 paramMaxs
[kMaxPowerParamIdx
] = 7
107 paramMins
[kRFfreqParamIdx
] = 0
108 paramMaxs
[kRFfreqParamIdx
] = 0
109 paramMins
[kWifiUpdateParamIdx
] = 0
110 paramMaxs
[kWifiUpdateParamIdx
] = 1
113 rem -- 433/868/915 (SX127x) '25 Hz', '50 Hz', '100 Hz', '200 Hz'
114 validAirRates127
[0] = 6
115 validAirRates127
[1] = 5
116 validAirRates127
[2] = 4
117 validAirRates127
[3] = 2
119 rem -- 2.4 GHz (SX128x) '50 Hz', '150 Hz', '250 Hz', '500 Hz'
120 validAirRates128
[0] = 6
121 validAirRates128
[1] = 5
122 validAirRates128
[2] = 3
123 validAirRates128
[3] = 1
124 validAirRates128
[4] = 0
127 nValidAirRates
= kNSX127Rates
151 state
= kInitializing
153 rem -- purge the crossfire packet fifo
154 result
= crossfirereceive(count
, command
, rxBuf
)
156 result
= crossfirereceive(count
, command
, rxBuf
)
159 rem gosub requestDeviceData
164 result
= crossfiresend(sendCommand
, sendLength
, transmitBuffer
)
171 rem -- crossfireTelemetryPush(0x2D, {0xEE, 0xEA, 0x00, 0x00}) ping until we get a resp
172 sendCommand
= PARAMETER_WRITE
174 transmitBuffer
[0]=0xEE
175 transmitBuffer
[1]=0xEA
176 transmitBuffer
[2]=0x00
177 transmitBuffer
[3]=0x00
182 sendWifiUpdatePacket:
183 sendCommand
= PARAMETER_WRITE
185 transmitBuffer
[0]=0xEE
186 transmitBuffer
[1]=0xEA
187 transmitBuffer
[2]=0xFE
188 transmitBuffer
[3]=0x01
193 sendParamIncDecPacket:
194 if state # kReceivedParams
then return
195 rem -- if gettime() - lastChangeTime < kMinCommandInterval10ms then return
197 origValue
= params
[selectedParam
]
198 if selectedParam
= kAirRateParamIdx
199 rem -- find the index of the current value
200 AirRateIdx
= params
[kAirRateParamIdx
]
203 nValidAirRates
= kNSX128Rates
204 while i
< nValidAirRates
205 validAirRates
[i
] = validAirRates128
[i
]
209 nValidAirRates
= kNSX127Rates
210 while i
< nValidAirRates
211 validAirRates
[i
] = validAirRates127
[i
]
216 while i
< nValidAirRates
217 if validAirRates
[i
] = AirRateIdx
then break
221 if i
>= nValidAirRates
226 value
= validAirRates
[i
]
228 value
= params
[selectedParam
]
230 if value
> paramMaxs
[selectedParam
]
231 value
= paramMaxs
[selectedParam
]
232 elseif value
< paramMins
[selectedParam
]
233 value
= paramMins
[selectedParam
]
237 if value
= origValue
then return
239 sendCommand
= PARAMETER_WRITE
241 transmitBuffer
[0]=0xEE
242 transmitBuffer
[1]=0xEA
243 transmitBuffer
[2]=selectedParam
+1
244 transmitBuffer
[3]=value
246 state
= kWaitForUpdate
247 lastChangeTime
= gettime()
257 rem -- N/B. rxBuf[0] maps to data[1] in ELRS.lua
258 result
= crossfirereceive(count
, command
, rxBuf
)
260 if (command
= 0x2D) & (rxBuf
[0] = 0xEA) & (rxBuf
[1] = 0xEE)
263 if ((rxBuf
[2] = 0xFF) & (count
= 12))
264 bindMode
= (rxBuf
[3] & 1)
265 wifiupdatemode
= (rxBuf
[3] & 2)
268 params
[kAirRateParamIdx
] = rxBuf
[4]
269 params
[kTLMintervalParamIdx
] = rxBuf
[5]
270 params
[kMaxPowerParamIdx
] = rxBuf
[6]
271 params
[kRFfreqParamIdx
] = rxBuf
[7]-1
278 state
= kReceivedParams
282 UartBadPkts
= rxBuf
[8]
283 UartGoodPkts
= rxBuf
[9] * 256 + rxBuf
[10]
285 elseif ((rxBuf
[2] = 0xFE) & (count
= 9))
286 rem -- First half of commit sha - 6 hexadecimal digits
291 commitSha
[i
] = intToHex
[j
]
293 commitSha
[i
] = kQuestionMark
300 result
= crossfirereceive(count
, command
, rxBuf
)
306 if selectedParam
>= kNTotalParams
then selectedParam
= 0
307 if selectedParam
= kRFfreqParamIdx
then selectedParam
+= 1
312 if selectedParam
< 0 then selectedParam
= kNTotalParams
- 1
313 if selectedParam
= kRFfreqParamIdx
then selectedParam
-= 1
318 gosub sendParamIncDecPacket
323 gosub sendParamIncDecPacket
327 gosub checkForPackets
329 if state
= kInitializing
330 rem -- crossfireTelemetryPush(0x2D, {0xEE, 0xEA, 0x00, 0x00}) -- ping until we get a resp
334 if (Event = eventDown
) |
(Event = eventDownRept
)
336 elseif (Event = eventUp
) |
(Event = eventUpRept
)
337 gosub previousParameter
338 elseif (Event = eventLeft
) |
(Event = eventLeftRept
)
339 gosub decrementParameter
340 elseif (Event = eventRight
) |
(Event = eventRightRept
)
341 gosub incrementParameter
342 elseif Event = activateBtn
343 if selectedParam
= kWifiUpdateParamIdx
then gosub sendWifiUpdatePacket
350 drawtext(0, yPos
, "ELRS", INVERS
)
351 if wifiupdatemode
= 2
352 drawtext(30, yPos
, "http://10.0.0.1")
354 drawtext(30, yPos
, "Bind not needed")
356 rem UartBadPkts = 250
357 rem UartGoodPkts = 250
358 drawnumber(86,yPos
, UartBadPkts
)
359 drawtext(86, yPos
, ":")
360 drawnumber(106,yPos
, UartGoodPkts
)
361 drawtext(28, yPos
, commitSha
)
363 rem if param = selectedParam then attr = INVERS
366 idx
= params
[param
]+1
367 yPos
= (param
+1)*ygap
368 drawtext(0, yPos
, "Pkt Rate:")
369 rem -- drawtext(valueXPos,yPos,"------\0AUTO \0 500Hz\0 250Hz\0 200Hz\0 150Hz\0 100Hz\0 50Hz\0 25Hz\0 4Hz"[AirRateIdx*7],(param=selectedParam)*INVERS)
370 drawtext(valueXPos
,yPos
,"------\0 500Hz\0 250Hz\0 200Hz\0 150Hz\0 100Hz\0 50Hz\0 25Hz\0 4Hz"[idx
*7],(param
=selectedParam
)*INVERS
)
373 idx
= params
[param
]+1
374 yPos
= (param
+1)*ygap
375 drawtext(0, yPos
, "TLM Ratio:")
376 drawtext(valueXPos
,yPos
,"------\0 Off\0 1:128\0 1:64\0 1:32\0 1:16\0 1:8\0 1:4\0 1:2"[idx
*7],(param
=selectedParam
)*INVERS
)
379 idx
= params
[param
]+1
380 yPos
= (param
+1)*ygap
381 drawtext(0, yPos
, "Power:")
382 drawtext(valueXPos
,yPos
,"------ \0 10 mW\0 25 mW\0 50 mW\0 100 mW\0 250 mW\0 500 mW\0 1 W\0 2 W"[idx
*8],(param
=selectedParam
)*INVERS
)
385 idx
= params
[param
]+1
386 yPos
= (param
+1)*ygap
387 drawtext(0, yPos
, "RF freq:")
388 drawtext(valueXPos
,yPos
,"------ \0 915 AU \0 915 FCC\0 868 EU \0 433 AU \0 433 EU \0 2G4 ISM"[idx
*9],(param
=selectedParam
)*INVERS
)
391 idx
= params
[param
]+1
392 yPos
= (param
+1)*ygap
393 drawtext(0, yPos
, "Wifi:")
394 drawtext(valueXPos
,yPos
,"Update\0Update\0"[idx
*7],(param
=selectedParam
)*INVERS
)
397 rem yPos = (param+1)*ygap
398 rem drawtext(0,yPos,"elrsPkts:")
399 rem drawnumber(valueXPos+15,yPos,elrsPkts)