Ghost menu basic handling (#8108)
This commit is contained in:
@@ -74,6 +74,7 @@ void menuRadioTools(event_t event);
|
||||
void menuRadioSpectrumAnalyser(event_t event);
|
||||
void menuRadioPowerMeter(event_t event);
|
||||
void menuRadioCalibration(event_t event);
|
||||
void menuGhostModuleConfig(event_t event);
|
||||
|
||||
static const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT] = {
|
||||
#if defined(RADIO_TOOLS)
|
||||
|
||||
@@ -76,6 +76,7 @@ void menuRadioTools(event_t event);
|
||||
void menuRadioCalibration(event_t event);
|
||||
void menuRadioSpectrumAnalyser(event_t event);
|
||||
void menuRadioPowerMeter(event_t event);
|
||||
void menuGhostModuleConfig(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT];
|
||||
|
||||
|
||||
@@ -79,6 +79,10 @@ if(PXX2 OR MULTIMODULE)
|
||||
add_gui_src(radio_spectrum_analyser.cpp)
|
||||
endif()
|
||||
|
||||
if(GHOST)
|
||||
add_gui_src(radio_ghost_module_config.cpp)
|
||||
endif()
|
||||
|
||||
if(LUA STREQUAL YES)
|
||||
set(SRC ${SRC} lua/widgets.cpp)
|
||||
# TODO set(GUI_SRC ${GUI_SRC} model_custom_scripts.cpp)
|
||||
|
||||
@@ -251,7 +251,7 @@ bool menuAboutView(event_t event);
|
||||
bool menuMainViewChannelsMonitor(event_t event);
|
||||
bool menuTextView(event_t event);
|
||||
bool menuScreensTheme(event_t event);
|
||||
bool menuRadioSpectrumAnalyser(event_t event);
|
||||
bool menuRadioGhostModuleConfig(event_t event);
|
||||
bool menuRadioPowerMeter(event_t event);
|
||||
|
||||
extern int8_t checkIncDec_Ret; // global helper vars
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 "opentx.h"
|
||||
#include "radio_ghost_module_config.h"
|
||||
|
||||
class GhostModuleConfigWindow: public Window
|
||||
{
|
||||
public:
|
||||
GhostModuleConfigWindow(Window * parent, const rect_t & rect) :
|
||||
Window(parent, rect, FORWARD_SCROLL | FORM_FORWARD_FOCUS | REFRESH_ALWAYS)
|
||||
{
|
||||
setFocus(SET_FOCUS_DEFAULT);
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
constexpr coord_t xOffset = 140;
|
||||
constexpr coord_t xOffset2 = 260;
|
||||
constexpr coord_t yOffset = 20;
|
||||
constexpr coord_t lineSpacing = 25;
|
||||
|
||||
for (uint8_t line = 0; line < GHST_MENU_LINES; line++) {
|
||||
if (reusableBuffer.ghostMenu.line[line].splitLine) {
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_LABEL_SELECT) {
|
||||
dc->drawSolidFilledRect(xOffset, yOffset + line * lineSpacing, getTextWidth(reusableBuffer.ghostMenu.line[line].menuText, 0,FONT(L)), getFontHeight(FONT(L)), FONT(L) | FOCUS_BGCOLOR);
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, reusableBuffer.ghostMenu.line[line].menuText, FONT(L) | DEFAULT_BGCOLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, reusableBuffer.ghostMenu.line[line].menuText, FONT(L));
|
||||
}
|
||||
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_VALUE_SELECT) {
|
||||
dc->drawSolidFilledRect(xOffset, yOffset + line * lineSpacing, getTextWidth( &reusableBuffer.ghostMenu.line[line].menuText[reusableBuffer.ghostMenu.line[line].splitLine], 0,FONT(L)), getFontHeight(0), FOCUS_BGCOLOR);
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, &reusableBuffer.ghostMenu.line[line].menuText[reusableBuffer.ghostMenu.line[line].splitLine], FONT(L) | DEFAULT_BGCOLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawText(xOffset2, yOffset + line * lineSpacing, &reusableBuffer.ghostMenu.line[line].menuText[reusableBuffer.ghostMenu.line[line].splitLine], FONT(L) | DEFAULT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_LABEL_SELECT) {
|
||||
dc->drawSolidFilledRect(xOffset, yOffset + line * lineSpacing, getTextWidth(reusableBuffer.ghostMenu.line[line].menuText, 0, FONT(L)), getFontHeight(FONT(L)), FOCUS_BGCOLOR);
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, reusableBuffer.ghostMenu.line[line].menuText, FONT(L) | DEFAULT_BGCOLOR);
|
||||
}
|
||||
else if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_VALUE_EDIT) {
|
||||
if (BLINK_ON_PHASE) {
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, reusableBuffer.ghostMenu.line[line].menuText, FONT(L));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dc->drawText(xOffset, yOffset + line * lineSpacing, reusableBuffer.ghostMenu.line[line].menuText, FONT(L) | DEFAULT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected:
|
||||
};
|
||||
|
||||
RadioGhostModuleConfig::RadioGhostModuleConfig(uint8_t moduleIdx) :
|
||||
Page(ICON_RADIO_TOOLS),
|
||||
moduleIdx(moduleIdx)
|
||||
{
|
||||
init();
|
||||
buildHeader(&header);
|
||||
buildBody(&body);
|
||||
setFocus(SET_FOCUS_DEFAULT);
|
||||
}
|
||||
|
||||
void RadioGhostModuleConfig::buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP + 10, LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT}, "GHOST MODULE", 0, MENU_COLOR);
|
||||
}
|
||||
|
||||
void RadioGhostModuleConfig::buildBody(FormWindow * window)
|
||||
{
|
||||
new GhostModuleConfigWindow(window, {0, 0, LCD_W, LCD_H - MENU_HEADER_HEIGHT - 5});
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void RadioGhostModuleConfig::onEvent(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
case EVT_ROTARY_LEFT:
|
||||
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:
|
||||
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;
|
||||
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):
|
||||
menuVerticalOffset = 0;
|
||||
memclear(&reusableBuffer.ghostMenu, sizeof(reusableBuffer.ghostMenu));
|
||||
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_NONE;
|
||||
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_CLOSE;
|
||||
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
|
||||
RTOS_WAIT_MS(10);
|
||||
deleteLater();
|
||||
break;
|
||||
}
|
||||
Page::onEvent(event);
|
||||
}
|
||||
#endif
|
||||
|
||||
void RadioGhostModuleConfig::init()
|
||||
{
|
||||
memclear(&reusableBuffer.ghostMenu, sizeof(reusableBuffer.ghostMenu));
|
||||
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_NONE;
|
||||
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_OPEN;
|
||||
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class RadioGhostModuleConfig: public Page
|
||||
{
|
||||
public:
|
||||
explicit RadioGhostModuleConfig(uint8_t moduleIdx);
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
uint8_t moduleIdx;
|
||||
|
||||
void buildHeader(Window * window);
|
||||
void buildBody(FormWindow * window);
|
||||
void init();
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <algorithm>
|
||||
#include "radio_tools.h"
|
||||
#include "radio_spectrum_analyser.h"
|
||||
#include "radio_ghost_module_config.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
#include "lua/lua_api.h"
|
||||
@@ -174,5 +175,16 @@ void RadioToolsPage::rebuild(FormWindow * window)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(GHOST)
|
||||
if (isModuleGhost(EXTERNAL_MODULE)) {
|
||||
new StaticText(window, grid.getLabelSlot(), "ghost", BUTTON_BACKGROUND, CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), "Ghost module config", [=]() -> uint8_t {
|
||||
new RadioGhostModuleConfig(EXTERNAL_MODULE);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
#endif
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -42,6 +42,13 @@ if(PXX2)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(GHOST)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
../common/stdlcd/radio_ghost_menu.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PXX2 OR MULTIMODULE)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 "opentx.h"
|
||||
|
||||
void menuGhostModuleConfig(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
memclear(&reusableBuffer.ghostMenu, sizeof(reusableBuffer.ghostMenu));
|
||||
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_NONE;
|
||||
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_OPEN;
|
||||
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
|
||||
break;
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
case EVT_ROTARY_LEFT:
|
||||
#elif defined(KEYS_GPIO_REG_UP)
|
||||
case EVT_KEY_BREAK(KEY_UP):
|
||||
#elif defined(KEYS_GPIO_REG_PLUS)
|
||||
case EVT_KEY_BREAK(KEY_PLUS):
|
||||
#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:
|
||||
#elif defined(KEYS_GPIO_REG_DOWN)
|
||||
case EVT_KEY_BREAK(KEY_DOWN):
|
||||
#elif defined(KEYS_GPIO_REG_MINUS)
|
||||
case EVT_KEY_BREAK(KEY_MINUS):
|
||||
#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):
|
||||
menuVerticalOffset = 0;
|
||||
memclear(&reusableBuffer.ghostMenu, sizeof(reusableBuffer.ghostMenu));
|
||||
reusableBuffer.ghostMenu.buttonAction = GHST_BTN_NONE;
|
||||
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_CLOSE;
|
||||
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
|
||||
RTOS_WAIT_MS(10);
|
||||
popMenu();
|
||||
break;
|
||||
}
|
||||
|
||||
if (reusableBuffer.ghostMenu.menuAction == GHST_MENU_CTRL_CLOSE) {
|
||||
popMenu();
|
||||
}
|
||||
|
||||
constexpr coord_t xOffset = LCD_W / 3 - 15;
|
||||
constexpr coord_t xOffset2 = LCD_W / 3 + LCD_W / 4;
|
||||
constexpr coord_t yOffset = 6;
|
||||
LcdFlags flags = 0;
|
||||
|
||||
for (uint8_t line = 0; line < GHST_MENU_LINES; line++) {
|
||||
flags = 0;
|
||||
if (reusableBuffer.ghostMenu.line[line].splitLine) {
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_LABEL_SELECT)
|
||||
flags = INVERS;
|
||||
lcdDrawText(xOffset, yOffset + line * FH, reusableBuffer.ghostMenu.line[line].menuText, flags);
|
||||
|
||||
flags = 0;
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_VALUE_SELECT)
|
||||
flags |= INVERS;
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_VALUE_EDIT)
|
||||
flags |= BLINK;
|
||||
lcdDrawText(xOffset2, yOffset + line * FH, &reusableBuffer.ghostMenu.line[line].menuText[reusableBuffer.ghostMenu.line[line].splitLine], flags);
|
||||
}
|
||||
else {
|
||||
if (reusableBuffer.ghostMenu.line[line].lineFlags & GHST_LINE_FLAGS_LABEL_SELECT)
|
||||
flags = INVERS;
|
||||
lcdDrawText(xOffset, yOffset + line * FH, reusableBuffer.ghostMenu.line[line].menuText, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,10 @@ void menuRadioTools(event_t event)
|
||||
addRadioModuleTool(index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
|
||||
#endif
|
||||
|
||||
#if defined(GHOST)
|
||||
if (isModuleGhost(EXTERNAL_MODULE))
|
||||
addRadioModuleTool(index++, "Ghost Menu", menuGhostModuleConfig, EXTERNAL_MODULE);
|
||||
#endif
|
||||
if (index == 0) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_NO_TOOLS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user