fix DRS LED flicker
This commit is contained in:
@ -88,7 +88,10 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
|
||||
float speed =
|
||||
(vehicle_state.speed - LED_SPEED_MIN) / (LED_SPEED_MAX - LED_SPEED_MIN);
|
||||
float num_leds_exact = speed * N_LEDS;
|
||||
num_leds_exact = fmin(N_LEDS, fmax(0, num_leds_exact));
|
||||
// clamp num_leds_exact to maximum of N_LEDS and exclude first LED if DRS is
|
||||
// active (vehicle_state.drs_led_active = 1)
|
||||
num_leds_exact =
|
||||
fmin(N_LEDS, fmax(vehicle_state.drs_led_active, num_leds_exact));
|
||||
int num_leds = num_leds_exact;
|
||||
float num_leds_frac = num_leds_exact - num_leds;
|
||||
|
||||
@ -98,12 +101,13 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
|
||||
uint8_t r, g, b;
|
||||
led_hsv_to_rgb(hue, 1.0f, 1.0f, &r, &g, &b);
|
||||
|
||||
// Fully illuminate first n LEDs
|
||||
for (int i = 0; i < num_leds; i++) {
|
||||
// Fully illuminate first n LEDs (start at second LED if DRS is active)
|
||||
for (int i = vehicle_state.drs_led_active; i < num_leds; i++) {
|
||||
led_set(i, r, g, b);
|
||||
}
|
||||
// Partially illuminate n+1th LED
|
||||
if (num_leds < N_LEDS) {
|
||||
// Partially illuminate n+1th LED if DRS LED is not active or n+1th led is
|
||||
// not DRS LED
|
||||
if (num_leds < N_LEDS && (!vehicle_state.drs_led_active || num_leds > 0)) {
|
||||
led_hsv_to_rgb(hue, 1.0f, num_leds_frac, &r, &g, &b);
|
||||
led_set(num_leds, r, g, b);
|
||||
}
|
||||
@ -111,6 +115,11 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
|
||||
for (int i = num_leds + 1; i < N_LEDS; i++) {
|
||||
led_set(i, 0, 0, 0);
|
||||
}
|
||||
|
||||
// set DRS LED (LED 0)
|
||||
if (vehicle_state.drs_led_active) {
|
||||
led_set(0, 0, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,9 +319,9 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *handle) {
|
||||
asm("nop" ::: "memory");
|
||||
}
|
||||
HAL_GPIO_WritePin(LED_LE_GPIO_Port, LED_LE_Pin, GPIO_PIN_RESET);
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
asm("nop" ::: "memory");
|
||||
}
|
||||
// for (size_t i = 0; i < 10; i++) {
|
||||
// asm("nop" ::: "memory");
|
||||
// }
|
||||
HAL_SPI_Transmit_DMA(hspi, (const uint8_t *)&led_buf[led_buf_idx], 3);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user