fix(v16): 6pos logic stuck at 6 when switched on (#5699)
This commit is contained in:
@@ -85,9 +85,11 @@ void boardBLInit()
|
|||||||
#if defined(SIXPOS_SWITCH_INDEX)
|
#if defined(SIXPOS_SWITCH_INDEX)
|
||||||
uint8_t lastADCState = 0;
|
uint8_t lastADCState = 0;
|
||||||
uint8_t sixPosState = 0;
|
uint8_t sixPosState = 0;
|
||||||
bool dirty = true;
|
bool sixPosInit = false;
|
||||||
|
bool sixPosDirty = true;
|
||||||
uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
||||||
{
|
{
|
||||||
|
if (sixPosInit) {
|
||||||
uint8_t currentADCState = 0;
|
uint8_t currentADCState = 0;
|
||||||
if (adcValue > 3800)
|
if (adcValue > 3800)
|
||||||
currentADCState = 6;
|
currentADCState = 6;
|
||||||
@@ -105,9 +107,14 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
|||||||
lastADCState = currentADCState;
|
lastADCState = currentADCState;
|
||||||
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
|
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
|
||||||
sixPosState = lastADCState - 1;
|
sixPosState = lastADCState - 1;
|
||||||
dirty = true;
|
sixPosDirty = true;
|
||||||
}
|
}
|
||||||
if (dirty) {
|
} else if (adcValue < 300) {
|
||||||
|
// Wait for nothing is pressed to start sampling, otherwise may goes into unknown state
|
||||||
|
sixPosInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sixPosDirty) {
|
||||||
for (uint8_t i = 0; i < 6; i++) {
|
for (uint8_t i = 0; i < 6; i++) {
|
||||||
if (i == sixPosState)
|
if (i == sixPosState)
|
||||||
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
|
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
|
||||||
@@ -115,7 +122,9 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
|||||||
ws2812_set_color(i, 0, 0, 0);
|
ws2812_set_color(i, 0, 0, 0);
|
||||||
}
|
}
|
||||||
ws2812_update(&_led_timer);
|
ws2812_update(&_led_timer);
|
||||||
|
sixPosDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (4096/5)*(sixPosState);
|
return (4096/5)*(sixPosState);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user