From 2c419094ae20535949b60283b1d31ecfb9b2247b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Grennerat?= Date: Tue, 16 Sep 2025 23:52:53 +0200 Subject: [PATCH] Setup variable refresh time for different UI components --- Core/Inc/dashboard.h | 4 +++- Core/Src/dashboard.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Core/Inc/dashboard.h b/Core/Inc/dashboard.h index 02b2dca..3fbcde6 100644 --- a/Core/Inc/dashboard.h +++ b/Core/Inc/dashboard.h @@ -18,7 +18,9 @@ void run_dashboard_loop(); void init(); -void update_values(); +// refresh_slow = 0 if it should not refresh the low-refresh rate information. +// refresh_mid = 0 if it should not refresh the mid-refresh rate information. +void update_values(uint8_t refresh_slow, uint8_t refresh_mid); void update_adc(); diff --git a/Core/Src/dashboard.c b/Core/Src/dashboard.c index 9f809b9..c986ea2 100644 --- a/Core/Src/dashboard.c +++ b/Core/Src/dashboard.c @@ -57,15 +57,26 @@ void run_dashboard_loop() { LCD_Fill_Screen(COLOR_OFF, 1); LCD_Fill_Screen(COLOR_BG, 0); HAL_Delay(1000); + + uint8_t i = 0; while (1) { - update_values(); + uint8_t refresh_slow = (i % 10) == 0; + uint8_t refresh_mid = (i % 3) == 0; + update_values(refresh_slow, refresh_mid); update_adc(); - HAL_Delay(100); + + HAL_Delay(50); + i++; + if (i == 120) { + i = 0; + } } } -void update_values() { +// refresh_slow = 0 if it should not refresh the low-refresh rate information. +// refresh_mid = 0 if it should not refresh the mid-refresh rate information. +void update_values(uint8_t refresh_slow, uint8_t refresh_mid) { // UART send 0201 2F D58D 03 uint8_t packet[1]; packet[0] = 0x2F;// COMM_GET_VALUES_SETUP @@ -115,18 +126,24 @@ void update_values() { if (!initialized) { draw_init(); initialized = 1; + refresh_slow = 1; + refresh_mid = 1; } //speed = (int32_t) (((float) speed) / 1.609344); //float wheel_diameter = 0.246; // in meter //speed = ((float) rpm) * 3.14159265359 * wheel_diameter * 60 / 1000; - draw_battery(input_voltage_filtered, battery_level, distance_abs, - distance_life); draw_power_bars(duty_cycle); - draw_speed((int32_t) (((float) speed) * 3.6), fault_code); - draw_power(current_in_tot, duty_cycle, input_voltage_filtered); - draw_temps(temp_fet, temp_motor); + if (refresh_mid) { + draw_speed((int32_t) (((float) speed) * 3.6), fault_code); + draw_power(current_in_tot, duty_cycle, input_voltage_filtered); + } + if (refresh_slow) { + draw_battery(input_voltage_filtered, battery_level, distance_abs, + distance_life); + draw_temps(temp_fet, temp_motor); + } } void update_adc() { // Replies to 0x24 0x65 for command id: 0, 1, 18, 19, 1B, 1D, C9, CA