diff --git a/.cproject b/.cproject
index 8a69f36..036e307 100644
--- a/.cproject
+++ b/.cproject
@@ -22,7 +22,8 @@
-
+
+
@@ -95,26 +96,26 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
-
-
+
+
-
-
-
+
+
-
+
diff --git a/Core/Inc/dashboard.h b/Core/Inc/dashboard.h
index 19be1d9..5a58aef 100644
--- a/Core/Inc/dashboard.h
+++ b/Core/Inc/dashboard.h
@@ -7,8 +7,8 @@
#define COLOR_SECONDARY 0x667f
#define COLOR_SUCCESS 0x3766
#define COLOR_ERROR 0xf226
-#define COLOR_BG 0xFFFF
-#define COLOR_FG 0x0000
+#define COLOR_FG 0xFFFF
+#define COLOR_BG 0x0000
#define COLOR_OFF 0x0000
diff --git a/Core/Inc/font.h b/Core/Inc/font.h
index 48824fd..9cb9092 100644
--- a/Core/Inc/font.h
+++ b/Core/Inc/font.h
@@ -41,7 +41,7 @@ void GFX_DrawChar(
uint16_t GFX_GetTextWidth(const char *text, const GFXfont *font, int8_t letter_spacing);
// Alignment: 0 => Left, 1 => Center, 2 => Right
-void GFX_DrawText(
+uint16_t GFX_DrawText(
uint16_t x,
uint16_t y,
const char *text,
diff --git a/Core/Src/LCD_driver.c b/Core/Src/LCD_driver.c
index b7a19a8..5d5c2bc 100644
--- a/Core/Src/LCD_driver.c
+++ b/Core/Src/LCD_driver.c
@@ -96,7 +96,6 @@ void LCD_Init(void) {
LCD_Write_Command(0x36);
LCD_Write_Data(0b00111100);
-
// Exit sleep
LCD_Write_Command(0x11);
HAL_Delay(150);
@@ -375,7 +374,6 @@ void LCD_Draw_Filled_Rectangle_Coord(
// while ((SPI3->SR & SPI_SR_BSY) != 0);//Attendre fin envoi trame
// CS_OFF;
//}
-
void LCD_DrawHollowRoundRect(
uint16_t x,
uint16_t y,
@@ -388,247 +386,260 @@ void LCD_DrawHollowRoundRect(
uint16_t fill_color,
uint8_t do_fill) {
- uint8_t radius_top_lines = radius_top ? radius_top - 1 : 0;
- uint8_t radius_bottom_lines = radius_bottom ? radius_bottom - 1 : 0;
+ uint8_t radius_top_lines = radius_top ? radius_top - 1 : 0;
+ uint8_t radius_bottom_lines = radius_bottom ? radius_bottom - 1 : 0;
- // Fill interior if requested
- if (do_fill) {
- uint16_t x_inner, y_inner, w_inner, h_inner;
- uint8_t radius_top_fill, radius_bottom_fill;
+// Fill interior if requested
+ if (do_fill) {
+ uint16_t x_inner, y_inner, w_inner, h_inner;
+ uint8_t radius_top_fill, radius_bottom_fill;
- if (border_width == 0) {
- // Full area fill (no border)
- x_inner = x;
- y_inner = y;
- w_inner = w;
- h_inner = h;
- radius_top_fill = radius_top;
- radius_bottom_fill = radius_bottom;
- } else {
- // Interior area (inside border)
- x_inner = x + border_width;
- y_inner = y + border_width;
- w_inner = (w > 2 * border_width) ? w - 2 * border_width : 0;
- h_inner = (h > 2 * border_width) ? h - 2 * border_width : 0;
+ if (border_width == 0) {
+// Full area fill (no border)
+ x_inner = x;
+ y_inner = y;
+ w_inner = w;
+ h_inner = h;
+ radius_top_fill = radius_top;
+ radius_bottom_fill = radius_bottom;
+ } else {
+// Interior area (inside border)
+ x_inner = x + border_width;
+ y_inner = y + border_width;
+ w_inner = (w > 2 * border_width) ? w - 2 * border_width : 0;
+ h_inner = (h > 2 * border_width) ? h - 2 * border_width : 0;
- radius_top_fill = (radius_top > border_width) ? radius_top - border_width : 0;
- radius_bottom_fill = (radius_bottom > border_width) ? radius_bottom - border_width : 0;
- }
+ radius_top_fill =
+ (radius_top > border_width) ? radius_top - border_width : 0;
+ radius_bottom_fill =
+ (radius_bottom > border_width) ? radius_bottom - border_width : 0;
+ }
- // Draw filled interior (only if dimensions are valid)
- if (w_inner > 0 && h_inner > 0) {
- uint16_t x_central = x_inner + radius_top_fill;
- uint16_t y_central = y;
- uint16_t w_central = w_inner - 2*radius_top_fill;
- uint16_t h_central = h;
- LCD_Draw_Rectangle(x_central, y_central, w_central, h_central, fill_color);
-
- uint16_t x_left = x;
- uint16_t y_left = y_inner + radius_top_fill;
- uint16_t w_left = x_inner + radius_top_fill + 1 - x;
- uint16_t h_left = h_inner - radius_bottom_fill - radius_top_fill;
- LCD_Draw_Rectangle(x_left, y_left, w_left, h_left, fill_color);
+// Draw filled interior (only if dimensions are valid)
+ if (w_inner > 0 && h_inner > 0) {
+ uint16_t x_central = x_inner + radius_top_fill;
+ uint16_t y_central = y;
+ if (w_inner > 2 * radius_top_fill) {
+ uint16_t w_central = w_inner - 2 * radius_top_fill;
+ uint16_t h_central = h;
+ LCD_Draw_Rectangle(x_central, y_central, w_central, h_central,
+ fill_color);
+ }
+ uint16_t x_left = x;
+ uint16_t y_left = y_inner + radius_top_fill;
+ if (x_inner + radius_top_fill + 1 > x) {
+ uint16_t w_left = x_inner + radius_top_fill + 1 - x;
+ if (h_inner > radius_bottom_fill + radius_top_fill) {
+ uint16_t h_left = h_inner - radius_bottom_fill - radius_top_fill;
+ LCD_Draw_Rectangle(x_left, y_left, w_left, h_left, fill_color);
+ if (x + w > w_left) {
uint16_t x_right = x + w - w_left;
LCD_Draw_Rectangle(x_right, y_left, w_left, h_left, fill_color);
-
-
- // Top-left rounded corner
- if (radius_top_fill > 0) {
- uint32_t r_sq = (uint32_t)radius_top_fill * radius_top_fill;
- int16_t center_x = x_inner + radius_top_fill - 1;
- int16_t center_y = y_inner + radius_top_fill - 1;
-
- for (int16_t i = x_inner; i < x_inner + radius_top_fill; i++) {
- for (int16_t j = y_inner; j < y_inner + radius_top_fill; j++) {
- int16_t dx = center_x - i;
- int16_t dy = center_y - j;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= r_sq) {
- LCD_Draw_Pixel(i, j, fill_color);
- }
- }
- }
- }
-
- // Top-right rounded corner
- if (radius_top_fill > 0) {
- uint32_t r_sq = (uint32_t)radius_top_fill * radius_top_fill;
- int16_t center_x = x_inner + w_inner - radius_top_fill;
- int16_t center_y = y_inner + radius_top_fill - 1;
-
- for (int16_t i = x_inner + w_inner - radius_top_fill; i < x_inner + w_inner; i++) {
- for (int16_t j = y_inner; j < y_inner + radius_top_fill; j++) {
- int16_t dx = i - center_x;
- int16_t dy = center_y - j;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= r_sq) {
- LCD_Draw_Pixel(i, j, fill_color);
- }
- }
- }
- }
-
- // Bottom-left rounded corner
- if (radius_bottom_fill > 0) {
- uint32_t r_sq = (uint32_t)radius_bottom_fill * radius_bottom_fill;
- int16_t center_x = x_inner + radius_bottom_fill - 1;
- int16_t center_y = y_inner + h_inner - radius_bottom_fill;
-
- for (int16_t i = x_inner; i < x_inner + radius_bottom_fill; i++) {
- for (int16_t j = y_inner + h_inner - radius_bottom_fill; j < y_inner + h_inner; j++) {
- int16_t dx = center_x - i;
- int16_t dy = j - center_y;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= r_sq) {
- LCD_Draw_Pixel(i, j, fill_color);
- }
- }
- }
- }
-
- // Bottom-right rounded corner
- if (radius_bottom_fill > 0) {
- uint32_t r_sq = (uint32_t)radius_bottom_fill * radius_bottom_fill;
- int16_t center_x = x_inner + w_inner - radius_bottom_fill;
- int16_t center_y = y_inner + h_inner - radius_bottom_fill;
-
- for (int16_t i = x_inner + w_inner - radius_bottom_fill; i < x_inner + w_inner; i++) {
- for (int16_t j = y_inner + h_inner - radius_bottom_fill; j < y_inner + h_inner; j++) {
- int16_t dx = i - center_x;
- int16_t dy = j - center_y;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= r_sq) {
- LCD_Draw_Pixel(i, j, fill_color);
- }
- }
- }
- }
+ }
}
+
+ }
+
+// Top-left rounded corner
+ if (radius_top_fill > 0) {
+ uint32_t r_sq = (uint32_t) radius_top_fill * radius_top_fill;
+ int16_t center_x = x_inner + radius_top_fill - 1;
+ int16_t center_y = y_inner + radius_top_fill - 1;
+
+ for (int16_t i = x_inner; i < x_inner + radius_top_fill; i++) {
+ for (int16_t j = y_inner; j < y_inner + radius_top_fill; j++) {
+ int16_t dx = center_x - i;
+ int16_t dy = center_y - j;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= r_sq) {
+ LCD_Draw_Pixel(i, j, fill_color);
+ }
+ }
+ }
+ }
+
+// Top-right rounded corner
+ if (radius_top_fill > 0) {
+ uint32_t r_sq = (uint32_t) radius_top_fill * radius_top_fill;
+ int16_t center_x = x_inner + w_inner - radius_top_fill;
+ int16_t center_y = y_inner + radius_top_fill - 1;
+
+ for (int16_t i = x_inner + w_inner - radius_top_fill;
+ i < x_inner + w_inner; i++) {
+ for (int16_t j = y_inner; j < y_inner + radius_top_fill; j++) {
+ int16_t dx = i - center_x;
+ int16_t dy = center_y - j;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= r_sq) {
+ LCD_Draw_Pixel(i, j, fill_color);
+ }
+ }
+ }
+ }
+
+// Bottom-left rounded corner
+ if (radius_bottom_fill > 0) {
+ uint32_t r_sq = (uint32_t) radius_bottom_fill * radius_bottom_fill;
+ int16_t center_x = x_inner + radius_bottom_fill - 1;
+ int16_t center_y = y_inner + h_inner - radius_bottom_fill;
+
+ for (int16_t i = x_inner; i < x_inner + radius_bottom_fill; i++) {
+ for (int16_t j = y_inner + h_inner - radius_bottom_fill;
+ j < y_inner + h_inner; j++) {
+ int16_t dx = center_x - i;
+ int16_t dy = j - center_y;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= r_sq) {
+ LCD_Draw_Pixel(i, j, fill_color);
+ }
+ }
+ }
+ }
+
+// Bottom-right rounded corner
+ if (radius_bottom_fill > 0) {
+ uint32_t r_sq = (uint32_t) radius_bottom_fill * radius_bottom_fill;
+ int16_t center_x = x_inner + w_inner - radius_bottom_fill;
+ int16_t center_y = y_inner + h_inner - radius_bottom_fill;
+
+ for (int16_t i = x_inner + w_inner - radius_bottom_fill;
+ i < x_inner + w_inner; i++) {
+ for (int16_t j = y_inner + h_inner - radius_bottom_fill;
+ j < y_inner + h_inner; j++) {
+ int16_t dx = i - center_x;
+ int16_t dy = j - center_y;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= r_sq) {
+ LCD_Draw_Pixel(i, j, fill_color);
+ }
+ }
+ }
+ }
+ }
+ }
+
+// Draw border only if requested (border_width > 0)
+ if (border_width > 0) {
+// Top horizontal border segment
+ if (w > 2 * radius_top_lines) {
+ uint16_t x_top = x + radius_top_lines;
+ uint16_t y_top = y;
+ uint16_t w_top = w - 2 * radius_top_lines;
+ uint16_t h_top = border_width;
+ LCD_Draw_Rectangle(x_top, y_top, w_top, h_top, color);
}
- // Draw border only if requested (border_width > 0)
- if (border_width > 0) {
- // Top horizontal border segment
- if (w > 2 * radius_top_lines) {
- uint16_t x_top = x + radius_top_lines;
- uint16_t y_top = y;
- uint16_t w_top = w - 2 * radius_top_lines;
- uint16_t h_top = border_width;
- LCD_Draw_Rectangle(x_top, y_top, w_top, h_top, color);
- }
-
- // Bottom horizontal border segment
- if (w > 2 * radius_bottom_lines) {
- uint16_t x_bottom = x + radius_bottom_lines;
- uint16_t y_bottom = y + h - border_width;
- uint16_t w_bottom = w - 2 * radius_bottom_lines;
- uint16_t h_bottom = border_width;
- LCD_Draw_Rectangle(x_bottom, y_bottom, w_bottom, h_bottom, color);
- }
-
- // Left vertical border segment
- if (h > radius_top_lines + radius_bottom_lines) {
- uint16_t x_left = x;
- uint16_t y_left = y + radius_top_lines;
- uint16_t w_left = border_width;
- uint16_t h_left = h - radius_top_lines - radius_bottom_lines;
- LCD_Draw_Rectangle(x_left, y_left, w_left, h_left, color);
- }
-
- // Right vertical border segment
- if (h > radius_top_lines + radius_bottom_lines) {
- uint16_t x_right = x + w - border_width;
- uint16_t y_right = y + radius_top_lines;
- uint16_t w_right = border_width;
- uint16_t h_right = h - radius_top_lines - radius_bottom_lines;
- LCD_Draw_Rectangle(x_right, y_right, w_right, h_right, color);
- }
-
- // Top-left rounded corner
- if (radius_top > 0) {
- int16_t inner_radius = radius_top - border_width;
- if (inner_radius < 0) inner_radius = 0;
- uint32_t inner_sq = (uint32_t)inner_radius * inner_radius;
- uint32_t outer_sq = (uint32_t)radius_top * radius_top;
- int16_t center_x = x + radius_top - 1;
- int16_t center_y = y + radius_top - 1;
-
- for (int16_t i = x; i < x + radius_top; i++) {
- for (int16_t j = y; j < y + radius_top; j++) {
- int16_t dx = center_x - i;
- int16_t dy = center_y - j;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= outer_sq && dist_sq > inner_sq) {
- LCD_Draw_Pixel(i, j, color);
- }
- }
- }
- }
-
- // Top-right rounded corner
- if (radius_top > 0) {
- int16_t inner_radius = radius_top - border_width;
- if (inner_radius < 0) inner_radius = 0;
- uint32_t inner_sq = (uint32_t)inner_radius * inner_radius;
- uint32_t outer_sq = (uint32_t)radius_top * radius_top;
- int16_t center_x = x + w - radius_top;
- int16_t center_y = y + radius_top - 1;
-
- for (int16_t i = x + w - radius_top; i < x + w; i++) {
- for (int16_t j = y; j < y + radius_top; j++) {
- int16_t dx = i - center_x;
- int16_t dy = center_y - j;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= outer_sq && dist_sq > inner_sq) {
- LCD_Draw_Pixel(i, j, color);
- }
- }
- }
- }
-
- // Bottom-left rounded corner
- if (radius_bottom > 0) {
- int16_t inner_radius = radius_bottom - border_width;
- if (inner_radius < 0) inner_radius = 0;
- uint32_t inner_sq = (uint32_t)inner_radius * inner_radius;
- uint32_t outer_sq = (uint32_t)radius_bottom * radius_bottom;
- int16_t center_x = x + radius_bottom - 1;
- int16_t center_y = y + h - radius_bottom;
-
- for (int16_t i = x; i < x + radius_bottom; i++) {
- for (int16_t j = y + h - radius_bottom; j < y + h; j++) {
- int16_t dx = center_x - i;
- int16_t dy = j - center_y;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= outer_sq && dist_sq > inner_sq) {
- LCD_Draw_Pixel(i, j, color);
- }
- }
- }
- }
-
- // Bottom-right rounded corner
- if (radius_bottom > 0) {
- int16_t inner_radius = radius_bottom - border_width;
- if (inner_radius < 0) inner_radius = 0;
- uint32_t inner_sq = (uint32_t)inner_radius * inner_radius;
- uint32_t outer_sq = (uint32_t)radius_bottom * radius_bottom;
- int16_t center_x = x + w - radius_bottom;
- int16_t center_y = y + h - radius_bottom;
-
- for (int16_t i = x + w - radius_bottom; i < x + w; i++) {
- for (int16_t j = y + h - radius_bottom; j < y + h; j++) {
- int16_t dx = i - center_x;
- int16_t dy = j - center_y;
- uint32_t dist_sq = (uint32_t)dx * dx + (uint32_t)dy * dy;
- if (dist_sq <= outer_sq && dist_sq > inner_sq) {
- LCD_Draw_Pixel(i, j, color);
- }
- }
- }
- }
+// Bottom horizontal border segment
+ if (w > 2 * radius_bottom_lines) {
+ uint16_t x_bottom = x + radius_bottom_lines;
+ uint16_t y_bottom = y + h - border_width;
+ uint16_t w_bottom = w - 2 * radius_bottom_lines;
+ uint16_t h_bottom = border_width;
+ LCD_Draw_Rectangle(x_bottom, y_bottom, w_bottom, h_bottom, color);
}
+
+// Left vertical border segment
+ if (h > radius_top_lines + radius_bottom_lines) {
+ uint16_t x_left = x;
+ uint16_t y_left = y + radius_top_lines;
+ uint16_t w_left = border_width;
+ uint16_t h_left = h - radius_top_lines - radius_bottom_lines;
+ LCD_Draw_Rectangle(x_left, y_left, w_left, h_left, color);
+ }
+
+// Right vertical border segment
+ if (h > radius_top_lines + radius_bottom_lines) {
+ uint16_t x_right = x + w - border_width;
+ uint16_t y_right = y + radius_top_lines;
+ uint16_t w_right = border_width;
+ uint16_t h_right = h - radius_top_lines - radius_bottom_lines;
+ LCD_Draw_Rectangle(x_right, y_right, w_right, h_right, color);
+ }
+
+// Top-left rounded corner
+ if (radius_top > 0) {
+ int16_t inner_radius = radius_top - border_width;
+ if (inner_radius < 0) inner_radius = 0;
+ uint32_t inner_sq = (uint32_t) inner_radius * inner_radius;
+ uint32_t outer_sq = (uint32_t) radius_top * radius_top;
+ int16_t center_x = x + radius_top - 1;
+ int16_t center_y = y + radius_top - 1;
+
+ for (int16_t i = x; i < x + radius_top; i++) {
+ for (int16_t j = y; j < y + radius_top; j++) {
+ int16_t dx = center_x - i;
+ int16_t dy = center_y - j;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= outer_sq && dist_sq > inner_sq) {
+ LCD_Draw_Pixel(i, j, color);
+ }
+ }
+ }
+ }
+
+// Top-right rounded corner
+ if (radius_top > 0) {
+ int16_t inner_radius = radius_top - border_width;
+ if (inner_radius < 0) inner_radius = 0;
+ uint32_t inner_sq = (uint32_t) inner_radius * inner_radius;
+ uint32_t outer_sq = (uint32_t) radius_top * radius_top;
+ int16_t center_x = x + w - radius_top;
+ int16_t center_y = y + radius_top - 1;
+
+ for (int16_t i = x + w - radius_top; i < x + w; i++) {
+ for (int16_t j = y; j < y + radius_top; j++) {
+ int16_t dx = i - center_x;
+ int16_t dy = center_y - j;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= outer_sq && dist_sq > inner_sq) {
+ LCD_Draw_Pixel(i, j, color);
+ }
+ }
+ }
+ }
+
+// Bottom-left rounded corner
+ if (radius_bottom > 0) {
+ int16_t inner_radius = radius_bottom - border_width;
+ if (inner_radius < 0) inner_radius = 0;
+ uint32_t inner_sq = (uint32_t) inner_radius * inner_radius;
+ uint32_t outer_sq = (uint32_t) radius_bottom * radius_bottom;
+ int16_t center_x = x + radius_bottom - 1;
+ int16_t center_y = y + h - radius_bottom;
+
+ for (int16_t i = x; i < x + radius_bottom; i++) {
+ for (int16_t j = y + h - radius_bottom; j < y + h; j++) {
+ int16_t dx = center_x - i;
+ int16_t dy = j - center_y;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= outer_sq && dist_sq > inner_sq) {
+ LCD_Draw_Pixel(i, j, color);
+ }
+ }
+ }
+ }
+
+// Bottom-right rounded corner
+ if (radius_bottom > 0) {
+ int16_t inner_radius = radius_bottom - border_width;
+ if (inner_radius < 0) inner_radius = 0;
+ uint32_t inner_sq = (uint32_t) inner_radius * inner_radius;
+ uint32_t outer_sq = (uint32_t) radius_bottom * radius_bottom;
+ int16_t center_x = x + w - radius_bottom;
+ int16_t center_y = y + h - radius_bottom;
+
+ for (int16_t i = x + w - radius_bottom; i < x + w; i++) {
+ for (int16_t j = y + h - radius_bottom; j < y + h; j++) {
+ int16_t dx = i - center_x;
+ int16_t dy = j - center_y;
+ uint32_t dist_sq = (uint32_t) dx * dx + (uint32_t) dy * dy;
+ if (dist_sq <= outer_sq && dist_sq > inner_sq) {
+ LCD_Draw_Pixel(i, j, color);
+ }
+ }
+ }
+ }
+ }
}
-
diff --git a/Core/Src/dashboard.c b/Core/Src/dashboard.c
index 7d2129e..05117b7 100644
--- a/Core/Src/dashboard.c
+++ b/Core/Src/dashboard.c
@@ -4,12 +4,22 @@
#include "monomaniacone14pt.h"
#include "monomaniacone20pt.h"
#include "monomaniacone72pt.h"
+#include
void run_dashboard_loop() {
init();
+ uint32_t i = 0;
while (1) {
+ draw_battery(654, i * 100, 1321, 343);
+
+ HAL_Delay(100);
+ if (i == 100) {
+ i = 0;
+ } else {
+ i++;
+ }
}
}
@@ -51,12 +61,13 @@ void draw_init() {
GFX_DrawChar(120, 40, '5', &monomaniacone20pt, COLOR_ERROR, COLOR_BG);
GFX_DrawText(LCD_WIDTH / 2, 50, "Bonjour Monsieur !", &monomaniacone12pt,
- COLOR_SECONDARY, COLOR_BG, 1, -2);
+ COLOR_SECONDARY, COLOR_BG, 1, -2);
GFX_DrawText(LCD_WIDTH / 2, 70, "Bonjour Monsieur !", &monomaniacone14pt,
- COLOR_SECONDARY, COLOR_BG, 1, -2);
+ COLOR_SECONDARY, COLOR_BG, 1, -2);
GFX_DrawText(LCD_WIDTH / 2, 100, "Bonjour MONSieur !", &monomaniacone20pt,
- COLOR_SUCCESS, COLOR_BG, 1, -2);
- GFX_DrawText(LCD_WIDTH / 2, 26+95, "12", &monomaniacone72pt, COLOR_FG, COLOR_BG, 1, -5);
+ COLOR_SUCCESS, COLOR_BG, 1, -2);
+ GFX_DrawText(LCD_WIDTH / 2, 26 + 95, "12", &monomaniacone72pt, COLOR_FG,
+ COLOR_BG, 1, -5);
// Draw a rectangle with different top/bottom radii
LCD_DrawHollowRoundRect(10, 10, 100, 50, 10, 0, 4, BLACK, COLOR_PRIMARY, 1);
@@ -67,10 +78,116 @@ void draw_init() {
LCD_DrawHollowRoundRect(130, 100, 60, 60, 10, 10, 0, 0, COLOR_ERROR, 1);
LCD_DrawHollowRoundRect(136, 106, 48, 48, 4, 4, 0, 0, COLOR_PRIMARY, 1);
- uint16_t bar_width = LCD_WIDTH - 12;
- LCD_DrawHollowRoundRect(4, LCD_HEIGHT - 30, bar_width+4, 26, 8, 8, 2,
- COLOR_FG, COLOR_SUCCESS, 0);
- LCD_DrawHollowRoundRect(4+2, LCD_HEIGHT - 30 + 2, 0.75 * bar_width, 22, 6, 6, 0,
- COLOR_FG, COLOR_SUCCESS, 1);
+ LCD_DrawHollowRoundRect(200, 100, 4, 20, 6, 6, 0, 0, COLOR_PRIMARY, 1);
+ LCD_DrawHollowRoundRect(200, 125, 6, 20, 6, 6, 0, 0, COLOR_PRIMARY, 1);
+ LCD_DrawHollowRoundRect(200, 150, 8, 20, 6, 6, 0, 0, COLOR_PRIMARY, 1);
}
+// Displays the battery voltage and percent, with the trip and life distances
+// Input voltage from COMM_GET_VALUES, scale 10
+// battery percent (level) from COMM_GET_VALUES_SETUP, scale 100
+// trip distance from COMM_GET_VALUES_SETUP, scale 100
+// life distance (odometer) from COMM_GET_VALUES_SETUP
+void draw_battery(
+ int16_t voltage,
+ int32_t percent,
+ int32_t trip_dist,
+ uint32_t life_dist) {
+
+ uint16_t bar_width = LCD_WIDTH - 12;
+ uint16_t bar_height = 22;
+ uint16_t filled_bar_width = (((float) (percent / 100)) / 100.0) * bar_width;
+ if(filled_bar_width < 6) {
+ 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_14 = LCD_HEIGHT - 6 - (22 - 18) / 2;
+
+ char voltage_text[8];
+ sprintf(voltage_text, "%.1fV", ((float) voltage) / 10.0);
+ char percent_text[6];
+ sprintf(percent_text, "%lu%%", percent / 100);
+ char distances_text[20];
+ sprintf(distances_text, "%.1fKm / %luKm", ((float) trip_dist) / 100.0,
+ life_dist);
+
+// Drawing the bars
+ LCD_DrawHollowRoundRect(4, LCD_HEIGHT - (bar_height + 4) - 4, bar_width + 4,
+ bar_height + 4, 8, 8, 2, COLOR_FG, COLOR_BG, 1);
+ if (filled_bar_width > 0) {
+ LCD_DrawHollowRoundRect(4 + 2, LCD_HEIGHT - (bar_height + 2) - 4,
+ filled_bar_width, bar_height, 6, 6, 0, 0, COLOR_SUCCESS, 1);
+ }
+
+// Drawing the values
+ uint16_t left_x = 10;
+ uint16_t right_x = LCD_WIDTH - 10;
+
+ if (percent > 20 * 100) {
+// Drawing the voltage to the left
+ left_x = 12
+ + GFX_DrawText(left_x, text_y_14, voltage_text, &monomaniacone14pt,
+ COLOR_BG, COLOR_SUCCESS, 0, -2);
+ } else {
+// Drawing the voltage to the right
+ right_x = -12
+ + GFX_DrawText(right_x, text_y_14, voltage_text, &monomaniacone14pt,
+ COLOR_FG, COLOR_BG, 2, -2);
+ }
+
+ if (percent > 50 * 100) {
+// Drawing the distances on the left
+ GFX_DrawText(left_x, text_y_14, distances_text, &monomaniacone14pt,
+ COLOR_BG, COLOR_SUCCESS, 0, -4);
+ } else {
+// Drawing the distances on the right
+ GFX_DrawText(right_x, text_y_14, distances_text, &monomaniacone14pt,
+ COLOR_FG, COLOR_BG, 2, -4);
+ }
+
+ if (percent > 80 * 100) {
+// Drawing the distances on the left
+ GFX_DrawText(filled_bar_end_x - 4, text_y_14, percent_text,
+ &monomaniacone14pt,
+ COLOR_BG, COLOR_SUCCESS, 2, 0);
+ } else {
+// Drawing the distances on the right
+ GFX_DrawText(filled_bar_end_x + 4, text_y_14, percent_text,
+ &monomaniacone14pt,
+ COLOR_FG, COLOR_BG, 0, 0);
+ }
+
+}
+
+// Displays the power bars at the top
+// Duty from COMM_GET_VALUES, scale 1000
+void draw_power_bars(int16_t duty) {
+
+}
+
+// Displays the huge speed counter with avg and max values.
+// Speed from COMM_GET_VALUES_SETUP, scale 1000
+void draw_speed(int32_t speed) {
+
+}
+
+// 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) {
+
+}
+
+// Displays the two ADS voltages
+// 2 voltages from COMM_GET_DECODED_ADC, scale 1 000 000
+void draw_adc(int32_t adc1, int32_t adc2) {
+
+}
+
+// Displays the controller and motor temperatures
+// 2 temperatures from COMM_GET_VALUES_SETUP, scale 10
+void draw_temps(int16_t temp_fet, int16_t temp_motor) {
+
+}
diff --git a/Core/Src/font.c b/Core/Src/font.c
index d8cdddd..8576180 100644
--- a/Core/Src/font.c
+++ b/Core/Src/font.c
@@ -82,7 +82,7 @@ uint16_t GFX_GetTextWidth(const char *text, const GFXfont *font, int8_t letter_s
return width;
}
-void GFX_DrawText(
+uint16_t GFX_DrawText(
uint16_t x,
uint16_t y,
const char *text,
@@ -122,4 +122,8 @@ void GFX_DrawText(
text++;
}
+ if(alignment == 2) {
+ return x;
+ }
+ return cursorX;
}