From 0dac6037ae4c6e333b51428843f2de71c343a8f1 Mon Sep 17 00:00:00 2001 From: Cliff Date: Tue, 14 Sep 2021 18:58:16 -0700 Subject: [PATCH] Trainer calibration button (#716) * Calibrate all at once with button, number boxes just show data * Switch r/o numberedit to statictext --- radio/src/gui/colorlcd/radio_trainer.cpp | 38 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/radio/src/gui/colorlcd/radio_trainer.cpp b/radio/src/gui/colorlcd/radio_trainer.cpp index 1cd52cfad..b97002405 100644 --- a/radio/src/gui/colorlcd/radio_trainer.cpp +++ b/radio/src/gui/colorlcd/radio_trainer.cpp @@ -29,6 +29,32 @@ RadioTrainerPage::RadioTrainerPage(): { } +class StaticNumber : public StaticText +{ + public: + StaticNumber(Window * parent, const rect_t & rect, std::function getValue, WindowFlags windowFlags = 0, LcdFlags textFlags = 0) : + StaticText(parent, rect, "", windowFlags, textFlags), + _getValue(std::move(getValue)) + { + } + + void paint(BitmapBuffer * dc) { + auto curval = _getValue(); + char buf[20]; + if(textFlags & PREC1) + snprintf(buf, sizeof(buf), "%d.%.1d", curval / 10, abs(curval % 10)); + else if(textFlags & PREC2) + snprintf(buf, sizeof(buf), "%d.%.2d", curval / 100, abs(curval % 100)); + else + snprintf(buf, sizeof(buf), "%d", curval); + text = buf; + StaticText::paint(dc); + } + + protected: + std::function _getValue; +}; + void RadioTrainerPage::build(FormWindow * window) { #if LCD_W > LCD_H @@ -62,13 +88,19 @@ void RadioTrainerPage::build(FormWindow * window) grid.nextLine(); // Trainer calibration - new StaticText(window, grid.getLabelSlot(), STR_CAL, 0, COLOR_THEME_PRIMARY1); + new TextButton(window, grid.getLabelSlot(), std::string(STR_CAL), [=]() -> uint8_t { + memcpy(g_eeGeneral.trainer.calib, ppmInput, sizeof(g_eeGeneral.trainer.calib)); + SET_DIRTY(); + return 0; + }); + for (int i = 0; i < NUM_STICKS; i++) { #if defined (PPM_UNIT_PERCENT_PREC1) - auto calib = new NumberEdit(window, grid.getFieldSlot(4, i), 0 , 0, [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) * 2; }, nullptr, 0, LEFT | PREC1); + auto calib = new StaticNumber(window, grid.getFieldSlot(4, i), [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) * 2; }, 0, LEFT | PREC1); #else - auto calib = new NumberEdit(window, grid.getFieldSlot(4, i), 0 , 0, [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) / 5; }, nullptr, 0, LEFT); + auto calib = new StaticNumber(window, grid.getFieldSlot(4, i), [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) / 5; }, 0, LEFT); #endif + calib->setWindowFlags(REFRESH_ALWAYS); } }