From 46fbd1d9b8affa1c2ea4fb930734e161689296a6 Mon Sep 17 00:00:00 2001 From: kevinkoenig Date: Sat, 4 Sep 2021 07:21:09 -0400 Subject: [PATCH 1/4] implement long press on curve in mixes to launch edit of curve --- radio/src/gui/colorlcd/menu_model.h | 6 +++ radio/src/gui/colorlcd/model_curves.cpp | 33 +++++++++++-- radio/src/gui/colorlcd/model_curves.h | 1 + radio/src/gui/colorlcd/model_mixes.cpp | 65 ++++++++++++++++++++++++- 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/radio/src/gui/colorlcd/menu_model.h b/radio/src/gui/colorlcd/menu_model.h index 97e778e8e..2764d8ef0 100644 --- a/radio/src/gui/colorlcd/menu_model.h +++ b/radio/src/gui/colorlcd/menu_model.h @@ -25,6 +25,12 @@ class ModelMenu: public TabsGroup { public: +#if defined(DEBUG_WINDOWS) + std::string getName() const override + { + return "ModelMenu"; + } +#endif ModelMenu(); }; diff --git a/radio/src/gui/colorlcd/model_curves.cpp b/radio/src/gui/colorlcd/model_curves.cpp index ac09e88e9..4a5ce3c61 100644 --- a/radio/src/gui/colorlcd/model_curves.cpp +++ b/radio/src/gui/colorlcd/model_curves.cpp @@ -24,6 +24,19 @@ #define SET_DIRTY() storageDirty(EE_MODEL) + +// initialize a new curves points to the default for a 5 point +// curve. +void initPoints(const CurveHeader &curve, int8_t *points) +{ + int dx = 2000 / (5 + curve.points - 1); + for (uint8_t i = 0; i < 5 + curve.points; i++) { + int x = -1000 + i * dx; + points[i] = x / 10; + } +} + + class CurveEditWindow : public Page { public: @@ -264,6 +277,20 @@ ModelCurvesPage::ModelCurvesPage() : { } + +// can be called from any other screen to edit a curve. +// currently called from model_mixes.cpp on longpress. +void ModelCurvesPage::pushEditCurve(int index) +{ + if (! isCurveUsed(index)) { + CurveHeader &curve = g_model.curves[index]; + int8_t * points = curveAddress(index); + initPoints(curve, points); + } + + new CurveEditWindow(index); +} + void ModelCurvesPage::rebuild(FormWindow * window, int8_t focusIndex) { coord_t scrollPosition = window->getScrollPositionY(); @@ -364,11 +391,7 @@ void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex) button->setPressHandler([=]() { Menu *menu = new Menu(window); menu->addLine(STR_EDIT, [=]() { - int dx = 2000 / (5 + curve.points - 1); - for (uint8_t i = 0; i < 5 + curve.points; i++) { - int x = -1000 + i * dx; - points[i] = x / 10; - } + initPoints(curve, points); editCurve(window, index); }); menu->addLine(STR_CURVE_PRESET, presetCurveFct); diff --git a/radio/src/gui/colorlcd/model_curves.h b/radio/src/gui/colorlcd/model_curves.h index 52fe9b1f4..a1cff5012 100644 --- a/radio/src/gui/colorlcd/model_curves.h +++ b/radio/src/gui/colorlcd/model_curves.h @@ -27,6 +27,7 @@ class ModelCurvesPage: public PageTab { public: ModelCurvesPage(); + static void pushEditCurve(int index); virtual void build(FormWindow * window) override { diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index 3d1682417..c04a9f230 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -24,12 +24,66 @@ #include "bitfield.h" #include "model_inputs.h" #include "gvar_numberedit.h" +#include "model_curves.h" + #define SET_DIRTY() storageDirty(EE_MODEL) - #define PASTE_BEFORE -2 #define PASTE_AFTER -1 +class CurvesListChoice : public Choice +{ + public: + CurvesListChoice(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0); + void setLongPressHandler(std::function handler); + +#if defined(HARDWARE_KEYS) + void onEvent(event_t event) override; +#endif + +#if defined(HARDWARE_TOUCH) + bool onTouchEnd(coord_t x, coord_t y) override; +#endif + +#if defined(DEBUG_WINDOWS) + std::string getName() const override + { + return "CurvesListChoice"; + } +#endif + +protected: + std::function longPressHandler = nullptr; +}; + +void CurvesListChoice::setLongPressHandler(std::function handler) +{ + longPressHandler = handler; +} + +CurvesListChoice::CurvesListChoice(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function setValue, WindowFlags windowFlags) : + Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags) +{ +} + +bool CurvesListChoice::onTouchEnd(coord_t x, coord_t y) +{ + return Choice::onTouchEnd(x,y); +} + +void CurvesListChoice::onEvent(event_t event) +{ + if (event == EVT_KEY_LONG(KEY_ENTER)) { + if (longPressHandler) { + killEvents(event); + longPressHandler(event); + return; + } + } + + Choice::onEvent(event); +} + uint8_t getMixesCount() { uint8_t count = 0; @@ -228,9 +282,16 @@ class MixEditWindow : public Page break; case CURVE_REF_CUSTOM: { - auto choice = new Choice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, + auto choice = new CurvesListChoice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value)); choice->setTextHandler([](int value) { return getCurveString(value); }); + choice->setLongPressHandler([this](event_t event) { + MixData *mix = mixAddress(mixIndex); + auto a = parent->getName(); + // if no curve is specified then dont link to curve page + if (mix->curve.value != 0) + ModelCurvesPage::pushEditCurve(abs(mix->curve.value) - 1); + }); break; } } From 6a10c821eb07e20abe54bfc899c7411926d5b8f1 Mon Sep 17 00:00:00 2001 From: kevinkoenig Date: Sat, 4 Sep 2021 07:48:50 -0400 Subject: [PATCH 2/4] implement long press to launch curves from input and mixes --- radio/src/gui/colorlcd/CMakeLists.txt | 1 + radio/src/gui/colorlcd/choiceex.cpp | 50 ++++++++++++++++++++++ radio/src/gui/colorlcd/choiceex.h | 46 ++++++++++++++++++++ radio/src/gui/colorlcd/model_inputs.cpp | 11 ++++- radio/src/gui/colorlcd/model_mixes.cpp | 56 +------------------------ 5 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 radio/src/gui/colorlcd/choiceex.cpp create mode 100644 radio/src/gui/colorlcd/choiceex.h diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index b5aea580f..edf9ca05b 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -66,6 +66,7 @@ set(GUI_SRC menu_screen.cpp screen_setup.cpp switch_warn_dialog.cpp + choiceex.cpp ) macro(add_gui_src src) diff --git a/radio/src/gui/colorlcd/choiceex.cpp b/radio/src/gui/colorlcd/choiceex.cpp new file mode 100644 index 000000000..96c44196e --- /dev/null +++ b/radio/src/gui/colorlcd/choiceex.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "choiceex.h" + +void ChoiceEx::setLongPressHandler(std::function handler) +{ + longPressHandler = handler; +} + +ChoiceEx::ChoiceEx(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function setValue, WindowFlags windowFlags) : + Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags) +{ +} + +bool ChoiceEx::onTouchEnd(coord_t x, coord_t y) +{ + return Choice::onTouchEnd(x,y); +} + +void ChoiceEx::onEvent(event_t event) +{ + if (event == EVT_KEY_LONG(KEY_ENTER)) { + if (longPressHandler) { + killEvents(event); + longPressHandler(event); + return; + } + } + + Choice::onEvent(event); +} + diff --git a/radio/src/gui/colorlcd/choiceex.h b/radio/src/gui/colorlcd/choiceex.h new file mode 100644 index 000000000..4b0aeac83 --- /dev/null +++ b/radio/src/gui/colorlcd/choiceex.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include "libopenui.h" + +class ChoiceEx : public Choice +{ + public: + ChoiceEx(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0); + void setLongPressHandler(std::function handler); + +#if defined(HARDWARE_KEYS) + void onEvent(event_t event) override; +#endif + +#if defined(HARDWARE_TOUCH) + bool onTouchEnd(coord_t x, coord_t y) override; +#endif + +#if defined(DEBUG_WINDOWS) + std::string getName() const override + { + return "CurvesListChoice"; + } +#endif + +protected: + std::function longPressHandler = nullptr; +}; + diff --git a/radio/src/gui/colorlcd/model_inputs.cpp b/radio/src/gui/colorlcd/model_inputs.cpp index 494cc61ac..afa12776b 100644 --- a/radio/src/gui/colorlcd/model_inputs.cpp +++ b/radio/src/gui/colorlcd/model_inputs.cpp @@ -22,6 +22,8 @@ #include "opentx.h" #include "gvar_numberedit.h" #include "libopenui.h" +#include "choiceex.h" +#include "model_curves.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -173,9 +175,16 @@ class InputEditWindow : public Page break; case CURVE_REF_CUSTOM: { - auto choice = new Choice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, + auto choice = new ChoiceEx(curveParamField, rect, -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value)); choice->setTextHandler([](int value) { return getCurveString(value); }); + choice->setLongPressHandler([this](event_t event) { + ExpoData *line = expoAddress(index); + + // if no curve is specified then dont link to curve page + if (line->curve.value != 0) + ModelCurvesPage::pushEditCurve(abs(line->curve.value) - 1); + }); break; } } diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index c04a9f230..65a4e82b8 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -21,6 +21,7 @@ #include "model_mixes.h" #include "opentx.h" #include "libopenui.h" +#include "choiceex.h" #include "bitfield.h" #include "model_inputs.h" #include "gvar_numberedit.h" @@ -31,59 +32,6 @@ #define PASTE_BEFORE -2 #define PASTE_AFTER -1 -class CurvesListChoice : public Choice -{ - public: - CurvesListChoice(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0); - void setLongPressHandler(std::function handler); - -#if defined(HARDWARE_KEYS) - void onEvent(event_t event) override; -#endif - -#if defined(HARDWARE_TOUCH) - bool onTouchEnd(coord_t x, coord_t y) override; -#endif - -#if defined(DEBUG_WINDOWS) - std::string getName() const override - { - return "CurvesListChoice"; - } -#endif - -protected: - std::function longPressHandler = nullptr; -}; - -void CurvesListChoice::setLongPressHandler(std::function handler) -{ - longPressHandler = handler; -} - -CurvesListChoice::CurvesListChoice(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function setValue, WindowFlags windowFlags) : - Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags) -{ -} - -bool CurvesListChoice::onTouchEnd(coord_t x, coord_t y) -{ - return Choice::onTouchEnd(x,y); -} - -void CurvesListChoice::onEvent(event_t event) -{ - if (event == EVT_KEY_LONG(KEY_ENTER)) { - if (longPressHandler) { - killEvents(event); - longPressHandler(event); - return; - } - } - - Choice::onEvent(event); -} - uint8_t getMixesCount() { uint8_t count = 0; @@ -282,7 +230,7 @@ class MixEditWindow : public Page break; case CURVE_REF_CUSTOM: { - auto choice = new CurvesListChoice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, + auto choice = new ChoiceEx(curveParamField, rect, -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value)); choice->setTextHandler([](int value) { return getCurveString(value); }); choice->setLongPressHandler([this](event_t event) { From 3113a30b943f41c214699797e9e1c2455fd3a9aa Mon Sep 17 00:00:00 2001 From: kevinkoenig Date: Sun, 5 Sep 2021 07:28:29 -0400 Subject: [PATCH 3/4] fixed file copyright to EdgeTx --- radio/src/gui/colorlcd/choiceex.cpp | 4 ++-- radio/src/gui/colorlcd/choiceex.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/radio/src/gui/colorlcd/choiceex.cpp b/radio/src/gui/colorlcd/choiceex.cpp index 96c44196e..88974b87c 100644 --- a/radio/src/gui/colorlcd/choiceex.cpp +++ b/radio/src/gui/colorlcd/choiceex.cpp @@ -1,7 +1,8 @@ /* - * Copyright (C) OpenTX + * Copyright (C) EdgeTX * * Based on code named + * opentx - https://github.com/opentx/opentx * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x @@ -17,7 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - #include "choiceex.h" void ChoiceEx::setLongPressHandler(std::function handler) diff --git a/radio/src/gui/colorlcd/choiceex.h b/radio/src/gui/colorlcd/choiceex.h index 4b0aeac83..bdf7f9792 100644 --- a/radio/src/gui/colorlcd/choiceex.h +++ b/radio/src/gui/colorlcd/choiceex.h @@ -1,7 +1,8 @@ /* - * Copyright (C) OpenTX + * Copyright (C) EdgeTX * * Based on code named + * opentx - https://github.com/opentx/opentx * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x From f4f6b219e416dbfb6396f772991c8a98a4e9b47c Mon Sep 17 00:00:00 2001 From: kevinkoenig Date: Sun, 5 Sep 2021 07:32:05 -0400 Subject: [PATCH 4/4] fixed compilation issue --- radio/src/gui/colorlcd/model_mixes.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index 9541b6c46..a068c936e 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -236,7 +236,6 @@ class MixEditWindow : public Page choice->setTextHandler([](int value) { return getCurveString(value); }); choice->setLongPressHandler([this](event_t event) { MixData *mix = mixAddress(mixIndex); - auto a = parent->getName(); // if no curve is specified then dont link to curve page if (mix->curve.value != 0) ModelCurvesPage::pushEditCurve(abs(mix->curve.value) - 1);