Endurance LEDs

This commit is contained in:
Jasper Blanckenburg 2024-06-12 21:05:13 +02:00
parent 0076387f21
commit 4c2c277fef
1 changed files with 10 additions and 24 deletions

View File

@ -80,31 +80,17 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
continue;
}
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));
int num_leds = num_leds_exact;
float num_leds_frac = num_leds_exact - num_leds;
float hue =
LED_SPEED_HUE_MIN - speed * (LED_SPEED_HUE_MIN - LED_SPEED_HUE_MAX);
hue = fmin(LED_SPEED_HUE_MIN, fmax(LED_SPEED_HUE_MAX, hue));
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++) {
led_set(i, r, g, b);
for (int i = 0; i <= 3; i++) {
int led_limit = (4 - i) * 3; // 3% per LED
int red = (vehicle_state.bat_delta_last >= led_limit) ? 0xFF : 0;
led_set(i, red, 0, 0);
}
// Partially illuminate n+1th LED
if (num_leds < N_LEDS) {
led_hsv_to_rgb(hue, 1.0f, num_leds_frac, &r, &g, &b);
led_set(num_leds, r, g, b);
}
// Turn off all other LEDs
for (int i = num_leds + 1; i < N_LEDS; i++) {
led_set(i, 0, 0, 0);
int blue = (vehicle_state.drs_active) ? 0xFF : 0;
led_set(4, 0, 0, blue);
for (int i = 5; i <= 9; i++) {
int led_limit = -((i - 4) * 3); // 3% per LED
int green = (vehicle_state.bat_delta_last <= led_limit) ? 0xFF : 0;
led_set(i, 0, green, 0);
}
}
}