Merge pull request #1040 from EdgeTX/sw-warnings

This commit is contained in:
Raphael Coeffic
2021-12-17 13:05:13 +01:00
committed by GitHub
49 changed files with 400 additions and 488 deletions
+17 -38
View File
@@ -20,37 +20,11 @@
*/
#include "switch_warn_dialog.h"
#include "switches.h"
bool SwitchWarnDialog::warningInactive()
{
GET_ADC_IF_MIXER_NOT_RUNNING();
getMovedSwitch();
bool warn = false;
for (int i = 0; i < NUM_SWITCHES; i++) {
if (SWITCH_WARNING_ALLOWED(i)) {
unsigned int state = ((states >> (3 * i)) & 0x07);
if (state && state - 1 != ((switches_states >> (i * 2)) & 0x03)) {
warn = true;
}
}
}
if (g_model.potsWarnMode) {
evalFlightModeMixes(e_perout_mode_normal, 0);
bad_pots = 0;
for (int i = 0; i < NUM_POTS + NUM_SLIDERS; i++) {
if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) {
continue;
}
if ( (g_model.potsWarnEnabled & (1 << i)) && (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) {
warn = true;
bad_pots |= (1 << i);
}
}
}
if (!warn)
if (!isSwitchWarningRequired(bad_pots))
return true;
if (last_bad_switches != switches_states || last_bad_pots != bad_pots) {
@@ -74,19 +48,24 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc)
FullScreenDialog::paint(dc);
coord_t x = ALERT_MESSAGE_LEFT;
coord_t y = ALERT_MESSAGE_TOP; // ALERT_FRAME_TOP + ALERT_FRAME_PADDING + ALERT_TITLE_LINE_HEIGHT * 3;
coord_t y = ALERT_MESSAGE_TOP;
swarnstate_t states = g_model.switchWarningState;
for (int i = 0; i < NUM_SWITCHES; ++i) {
if (SWITCH_WARNING_ALLOWED(i)) {
unsigned int state = ((g_model.switchWarningState >> (3 * i)) & 0x07);
if (state && state - 1 != ((switches_states >> (i * 2)) & 0x03)) {
if (y < LCD_H) {
x = drawSwitch(dc, x, y, SWSRC_FIRST_SWITCH + i * 3 + state - 1, COLOR_THEME_PRIMARY1 | FONT(BOLD));
x += 5;
}
else {
dc->drawText(x, y, "...", COLOR_THEME_PRIMARY1 | FONT(BOLD));
break;
swarnstate_t mask = ((swarnstate_t)0x07 << (i*3));
if (states & mask) {
if ((switches_states & mask) != (states & mask)) {
swarnstate_t state = (states >> (i*3)) & 0x07;
if (x < LCD_W) {
x = drawSwitch(dc, x, y, SWSRC_FIRST_SWITCH + i * 3 + state - 1,
COLOR_THEME_PRIMARY1 | FONT(BOLD));
x += 5;
}
else {
dc->drawText(x, y, "...", COLOR_THEME_PRIMARY1 | FONT(BOLD));
break;
}
}
}
}
+2 -4
View File
@@ -33,7 +33,6 @@ class SwitchWarnDialog: public FullScreenDialog {
FullScreenDialog(WARNING_TYPE_ALERT, STR_SWITCHWARN)
{
last_bad_switches = 0xff;
states = g_model.switchWarningState;
bad_pots = 0;
last_bad_pots = 0xff;
setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this));
@@ -50,9 +49,8 @@ class SwitchWarnDialog: public FullScreenDialog {
protected:
swarnstate_t last_bad_switches;
swarnstate_t states;
uint8_t bad_pots;
uint8_t last_bad_pots;
uint8_t bad_pots;
uint8_t last_bad_pots;
bool warningInactive();
};