Fix switch handling on X9E, cleanup/harmonize code for all revisions
This commit is contained in:
@@ -38,14 +38,8 @@
|
||||
|
||||
uint8_t switchToMix(uint8_t source)
|
||||
{
|
||||
if (source <= 5*3)
|
||||
return MIXSRC_FIRST_SWITCH + (source-1) / 3;
|
||||
else if (source <= 17)
|
||||
return MIXSRC_SF;
|
||||
else if (source <= 20)
|
||||
return MIXSRC_SG;
|
||||
else
|
||||
return MIXSRC_SH;
|
||||
div_t qr = div(source-1, 3);
|
||||
return qr.quot+MIXSRC_FIRST_SWITCH;
|
||||
}
|
||||
|
||||
int circularIncDec(int current, int inc, int min, int max, IsValueAvailable isValueAvailable)
|
||||
@@ -94,6 +88,10 @@ bool isSourceAvailable(int source)
|
||||
return IS_POT_AVAILABLE(POT1+source-MIXSRC_FIRST_POT);
|
||||
}
|
||||
|
||||
if (source>=MIXSRC_FIRST_SWITCH && source<=MIXSRC_LAST_SWITCH) {
|
||||
return SWITCH_EXISTS(source-MIXSRC_FIRST_SWITCH);
|
||||
}
|
||||
|
||||
#if !defined(HELI)
|
||||
if (source>=MIXSRC_CYC1 && source<=MIXSRC_CYC3)
|
||||
return false;
|
||||
@@ -109,7 +107,7 @@ bool isSourceAvailable(int source)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source>=MIXSRC_SW1 && source<=MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
if (source>=MIXSRC_FIRST_LOGICAL_SWITCH && source<=MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
LogicalSwitchData * cs = lswAddress(source-MIXSRC_SW1);
|
||||
return (cs->func != LS_FUNC_NONE);
|
||||
}
|
||||
@@ -156,9 +154,12 @@ bool isInputSourceAvailable(int source)
|
||||
if (source>=MIXSRC_Rud && source<=MIXSRC_MAX)
|
||||
return true;
|
||||
|
||||
if (source>=MIXSRC_TrimRud && source<MIXSRC_SW1)
|
||||
if (source>=MIXSRC_FIRST_TRIM && source<=MIXSRC_LAST_TRIM)
|
||||
return true;
|
||||
|
||||
if (source>=MIXSRC_FIRST_SWITCH && source<=MIXSRC_LAST_SWITCH)
|
||||
return SWITCH_EXISTS(source-MIXSRC_FIRST_SWITCH);
|
||||
|
||||
if (source>=MIXSRC_FIRST_CH && source<=MIXSRC_LAST_CH)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ int8_t checkIncDecMovedSwitch(int8_t val)
|
||||
div_t info = switchInfo(swtch);
|
||||
if (IS_TOGGLE(info.quot)) {
|
||||
if (info.rem != 0) {
|
||||
val = (val == swtch ? swtch+2 : swtch);
|
||||
val = (val == swtch ? swtch-2 : swtch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -571,7 +571,6 @@ void menuMainView(uint8_t event)
|
||||
lcd_bmp(BITMAP_X, BITMAP_Y, modelBitmap);
|
||||
|
||||
// Switches
|
||||
#if defined(REV9E)
|
||||
if (getSwitchCount() > 8) {
|
||||
for (int i=0; i<NUM_SWITCHES; ++i) {
|
||||
div_t qr = div(i, 9);
|
||||
@@ -591,39 +590,13 @@ void menuMainView(uint8_t event)
|
||||
int index = 0;
|
||||
for (int i=0; i<NUM_SWITCHES; ++i) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
getvalue_t val = getValue(MIXSRC_SA+i);
|
||||
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH+i);
|
||||
getvalue_t sw = ((val < 0) ? 3*i+1 : ((val == 0) ? 3*i+2 : 3*i+3));
|
||||
putsSwitches((g_eeGeneral.view == VIEW_INPUTS) ? (index<4 ? 8*FW+3 : 24*FW+1) : (index<4 ? 3*FW+2 : 8*FW-1), (index%4)*FH+3*FH, sw, 0);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (int i=0; i<8; ++i) {
|
||||
getvalue_t sw;
|
||||
getvalue_t val;
|
||||
// TODO simplify this + reuse code in checkSwitches() + Menu MODELSETUP
|
||||
switch(i) {
|
||||
case 5:
|
||||
sw = getValue(MIXSRC_SF) > 0 ? 3*i+2 : 3*i+1;
|
||||
break;
|
||||
case 6:
|
||||
val = getValue(MIXSRC_SG);
|
||||
sw = ((val < 0) ? 3*i : ((val == 0) ? 3*i+1 : 3*i+2));
|
||||
break;
|
||||
case 7:
|
||||
sw = getValue(MIXSRC_SH) > 0 ? 3*i+1 : 3*i;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
val = getValue(MIXSRC_SA+i);
|
||||
sw = ((val < 0) ? 3*i+1 : ((val == 0) ? 3*i+2 : 3*i+3));
|
||||
break;
|
||||
}
|
||||
}
|
||||
putsSwitches((g_eeGeneral.view == VIEW_INPUTS) ? (i<4 ? 8*FW+3 : 24*FW+1) : (i<4 ? 3*FW+2 : 8*FW-1), (i%4)*FH+3*FH, sw, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_eeGeneral.view == VIEW_TIMERS) {
|
||||
displayTimers();
|
||||
|
||||
Reference in New Issue
Block a user