refactor(color): use LVGL styles and objects for UI, legacy cleanup (#4407)
This commit is contained in:
+68
-75
@@ -27,18 +27,20 @@
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#if defined(LIBOPENUI)
|
||||
#include "libopenui.h"
|
||||
#include "gui/colorlcd/LvglWrapper.h"
|
||||
#include "gui/colorlcd/view_main.h"
|
||||
#include "theme.h"
|
||||
#include "libopenui.h"
|
||||
#include "gui/colorlcd/LvglWrapper.h"
|
||||
#include "gui/colorlcd/view_main.h"
|
||||
#include "startup_shutdown.h"
|
||||
#include "theme.h"
|
||||
#include "themes/etx_lv_theme.h"
|
||||
#endif
|
||||
|
||||
#if defined(CLI)
|
||||
#include "cli.h"
|
||||
#include "cli.h"
|
||||
#endif
|
||||
|
||||
#if defined(LUA)
|
||||
#include "lua/lua_event.h"
|
||||
#include "lua/lua_event.h"
|
||||
#endif
|
||||
|
||||
uint8_t currentSpeakerVolume = 255;
|
||||
@@ -55,7 +57,6 @@ static Menu* _usbMenu = nullptr;
|
||||
void closeUsbMenu()
|
||||
{
|
||||
if (_usbMenu && !usbPlugged()) {
|
||||
|
||||
// USB has been unplugged meanwhile
|
||||
_usbMenu->deleteLater();
|
||||
}
|
||||
@@ -64,12 +65,10 @@ void closeUsbMenu()
|
||||
void openUsbMenu()
|
||||
{
|
||||
if (_usbMenu || _usbDisabled) return;
|
||||
|
||||
|
||||
_usbMenu = new Menu(MainWindow::instance());
|
||||
|
||||
_usbMenu->setCloseHandler([]() {
|
||||
_usbMenu = nullptr;
|
||||
});
|
||||
_usbMenu->setCloseHandler([]() { _usbMenu = nullptr; });
|
||||
|
||||
_usbMenu->setCancelHandler([]() {
|
||||
if (usbPlugged() && (getSelectedUsbMode() == USB_UNSELECTED_MODE)) {
|
||||
@@ -101,8 +100,7 @@ void onUSBConnectMenu(const char *result)
|
||||
{
|
||||
if (result == STR_USB_MASS_STORAGE) {
|
||||
setSelectedUsbMode(USB_MASS_STORAGE_MODE);
|
||||
}
|
||||
else if (result == STR_USB_JOYSTICK) {
|
||||
} else if (result == STR_USB_JOYSTICK) {
|
||||
setSelectedUsbMode(USB_JOYSTICK_MODE);
|
||||
}
|
||||
#if defined(USB_SERIAL)
|
||||
@@ -134,6 +132,10 @@ void closeUsbMenu()
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(COLORLCD)
|
||||
static UsbSDConnected* usbConnectedWindow = nullptr;
|
||||
#endif
|
||||
|
||||
void handleUsbConnection()
|
||||
{
|
||||
#if defined(STM32) && !defined(SIMU)
|
||||
@@ -144,20 +146,17 @@ void handleUsbConnection()
|
||||
TRACE("USB unplugged");
|
||||
closeUsbMenu();
|
||||
_pluggedUsb = false;
|
||||
}
|
||||
else if (!_pluggedUsb && usbPlugged()) {
|
||||
} else if (!_pluggedUsb && usbPlugged()) {
|
||||
TRACE("USB plugged");
|
||||
_pluggedUsb = true;
|
||||
_usbDisabled = false;
|
||||
}
|
||||
|
||||
if (!_usbDisabled && !usbStarted() && usbPlugged()) {
|
||||
|
||||
if (!_usbDisabled && !usbStarted() && usbPlugged()) {
|
||||
if (getSelectedUsbMode() == USB_UNSELECTED_MODE) {
|
||||
if (g_eeGeneral.USBMode == USB_UNSELECTED_MODE) {
|
||||
openUsbMenu();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setSelectedUsbMode(g_eeGeneral.USBMode);
|
||||
}
|
||||
}
|
||||
@@ -165,9 +164,11 @@ void handleUsbConnection()
|
||||
// Mode might have been selected in previous block
|
||||
// so re-evaluate the condition
|
||||
if (getSelectedUsbMode() != USB_UNSELECTED_MODE) {
|
||||
|
||||
if (getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
|
||||
edgeTxClose(false);
|
||||
#if defined(COLORLCD)
|
||||
usbConnectedWindow = new UsbSDConnected();
|
||||
#endif
|
||||
}
|
||||
#if defined(USB_SERIAL)
|
||||
else if (getSelectedUsbMode() == USB_SERIAL_MODE) {
|
||||
@@ -185,6 +186,10 @@ void handleUsbConnection()
|
||||
TRACE("USB stopped");
|
||||
if (getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
|
||||
edgeTxResume();
|
||||
#if defined(COLORLCD)
|
||||
usbConnectedWindow->deleteLater();
|
||||
usbConnectedWindow = nullptr;
|
||||
#endif
|
||||
pushEvent(EVT_ENTRY);
|
||||
} else if (getSelectedUsbMode() == USB_SERIAL_MODE) {
|
||||
serialStop(SP_VCP);
|
||||
@@ -192,7 +197,7 @@ void handleUsbConnection()
|
||||
TRACE("reset selected USB mode");
|
||||
setSelectedUsbMode(USB_UNSELECTED_MODE);
|
||||
}
|
||||
#endif // defined(STM32) && !defined(SIMU)
|
||||
#endif // defined(STM32) && !defined(SIMU)
|
||||
}
|
||||
|
||||
#if defined(JACK_DETECT_GPIO) && !defined(SIMU)
|
||||
@@ -207,8 +212,7 @@ bool isJackPlugged()
|
||||
debounced_state = false;
|
||||
}
|
||||
last_state = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (last_state) {
|
||||
debounced_state = true;
|
||||
}
|
||||
@@ -224,14 +228,13 @@ uint8_t jackState = SPEAKER_ACTIVE;
|
||||
const char STR_JACK_HEADPHONE[] = "Headphone";
|
||||
const char STR_JACK_TRAINER[] = "Trainer";
|
||||
|
||||
void onJackConnectMenu(const char * result)
|
||||
void onJackConnectMenu(const char* result)
|
||||
{
|
||||
if (result == STR_JACK_HEADPHONE) {
|
||||
jackState = HEADPHONE_ACTIVE;
|
||||
disableSpeaker();
|
||||
enableHeadphone();
|
||||
}
|
||||
else if (result == STR_JACK_TRAINER) {
|
||||
} else if (result == STR_JACK_TRAINER) {
|
||||
jackState = TRAINER_ACTIVE;
|
||||
enableTrainer();
|
||||
}
|
||||
@@ -244,19 +247,16 @@ void handleJackConnection()
|
||||
jackState = HEADPHONE_ACTIVE;
|
||||
disableSpeaker();
|
||||
enableHeadphone();
|
||||
}
|
||||
else if (g_eeGeneral.jackMode == JACK_TRAINER_MODE) {
|
||||
} else if (g_eeGeneral.jackMode == JACK_TRAINER_MODE) {
|
||||
jackState = TRAINER_ACTIVE;
|
||||
enableTrainer();
|
||||
}
|
||||
else if (popupMenuItemsCount == 0) {
|
||||
} else if (popupMenuItemsCount == 0) {
|
||||
POPUP_MENU_START(onJackConnectMenu, 2, STR_JACK_HEADPHONE, STR_JACK_TRAINER);
|
||||
}
|
||||
}
|
||||
else if (jackState == SPEAKER_ACTIVE && !isJackPlugged() && popupMenuItemsCount > 0 && popupMenuHandler == onJackConnectMenu) {
|
||||
} else if (jackState == SPEAKER_ACTIVE && !isJackPlugged() &&
|
||||
popupMenuItemsCount > 0 && popupMenuHandler == onJackConnectMenu) {
|
||||
popupMenuItemsCount = 0;
|
||||
}
|
||||
else if (jackState != SPEAKER_ACTIVE && !isJackPlugged()) {
|
||||
} else if (jackState != SPEAKER_ACTIVE && !isJackPlugged()) {
|
||||
jackState = SPEAKER_ACTIVE;
|
||||
enableSpeaker();
|
||||
}
|
||||
@@ -325,7 +325,7 @@ void checkEeprom()
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BAT_AVG_SAMPLES 8
|
||||
#define BAT_AVG_SAMPLES 8
|
||||
|
||||
void checkBatteryAlarms()
|
||||
{
|
||||
@@ -345,12 +345,11 @@ void checkBattery()
|
||||
g_vbat100mV = (getBatteryVoltage() + 5) / 10;
|
||||
batSum = 0;
|
||||
sampleCount = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
batSum += getBatteryVoltage();
|
||||
// TRACE("checkBattery(): sampled = %d", getBatteryVoltage());
|
||||
if (++sampleCount >= BAT_AVG_SAMPLES) {
|
||||
g_vbat100mV = (batSum + BAT_AVG_SAMPLES * 5 ) / (BAT_AVG_SAMPLES * 10);
|
||||
g_vbat100mV = (batSum + BAT_AVG_SAMPLES * 5) / (BAT_AVG_SAMPLES * 10);
|
||||
batSum = 0;
|
||||
sampleCount = 0;
|
||||
// TRACE("checkBattery(): g_vbat100mV = %d", g_vbat100mV);
|
||||
@@ -358,10 +357,7 @@ void checkBattery()
|
||||
}
|
||||
}
|
||||
|
||||
void periodicTick_1s()
|
||||
{
|
||||
checkBattery();
|
||||
}
|
||||
void periodicTick_1s() { checkBattery(); }
|
||||
|
||||
void periodicTick_10s()
|
||||
{
|
||||
@@ -375,7 +371,7 @@ void periodicTick()
|
||||
{
|
||||
static uint8_t count10s;
|
||||
static uint32_t lastTime;
|
||||
if ( (get_tmr10ms() - lastTime) >= 100 ) {
|
||||
if ((get_tmr10ms() - lastTime) >= 100) {
|
||||
lastTime += 100;
|
||||
periodicTick_1s();
|
||||
if (++count10s >= 10) {
|
||||
@@ -388,7 +384,6 @@ void periodicTick()
|
||||
#if defined(GUI) && defined(COLORLCD)
|
||||
void guiMain(event_t evt)
|
||||
{
|
||||
|
||||
#if defined(LUA)
|
||||
uint32_t t0 = get_tmr10ms();
|
||||
static uint32_t lastLuaTime = 0;
|
||||
@@ -422,7 +417,7 @@ void guiMain(event_t evt)
|
||||
}
|
||||
mainRequestFlags &= ~(1u << REQUEST_MAIN_VIEW);
|
||||
}
|
||||
|
||||
|
||||
bool screenshotRequested = (mainRequestFlags & (1u << REQUEST_SCREENSHOT));
|
||||
if (screenshotRequested) {
|
||||
writeScreenshot();
|
||||
@@ -431,7 +426,8 @@ void guiMain(event_t evt)
|
||||
}
|
||||
#elif defined(GUI)
|
||||
|
||||
bool handleGui(event_t event) {
|
||||
bool handleGui(event_t event)
|
||||
{
|
||||
bool refreshNeeded;
|
||||
#if defined(LUA)
|
||||
bool isTelemView =
|
||||
@@ -476,25 +472,28 @@ void guiMain(event_t evt)
|
||||
maxLuaInterval = interval;
|
||||
}
|
||||
|
||||
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running)
|
||||
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is
|
||||
// running)
|
||||
luaTask(false);
|
||||
|
||||
t0 = get_tmr10ms() - t0;
|
||||
if (t0 > maxLuaDuration) {
|
||||
maxLuaDuration = t0;
|
||||
}
|
||||
#endif //#if defined(LUA)
|
||||
#endif // #if defined(LUA)
|
||||
|
||||
// wait for LCD DMA to finish before continuing, because code from this point
|
||||
// is allowed to change the contents of LCD buffer
|
||||
//
|
||||
// WARNING: make sure no code above this line does any change to the LCD display buffer!
|
||||
// WARNING: make sure no code above this line does any change to the LCD
|
||||
// display buffer!
|
||||
//
|
||||
lcdRefreshWait();
|
||||
|
||||
if (menuEvent) {
|
||||
// we have a popupMenuActive entry or exit event
|
||||
menuVerticalPosition = (menuEvent == EVT_ENTRY_UP) ? menuVerticalPositions[menuLevel] : 0;
|
||||
menuVerticalPosition =
|
||||
(menuEvent == EVT_ENTRY_UP) ? menuVerticalPositions[menuLevel] : 0;
|
||||
menuHorizontalPosition = 0;
|
||||
evt = menuEvent;
|
||||
menuEvent = 0;
|
||||
@@ -502,8 +501,7 @@ void guiMain(event_t evt)
|
||||
|
||||
if (isEventCaughtByPopup()) {
|
||||
refreshNeeded |= handleGui(0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
refreshNeeded |= handleGui(evt);
|
||||
evt = 0;
|
||||
}
|
||||
@@ -511,21 +509,19 @@ void guiMain(event_t evt)
|
||||
if (warningText) {
|
||||
// show warning on top of the normal menus
|
||||
DISPLAY_WARNING(evt);
|
||||
}
|
||||
else if (popupMenuItemsCount > 0) {
|
||||
} else if (popupMenuItemsCount > 0) {
|
||||
// show popup menu on top of the normal menus
|
||||
const char * result = runPopupMenu(evt);
|
||||
const char *result = runPopupMenu(evt);
|
||||
if (result) {
|
||||
TRACE("popupMenuHandler(%s)", result);
|
||||
auto handler = popupMenuHandler;
|
||||
if (result != STR_UPDATE_LIST)
|
||||
CLEAR_POPUP();
|
||||
if (result != STR_UPDATE_LIST) CLEAR_POPUP();
|
||||
handler(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshNeeded) lcdRefresh();
|
||||
|
||||
|
||||
if (mainRequestFlags & (1u << REQUEST_SCREENSHOT)) {
|
||||
writeScreenshot();
|
||||
mainRequestFlags &= ~(1u << REQUEST_SCREENSHOT);
|
||||
@@ -534,7 +530,7 @@ void guiMain(event_t evt)
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
void initLoggingTimer();
|
||||
void initLoggingTimer();
|
||||
#endif
|
||||
|
||||
void perMain()
|
||||
@@ -545,12 +541,12 @@ void perMain()
|
||||
|
||||
if (!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE)) {
|
||||
checkEeprom();
|
||||
|
||||
#if !defined(SIMU) // use FreeRTOS software timer if radio firmware
|
||||
initLoggingTimer(); // initialize software timer for logging
|
||||
#else
|
||||
logsWrite(); // call logsWrite the old way for simu
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU) // use FreeRTOS software timer if radio firmware
|
||||
initLoggingTimer(); // initialize software timer for logging
|
||||
#else
|
||||
logsWrite(); // call logsWrite the old way for simu
|
||||
#endif
|
||||
}
|
||||
|
||||
handleUsbConnection();
|
||||
@@ -582,16 +578,15 @@ void perMain()
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE))
|
||||
&& SD_CARD_PRESENT() && !sdMounted()) {
|
||||
if ((!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE)) &&
|
||||
SD_CARD_PRESENT() && !sdMounted()) {
|
||||
sdMount();
|
||||
}
|
||||
|
||||
#if !defined(EEPROM)
|
||||
// In case the SD card is removed during the session
|
||||
if ((!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE))
|
||||
&& !SD_CARD_PRESENT() && !UNEXPECTED_SHUTDOWN()) {
|
||||
|
||||
if ((!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE)) &&
|
||||
!SD_CARD_PRESENT() && !UNEXPECTED_SHUTDOWN()) {
|
||||
// TODO: implement for b/w
|
||||
#if defined(COLORLCD)
|
||||
drawFatalErrorScreen(STR_NO_SDCARD);
|
||||
@@ -602,10 +597,8 @@ void perMain()
|
||||
|
||||
if (usbPlugged() && getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
|
||||
#if defined(LIBOPENUI)
|
||||
// draw some image showing USB
|
||||
lcdInitDirectDrawing();
|
||||
EdgeTxTheme::instance()->drawUsbPluggedScreen(lcd);
|
||||
lcdRefresh();
|
||||
LvglWrapper::instance()->run();
|
||||
usbConnectedWindow->checkEvents();
|
||||
#else
|
||||
// disable access to menus
|
||||
lcdClear();
|
||||
@@ -652,7 +645,7 @@ void perMain()
|
||||
|
||||
#if defined(PCBX9E) && !defined(SIMU)
|
||||
toplcdRefreshStart();
|
||||
setTopFirstTimer(getValue(MIXSRC_FIRST_TIMER+g_model.toplcdTimer));
|
||||
setTopFirstTimer(getValue(MIXSRC_FIRST_TIMER + g_model.toplcdTimer));
|
||||
setTopSecondTimer(g_eeGeneral.globalTimer + sessionTimer);
|
||||
setTopRssi(TELEMETRY_RSSI());
|
||||
setTopBatteryValue(g_vbat100mV);
|
||||
|
||||
Reference in New Issue
Block a user