fix DRS LED flicker

This commit is contained in:
2025-04-18 20:34:54 +02:00
parent 80e38cc036
commit 0913466808
3 changed files with 26 additions and 14 deletions

View File

@ -9,11 +9,10 @@
#include "stm32h7xx_hal_gpio.h"
#include "tx_api.h"
#include "vehicle.h"
#include "leds.h"
#include "vehicle_state.h"
#define DRS_BUTTON_IDX (6)
#define DRS_PRESS_WAIT_CYCLES (1000)
#define DRS_PRESS_WAIT_CYCLES (10)
static int drs_press_buf_cycles = 0;
void ui_thread_entry(ULONG _) {
@ -50,13 +49,15 @@ void ui_thread_entry(ULONG _) {
tx_event_flags_set(&gui_update_events, GUI_UPDATE_NEXT_SCREEN, TX_OR);
}
// check for DRS button
if (button_states[DRS_BUTTON_IDX] == GPIO_PIN_SET) {
// Set leftmost led to blue to indicate DRS activation
drs_press_buf_cycles = DRS_PRESS_WAIT_CYCLES;
led_set(0, 0, 0, 255);
} if (drs_press_buf_cycles < 0) {
vehicle_state.drs_led_active = 1;
}
if (drs_press_buf_cycles < 0) {
// Assume no longer active, turn off
led_set(0, 0, 0, 0);
vehicle_state.drs_led_active = 0;
} else if (drs_press_buf_cycles >= 0) {
drs_press_buf_cycles--;
}