diff --git a/radio/src/gui/colorlcd/radio_ghost_module_config.cpp b/radio/src/gui/colorlcd/radio_ghost_module_config.cpp index 0fc095160..2bd04dee2 100644 --- a/radio/src/gui/colorlcd/radio_ghost_module_config.cpp +++ b/radio/src/gui/colorlcd/radio_ghost_module_config.cpp @@ -34,8 +34,13 @@ class GhostModuleConfigWindow: public Window void paint(BitmapBuffer * dc) override { +#if LCD_H > LCD_W + constexpr coord_t xOffset = 20; + constexpr coord_t xOffset2 = 140; +#else constexpr coord_t xOffset = 140; constexpr coord_t xOffset2 = 260; +#endif constexpr coord_t yOffset = 20; constexpr coord_t lineSpacing = 25; @@ -84,6 +89,9 @@ RadioGhostModuleConfig::RadioGhostModuleConfig(uint8_t moduleIdx) : buildHeader(&header); buildBody(&body); setFocus(SET_FOCUS_DEFAULT); +#if defined(TRIMS_EMULATE_BUTTONS) + setTrimsAsButtons(true); // Use trim joysticks to operate menu (e.g. on NV14) +#endif } void RadioGhostModuleConfig::buildHeader(Window * window) @@ -102,19 +110,23 @@ void RadioGhostModuleConfig::onEvent(event_t event) switch (event) { #if defined(ROTARY_ENCODER_NAVIGATION) case EVT_ROTARY_LEFT: +#else + case EVT_KEY_BREAK(KEY_UP): +#endif reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYUP; reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE; moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL; break; -#endif #if defined(ROTARY_ENCODER_NAVIGATION) case EVT_ROTARY_RIGHT: +#else + case EVT_KEY_BREAK(KEY_DOWN): +#endif reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYDOWN; reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE; moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL; break; -#endif case EVT_KEY_FIRST(KEY_ENTER): reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYPRESS; @@ -135,6 +147,9 @@ void RadioGhostModuleConfig::onEvent(event_t event) moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL; RTOS_WAIT_MS(10); Page::onEvent(event); +#if defined(TRIMS_EMULATE_BUTTONS) + setTrimsAsButtons(false); // switch trims back to normal +#endif break; } } @@ -151,6 +166,9 @@ void RadioGhostModuleConfig::checkEvents() else if (reusableBuffer.ghostMenu.menuStatus == GHST_MENU_STATUS_CLOSING) { RTOS_WAIT_MS(10); deleteLater(); +#if defined(TRIMS_EMULATE_BUTTONS) + setTrimsAsButtons(false); // switch trims back to normal +#endif } } #endif diff --git a/radio/src/targets/nv14/board.h b/radio/src/targets/nv14/board.h index 4090164c1..6de0eaf03 100644 --- a/radio/src/targets/nv14/board.h +++ b/radio/src/targets/nv14/board.h @@ -244,6 +244,9 @@ uint8_t keyState(uint8_t index); uint32_t switchState(uint8_t index); uint32_t readKeys(); uint32_t readTrims(); +void setTrimsAsButtons(bool); +bool getTrimsAsButtons(); +#define TRIMS_EMULATE_BUTTONS #define NUM_TRIMS NUM_STICKS #define NUM_TRIMS_KEYS (NUM_TRIMS * 2) #define TRIMS_PRESSED() (readTrims()) diff --git a/radio/src/targets/nv14/keys_driver.cpp b/radio/src/targets/nv14/keys_driver.cpp index ca2766dac..ee06ade87 100644 --- a/radio/src/targets/nv14/keys_driver.cpp +++ b/radio/src/targets/nv14/keys_driver.cpp @@ -22,17 +22,24 @@ #include "opentx.h" #include "hal/adc_driver.h" +bool trimsAsButtons = false; + +void setTrimsAsButtons(bool val) { trimsAsButtons = val; } + +bool getTrimsAsButtons() +{ + bool lua = false; +#if defined(LUA) + lua = isLuaStandaloneRunning(); +#endif + return (trimsAsButtons || lua); +} + uint32_t readKeys() { uint32_t result = 0; - bool getKeys = true; -#if defined(LUA) - if (!isLuaStandaloneRunning()) { - getKeys = false; - } -#endif - if (getKeys) { + if (getTrimsAsButtons()) { if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL) result |= 1 << KEY_RADIO; if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR) @@ -64,13 +71,7 @@ uint32_t readTrims() { uint32_t result = 0; - bool getTrim = true; -#if defined(LUA) - if (isLuaStandaloneRunning()) { - getTrim = false; - } -#endif - if(!getTrim) return result; + if(getTrimsAsButtons()) return result; if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL) result |= 1 << (TRM_LH_DWN - TRM_BASE); if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR) @@ -178,4 +179,5 @@ void keysInit() GPIO_InitStructure.GPIO_Pin = KEYS_GPIOJ_PINS; GPIO_Init(GPIOJ, &GPIO_InitStructure); + setTrimsAsButtons(false); } diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index dbd5462de..caac33826 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -560,6 +560,21 @@ bool trimDown(uint8_t idx) return readTrims() & (1 << idx); } +#if defined(TRIMS_EMULATE_BUTTONS) +bool trimsAsButtons = false; + +void setTrimsAsButtons(bool val) { trimsAsButtons = val; } + +bool getTrimsAsButtons() +{ + bool lua = false; +#if defined(LUA) + lua = isLuaStandaloneRunning(); +#endif + return (trimsAsButtons || lua); +} +#endif + uint32_t readKeys() { uint32_t result = 0;