fix: switch position if disabled or transitioning
This commit is contained in:
committed by
Malte Langermann
parent
fc6ad808ad
commit
c15c5ea9eb
@@ -88,6 +88,7 @@ uint8_t switchGetMaxFctSwitches()
|
|||||||
uint32_t switchState(uint8_t pos_idx)
|
uint32_t switchState(uint8_t pos_idx)
|
||||||
{
|
{
|
||||||
auto d = div(pos_idx, 3);
|
auto d = div(pos_idx, 3);
|
||||||
|
if (d.quot >= n_total_switches) return 0;
|
||||||
return stm32_switch_get_state(&_switch_defs[d.quot], (SwitchHwPos)d.rem);
|
return stm32_switch_get_state(&_switch_defs[d.quot], (SwitchHwPos)d.rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-9
@@ -102,15 +102,10 @@ void initLoggingTimer() { // called cyclic
|
|||||||
|
|
||||||
void writeHeader();
|
void writeHeader();
|
||||||
|
|
||||||
#if defined(PCBFRSKY) || defined(PCBNV14)
|
int getSwitchState(uint8_t swtch) {
|
||||||
int getSwitchState(uint8_t swtch) {
|
int value = getValue(MIXSRC_FIRST_SWITCH + swtch);
|
||||||
int value = getValue(MIXSRC_FIRST_SWITCH + swtch);
|
return (value == 0) ? 0 : (value < 0) ? -1 : +1;
|
||||||
return (value == 0) ? 0 : (value < 0) ? -1 : +1;
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define GET_2POS_STATE(sw) (switchState(SW_ ## sw) ? -1 : 1)
|
|
||||||
#define GET_3POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : (switchState(SW_ ## sw ## 2) ? 1 : 0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void logsInit()
|
void logsInit()
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-3
@@ -280,7 +280,7 @@ static uint64_t checkSwitchPosition(uint8_t idx, bool startup)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SWITCH_HW_MID:
|
case SWITCH_HW_MID:
|
||||||
if (startup || SWITCH_POSITION(index) ||
|
if (startup || SWITCH_POSITION(index + 1) ||
|
||||||
g_eeGeneral.switchesDelay == SWITCHES_DELAY_NONE ||
|
g_eeGeneral.switchesDelay == SWITCHES_DELAY_NONE ||
|
||||||
(switchesMidposStart[idx] &&
|
(switchesMidposStart[idx] &&
|
||||||
(tmr10ms_t)(get_tmr10ms() - switchesMidposStart[idx]) >
|
(tmr10ms_t)(get_tmr10ms() - switchesMidposStart[idx]) >
|
||||||
@@ -308,6 +308,7 @@ void getSwitchesPosition(bool startup)
|
|||||||
{
|
{
|
||||||
uint64_t newPos = 0;
|
uint64_t newPos = 0;
|
||||||
for (unsigned i = 0; i < switchGetMaxSwitches(); i++) {
|
for (unsigned i = 0; i < switchGetMaxSwitches(); i++) {
|
||||||
|
if (!SWITCH_EXISTS(i)) continue;
|
||||||
newPos |= checkSwitchPosition(i, startup);
|
newPos |= checkSwitchPosition(i, startup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,8 +571,14 @@ bool getSwitch(swsrc_t swtch, uint8_t flags)
|
|||||||
if (cs_idx < max_reg_pos) {
|
if (cs_idx < max_reg_pos) {
|
||||||
if (flags & GETSWITCH_MIDPOS_DELAY)
|
if (flags & GETSWITCH_MIDPOS_DELAY)
|
||||||
result = SWITCH_POSITION(cs_idx);
|
result = SWITCH_POSITION(cs_idx);
|
||||||
else
|
else {
|
||||||
result = switchState(cs_idx);
|
div_t qr = div(cs_idx, 3);
|
||||||
|
if (SWITCH_EXISTS(qr.quot)) {
|
||||||
|
result = switchState(cs_idx);
|
||||||
|
} else {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if defined(FUNCTION_SWITCHES)
|
#if defined(FUNCTION_SWITCHES)
|
||||||
else if (cs_idx - max_reg_pos < switchGetMaxFctSwitches() * 3) {
|
else if (cs_idx - max_reg_pos < switchGetMaxFctSwitches() * 3) {
|
||||||
|
|||||||
Reference in New Issue
Block a user