fix(v16): proper init adcValues (#5701)

This commit is contained in:
richardclli
2024-12-12 11:21:10 +10:00
committed by GitHub
parent 6d17448be5
commit 0f86cd9a95
2 changed files with 23 additions and 29 deletions
+3
View File
@@ -35,6 +35,9 @@ static uint16_t adcValues[MAX_ANALOG_INPUTS] __DMA;
bool adcInit(const etx_hal_adc_driver_t* driver) bool adcInit(const etx_hal_adc_driver_t* driver)
{ {
// Init buffer, provides non random values before mixer task starts
memset(adcValues, 0, sizeof(adcValues));
// If there is an init function, it MUST succeed // If there is an init function, it MUST succeed
if (driver && (!driver->init || driver->init())) { if (driver && (!driver->init || driver->init())) {
_hal_adc_driver = driver; _hal_adc_driver = driver;
+3 -12
View File
@@ -85,11 +85,9 @@ 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 sixPosInit = false; bool dirty = true;
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;
@@ -107,14 +105,9 @@ 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;
sixPosDirty = true; dirty = true;
} }
} else if (adcValue < 300) { if (dirty) {
// 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);
@@ -122,9 +115,7 @@ 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