Skip to content

Commit

Permalink
fix(v16): proper init adcValues (EdgeTX#5701)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardclli authored Dec 12, 2024
1 parent 6d17448 commit 0f86cd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
3 changes: 3 additions & 0 deletions radio/src/hal/adc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ static uint16_t adcValues[MAX_ANALOG_INPUTS] __DMA;

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 (driver && (!driver->init || driver->init())) {
_hal_adc_driver = driver;
Expand Down
49 changes: 20 additions & 29 deletions radio/src/targets/horus/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,46 +85,37 @@ void boardBLInit()
#if defined(SIXPOS_SWITCH_INDEX)
uint8_t lastADCState = 0;
uint8_t sixPosState = 0;
bool sixPosInit = false;
bool sixPosDirty = true;
bool dirty = true;
uint16_t getSixPosAnalogValue(uint16_t adcValue)
{
if (sixPosInit) {
uint8_t currentADCState = 0;
if (adcValue > 3800)
currentADCState = 6;
else if (adcValue > 3100)
currentADCState = 5;
else if (adcValue > 2300)
currentADCState = 4;
else if (adcValue > 1500)
currentADCState = 3;
else if (adcValue > 1000)
currentADCState = 2;
else if (adcValue > 400)
currentADCState = 1;
if (lastADCState != currentADCState) {
lastADCState = currentADCState;
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
sixPosState = lastADCState - 1;
sixPosDirty = true;
}
} else if (adcValue < 300) {
// Wait for nothing is pressed to start sampling, otherwise may goes into unknown state
sixPosInit = true;
uint8_t currentADCState = 0;
if (adcValue > 3800)
currentADCState = 6;
else if (adcValue > 3100)
currentADCState = 5;
else if (adcValue > 2300)
currentADCState = 4;
else if (adcValue > 1500)
currentADCState = 3;
else if (adcValue > 1000)
currentADCState = 2;
else if (adcValue > 400)
currentADCState = 1;
if (lastADCState != currentADCState) {
lastADCState = currentADCState;
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
sixPosState = lastADCState - 1;
dirty = true;
}

if (sixPosDirty) {
if (dirty) {
for (uint8_t i = 0; i < 6; i++) {
if (i == sixPosState)
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
else
ws2812_set_color(i, 0, 0, 0);
}
ws2812_update(&_led_timer);
sixPosDirty = false;
}

return (4096/5)*(sixPosState);
}
#endif
Expand Down

0 comments on commit 0f86cd9

Please sign in to comment.