Power displaying
This commit is contained in:
parent
38d8a6eaa1
commit
88c00aacbd
@ -14,7 +14,9 @@ void run_dashboard_loop() {
|
||||
|
||||
draw_battery(654, i * 100 / 4, 1321, 343);
|
||||
draw_speed(i * 1000 / 4);
|
||||
draw_power_bars(1000 - (int16_t) i * 1000 / 200);
|
||||
int16_t duty = 1000 - (int16_t) i * 1000 / 200;
|
||||
draw_power_bars(duty);
|
||||
draw_power(100 * i / 20 * (duty < 0 ? -1 : 1), duty, 60 * 10);
|
||||
|
||||
HAL_Delay(50);
|
||||
if (i == 400) {
|
||||
@ -52,6 +54,9 @@ void LCD_DrawHollowRoundRect(
|
||||
uint16_t fill_color,
|
||||
uint8_t do_fill);
|
||||
|
||||
#define LEFT_CENTER_COL1 38
|
||||
#define LEFT_CENTER_COL2 116
|
||||
#define RIGHT_CENTER 400
|
||||
void draw_init() {
|
||||
LCD_Fill_Screen(COLOR_OFF, 1);
|
||||
LCD_Fill_Screen(COLOR_BG, 0);
|
||||
@ -112,7 +117,7 @@ void draw_battery(
|
||||
filled_bar_width = 6;// Must be at least the size of the border radius.
|
||||
}
|
||||
uint16_t filled_bar_end_x = 4 + 2 + filled_bar_width;
|
||||
uint16_t text_y_12 = LCD_HEIGHT - 6 - (22 - 16) / 2;
|
||||
//uint16_t text_y_12 = LCD_HEIGHT - 6 - (22 - 16) / 2;
|
||||
uint16_t text_y_14 = LCD_HEIGHT - 6 - (22 - 18) / 2;
|
||||
|
||||
char voltage_text[8];
|
||||
@ -202,7 +207,8 @@ void draw_power_bars(int16_t dutyy) {
|
||||
}
|
||||
} else {
|
||||
if (last_width < width) {
|
||||
LCD_Draw_Rectangle(origin + last_width, 0, width - last_width, 20, color);
|
||||
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);
|
||||
}
|
||||
@ -214,13 +220,13 @@ void draw_power_bars(int16_t dutyy) {
|
||||
|
||||
// Displays the huge speed counter with avg and max values.
|
||||
// Speed from COMM_GET_VALUES_SETUP, scale 1000
|
||||
uint32_t last_speed = 0;
|
||||
uint32_t last_speed = 30;
|
||||
uint32_t max_speed = 0;
|
||||
uint32_t last_avg_speed = 0;
|
||||
uint32_t last_avg_speed = 30;
|
||||
uint32_t avg_speed_tot = 0;// You need to ride super fast for a super long time for it to overflow ;)
|
||||
uint32_t avg_speed_count = 0;
|
||||
void draw_speed(int32_t speedd) {
|
||||
uint16_t erase_width = 90;// width to erase from center
|
||||
|
||||
uint32_t speed = speedd < 0 ? -speedd / 1000 : speedd / 1000;
|
||||
if (speed >= 100) {
|
||||
speed = 99;
|
||||
@ -244,6 +250,7 @@ void draw_speed(int32_t speedd) {
|
||||
// Draw
|
||||
if (last_speed != speed) {
|
||||
last_speed = speed;
|
||||
uint16_t erase_width = 85;// width to erase from center
|
||||
char speed_text[4];
|
||||
sprintf(speed_text, "%lu", speed);
|
||||
LCD_Draw_Rectangle(LCD_WIDTH / 2 - erase_width, 22, 2 * erase_width, 110,
|
||||
@ -254,6 +261,7 @@ void draw_speed(int32_t speedd) {
|
||||
|
||||
if (update_stats) {
|
||||
char stats_text[20];
|
||||
uint16_t erase_width = 90;// width to erase from center
|
||||
sprintf(stats_text, "avg: %lu max: %lu", avg_speed, max_speed);
|
||||
LCD_Draw_Rectangle(LCD_WIDTH / 2 - erase_width, 140, 2 * erase_width, 25,
|
||||
COLOR_BG);
|
||||
@ -262,11 +270,59 @@ void draw_speed(int32_t speedd) {
|
||||
}
|
||||
}
|
||||
|
||||
int16_t last_current = 99;
|
||||
uint16_t last_duty = 99;
|
||||
int32_t last_power = 1000;
|
||||
// Displays Current, Duty, Watts
|
||||
// Current from COMM_GET_VALUES, scale 100
|
||||
// Duty from COMM_GET_VALUES, scale 1000
|
||||
// Input voltage from COMM_GET_VALUES, scale 10
|
||||
void draw_power(int32_t amps, int16_t duty, int16_t voltage) {
|
||||
void draw_power(int32_t current_i, int16_t duty_i, int16_t voltage_i) {
|
||||
|
||||
int16_t current = current_i / 100;
|
||||
uint16_t duty = duty_i < 0 ? -duty_i / 10 : duty_i / 10;
|
||||
int32_t power = ((int32_t) voltage_i) * ((int32_t) current_i) / 10000 * 10;
|
||||
|
||||
if (current != last_current) {
|
||||
last_current = current;
|
||||
if(current >= 100) {
|
||||
current = 99;
|
||||
}else if(current <= -100){
|
||||
current = -99;
|
||||
}
|
||||
|
||||
char text[8];
|
||||
sprintf(text, "%dA", current);
|
||||
LCD_Draw_Rectangle(LEFT_CENTER_COL1 - 38, 30, 2 * 39, 35, COLOR_BG);
|
||||
GFX_DrawText(LEFT_CENTER_COL1, 60, text, &monomaniacone20pt,
|
||||
COLOR_PRIMARY, COLOR_BG, 1, -2);
|
||||
}
|
||||
if (duty != last_duty) {
|
||||
last_duty = duty;
|
||||
if (duty >= 100) {
|
||||
duty = 99;
|
||||
}
|
||||
|
||||
char text[8];
|
||||
sprintf(text, "%u%%", duty);
|
||||
LCD_Draw_Rectangle(LEFT_CENTER_COL2 - 39, 30, 2 * 39, 35, COLOR_BG);
|
||||
GFX_DrawText(LEFT_CENTER_COL2, 60, text, &monomaniacone20pt,
|
||||
COLOR_PRIMARY, COLOR_BG, 1, -2);
|
||||
}
|
||||
if (power != last_power) {
|
||||
last_power = power;
|
||||
if (power >= 10000) {
|
||||
power = 9999;
|
||||
}else if(power <= -10000) {
|
||||
power = -9999;
|
||||
}
|
||||
|
||||
char text[10];
|
||||
sprintf(text, "%dW", power);
|
||||
LCD_Draw_Rectangle(RIGHT_CENTER - 70, 30, 2 * 70, 35, COLOR_BG);
|
||||
GFX_DrawText(RIGHT_CENTER, 60, text, &monomaniacone20pt,
|
||||
COLOR_PRIMARY, COLOR_BG, 1, -2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user