@@ -341,11 +341,11 @@ class SensorButton : public Button {
341341 }
342342};
343343
344- class TelemetrySourceChoice : public ChoiceEx
344+ class TelemetrySourceChoice : public Choice
345345{
346346public:
347- TelemetrySourceChoice (FormGroup *window, const rect_t &rect, uint8_t *source, IsValueAvailable isValueAvailable, char negativeGVarPrefix= 0 ) :
348- ChoiceEx (window, rect, negativeGVarPrefix!= 0 ?- 128 : 0 , 127 , GET_DEFAULT (static_cast <int8_t >(*source)), [=](int16_t newValue){*source=newValue;})
347+ TelemetrySourceChoice (Window *window, const rect_t &rect, uint8_t *source, IsValueAvailable isValueAvailable) :
348+ Choice (window, rect, 0 , 127 , GET_DEFAULT (static_cast <int8_t >(*source)), [=](int16_t newValue){*source=newValue;})
349349 {
350350 setAvailableHandler ([=](int16_t value) -> bool {
351351 if (value == 0 ) return true ;
@@ -365,6 +365,7 @@ class TelemetrySourceChoice : public ChoiceEx
365365 if (GV_IS_GV_VALUE (value, -MAX_TELEMETRY_SENSORS , MAX_TELEMETRY_SENSORS )) {
366366 int index = GV_INDEX_CALCULATION (value, -MAX_TELEMETRY_SENSORS , MAX_TELEMETRY_SENSORS );
367367 std::string ret (getGVarString (index));
368+ fprintf (stderr," >>>>>> GV %d %d %s\n " ,value,index,ret.c_str ());
368369 if (value>0 ) {
369370 ret[0 ] = negativeGVarPrefix;
370371 }
@@ -379,76 +380,28 @@ class TelemetrySourceChoice : public ChoiceEx
379380 return std::string (getSourceString (MIXSRC_FIRST_TELEM +(value-1 )*3 ));
380381 }
381382 });
382- }
383- };
384-
385- class SensorButton : public Button {
386- public:
387- SensorButton (FormGroup * parent, const rect_t &rect, uint8_t index, uint8_t number) :
388- Button (parent, rect),
389- index (index),
390- number (number)
391- {
392- }
393-
394- static constexpr coord_t line1 = 1 ;
395-
396- void checkEvents () override
397- {
398- uint32_t now = RTOS_GET_MS ();
399- if (now - lastRefresh >= 200 ) {
400- // update at least every 200ms
401- invalidate ();
402- }
403-
404- TelemetryItem & telemetryItem = telemetryItems[index];
405- if (telemetryItem.isFresh ()) {
406- invalidate ();
407- }
408-
409- Button::checkEvents ();
383+ setRangeMapHandler ([=](int n) {
384+ // Map range of choice values so GVars are in correct order.
385+ if (n <= -120 )
386+ n += GV1_SMALL * 2 - MAX_GVARS ;
387+ else if (n >= 119 )
388+ n -= GV1_SMALL * 2 - MAX_GVARS ;
389+ return n;
390+ });
410391 }
411392
412- void paint (BitmapBuffer * dc) override
393+ void setGVPrefix ( char prefix)
413394 {
414- TelemetryItem &telemetryItem = telemetryItems[index];
415-
416- if (telemetryItem.isAvailable ())
417- dc->drawSolidFilledRect (2 , 2 , rect.w - 4 , rect.h - 4 , COLOR_THEME_ACTIVE );
418- else
419- dc->drawSolidFilledRect (2 , 2 , rect.w - 4 , rect.h - 4 , COLOR_THEME_PRIMARY2 );
420-
421- if (telemetryItem.isFresh ())
422- dc->drawFilledCircle (SENSOR_COL2 - 10 , (2 + rect.h - 4 )/2 , 4 , COLOR_THEME_SECONDARY1 );
423-
424- dc->drawSizedText (SENSOR_COL1 , line1, g_model.telemetrySensors [index].label , TELEM_LABEL_LEN );
425-
426- if (telemetryItem.isAvailable ()) {
427- LcdFlags color = telemetryItem.isOld () ? COLOR_THEME_WARNING : COLOR_THEME_SECONDARY1 ;
428- drawSensorCustomValue (dc, SENSOR_COL2 , line1, index, getValue (MIXSRC_FIRST_TELEM + 3 * index), LEFT | color);
429- }
430- else {
431- dc->drawText (SENSOR_COL2 , line1, " ---" , COLOR_THEME_SECONDARY1 );
432- }
433-
434- TelemetrySensor * sensor = & g_model.telemetrySensors [index];
435- if (IS_SPEKTRUM_PROTOCOL ()) {
436- drawHexNumber (dc, SENSOR_COL3 , line1, sensor->id , LEFT );
437- }
438- else if (sensor->type == TELEM_TYPE_CUSTOM && !g_model.ignoreSensorIds ) {
439- dc->drawNumber (SENSOR_COL3 , line1, sensor->instance , LEFT );
395+ if (modelGVEnabled ()) {
396+ negativeGVarPrefix = prefix;
397+ setMin (negativeGVarPrefix != 0 ? -128 : 0 );
398+ if (getIntValue () < getMin ())
399+ setValue (getMin ());
440400 }
441-
442- if (hasFocus ())
443- dc->drawSolidRect (0 , 0 , rect.w , rect.h , 2 , COLOR_THEME_FOCUS );
444- else
445- dc->drawSolidRect (0 , 0 , rect.w , rect.h , 1 , COLOR_THEME_SECONDARY2 );
446401 }
447-
402+
448403 protected:
449- uint8_t index;
450- uint8_t number;
451- uint32_t lastRefresh = 0 ;
404+ char negativeGVarPrefix;
452405};
453406
454407class SensorLiveValue : public Window {
@@ -534,6 +487,7 @@ class SensorEditWindow : public Page {
534487 };
535488
536489 FormWindow::Line* paramLines[P_COUNT ] = {};
490+ TelemetrySourceChoice* calcSource[4 ] = {};
537491
538492 void buildHeader (Window * window)
539493 {
@@ -571,6 +525,16 @@ class SensorEditWindow : public Page {
571525 }
572526 }
573527
528+ void setGVPrefix (int n, uint8_t formula)
529+ {
530+ if (formula == TELEM_FORMULA_MULTIPLY )
531+ calcSource[n]->setGVPrefix (' /' );
532+ else if (formula < TELEM_FORMULA_MULTIPLY )
533+ calcSource[n]->setGVPrefix (' -' );
534+ else
535+ calcSource[n]->setGVPrefix (0 );
536+ }
537+
574538 void updateSensorParameters ()
575539 {
576540 TelemetrySensor * sensor = &g_model.telemetrySensors [index];
@@ -601,28 +565,20 @@ class SensorEditWindow : public Page {
601565 if (sensor->unit < UNIT_FIRST_VIRTUAL ) {
602566 if (sensor->type == TELEM_TYPE_CALCULATED ) {
603567 if (sensor->formula == TELEM_FORMULA_CELL ) {
604- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_CELLSENSOR , 0 , COLOR_THEME_PRIMARY1 );
605- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), &sensor->cell .source , isCellsSensor);
568+ lv_obj_clear_flag (paramLines[P_CELLSENSOR ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
606569 }
607570 else if (sensor->formula == TELEM_FORMULA_DIST ) {
608- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_GPSSENSOR , 0 , COLOR_THEME_PRIMARY1 );
609- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), &sensor->dist .gps , isGPSSensor);
571+ lv_obj_clear_flag (paramLines[P_GPSSENSOR ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
610572 }
611573 else if (sensor->formula == TELEM_FORMULA_CONSUMPTION ) {
612- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_CURRENTSENSOR , 0 , COLOR_THEME_PRIMARY1 );
613- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), &sensor->consumption .source , isSensorAvailable);
574+ lv_obj_clear_flag (paramLines[P_CURRENTSENSOR ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
614575 }
615576 else if (sensor->formula == TELEM_FORMULA_TOTALIZE ) {
616- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_SOURCE , 0 , COLOR_THEME_PRIMARY1 );
617- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), &sensor->consumption .source , isSensorAvailable);
618- }
619- else if (sensor->formula == TELEM_FORMULA_MULTIPLY ) {
620- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_SOURCE + std::to_string (1 ), 0 , COLOR_THEME_PRIMARY1 );
621- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), (uint8_t *) &sensor->calc .sources [0 ], isSensorAvailable, ' /' );
577+ lv_obj_clear_flag (paramLines[P_CONSUMPTIONSOURCE ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
622578 }
623579 else {
624- new StaticText (sensorParametersWindow, grid. getLabelSlot (), STR_SOURCE + std::to_string ( 1 ), 0 , COLOR_THEME_PRIMARY1 );
625- new TelemetrySourceChoice (sensorParametersWindow, grid. getFieldSlot (), ( uint8_t *) & sensor->calc . sources [ 0 ], isSensorAvailable, ' - ' );
580+ lv_obj_clear_flag (paramLines[ P_CALC0 ]-> getLvObj (), LV_OBJ_FLAG_HIDDEN );
581+ setGVPrefix ( 0 , sensor->formula );
626582 }
627583 }
628584 else {
@@ -642,16 +598,11 @@ class SensorEditWindow : public Page {
642598 lv_obj_clear_flag (paramLines[P_CELLINDEX ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
643599 }
644600 else if (sensor->formula == TELEM_FORMULA_DIST ) {
645- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_ALTSENSOR , 0 , COLOR_THEME_PRIMARY1 );
646- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), &sensor->dist .alt , isAltSensor);
647- }
648- else if (sensor->formula == TELEM_FORMULA_MULTIPLY ) {
649- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_SOURCE + std::to_string (2 ), 0 , COLOR_THEME_PRIMARY1 );
650- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), (uint8_t *) &sensor->calc .sources [1 ], isSensorAvailable, ' /' );
601+ lv_obj_clear_flag (paramLines[P_ALTSENSOR ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
651602 }
652603 else {
653- new StaticText (sensorParametersWindow, grid. getLabelSlot (), STR_SOURCE + std::to_string ( 2 ), 0 , COLOR_THEME_PRIMARY1 );
654- new TelemetrySourceChoice (sensorParametersWindow, grid. getFieldSlot (), ( uint8_t *) & sensor->calc . sources [ 1 ], isSensorAvailable, ' - ' );
604+ lv_obj_clear_flag (paramLines[ P_CALC1 ]-> getLvObj (), LV_OBJ_FLAG_HIDDEN );
605+ setGVPrefix ( 1 , sensor->formula );
655606 }
656607 }
657608 else if (sensor->unit == UNIT_RPMS ) {
@@ -663,13 +614,10 @@ class SensorEditWindow : public Page {
663614 }
664615
665616 if ((sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY )) {
666- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_SOURCE + std::to_string (3 ), 0 , COLOR_THEME_PRIMARY1 );
667- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), (uint8_t *) &sensor->calc .sources [2 ], isSensorAvailable, ' -' );
668- grid.nextLine ();
669-
670- new StaticText (sensorParametersWindow, grid.getLabelSlot (), STR_SOURCE + std::to_string (4 ), 0 , COLOR_THEME_PRIMARY1 );
671- new TelemetrySourceChoice (sensorParametersWindow, grid.getFieldSlot (), (uint8_t *) &sensor->calc .sources [3 ], isSensorAvailable, ' -' );
672- grid.nextLine ();
617+ lv_obj_clear_flag (paramLines[P_CALC2 ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
618+ setGVPrefix (2 , sensor->formula );
619+ lv_obj_clear_flag (paramLines[P_CALC3 ]->getLvObj (), LV_OBJ_FLAG_HIDDEN );
620+ setGVPrefix (3 , sensor->formula );
673621 }
674622
675623 // Auto Offset
@@ -795,23 +743,23 @@ class SensorEditWindow : public Page {
795743
796744 paramLines[P_CELLSENSOR ] = form->newLine (&grid);
797745 new StaticText (paramLines[P_CELLSENSOR ], rect_t {}, STR_CELLSENSOR , 0 , COLOR_THEME_PRIMARY1 );
798- new SensorSourceChoice (paramLines[P_CELLSENSOR ], rect_t {}, &sensor->cell .source , isCellsSensor);
746+ new TelemetrySourceChoice (paramLines[P_CELLSENSOR ], rect_t {}, &sensor->cell .source , isCellsSensor);
799747
800748 paramLines[P_GPSSENSOR ] = form->newLine (&grid);
801749 new StaticText (paramLines[P_GPSSENSOR ], rect_t {}, STR_GPSSENSOR , 0 , COLOR_THEME_PRIMARY1 );
802- new SensorSourceChoice (paramLines[P_GPSSENSOR ], rect_t {}, &sensor->dist .gps , isGPSSensor);
750+ new TelemetrySourceChoice (paramLines[P_GPSSENSOR ], rect_t {}, &sensor->dist .gps , isGPSSensor);
803751
804752 paramLines[P_CURRENTSENSOR ] = form->newLine (&grid);
805753 new StaticText (paramLines[P_CURRENTSENSOR ], rect_t {}, STR_CURRENTSENSOR , 0 , COLOR_THEME_PRIMARY1 );
806- new SensorSourceChoice (paramLines[P_CURRENTSENSOR ], rect_t {}, &sensor->consumption .source , isSensorAvailable);
754+ new TelemetrySourceChoice (paramLines[P_CURRENTSENSOR ], rect_t {}, &sensor->consumption .source , isSensorAvailable);
807755
808756 paramLines[P_CONSUMPTIONSOURCE ] = form->newLine (&grid);
809757 new StaticText (paramLines[P_CONSUMPTIONSOURCE ], rect_t {}, STR_SOURCE , 0 , COLOR_THEME_PRIMARY1 );
810- new SensorSourceChoice (paramLines[P_CONSUMPTIONSOURCE ], rect_t {}, &sensor->consumption .source , isSensorAvailable);
758+ new TelemetrySourceChoice (paramLines[P_CONSUMPTIONSOURCE ], rect_t {}, &sensor->consumption .source , isSensorAvailable);
811759
812760 paramLines[P_CALC0 ] = form->newLine (&grid);
813761 new StaticText (paramLines[P_CALC0 ], rect_t {}, STR_SOURCE + std::to_string (1 ), 0 , COLOR_THEME_PRIMARY1 );
814- new SensorSourceChoice (paramLines[P_CALC0 ], rect_t {}, (uint8_t *) &sensor->calc .sources [0 ], isSensorAvailable);
762+ calcSource[ 0 ] = new TelemetrySourceChoice (paramLines[P_CALC0 ], rect_t {}, (uint8_t *) &sensor->calc .sources [0 ], isSensorAvailable);
815763
816764 paramLines[P_BLADES ] = form->newLine (&grid);
817765 new StaticText (paramLines[P_BLADES ], rect_t {}, STR_BLADES , 0 , COLOR_THEME_PRIMARY1 );
@@ -828,11 +776,11 @@ class SensorEditWindow : public Page {
828776
829777 paramLines[P_ALTSENSOR ] = form->newLine (&grid);
830778 new StaticText (paramLines[P_ALTSENSOR ], rect_t {}, STR_ALTSENSOR , 0 , COLOR_THEME_PRIMARY1 );
831- new SensorSourceChoice (paramLines[P_ALTSENSOR ], rect_t {}, &sensor->dist .alt , isAltSensor);
779+ new TelemetrySourceChoice (paramLines[P_ALTSENSOR ], rect_t {}, &sensor->dist .alt , isAltSensor);
832780
833781 paramLines[P_CALC1 ] = form->newLine (&grid);
834782 new StaticText (paramLines[P_CALC1 ], rect_t {}, STR_SOURCE + std::to_string (2 ), 0 , COLOR_THEME_PRIMARY1 );
835- new SensorSourceChoice (paramLines[P_CALC1 ], rect_t {}, (uint8_t *) &sensor->calc .sources [1 ], isSensorAvailable);
783+ calcSource[ 1 ] = new TelemetrySourceChoice (paramLines[P_CALC1 ], rect_t {}, (uint8_t *) &sensor->calc .sources [1 ], isSensorAvailable);
836784
837785 paramLines[P_MULT ] = form->newLine (&grid);
838786 new StaticText (paramLines[P_MULT ], rect_t {}, STR_MULTIPLIER , 0 , COLOR_THEME_PRIMARY1 );
@@ -845,11 +793,11 @@ class SensorEditWindow : public Page {
845793
846794 paramLines[P_CALC2 ] = form->newLine (&grid);
847795 new StaticText (paramLines[P_CALC2 ], rect_t {}, STR_SOURCE + std::to_string (3 ), 0 , COLOR_THEME_PRIMARY1 );
848- new SensorSourceChoice (paramLines[P_CALC2 ], rect_t {}, (uint8_t *) &sensor->calc .sources [2 ], isSensorAvailable);
796+ calcSource[ 2 ] = new TelemetrySourceChoice (paramLines[P_CALC2 ], rect_t {}, (uint8_t *) &sensor->calc .sources [2 ], isSensorAvailable);
849797
850798 paramLines[P_CALC3 ] = form->newLine (&grid);
851799 new StaticText (paramLines[P_CALC3 ], rect_t {}, STR_SOURCE + std::to_string (4 ), 0 , COLOR_THEME_PRIMARY1 );
852- new SensorSourceChoice (paramLines[P_CALC3 ], rect_t {}, (uint8_t *) &sensor->calc .sources [3 ], isSensorAvailable);
800+ calcSource[ 3 ] = new TelemetrySourceChoice (paramLines[P_CALC3 ], rect_t {}, (uint8_t *) &sensor->calc .sources [3 ], isSensorAvailable);
853801
854802 paramLines[P_AUTOOFFSET ] = form->newLine (&grid);
855803 new StaticText (paramLines[P_AUTOOFFSET ], rect_t {}, STR_AUTOOFFSET , 0 , COLOR_THEME_PRIMARY1 );
0 commit comments