chore(radio): Cleanup startup code, fix throttle warning led color, startup haptic option (#4027)

This commit is contained in:
philmoz
2023-11-05 18:53:26 +10:00
committed by GitHub
parent 4bdbf74327
commit 7190f00374
48 changed files with 448 additions and 541 deletions
+49 -41
View File
@@ -49,36 +49,63 @@ FullScreenDialog::FullScreenDialog(
bringToTop();
init();
build();
lv_obj_add_event_cb(lvobj, FullScreenDialog::long_pressed, LV_EVENT_LONG_PRESSED, nullptr);
lv_obj_add_event_cb(lvobj, FullScreenDialog::on_draw, LV_EVENT_DRAW_MAIN_BEGIN, nullptr);
}
void FullScreenDialog::init()
void FullScreenDialog::on_draw(lv_event_t* e)
{
if (!loaded) {
loaded = true;
std::string t;
if (type == WARNING_TYPE_ALERT) {
#if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_IT) || defined(TRANSLATIONS_CZ)
t = std::string(STR_WARNING) + "\n" + title;
#else
t = title + "\n" + STR_WARNING;
#endif
} else if (!title.empty()) {
t = title;
auto dlg = (FullScreenDialog*)lv_obj_get_user_data(lv_event_get_target(e));
if (dlg) {
if (!dlg->loaded) {
dlg->loaded = true;
dlg->delayedInit();
}
new StaticText(this,
rect_t{ALERT_TITLE_LEFT, ALERT_TITLE_TOP, LCD_W - ALERT_TITLE_LEFT - PAGE_PADDING, LCD_H - ALERT_TITLE_TOP - PAGE_PADDING},
t.c_str(), 0, COLOR_THEME_WARNING | FONT(XL));
}
}
messageLabel = new StaticText(this,
rect_t{ALERT_MESSAGE_LEFT, ALERT_MESSAGE_TOP, LCD_W - ALERT_MESSAGE_LEFT - PAGE_PADDING, LCD_H - ALERT_MESSAGE_TOP - PAGE_PADDING},
message.c_str(), 0, COLOR_THEME_PRIMARY1 | FONT(BOLD));
void FullScreenDialog::build()
{
std::string t;
if (type == WARNING_TYPE_ALERT) {
#if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_IT) || defined(TRANSLATIONS_CZ)
t = std::string(STR_WARNING) + "\n" + title;
#else
t = title + "\n" + STR_WARNING;
#endif
} else if (!title.empty()) {
t = title;
}
new StaticText(this,
rect_t{ALERT_TITLE_LEFT, ALERT_TITLE_TOP, LCD_W - ALERT_TITLE_LEFT - PAGE_PADDING, LCD_H - ALERT_TITLE_TOP - PAGE_PADDING},
t.c_str(), 0, COLOR_THEME_WARNING | FONT(XL));
if (!action.empty()) {
auto btn = new TextButton(this, { (LCD_W - 280) / 2, LCD_H - 48, 280, 40 }, action.c_str(),
messageLabel = new StaticText(this,
rect_t{ALERT_MESSAGE_LEFT, ALERT_MESSAGE_TOP, LCD_W - ALERT_MESSAGE_LEFT - PAGE_PADDING, LCD_H - ALERT_MESSAGE_TOP - PAGE_PADDING},
message.c_str(), 0, COLOR_THEME_PRIMARY1 | FONT(BOLD));
if (!action.empty()) {
auto btn = new TextButton(this, { (LCD_W - 280) / 2, LCD_H - 48, 280, 40 }, action.c_str(),
[=]() {
closeDialog();
return 0;
}, COLOR_THEME_PRIMARY1 | FONT(BOLD));
lv_obj_set_style_bg_color(btn->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(btn->getLvObj(), LV_OPA_COVER, 0);
lv_obj_set_style_text_color(btn->getLvObj(), makeLvColor(COLOR_THEME_PRIMARY1), 0);
} else {
if (type == WARNING_TYPE_CONFIRM) {
auto btn = new TextButton(this, { LCD_W / 3 - 50, LCD_H - 48, 100, 40 }, STR_EXIT,
[=]() {
deleteLater();
return 0;
}, COLOR_THEME_PRIMARY1 | FONT(BOLD));
lv_obj_set_style_bg_color(btn->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(btn->getLvObj(), LV_OPA_COVER, 0);
lv_obj_set_style_text_color(btn->getLvObj(), makeLvColor(COLOR_THEME_PRIMARY1), 0);
btn = new TextButton(this, { LCD_W * 2 / 3 - 50, LCD_H - 48, 100, 40 }, STR_OK,
[=]() {
closeDialog();
return 0;
@@ -86,25 +113,6 @@ void FullScreenDialog::init()
lv_obj_set_style_bg_color(btn->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(btn->getLvObj(), LV_OPA_COVER, 0);
lv_obj_set_style_text_color(btn->getLvObj(), makeLvColor(COLOR_THEME_PRIMARY1), 0);
} else {
if (type == WARNING_TYPE_CONFIRM) {
auto btn = new TextButton(this, { LCD_W / 3 - 50, LCD_H - 48, 100, 40 }, STR_EXIT,
[=]() {
deleteLater();
return 0;
}, COLOR_THEME_PRIMARY1 | FONT(BOLD));
lv_obj_set_style_bg_color(btn->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(btn->getLvObj(), LV_OPA_COVER, 0);
lv_obj_set_style_text_color(btn->getLvObj(), makeLvColor(COLOR_THEME_PRIMARY1), 0);
btn = new TextButton(this, { LCD_W * 2 / 3 - 50, LCD_H - 48, 100, 40 }, STR_OK,
[=]() {
closeDialog();
return 0;
}, COLOR_THEME_PRIMARY1 | FONT(BOLD));
lv_obj_set_style_bg_color(btn->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_opa(btn->getLvObj(), LV_OPA_COVER, 0);
lv_obj_set_style_text_color(btn->getLvObj(), makeLvColor(COLOR_THEME_PRIMARY1), 0);
}
}
}
}
+3 -1
View File
@@ -79,9 +79,11 @@ class FullScreenDialog : public Window
bool loaded = false;
StaticText* messageLabel;
virtual void init();
virtual void delayedInit() {}
void build();
static void long_pressed(lv_event_t* e);
static void on_draw(lv_event_t* e);
};
#endif // _FULLSCREEN_DIALOG_H_
+51 -2
View File
@@ -19,7 +19,11 @@
* GNU General Public License for more details.
*/
#if defined(SPLASH)
#include "opentx.h"
#include "inactivity_timer.h"
#include "stamp.h"
extern void checkSpeakerVolume();
#include "opentx.h"
#include "stamp.h"
@@ -125,4 +129,49 @@ void drawSplash()
MainWindow::instance()->setActiveScreen();
}
#endif
static tmr10ms_t splashStartTime = 0;
void startSplash()
{
if (!UNEXPECTED_SHUTDOWN()) {
splashStartTime = get_tmr10ms();
drawSplash();
}
}
void waitSplash()
{
// Handle color splash screen
if (splashStartTime) {
#if defined(SIMU)
// Simulator - inputsMoved() returns true immediately without this!
RTOS_WAIT_TICKS(30);
#endif // defined(SIMU)
splashStartTime += SPLASH_TIMEOUT;
while (splashStartTime > get_tmr10ms()) {
WDG_RESET();
checkSpeakerVolume();
checkBacklight();
RTOS_WAIT_TICKS(10);
auto evt = getEvent();
if (evt || inactivityCheckInputs()) {
if (evt)
killEvents(evt);
break;
}
#if defined(SIMU)
// Allow simulator to exit if closed while splash showing
uint32_t pwr_check = pwrCheck();
if (pwr_check == e_power_off) {
break;
}
#endif // defined(SIMU)
}
// Reset timer so special/global functions set to !1x don't get triggered
START_SILENCE_PERIOD();
}
}
+27 -20
View File
@@ -26,33 +26,30 @@ SwitchWarnDialog::SwitchWarnDialog() :
FullScreenDialog(WARNING_TYPE_ALERT, STR_SWITCHWARN, "", STR_PRESS_ANY_KEY_TO_SKIP)
{
last_bad_switches = 0xff;
bad_pots = 0;
last_bad_pots = 0x0;
setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this));
}
void SwitchWarnDialog::init()
void SwitchWarnDialog::delayedInit()
{
if (!loaded) {
FullScreenDialog::init();
lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_DOT);
}
lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_DOT);
AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT);
}
bool SwitchWarnDialog::warningInactive()
{
uint16_t bad_pots;
if (!isSwitchWarningRequired(bad_pots))
return true;
if (last_bad_switches != switches_states || last_bad_pots != bad_pots) {
// Redraw to update list of switches that need attention
invalidate();
if (last_bad_switches == 0xff || last_bad_pots & 0x7ff) {
AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT);
}
}
last_bad_pots = bad_pots;
last_bad_switches = switches_states;
last_bad_pots = bad_pots;
last_bad_switches = switches_states;
}
return false;
}
@@ -61,14 +58,6 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc)
{
if (!running) return;
FullScreenDialog::paint(dc);
}
void SwitchWarnDialog::checkEvents()
{
if (!running) return;
FullScreenDialog::checkEvents();
if (deleted()) return;
std::string warn_txt;
swarnstate_t states = g_model.switchWarningState;
@@ -98,3 +87,21 @@ void SwitchWarnDialog::checkEvents()
messageLabel->setText(warn_txt);
}
ThrottleWarnDialog::ThrottleWarnDialog(const char* msg) :
FullScreenDialog(WARNING_TYPE_ALERT, TR_THROTTLE_UPPERCASE, msg, STR_PRESS_ANY_KEY_TO_SKIP)
{
setCloseCondition(std::bind(&ThrottleWarnDialog::warningInactive, this));
}
void ThrottleWarnDialog::delayedInit()
{
lv_label_set_long_mode(messageLabel->getLvObj(), LV_LABEL_LONG_DOT);
AUDIO_ERROR_MESSAGE(AU_THROTTLE_ALERT);
}
bool ThrottleWarnDialog::warningInactive()
{
extern bool isThrottleWarningAlertNeeded();
return !isThrottleWarningAlertNeeded();
}
+15 -6
View File
@@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/
#ifndef _SWITCH_WARN_DIALOG_H_
#define _SWITCH_WARN_DIALOG_H_
#pragma once
#include "fullscreen_dialog.h"
#include "mainwindow.h"
@@ -35,18 +34,28 @@ class SwitchWarnDialog : public FullScreenDialog
std::string getName() const override { return "SwitchWarnDialog"; }
#endif
void checkEvents() override;
void paint(BitmapBuffer* dc) override;
protected:
swarnstate_t last_bad_switches;
uint16_t bad_pots;
uint16_t last_bad_pots;
StaticText* warn_label;
bool warningInactive();
void init() override;
void delayedInit() override;
};
class ThrottleWarnDialog : public FullScreenDialog
{
public:
ThrottleWarnDialog(const char* msg);
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "ThrottleWarnDialog"; }
#endif
protected:
bool warningInactive();
void delayedInit() override;
};