fix(ghst): Fix Ghost module remote menu for radios with rotenc (#2618)

This commit is contained in:
3djc
2022-11-06 09:47:14 +10:00
committed by GitHub
parent 579758a221
commit 1738851a46
2 changed files with 40 additions and 34 deletions
@@ -22,7 +22,6 @@
#include "opentx.h"
#include "radio_ghost_module_config.h"
#include "libopenui.h"
#include "telemetry/ghost.h"
#include "telemetry/ghost_menu.h"
@@ -85,6 +84,40 @@ class GhostModuleConfigWindow: public Window
protected:
};
static void ghostmoduleconfig_cb(lv_event_t* e)
{
RadioGhostModuleConfig* ghostmoduleconfig = (RadioGhostModuleConfig*)lv_event_get_user_data(e);
if (!ghostmoduleconfig || ghostmoduleconfig->deleted()) return;
uint32_t key = lv_event_get_key(e);
switch (key) {
case LV_KEY_LEFT:
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYUP;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
break;
case LV_KEY_RIGHT:
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYDOWN;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
break;
case LV_KEY_ENTER:
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYPRESS;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
break;
}
}
void RadioGhostModuleConfig::onCancel()
{
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYLEFT;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
}
RadioGhostModuleConfig::RadioGhostModuleConfig(uint8_t moduleIdx) :
Page(ICON_RADIO_TOOLS),
moduleIdx(moduleIdx)
@@ -92,7 +125,11 @@ RadioGhostModuleConfig::RadioGhostModuleConfig(uint8_t moduleIdx) :
init();
buildHeader(&header);
buildBody(&body);
// setFocus(SET_FOCUS_DEFAULT);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_group_add_obj(lv_group_get_default(), lvobj);
lv_group_set_editing(lv_group_get_default(), true);
lv_obj_add_event_cb(lvobj, ghostmoduleconfig_cb, LV_EVENT_KEY, this);
#if defined(TRIMS_EMULATE_BUTTONS)
setTrimsAsButtons(true); // Use trim joysticks to operate menu (e.g. on NV14)
#endif
@@ -112,38 +149,6 @@ void RadioGhostModuleConfig::buildBody(FormWindow * window)
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;
#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;
case EVT_KEY_FIRST(KEY_ENTER):
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYPRESS;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
break;
case EVT_KEY_BREAK(KEY_EXIT):
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_JOYLEFT;
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_NONE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
break;
case EVT_KEY_LONG(KEY_EXIT):
memclear(&reusableBuffer.ghostMenu, sizeof(reusableBuffer.ghostMenu));
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_NONE;
@@ -31,6 +31,7 @@ class RadioGhostModuleConfig: public Page
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
void checkEvents() override;
void onCancel() override;
#endif
protected: