@@ -254,6 +254,8 @@ local MSP_SET_RC_TUNING = 204
254
254
-- BF specials
255
255
local MSP_PID_ADVANCED = 94
256
256
local MSP_SET_PID_ADVANCED = 95
257
+ local MSP_VTX_CONFIG = 88
258
+ local MSP_VTX_SET_CONFIG = 89
257
259
258
260
local MSP_EEPROM_WRITE = 250
259
261
@@ -267,6 +269,24 @@ local MENU_DISP = 5
267
269
268
270
local gState = PAGE_DISPLAY
269
271
272
+ local function postReadVTX (page )
273
+ if page .values [1 ] == 3 then -- SmartAudio
274
+ page .fields [3 ].table = { 25 , 200 , 500 , 800 }
275
+ page .fields [3 ].max = 4
276
+ elseif page .values [1 ] == 4 then -- Tramp
277
+ page .fields [3 ].table = { 25 , 100 , 200 , 400 , 600 }
278
+ page .fields [3 ].max = 5
279
+ else
280
+ -- TODO: print label on unavailable (0xFF) vs. unsupported (0)
281
+ -- page.values = nil
282
+ end
283
+ end
284
+
285
+ local function getWriteValuesVTX (values )
286
+ local channel = (values [2 ]- 1 )* 8 + values [3 ]- 1
287
+ return { bit32.band (channel ,0xFF ), bit32.rshift (channel ,8 ), values [4 ], values [5 ] }
288
+ end
289
+
270
290
local SetupPages = {
271
291
{
272
292
title = " PIDs" ,
@@ -314,23 +334,50 @@ local SetupPages = {
314
334
},
315
335
read = MSP_RC_TUNING ,
316
336
write = MSP_SET_RC_TUNING ,
337
+ },
338
+ {
339
+ title = " VTX" ,
340
+ text = {},
341
+ fields = {
342
+ -- Super Rate
343
+ { t = " Band" , x = 35 , y = 68 , sp = 80 , i = 2 , min = 1 , max = 5 , table = { " A" , " B" , " E" , " F" , " R" } },
344
+ { t = " Channel" , x = 35 , y = 96 , sp = 80 , i = 3 , min = 1 , max = 8 },
345
+ { t = " Power" , x = 35 , y = 124 , sp = 80 , i = 4 , min = 1 },
346
+ { t = " Pit" , x = 35 , y = 152 , sp = 80 , i = 5 , min = 0 , max = 1 , table = { [0 ]= " OFF" , " ON" } },
347
+ { t = " (Dev)" , x = 240 , y = 68 , sp = 48 , i = 1 , ro = true , table = {[3 ]= " SmartAudio" ,[4 ]= " Tramp" } },
348
+ },
349
+ read = MSP_VTX_CONFIG ,
350
+ write = MSP_VTX_SET_CONFIG ,
351
+ postRead = postReadVTX ,
352
+ getWriteValues = getWriteValuesVTX ,
353
+ saveMaxRetries = 0 ,
354
+ saveTimeout = 200 -- 2s
317
355
}
318
356
}
319
357
320
358
local currentPage = 1
321
359
local currentLine = 1
322
360
local saveTS = 0
361
+ local saveTimeout = 0
323
362
local saveRetries = 0
363
+ local saveMaxRetries = 0
324
364
325
365
local function saveSettings (new )
326
366
local page = SetupPages [currentPage ]
327
367
if page .values then
328
- mspSendRequest (page .write ,page .values )
368
+ if page .getWriteValues then
369
+ mspSendRequest (page .write ,page .getWriteValues (page .values ))
370
+ else
371
+ mspSendRequest (page .write ,page .values )
372
+ end
329
373
saveTS = getTime ()
330
374
if gState == PAGE_SAVING then
331
375
saveRetries = saveRetries + 1
332
376
else
333
377
gState = PAGE_SAVING
378
+ saveRetries = 0
379
+ saveMaxRetries = page .saveMaxRetries or 2 -- default 2
380
+ saveTimeout = page .saveTimeout or 150 -- default 1.5s
334
381
end
335
382
end
336
383
end
@@ -366,7 +413,9 @@ local function processMspReply(cmd,rx_buf)
366
413
367
414
-- ignore replies to write requests for now
368
415
if cmd == page .write then
369
- mspSendRequest (MSP_EEPROM_WRITE ,{})
416
+ if cmd ~= MSP_VTX_SET_CONFIG then
417
+ mspSendRequest (MSP_EEPROM_WRITE ,{})
418
+ end
370
419
return
371
420
end
372
421
@@ -386,6 +435,10 @@ local function processMspReply(cmd,rx_buf)
386
435
for i = 1 ,# (rx_buf ) do
387
436
page .values [i ] = rx_buf [i ]
388
437
end
438
+
439
+ if page .postRead ~= nil then
440
+ page .postRead (page )
441
+ end
389
442
end
390
443
end
391
444
@@ -466,18 +519,22 @@ local function drawScreen(page,page_locked)
466
519
467
520
local idx = f .i or i
468
521
if page .values and page .values [idx ] then
469
- lcd .drawText (f .x + spacing , f .y , page .values [idx ], text_options )
522
+ local val = page .values [idx ]
523
+ if f .table and f .table [page .values [idx ]] then
524
+ val = f .table [page .values [idx ]]
525
+ end
526
+ lcd .drawText (f .x + spacing , f .y , val , text_options )
470
527
else
471
528
lcd .drawText (f .x + spacing , f .y , " ---" , text_options )
472
529
end
473
530
end
474
531
end
475
532
476
- local function clipValue (val )
477
- if val < 0 then
478
- val = 0
479
- elseif val > 255 then
480
- val = 255
533
+ local function clipValue (val , min , max )
534
+ if val < min then
535
+ val = min
536
+ elseif val > max then
537
+ val = max
481
538
end
482
539
483
540
return val
@@ -492,7 +549,7 @@ local function incValue(inc)
492
549
local page = SetupPages [currentPage ]
493
550
local field = page .fields [currentLine ]
494
551
local idx = field .i or currentLine
495
- page .values [idx ] = clipValue (page .values [idx ] + inc )
552
+ page .values [idx ] = clipValue (page .values [idx ] + inc , field . min or 0 , field . max or 255 )
496
553
end
497
554
498
555
local function drawMenu ()
@@ -526,14 +583,13 @@ local function run(event)
526
583
end
527
584
lastRunTS = now
528
585
529
- -- TODO: implement retry + retry counter
530
- if (gState == PAGE_SAVING ) and (saveTS + 150 < now ) then
531
- if saveRetries < 2 then
586
+ if (gState == PAGE_SAVING ) and (saveTS + saveTimeout < now ) then
587
+ if saveRetries < saveMaxRetries then
532
588
saveSettings ()
533
589
else
534
- -- two retries and still no success
590
+ -- max retries reached
535
591
gState = PAGE_DISPLAY
536
- saveTS = 0
592
+ invalidatePages ()
537
593
end
538
594
end
539
595
@@ -577,7 +633,7 @@ local function run(event)
577
633
local page = SetupPages [currentPage ]
578
634
local field = page .fields [currentLine ]
579
635
local idx = field .i or currentLine
580
- if page .values and page .values [idx ] then
636
+ if page .values and page .values [idx ] and ( field . ro ~= true ) then
581
637
gState = EDITING
582
638
end
583
639
end
0 commit comments