Setup variable refresh time for different UI components

This commit is contained in:
Clément Grennerat 2025-09-16 23:52:53 +02:00
parent 93a3dd8afd
commit 2c419094ae
2 changed files with 28 additions and 9 deletions

View File

@ -18,7 +18,9 @@
void run_dashboard_loop(); void run_dashboard_loop();
void init(); 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(); void update_adc();

View File

@ -57,15 +57,26 @@ void run_dashboard_loop() {
LCD_Fill_Screen(COLOR_OFF, 1); LCD_Fill_Screen(COLOR_OFF, 1);
LCD_Fill_Screen(COLOR_BG, 0); LCD_Fill_Screen(COLOR_BG, 0);
HAL_Delay(1000); HAL_Delay(1000);
uint8_t i = 0;
while (1) { 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(); 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 // UART send 0201 2F D58D 03
uint8_t packet[1]; uint8_t packet[1];
packet[0] = 0x2F;// COMM_GET_VALUES_SETUP packet[0] = 0x2F;// COMM_GET_VALUES_SETUP
@ -115,19 +126,25 @@ void update_values() {
if (!initialized) { if (!initialized) {
draw_init(); draw_init();
initialized = 1; initialized = 1;
refresh_slow = 1;
refresh_mid = 1;
} }
//speed = (int32_t) (((float) speed) / 1.609344); //speed = (int32_t) (((float) speed) / 1.609344);
//float wheel_diameter = 0.246; // in meter //float wheel_diameter = 0.246; // in meter
//speed = ((float) rpm) * 3.14159265359 * wheel_diameter * 60 / 1000; //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_power_bars(duty_cycle);
if (refresh_mid) {
draw_speed((int32_t) (((float) speed) * 3.6), fault_code); draw_speed((int32_t) (((float) speed) * 3.6), fault_code);
draw_power(current_in_tot, duty_cycle, input_voltage_filtered); 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); draw_temps(temp_fet, temp_motor);
} }
}
void update_adc() { void update_adc() {
// Replies to 0x24 0x65 for command id: 0, 1, 18, 19, 1B, 1D, C9, CA // Replies to 0x24 0x65 for command id: 0, 1, 18, 19, 1B, 1D, C9, CA
// 0 1 24 25 27 29 201 202 // 0 1 24 25 27 29 201 202