Duty cycle bar displaying
This commit is contained in:
parent
fda9a1add3
commit
38d8a6eaa1
@ -13,10 +13,11 @@ void run_dashboard_loop() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
draw_battery(654, i * 100 / 4, 1321, 343);
|
draw_battery(654, i * 100 / 4, 1321, 343);
|
||||||
draw_speed(i * 1000 / 2);
|
draw_speed(i * 1000 / 4);
|
||||||
|
draw_power_bars(1000 - (int16_t) i * 1000 / 200);
|
||||||
|
|
||||||
HAL_Delay(100);
|
HAL_Delay(50);
|
||||||
if (i == 200) {
|
if (i == 400) {
|
||||||
i = 0;
|
i = 0;
|
||||||
} else {
|
} else {
|
||||||
i++;
|
i++;
|
||||||
@ -172,11 +173,43 @@ void draw_battery(
|
|||||||
|
|
||||||
// Displays the power bars at the top
|
// Displays the power bars at the top
|
||||||
// Duty from COMM_GET_VALUES, scale 1000
|
// Duty from COMM_GET_VALUES, scale 1000
|
||||||
void draw_power_bars(int16_t duty) {
|
uint16_t last_width = 0;
|
||||||
|
uint8_t last_regen = 0;
|
||||||
|
void draw_power_bars(int16_t dutyy) {
|
||||||
uint16_t offset = LCD_WIDTH / 2;
|
uint16_t offset = LCD_WIDTH / 2;
|
||||||
uint16_t max_width = LCD_WIDTH / 2;
|
uint16_t max_width = LCD_WIDTH / 2;
|
||||||
|
uint8_t regen = dutyy < 0;
|
||||||
|
uint16_t duty = regen ? -dutyy : dutyy;
|
||||||
|
duty *= 1/0.8; // 80% duty means the bar is at 100%
|
||||||
|
uint16_t width = ((float) duty / 1000.0) * max_width;
|
||||||
|
|
||||||
uint16_t width = (duty / 100) * max_width / 10;
|
uint16_t last_origin = last_regen ? offset - last_width : offset;
|
||||||
|
uint16_t origin = regen ? offset - width : offset;
|
||||||
|
uint16_t color = regen ? COLOR_ERROR : COLOR_SUCCESS;
|
||||||
|
|
||||||
|
if(regen != last_regen) {
|
||||||
|
LCD_Draw_Rectangle(last_origin, 0, last_width, 20, COLOR_BG);
|
||||||
|
LCD_Draw_Rectangle(origin, 0, width, 20, color);
|
||||||
|
last_regen = regen;
|
||||||
|
last_width = width;
|
||||||
|
|
||||||
|
}else if (width != last_width){
|
||||||
|
if(regen) {
|
||||||
|
if (last_origin < origin) {
|
||||||
|
LCD_Draw_Rectangle(last_origin, 0, origin - last_origin, 20, COLOR_BG);
|
||||||
|
}else {
|
||||||
|
LCD_Draw_Rectangle(origin, 0, last_origin - origin, 20, color);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (last_width < width) {
|
||||||
|
LCD_Draw_Rectangle(origin + last_width, 0, width - last_width, 20, color);
|
||||||
|
}else {
|
||||||
|
LCD_Draw_Rectangle(origin + width, 0, last_width - width, 20, COLOR_BG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last_width = width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Displays the huge speed counter with avg and max values.
|
// Displays the huge speed counter with avg and max values.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user