@@ -31,7 +31,7 @@ local fields = {}
3131local devices = {}
3232local goodBadPkt = " ?/???"
3333local elrsFlags = 0
34- local elrsFlagsInfo
34+ local elrsFlagsInfo = " "
3535local fields_count = 0
3636local backButtonId = 2
3737local devicesRefreshTimeout = 50
@@ -42,6 +42,8 @@ local commandRunningIndicator = 1
4242local expectedChunks = - 1
4343local deviceIsELRS = false
4444local linkstatTimeout = 100
45+ local titleShowWarn = false
46+ local titleShowWarnTimeout = 100
4547
4648local COL2 = 70
4749local maxLineIndex = 7
368370
369371local function fieldStringDisplay (field , y , attr )
370372 if edit == true and attr then
371- -- lcd.drawText(COL2, y, field.value, FIXEDWIDTH) -- NOTE: FIXEDWIDTH unknown....
372- -- lcd.drawText(134+6*charIndex, y, string.sub(field.value, charIndex, charIndex), FIXEDWIDTH + attr) -- NOTE: FIXEDWIDTH unknown....
373373 lcd .drawText (COL2 , y , field .value , attr )
374374 lcd .drawText (COL2 + 6 * (charIndex - 1 ), y , string.sub (field .value , charIndex , charIndex ), attr )
375375 else
@@ -491,7 +491,7 @@ local functions = {
491491
492492local function createDeviceField () -- put other device in the field list
493493 fields [fields_count + 2 +# devices ] = fields [backButtonId ]
494- backButtonId = fields_count + 2 +# devices
494+ backButtonId = fields_count + 2 +# devices -- move back button to the end of the list, so it will always show up at the bottom.
495495 for i = 1 , # devices do
496496 if devices [i ].id == deviceId then
497497 fields [fields_count + 1 + i ] = {id = fields_count + 1 + i , name = devices [i ].name , parent = 255 , type = 15 }
@@ -559,11 +559,15 @@ local function parseElrsInfoMessage(data)
559559 fieldChunk = 0
560560 return
561561 end
562+
562563 local badPkt = data [3 ]
563564 local goodPkt = (data [4 ]* 256 ) + data [5 ]
564- goodBadPkt = tostring (badPkt ) .. " /" .. tostring (goodPkt )
565565 elrsFlags = data [6 ]
566- elrsFlagsInfo = elrsFlags ~= 0 and fieldGetString (data , 7 ) or nil
566+
567+ local state = (bit32.btest (elrsFlags , 1 ) and " C" ) or " -"
568+
569+ goodBadPkt = tostring (badPkt ) .. " /" .. tostring (goodPkt ) .. state
570+ elrsFlagsInfo = fieldGetString (data , 7 )
567571end
568572
569573local function refreshNext ()
@@ -591,7 +595,7 @@ local function refreshNext()
591595 elseif time > fieldTimeout and not edit then
592596 if allParamsLoaded < 1 or statusComplete == 0 then
593597 crossfireTelemetryPush (0x2C , { deviceId , handsetId , fieldId , fieldChunk })
594- fieldTimeout = time + 300 -- 3s
598+ fieldTimeout = time + 50 -- 0.5s
595599 end
596600 end
597601
@@ -605,26 +609,47 @@ local function refreshNext()
605609 end
606610 linkstatTimeout = time + 100
607611 end
612+ if time > titleShowWarnTimeout then
613+ if elrsFlags > 3 and titleShowWarn == false then -- if elrsFlags bit set is bit higher than bit 0 and bit 1, it is warning flags
614+ titleShowWarn = true
615+ else
616+ titleShowWarn = false
617+ end
618+ titleShowWarnTimeout = time + 100
619+ end
608620end
609621
610622local function lcd_title ()
611- local title = (allParamsLoaded == 1 or elrsFlags > 0 ) and deviceName or " Loading..."
623+ local title = allParamsLoaded == 1 and deviceName or " Loading..."
624+ lcd .clear ()
625+
612626 if lcdIsColor then
613627 -- Color screen
614628 local EBLUE = lcd .RGB (0x43 , 0x61 , 0xAA )
615629 local EGREEN = lcd .RGB (0x9f , 0xc7 , 0x6f )
630+ local EGREY1 = lcd .RGB (0x91 , 0xb2 , 0xc9 )
631+ local EGREY2 = lcd .RGB (0x6f , 0x62 , 0x7f )
616632 local barHeight = 30
617633
618- lcd .clear ()
619634 -- Field display area (white w/ 2px green border)
620635 lcd .setColor (CUSTOM_COLOR , EGREEN )
621636 lcd .drawRectangle (0 , 0 , LCD_W , LCD_H , CUSTOM_COLOR )
622637 lcd .drawRectangle (1 , 0 , LCD_W - 2 , LCD_H - 1 , CUSTOM_COLOR )
623638 -- title bar
624639 lcd .drawFilledRectangle (0 , 0 , LCD_W , barHeight , CUSTOM_COLOR )
640+ lcd .setColor (CUSTOM_COLOR , EGREY1 )
641+ lcd .drawFilledRectangle (LCD_W - textSize , 0 , textSize , barHeight , CUSTOM_COLOR )
642+ lcd .setColor (CUSTOM_COLOR , EGREY2 )
643+ lcd .drawRectangle (LCD_W - textSize , 0 , textSize , barHeight - 1 , CUSTOM_COLOR )
644+ lcd .drawRectangle (LCD_W - textSize , 1 , textSize - 1 , barHeight - 2 , CUSTOM_COLOR ) -- left and bottom line only 1px, make it look bevelled
625645 lcd .setColor (CUSTOM_COLOR , BLACK )
626- lcd .drawText (textXoffset + 1 , 4 , title , CUSTOM_COLOR )
627- lcd .drawText (LCD_W - 3 , 4 , goodBadPkt , RIGHT + BOLD + CUSTOM_COLOR )
646+ if titleShowWarn == false then
647+ lcd .drawText (textXoffset + 1 , 4 , title , CUSTOM_COLOR )
648+ lcd .drawText (LCD_W - 5 , 4 , goodBadPkt , RIGHT + BOLD + CUSTOM_COLOR )
649+ else
650+ lcd .drawText (textXoffset + 1 , 4 , elrsFlagsInfo , CUSTOM_COLOR )
651+ lcd .drawText (LCD_W - textSize - 5 , 4 , tostring (elrsFlags ), RIGHT + BOLD + CUSTOM_COLOR )
652+ end
628653 -- progress bar
629654 if allParamsLoaded ~= 1 and fields_count > 0 then
630655 local barW = (COL2 - 4 )* fieldId / fields_count
@@ -637,23 +662,31 @@ local function lcd_title()
637662 -- B&W screen
638663 local barHeight = 9
639664
640- lcd .clear ()
641- lcd .drawText (LCD_W , 1 , goodBadPkt , RIGHT )
642- -- keep the title this way to keep the script from error when module is not set correctly
665+ if titleShowWarn == false then
666+ lcd .drawText (LCD_W - 1 , 1 , goodBadPkt , RIGHT )
667+ lcd .drawLine (LCD_W - 10 , 0 , LCD_W - 10 , barHeight - 1 , SOLID , INVERS )
668+ else
669+ lcd .drawText (LCD_W , 1 , tostring (elrsFlags ), RIGHT )
670+ end
671+
643672 if allParamsLoaded ~= 1 and fields_count > 0 then
644673 lcd .drawFilledRectangle (COL2 , 0 , LCD_W , barHeight , GREY_DEFAULT )
645674 lcd .drawGauge (0 , 0 , COL2 , barHeight , fieldId , fields_count , 0 )
646675 else
647676 lcd .drawFilledRectangle (0 , 0 , LCD_W , barHeight , GREY_DEFAULT )
648- lcd .drawText (textXoffset , 1 , title , INVERS )
677+ if titleShowWarn == false then
678+ lcd .drawText (textXoffset , 1 , title , INVERS )
679+ else
680+ lcd .drawText (textXoffset , 1 , elrsFlagsInfo , INVERS )
681+ end
649682 end
650683 end
651684end
652685
653686
654687local function lcd_warn ()
655- lcd .drawText (textSize * 3 ,textSize * 2 ,tostring (elrsFlags ).. " : " .. elrsFlagsInfo ,0 )
656- lcd .drawText (textSize * 10 ,textSize * 6 ," ok" ,BLINK + INVERS )
688+ lcd .drawText (textSize * 3 , textSize * 2 , tostring (elrsFlags ).. " : " .. elrsFlagsInfo , 0 )
689+ lcd .drawText (textSize * 10 , textSize * 6 , " ok" , BLINK + INVERS )
657690end
658691
659692local function handleDevicePageEvent (event )
@@ -680,7 +713,7 @@ local function handleDevicePageEvent(event)
680713 fields [backButtonId ].parent = 255
681714 end
682715 elseif event == EVT_VIRTUAL_ENTER then -- toggle editing/selecting current field
683- if elrsFlags > 0 then
716+ if elrsFlags > 0x1F then
684717 elrsFlags = 0
685718 crossfireTelemetryPush (0x2D , { deviceId , handsetId , 0x2E , 0x00 })
686719 else
@@ -733,8 +766,7 @@ local function runDevicePage(event)
733766 if # devices > 1 then -- show other device folder
734767 fields [fields_count + 1 ].parent = 0
735768 end
736-
737- if elrsFlags > 0 then
769+ if elrsFlags > 0x1F then
738770 lcd_warn ()
739771 else
740772 for y = 1 , maxLineIndex + 1 do
@@ -794,14 +826,14 @@ local function runPopupPage(event)
794826 return 0
795827end
796828
797- local function setLCDvar ()
829+ local function setLCDvar () -- set constant value depending on LCD resolution
798830 lcdIsColor = lcd .RGB ~= nil
799831 if LCD_W == 480 then
800832 COL2 = 240
801833 maxLineIndex = 10
802834 textXoffset = 3
803835 textYoffset = 10
804- textSize = 22
836+ textSize = 22 -- textSize is actually referring to the text Height
805837 else
806838 if LCD_W == 212 then
807839 COL2 = 110
@@ -821,7 +853,7 @@ local function setMock()
821853 if string.sub (rv , - 5 ) ~= " -simu" then return end
822854 local mock = loadScript (" mockup/elrsmock.lua" )
823855 if mock == nil then return end
824- fields , goodBadPkt = mock (), " 0/500"
856+ fields , goodBadPkt = mock (), " 0/500 C "
825857 fields_count = # fields - 1
826858 fieldId = # fields - 3
827859end
0 commit comments