Alternate color of testing view rows

This commit is contained in:
Jasper Blanckenburg 2022-03-14 14:30:33 +01:00
parent fc65d22450
commit 37123a43e8
2 changed files with 45 additions and 16 deletions

View File

@ -4,6 +4,15 @@
#include "FT18_STW_INIT.h"
#include "FT_2018_STW_CAN.h"
String pad_left(String orig, int len, char pad_char) {
String result = {orig};
for (int i = orig.length(); i < len; i++) {
result = pad_char + result;
}
return result;
}
EDIPTFT tft(true, false);
String bezeichnungen[] = {"T_mot", "T_oil", "P_oil", "% fa",
"U_batt", "P_wat", "T_air", "P_b_front",
@ -289,6 +298,8 @@ void alarm(String textstr) {
}
void redraw_view_driver() {
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
// Boxes
tft.drawLine(0, 110, 320, 110);
tft.drawLine(120, 0, 120, 110);
@ -343,11 +354,14 @@ void redraw_view_testing() {
tft.setTextFont(EA_FONT7X12);
tft.setTextSize(2, 2);
int start = 10 * testing_page;
for (int i = start; i <= min(VAL_LAST, start + 9); i++) {
String text = get_label((Value)i) + ":";
int y = (i % 10) * 24;
tft.clearRect(220, y, 320, y + 23);
tft.drawText(10, y, 'L', text.c_str());
tft.setTextColor(EA_WHITE, EA_BLACK);
for (int i = start; i <= min(VAL_LAST, start + 9); i += 2) {
redraw_label_testing(i, EA_BLACK);
}
tft.setTextColor(EA_WHITE, EA_DARKGREY);
for (int i = start + 1; i <= min(VAL_LAST, start + 9); i += 2) {
redraw_label_testing(i, EA_DARKGREY);
}
update_view_testing();
@ -375,12 +389,28 @@ void update_view_testing() {
tft.setTextSize(2, 2);
int start = 10 * testing_page;
for (int i = start; i <= min(VAL_LAST, start + 9); i++) {
String text = get_value((Value)i);
int y = (i % 10) * 24;
tft.clearRect(220, y, 310, y + 23);
tft.drawText(310, y, 'R', text.c_str());
tft.setTextColor(EA_WHITE, EA_BLACK);
for (int i = start; i <= min(VAL_LAST, start + 9); i += 2) {
update_value_testing(i);
}
tft.setTextColor(EA_WHITE, EA_DARKGREY);
for (int i = start + 1; i <= min(VAL_LAST, start + 9); i += 2) {
update_value_testing(i);
}
}
void redraw_label_testing(int i, uint8_t color) {
String text = get_label((Value)i) + ":";
int y = (i % 10) * 24;
tft.drawRectf(0, y, 320, y + 23, color);
tft.drawText(10, y, 'L', text.c_str());
}
void update_value_testing(int i) {
String text = pad_left(get_value((Value)i), 5);
int y = (i % 10) * 24;
tft.drawText(310, y, 'R', text.c_str());
}
DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
@ -443,12 +473,7 @@ void TireTempBox::update_value(int val_new) {
} else {
color = TT_COL3;
}
String val_str = String(val_new);
if (val_str.length() == 1) {
val_str = " " + val_str;
} else if (val_str.length() == 2) {
val_str = " " + val_str;
}
String val_str = pad_left(String(val_new), 3);
DataBox::update_value(val_str);
}
}

View File

@ -21,6 +21,8 @@
#define TOIL_ALARM_TIME 10000 // ms
#define ENC_DISPLAY_TIME 1000 // ms
String pad_left(String orig, int len, char pad_char = ' ');
enum DisplayView { VIEW_DRIVER, VIEW_TESTING, VIEW_LAST = VIEW_TESTING };
enum Value {
@ -64,6 +66,8 @@ void redraw_view_driver();
void update_view_driver();
void redraw_view_testing();
void update_view_testing();
void redraw_label_testing(int i, uint8_t bg_color);
void update_value_testing(int i);
class DataBox {
public: