Temperature indicators displaying

This commit is contained in:
Clément Grennerat 2025-09-15 22:02:46 +02:00
parent 88c00aacbd
commit 0fa53919e0
5 changed files with 231 additions and 26 deletions

View File

@ -123,6 +123,13 @@ void LCD_DrawHollowRoundRect(
uint16_t fill_color, uint16_t fill_color,
uint8_t do_fill); uint8_t do_fill);
// Build icons with https://notisrac.github.io/FileToCArray/
void LCD_Draw_Icon(const uint8_t *icon, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fg_color, uint16_t bg_color);
// Three colors icon, 8bits/pixel RRRGGGBB, RRR > 0x800 => FG, GGG > 0x800 => ALT, BB > 0x80 => BG
// Build icons with https://notisrac.github.io/FileToCArray/
void LCD_Draw_Icon_3(const uint8_t *icon, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fg_color, uint16_t alt_color, uint16_t bg_color);
#endif #endif
/*******************PARTIE ISSUE DE LA LIB ILI9193_GFX.h***************************/ /*******************PARTIE ISSUE DE LA LIB ILI9193_GFX.h***************************/

File diff suppressed because one or more lines are too long

View File

@ -643,3 +643,90 @@ void LCD_DrawHollowRoundRect(
} }
} }
// Build icons with https://notisrac.github.io/FileToCArray/
void LCD_Draw_Icon(
const uint8_t *icon,
uint16_t x,
uint16_t y,
uint16_t w,
uint16_t h,
uint16_t fg_color,
uint16_t bg_color) {
LCD_Set_Address(x, y, x + w - 1, y + h - 1);
uint16_t pendingPixelCount = 0;
uint8_t pendingPixelBit = 0;
uint16_t i = 0;
for (int line = 0; line < h; line++) {
for (int col = 0; col < w; col++) {
uint16_t byteIndex = i / 8;
uint8_t bitIndex = i % 8;
uint8_t pixelBit = (icon[byteIndex] & (0x80 >> bitIndex)) ? 1 : 0;
if (pixelBit == pendingPixelBit) {
pendingPixelCount++;
} else {
if (pendingPixelCount != 0) {
LCD_Draw_Colour_Burst(pendingPixelBit ? fg_color : bg_color,
pendingPixelCount);
pendingPixelCount = 1;
}
pendingPixelBit = pixelBit;
}
i++;
}
}
if (pendingPixelCount != 0) {
LCD_Draw_Colour_Burst(pendingPixelBit ? fg_color : bg_color,
pendingPixelCount);
}
}
// Three colors icon, 8bits/pixel RRRGGGBB, RRR >= 0b100 => FG, GGG >= 0b100 => ALT, BB >= 0b10 => BG
// Build icons with https://notisrac.github.io/FileToCArray/
void LCD_Draw_Icon_3(
const uint8_t *icon,
uint16_t x,
uint16_t y,
uint16_t w,
uint16_t h,
uint16_t fg_color,
uint16_t alt_color,
uint16_t bg_color) {
LCD_Set_Address(x, y, x + w - 1, y + h - 1);
uint16_t pendingPixelCount = 0;
uint16_t pendingPixelColor = 0;
uint16_t i = 0;
for (int line = 0; line < h; line++) {
for (int col = 0; col < w; col++) {
uint8_t pixelByte = icon[i];
uint8_t rrr = (pixelByte & 0b11100000) >> 5;
uint8_t ggg = (pixelByte & 0b00011100) >> 2;
//uint8_t bb = (pixelByte & 0b00000011);
uint16_t color =
rrr >= 0b100 ? fg_color : (ggg >= 0b100 ? alt_color : bg_color);
LCD_Draw_Colour_Burst(color, 1);
// if (color == pendingPixelColor) {
// pendingPixelCount++;
// } else {
// if (pendingPixelCount != 0) {
// LCD_Draw_Colour_Burst(color, pendingPixelCount);
// pendingPixelCount = 1;
// }
// pendingPixelColor = color;
// }
i++;
}
}
if (pendingPixelCount != 0) {
LCD_Draw_Colour_Burst(pendingPixelColor, pendingPixelCount);
}
}

View File

@ -1,5 +1,6 @@
#include "dashboard.h" #include "dashboard.h"
#include "font.h" #include "font.h"
#include "icons.h"
//#include "monomaniacone12pt.h" //#include "monomaniacone12pt.h"
#include "monomaniacone14pt.h" #include "monomaniacone14pt.h"
#include "monomaniacone20pt.h" #include "monomaniacone20pt.h"
@ -18,6 +19,10 @@ void run_dashboard_loop() {
draw_power_bars(duty); draw_power_bars(duty);
draw_power(100 * i / 20 * (duty < 0 ? -1 : 1), duty, 60 * 10); draw_power(100 * i / 20 * (duty < 0 ? -1 : 1), duty, 60 * 10);
draw_adc((i % 34) * 100000, ((400 - i + 16) % 34) * 100000);
draw_temps((4 * i) % 900, ((10 * i) + 450) % 900);
HAL_Delay(50); HAL_Delay(50);
if (i == 400) { if (i == 400) {
i = 0; i = 0;
@ -57,10 +62,25 @@ void LCD_DrawHollowRoundRect(
#define LEFT_CENTER_COL1 38 #define LEFT_CENTER_COL1 38
#define LEFT_CENTER_COL2 116 #define LEFT_CENTER_COL2 116
#define RIGHT_CENTER 400 #define RIGHT_CENTER 400
void draw_init() { void draw_init() {
LCD_Fill_Screen(COLOR_OFF, 1); LCD_Fill_Screen(COLOR_OFF, 1);
LCD_Fill_Screen(COLOR_BG, 0); LCD_Fill_Screen(COLOR_BG, 0);
// Draw footpad sensors rect
uint16_t sensor_width = 126;
LCD_DrawHollowRoundRect(RIGHT_CENTER - sensor_width / 2, 70, sensor_width, 73,
15, 0, 6, COLOR_PRIMARY, 0, 0);
LCD_Draw_Rectangle(RIGHT_CENTER - 3, 76, 6, 61, COLOR_PRIMARY);
// Draw temp icons
LCD_Draw_Icon_3(motort_icon, LEFT_CENTER_COL1 - MOTORT_ICON_WIDTH / 2, 73,
MOTORT_ICON_WIDTH, MOTORT_ICON_HEIGHT, COLOR_SECONDARY, COLOR_ERROR,
COLOR_BG);
LCD_Draw_Icon_3(chipt_icon, LEFT_CENTER_COL2 - CHIPT_ICON_WIDTH / 2, 73,
CHIPT_ICON_WIDTH, CHIPT_ICON_HEIGHT, COLOR_PRIMARY, COLOR_ERROR,
COLOR_BG);
// GFX_DrawChar(40, 40, '!', &monomaniacone20pt, COLOR_PRIMARY, COLOR_BG); // GFX_DrawChar(40, 40, '!', &monomaniacone20pt, COLOR_PRIMARY, COLOR_BG);
// GFX_DrawChar(60, 40, '2', &monomaniacone20pt, COLOR_PRIMARY, COLOR_BG); // GFX_DrawChar(60, 40, '2', &monomaniacone20pt, COLOR_PRIMARY, COLOR_BG);
// GFX_DrawChar(80, 40, '3', &monomaniacone20pt, COLOR_SECONDARY, COLOR_BG); // GFX_DrawChar(80, 40, '3', &monomaniacone20pt, COLOR_SECONDARY, COLOR_BG);
@ -282,6 +302,11 @@ void draw_power(int32_t current_i, int16_t duty_i, int16_t voltage_i) {
int16_t current = current_i / 100; int16_t current = current_i / 100;
uint16_t duty = duty_i < 0 ? -duty_i / 10 : duty_i / 10; 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; int32_t power = ((int32_t) voltage_i) * ((int32_t) current_i) / 10000 * 10;
if (power >= 1000) {
power = power / 100 * 100;
} else if (power <= -1000) {
power = power / 100 * 100;
}
if (current != last_current) { if (current != last_current) {
last_current = current; last_current = current;
@ -318,7 +343,7 @@ void draw_power(int32_t current_i, int16_t duty_i, int16_t voltage_i) {
} }
char text[10]; char text[10];
sprintf(text, "%dW", power); sprintf(text, "%ldW", power);
LCD_Draw_Rectangle(RIGHT_CENTER - 70, 30, 2 * 70, 35, COLOR_BG); LCD_Draw_Rectangle(RIGHT_CENTER - 70, 30, 2 * 70, 35, COLOR_BG);
GFX_DrawText(RIGHT_CENTER, 60, text, &monomaniacone20pt, GFX_DrawText(RIGHT_CENTER, 60, text, &monomaniacone20pt,
COLOR_PRIMARY, COLOR_BG, 1, -2); COLOR_PRIMARY, COLOR_BG, 1, -2);
@ -326,14 +351,100 @@ void draw_power(int32_t current_i, int16_t duty_i, int16_t voltage_i) {
} }
uint16_t last_adc1 = 1000;
uint16_t last_adc2 = 1000;
uint16_t adc_threshold = 29;
// Displays the two ADS voltages // Displays the two ADS voltages
//2 voltages from COMM_GET_DECODED_ADC, scale 1 000 000 //2 voltages from COMM_GET_DECODED_ADC, scale 1 000 000
void draw_adc(int32_t adc1, int32_t adc2) { void draw_adc(int32_t adc1_scaled, int32_t adc2_scaled) {
uint16_t adc1 =
adc1_scaled < 0 ? -adc1_scaled / 100000 : adc1_scaled / 100000;
uint16_t adc2 =
adc2_scaled < 0 ? -adc2_scaled / 100000 : adc2_scaled / 100000;
if (adc1 > 33) {
adc1 = 33;
}
if (adc2 > 33) {
adc2 = 33;
}
// Max filled height = 39
if (adc1 != last_adc1) {
uint16_t filled_height = adc1 * 39 / 33;
uint16_t free_height = 61 - filled_height;
// Reset the top part
LCD_Draw_Rectangle(RIGHT_CENTER - 3 - 54 + 2, 76 + 2, 54 - 4, 2, COLOR_BG);
LCD_Draw_Rectangle(RIGHT_CENTER - 3 - 54 + 0, 76 + 4, 54, free_height - 4,
COLOR_BG);
// Draw the colored zone
uint16_t color = adc1 >= adc_threshold ? COLOR_SUCCESS : COLOR_ERROR;
LCD_Draw_Rectangle(RIGHT_CENTER - 3 - 54, 76 + free_height, 54,
filled_height, color);
// Draw the text
char text[8];
sprintf(text, "%.1fV", ((float) adc1) / 10);
GFX_DrawText(RIGHT_CENTER - 3 - 27, 76 + free_height - 2, text,
&monomaniacone14pt, color, COLOR_BG, 1, -2);
last_adc1 = adc1;
}
// Max filled height = 39
if (adc2 != last_adc2) {
uint16_t filled_height = adc2 * 39 / 33;
uint16_t free_height = 61 - filled_height;
// Reset the top part
LCD_Draw_Rectangle(RIGHT_CENTER + 3 + 2, 76 + 2, 54 - 4, 2, COLOR_BG);
LCD_Draw_Rectangle(RIGHT_CENTER + 3 + 0, 76 + 4, 54, free_height - 4,
COLOR_BG);
// Draw the colored zone
uint16_t color = adc2 >= adc_threshold ? COLOR_SUCCESS : COLOR_ERROR;
LCD_Draw_Rectangle(RIGHT_CENTER + 3, 76 + free_height, 54, filled_height,
color);
// Draw the text
char text[8];
sprintf(text, "%.1fV", ((float) adc2) / 10);
GFX_DrawText(RIGHT_CENTER + 3 + 27, 76 + free_height - 2, text,
&monomaniacone14pt, color, COLOR_BG, 1, -2);
last_adc2 = adc2;
}
} }
uint16_t last_temp_fet = 1000;
uint16_t last_temp_mot = 1000;
// Displays the controller and motor temperatures // Displays the controller and motor temperatures
// 2 temperatures from COMM_GET_VALUES_SETUP, scale 10 // 2 temperatures from COMM_GET_VALUES_SETUP, scale 10
void draw_temps(int16_t temp_fet, int16_t temp_motor) { void draw_temps(int16_t temp_fet_scaled, int16_t temp_motor_scaled) {
uint16_t temp_fet = temp_fet_scaled < 0 ? 0 : temp_fet_scaled / 10;
uint16_t temp_mot = temp_motor_scaled < 0 ? 0 : temp_motor_scaled / 10;
if(temp_fet > 99) {
temp_fet = 99;
}
if(temp_mot > 99) {
temp_mot = 99;
}
if (temp_mot != last_temp_mot) {
last_temp_mot = temp_mot;
char text[8];
sprintf(text, "%u>C", temp_mot);
LCD_Draw_Rectangle(LEFT_CENTER_COL1 - 38, 138, 2 * 39, 25, COLOR_BG);
GFX_DrawText(LEFT_CENTER_COL1, 159, text, &monomaniacone14pt, COLOR_SECONDARY, COLOR_BG, 1, -1);
}
if (temp_fet != last_temp_fet) {
last_temp_fet = temp_fet;
char text[8];
sprintf(text, "%u>C", temp_fet);
LCD_Draw_Rectangle(LEFT_CENTER_COL2 - 39, 138, 2 * 39, 25, COLOR_BG);
GFX_DrawText(LEFT_CENTER_COL2, 159, text, &monomaniacone14pt, COLOR_PRIMARY, COLOR_BG, 1, -1);
}
} }

View File

@ -32,7 +32,7 @@ void GFX_DrawChar(
for (uint8_t col = 0; col < glyph->width; col++) { for (uint8_t col = 0; col < glyph->width; col++) {
uint16_t byteIndex = glyph->bitmapOffset + (bitPos / 8); uint16_t byteIndex = glyph->bitmapOffset + (bitPos / 8);
uint8_t bitIndex = bitPos % 8; uint8_t bitIndex = bitPos % 8;
uint8_t pixelBit = font->bitmaps[byteIndex] & (0x80 >> bitIndex); uint8_t pixelBit = (font->bitmaps[byteIndex] & (0x80 >> bitIndex)) ? 1 : 0;
if (pixelBit == pendingPixelBit) { if (pixelBit == pendingPixelBit) {
pendingPixelCount++; pendingPixelCount++;