fix(v16): proper init adcValues (#5701)
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -85,36 +85,29 @@ 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;
|
else if (adcValue > 3100)
|
||||||
else if (adcValue > 3100)
|
currentADCState = 5;
|
||||||
currentADCState = 5;
|
else if (adcValue > 2300)
|
||||||
else if (adcValue > 2300)
|
currentADCState = 4;
|
||||||
currentADCState = 4;
|
else if (adcValue > 1500)
|
||||||
else if (adcValue > 1500)
|
currentADCState = 3;
|
||||||
currentADCState = 3;
|
else if (adcValue > 1000)
|
||||||
else if (adcValue > 1000)
|
currentADCState = 2;
|
||||||
currentADCState = 2;
|
else if (adcValue > 400)
|
||||||
else if (adcValue > 400)
|
currentADCState = 1;
|
||||||
currentADCState = 1;
|
if (lastADCState != currentADCState) {
|
||||||
if (lastADCState != currentADCState) {
|
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;
|
|
||||||
}
|
|
||||||
} else if (adcValue < 300) {
|
|
||||||
// Wait for nothing is pressed to start sampling, otherwise may goes into unknown state
|
|
||||||
sixPosInit = true;
|
|
||||||
}
|
}
|
||||||
|
if (dirty) {
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user