Merge pull request #1040 from EdgeTX/sw-warnings
This commit is contained in:
@@ -657,7 +657,6 @@ void menuModelSetup(event_t event)
|
||||
g_model.disableThrottleWarning = !editCheckBox(!g_model.disableThrottleWarning, MODEL_SETUP_2ND_COLUMN, y, STR_THROTTLE_WARNING, attr, event);
|
||||
break;
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
case ITEM_MODEL_SETUP_SWITCHES_WARNING2:
|
||||
if (i==0) {
|
||||
if (CURSOR_MOVED_LEFT(event))
|
||||
@@ -666,10 +665,8 @@ void menuModelSetup(event_t event)
|
||||
menuVerticalOffset++;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_MODEL_SETUP_SWITCHES_WARNING1:
|
||||
#if defined(PCBTARANIS)
|
||||
{
|
||||
#define FIRSTSW_STR STR_VSRCRAW+(MIXSRC_FIRST_SWITCH-MIXSRC_Rud+1)*length
|
||||
uint8_t switchWarningsCount = getSwitchWarningsCount();
|
||||
@@ -705,10 +702,18 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (menuHorizontalPosition < 0 || menuHorizontalPosition >= switchWarningsCount) {
|
||||
if (menuHorizontalPosition < 0 ||
|
||||
menuHorizontalPosition >= switchWarningsCount) {
|
||||
START_NO_HIGHLIGHT();
|
||||
getMovedSwitch();
|
||||
g_model.switchWarningState = switches_states;
|
||||
// Mask switches enabled for warnings
|
||||
swarnstate_t sw_mask = 0;
|
||||
for(uint8_t i=0; i<NUM_SWITCHES; i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i))
|
||||
if (g_model.switchWarningState & (0x07 << (3 * i)))
|
||||
sw_mask |= (0x07 << (3 * i));
|
||||
}
|
||||
g_model.switchWarningState = switches_states & sw_mask;
|
||||
AUDIO_WARNING1();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
@@ -722,80 +727,37 @@ void menuModelSetup(event_t event)
|
||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
div_t qr = div(current, MAX_SWITCH_PER_LINE);
|
||||
if (!READ_ONLY() && event==EVT_KEY_BREAK(KEY_ENTER) && attr && l_posHorz == current && old_posHorz >= 0) {
|
||||
g_model.switchWarningEnable ^= (1 << i);
|
||||
if (!READ_ONLY() && event == EVT_KEY_BREAK(KEY_ENTER) && attr &&
|
||||
l_posHorz == current && old_posHorz >= 0) {
|
||||
uint8_t curr_state = (states & 0x07);
|
||||
// remove old setting
|
||||
g_model.switchWarningState &= ~(0x07 << (3 * i));
|
||||
// add the new one (if switch UP and 2POS, jump directly to DOWN)
|
||||
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
|
||||
g_model.switchWarningState |= (curr_state & 0x03) << (3 * i);
|
||||
storageDirty(EE_MODEL);
|
||||
#if defined(PCBXLITE)
|
||||
s_editMode = 0;
|
||||
#endif
|
||||
}
|
||||
uint8_t swactive = !(g_model.switchWarningEnable & (1<<i));
|
||||
c = (STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03];
|
||||
// lcdDrawChar(MODEL_SETUP_2ND_COLUMN+qr.rem*(2*FW+1), y+FH*qr.quot, 'A'+i, attr && (menuHorizontalPosition==current) ? INVERS : 0);
|
||||
lcdDrawSizedText(MODEL_SETUP_2ND_COLUMN + qr.rem*((2*FW)+1), y+FH*qr.quot, FIRSTSW_STR+(i*length)+3, 1, attr && (menuHorizontalPosition==current) ? INVERS : 0);
|
||||
if (swactive) lcdDrawChar(lcdNextPos, y+FH*qr.quot, c);
|
||||
c = (" " STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03];
|
||||
lcdDrawSizedText(
|
||||
MODEL_SETUP_2ND_COLUMN + qr.rem * ((2 * FW) + 1),
|
||||
y + FH * qr.quot, FIRSTSW_STR + (i * length) + 3, 1,
|
||||
attr && (menuHorizontalPosition == current) ? INVERS : 0);
|
||||
lcdDrawChar(lcdNextPos, y + FH * qr.quot, c);
|
||||
++current;
|
||||
}
|
||||
states >>= 2;
|
||||
states >>= 3;
|
||||
}
|
||||
if (attr && ((menuHorizontalPosition < 0) || menuHorizontalPosition >= switchWarningsCount)) {
|
||||
lcdDrawFilledRect(MODEL_SETUP_2ND_COLUMN-1, y-1, 8*(2*FW+1), 1+FH*((current+4)/5));
|
||||
if (attr && ((menuHorizontalPosition < 0) ||
|
||||
menuHorizontalPosition >= switchWarningsCount)) {
|
||||
lcdDrawFilledRect(MODEL_SETUP_2ND_COLUMN - 1, y - 1,
|
||||
8 * (2 * FW + 1), 1 + FH * ((current + 4) / 5));
|
||||
}
|
||||
#else // PCBTARANIS
|
||||
{
|
||||
lcdDrawTextAlignedLeft(y, STR_SWITCHWARNING);
|
||||
swarnstate_t states = g_model.switchWarningState;
|
||||
char c;
|
||||
if (attr) {
|
||||
s_editMode = 0;
|
||||
if (!READ_ONLY()) {
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (menuHorizontalPosition < NUM_SWITCHES-1) {
|
||||
g_model.switchWarningEnable ^= (1 << menuHorizontalPosition);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (menuHorizontalPosition == NUM_SWITCHES-1) {
|
||||
START_NO_HIGHLIGHT();
|
||||
getMovedSwitch();
|
||||
g_model.switchWarningState = switches_states;
|
||||
AUDIO_WARNING1();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
killEvents(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < NUM_SWITCHES-1/*not on TRN switch*/; i++) {
|
||||
uint8_t swactive = !(g_model.switchWarningEnable & (1u << i));
|
||||
uint8_t swattr = 0;
|
||||
|
||||
if (IS_3POS(i)) {
|
||||
c = '0' + (states & 0x03);
|
||||
states >>= 2u;
|
||||
}
|
||||
else {
|
||||
if ((states & 0x01) && swactive)
|
||||
swattr = INVERS;
|
||||
c = *(STR_VSWITCHES - 2 + 9 + (3*(i+1)));
|
||||
states >>= 1u;
|
||||
}
|
||||
if (attr && (menuHorizontalPosition == i)) {
|
||||
swattr = BLINK | INVERS;
|
||||
}
|
||||
lcdDrawChar(MODEL_SETUP_2ND_COLUMN+i*FW, y, swactive ? c : '-', swattr);
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN+(NUM_SWITCHES*FW), y, "<]", (menuHorizontalPosition == NUM_SWITCHES-1 && !NO_HIGHLIGHT()) ? attr : 0);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
case ITEM_MODEL_SETUP_POTS_WARNING:
|
||||
lcdDrawTextAlignedLeft(y, STR_POTWARNING);
|
||||
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, "\004""OFF\0""Man\0""Auto", g_model.potsWarnMode, (menuHorizontalPosition == 0) ? attr : 0);
|
||||
@@ -842,7 +804,6 @@ void menuModelSetup(event_t event)
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_MODEL_SETUP_BEEP_CENTER:
|
||||
lcdDrawTextAlignedLeft(y, STR_BEEPCTR);
|
||||
|
||||
@@ -33,16 +33,6 @@ void drawSplash()
|
||||
{
|
||||
lcdClear();
|
||||
lcdDraw1bitBitmap(0, 0, splash_lbm, 0, 0);
|
||||
|
||||
#if MENUS_LOCK == 1
|
||||
if (readonly == false) {
|
||||
lcdDrawFilledRect((LCD_W - (sizeof(TR_UNLOCKED) - 1) * FW) / 2 - 9, 50,
|
||||
(sizeof(TR_UNLOCKED) - 1) * FW + 16, 11, SOLID,
|
||||
ERASE | ROUND);
|
||||
lcdDrawText((LCD_W - (sizeof(TR_UNLOCKED) - 1) * FW) / 2, 53, STR_UNLOCKED);
|
||||
}
|
||||
#endif
|
||||
|
||||
lcdRefresh();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -461,7 +461,6 @@ void menuMainView(event_t event)
|
||||
POPUP_MENU_START(onMainViewMenu);
|
||||
break;
|
||||
|
||||
#if MENUS_LOCK != 2 /*no menus*/
|
||||
#if defined(EVT_KEY_LAST_MENU)
|
||||
case EVT_KEY_LAST_MENU:
|
||||
pushMenu(lastPopMenu());
|
||||
@@ -478,7 +477,7 @@ void menuMainView(event_t event)
|
||||
pushMenu(menuTabGeneral[0]);
|
||||
killEvents(event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_NO_TRIMS)
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
if (!trimSelection.preEnterValid) {
|
||||
|
||||
@@ -679,7 +679,14 @@ void menuModelSetup(event_t event)
|
||||
if (menuHorizontalPosition < 0) {
|
||||
START_NO_HIGHLIGHT();
|
||||
getMovedSwitch();
|
||||
g_model.switchWarningState = switches_states;
|
||||
// Mask switches enabled for warnings
|
||||
swarnstate_t sw_mask = 0;
|
||||
for(uint8_t i=0; i<NUM_SWITCHES; i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i))
|
||||
if (g_model.switchWarningState & (0x07 << (3 * i)))
|
||||
sw_mask |= (0x07 << (3 * i));
|
||||
}
|
||||
g_model.switchWarningState = switches_states & sw_mask;
|
||||
AUDIO_WARNING1();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
@@ -695,17 +702,25 @@ void menuModelSetup(event_t event)
|
||||
for (int i=0; i<NUM_SWITCHES; i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
div_t qr = div(current, 8);
|
||||
if (!READ_ONLY() && event==EVT_KEY_BREAK(KEY_ENTER) && line && l_posHorz==current) {
|
||||
g_model.switchWarningEnable ^= (1 << i);
|
||||
if (!READ_ONLY() && event == EVT_KEY_BREAK(KEY_ENTER) && line &&
|
||||
l_posHorz == current) {
|
||||
uint8_t curr_state = (states & 0x07);
|
||||
// remove old setting
|
||||
g_model.switchWarningState &= ~(0x07 << (3 * i));
|
||||
// add the new one (if switch UP and 2POS, jump directly to DOWN)
|
||||
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
|
||||
g_model.switchWarningState |= (curr_state & 0x03) << (3 * i);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
uint8_t swactive = !(g_model.switchWarningEnable & (1<<i));
|
||||
c = (STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03];
|
||||
lcdDrawChar(MODEL_SETUP_2ND_COLUMN+qr.rem*(2*FW+1), y+FH*qr.quot, 'A'+i, line && (menuHorizontalPosition==current) ? INVERS : 0);
|
||||
if (swactive) lcdDrawChar(lcdNextPos, y+FH*qr.quot, c);
|
||||
c = (" " STR_CHAR_UP "-" STR_CHAR_DOWN)[states & 0x03];
|
||||
lcdDrawChar(
|
||||
MODEL_SETUP_2ND_COLUMN + qr.rem * (2 * FW + 1),
|
||||
y + FH * qr.quot, 'A' + i,
|
||||
line && (menuHorizontalPosition == current) ? INVERS : 0);
|
||||
lcdDrawChar(lcdNextPos, y + FH * qr.quot, c);
|
||||
++current;
|
||||
}
|
||||
states >>= 2;
|
||||
states >>= 3;
|
||||
}
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
#if defined(PCBX9E)
|
||||
|
||||
@@ -37,16 +37,6 @@ void drawSplash()
|
||||
{
|
||||
lcdClear();
|
||||
lcdDrawRleBitmap(0, 0, splash_lbm);
|
||||
|
||||
#if MENUS_LOCK == 1
|
||||
if (readonly == false) {
|
||||
lcdDrawFilledRect((LCD_W - (sizeof(TR_UNLOCKED) - 1) * FW) / 2 - 9, 50,
|
||||
(sizeof(TR_UNLOCKED) - 1) * FW + 16, 11, SOLID,
|
||||
ERASE | ROUND);
|
||||
lcdDrawText((LCD_W - (sizeof(TR_UNLOCKED) - 1) * FW) / 2, 53, STR_UNLOCKED);
|
||||
}
|
||||
#endif
|
||||
|
||||
lcdRefresh();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -449,7 +449,6 @@ void menuMainView(event_t event)
|
||||
POPUP_MENU_START(onMainViewMenu);
|
||||
break;
|
||||
|
||||
#if MENUS_LOCK != 2/*no menus*/
|
||||
case EVT_KEY_BREAK(KEY_MENU):
|
||||
pushMenu(menuModelSelect);
|
||||
break;
|
||||
@@ -458,7 +457,6 @@ void menuMainView(event_t event)
|
||||
pushMenu(menuTabGeneral[0]);
|
||||
killEvents(event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case EVT_KEY_BREAK(KEY_PAGE):
|
||||
storageDirty(EE_MODEL);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user