fix DRS LED flicker
This commit is contained in:
parent
80e38cc036
commit
0913466808
@ -183,6 +183,8 @@ typedef struct {
|
|||||||
ConePosition cone_pos[NUM_CONES];
|
ConePosition cone_pos[NUM_CONES];
|
||||||
|
|
||||||
ParamType last_param_confirmed;
|
ParamType last_param_confirmed;
|
||||||
|
|
||||||
|
uint8_t drs_led_active;
|
||||||
} VehicleState;
|
} VehicleState;
|
||||||
|
|
||||||
extern VehicleState vehicle_state;
|
extern VehicleState vehicle_state;
|
||||||
|
@ -88,7 +88,10 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
|
|||||||
float speed =
|
float speed =
|
||||||
(vehicle_state.speed - LED_SPEED_MIN) / (LED_SPEED_MAX - LED_SPEED_MIN);
|
(vehicle_state.speed - LED_SPEED_MIN) / (LED_SPEED_MAX - LED_SPEED_MIN);
|
||||||
float num_leds_exact = speed * N_LEDS;
|
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;
|
int num_leds = num_leds_exact;
|
||||||
float num_leds_frac = num_leds_exact - num_leds;
|
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;
|
uint8_t r, g, b;
|
||||||
led_hsv_to_rgb(hue, 1.0f, 1.0f, &r, &g, &b);
|
led_hsv_to_rgb(hue, 1.0f, 1.0f, &r, &g, &b);
|
||||||
|
|
||||||
// Fully illuminate first n LEDs
|
// Fully illuminate first n LEDs (start at second LED if DRS is active)
|
||||||
for (int i = 0; i < num_leds; i++) {
|
for (int i = vehicle_state.drs_led_active; i < num_leds; i++) {
|
||||||
led_set(i, r, g, b);
|
led_set(i, r, g, b);
|
||||||
}
|
}
|
||||||
// Partially illuminate n+1th LED
|
// Partially illuminate n+1th LED if DRS LED is not active or n+1th led is
|
||||||
if (num_leds < N_LEDS) {
|
// 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_hsv_to_rgb(hue, 1.0f, num_leds_frac, &r, &g, &b);
|
||||||
led_set(num_leds, 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++) {
|
for (int i = num_leds + 1; i < N_LEDS; i++) {
|
||||||
led_set(i, 0, 0, 0);
|
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");
|
asm("nop" ::: "memory");
|
||||||
}
|
}
|
||||||
HAL_GPIO_WritePin(LED_LE_GPIO_Port, LED_LE_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(LED_LE_GPIO_Port, LED_LE_Pin, GPIO_PIN_RESET);
|
||||||
for (size_t i = 0; i < 10; i++) {
|
// for (size_t i = 0; i < 10; i++) {
|
||||||
asm("nop" ::: "memory");
|
// asm("nop" ::: "memory");
|
||||||
}
|
// }
|
||||||
HAL_SPI_Transmit_DMA(hspi, (const uint8_t *)&led_buf[led_buf_idx], 3);
|
HAL_SPI_Transmit_DMA(hspi, (const uint8_t *)&led_buf[led_buf_idx], 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,10 @@
|
|||||||
#include "stm32h7xx_hal_gpio.h"
|
#include "stm32h7xx_hal_gpio.h"
|
||||||
#include "tx_api.h"
|
#include "tx_api.h"
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
|
#include "vehicle_state.h"
|
||||||
#include "leds.h"
|
|
||||||
|
|
||||||
#define DRS_BUTTON_IDX (6)
|
#define DRS_BUTTON_IDX (6)
|
||||||
#define DRS_PRESS_WAIT_CYCLES (1000)
|
#define DRS_PRESS_WAIT_CYCLES (10)
|
||||||
static int drs_press_buf_cycles = 0;
|
static int drs_press_buf_cycles = 0;
|
||||||
|
|
||||||
void ui_thread_entry(ULONG _) {
|
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);
|
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) {
|
if (button_states[DRS_BUTTON_IDX] == GPIO_PIN_SET) {
|
||||||
// Set leftmost led to blue to indicate DRS activation
|
// Set leftmost led to blue to indicate DRS activation
|
||||||
drs_press_buf_cycles = DRS_PRESS_WAIT_CYCLES;
|
drs_press_buf_cycles = DRS_PRESS_WAIT_CYCLES;
|
||||||
led_set(0, 0, 0, 255);
|
vehicle_state.drs_led_active = 1;
|
||||||
} if (drs_press_buf_cycles < 0) {
|
}
|
||||||
|
if (drs_press_buf_cycles < 0) {
|
||||||
// Assume no longer active, turn off
|
// 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) {
|
} else if (drs_press_buf_cycles >= 0) {
|
||||||
drs_press_buf_cycles--;
|
drs_press_buf_cycles--;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user