fix(rgbled): double-buffer WS2812 strip to eliminate races (#7304)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
462b0351ef
commit
ac4c4d7b6b
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_ws2812.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
@@ -72,44 +71,6 @@ HardwareOptions hardwareOptions;
|
||||
#include "storage/storage.h"
|
||||
#endif
|
||||
|
||||
#if defined(SIXPOS_SWITCH_INDEX)
|
||||
uint8_t lastADCState = 0;
|
||||
uint8_t sixPosState = 0;
|
||||
bool dirty = true;
|
||||
uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
rgbLedColorApply();
|
||||
}
|
||||
return (4096/5)*(sixPosState);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SALED_PWR_GPIO)
|
||||
void SALEDpwrInit()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user