Fix float casting, otherwise it is always 0.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-09-27 19:37:57 +02:00
parent e32870bedb
commit 50e54ed984
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

@ -50,17 +50,21 @@ void led_blinking_task() {
uint32_t led_on = (led_mode & LED_ON_MASK) >> LED_ON_SHIFT;
// how far in the current state from 0 - 1
float progress = (board_millis() - start_ms) / (stop_ms - start_ms);
float progress = 0;
if (!state){
if (stop_ms > start_ms) {
progress = (float)(board_millis() - start_ms) / (stop_ms - start_ms);
}
if (!state) {
// fading down so 1 -> 0
progress = 1 - progress;
progress = 1. - progress;
}
// maybe quick return if progress didn't changed much ?
// current one from 0 - 1
float led_brightness = (led_max_brightness / MAX_BTNESS) * progress;
// current one from 0 - 1
float led_brightness = ((float)led_max_brightness / MAX_BTNESS) * progress;
led_driver_color(led_color, led_brightness);