Rename driver/testing pages to views

This commit is contained in:
Jasper Blanckenburg 2022-03-14 14:06:52 +01:00
parent 4de2baa867
commit fc65d22450
2 changed files with 54 additions and 28 deletions

View File

@ -21,6 +21,8 @@ TireTempBox fr_box(164, 130, 240, 176, 202, 124, EA_FONT7X12, 3, 5, 'C');
TireTempBox rl_box(80, 184, 156, 230, 118, 178, EA_FONT7X12, 3, 5, 'C'); TireTempBox rl_box(80, 184, 156, 230, 118, 178, EA_FONT7X12, 3, 5, 'C');
TireTempBox rr_box(164, 184, 240, 230, 202, 178, EA_FONT7X12, 3, 5, 'C'); TireTempBox rr_box(164, 184, 240, 230, 202, 178, EA_FONT7X12, 3, 5, 'C');
int testing_page = 0;
void init_display() { void init_display() {
pinMode(writeprotect, OUTPUT); pinMode(writeprotect, OUTPUT);
digitalWrite(writeprotect, HIGH); digitalWrite(writeprotect, HIGH);
@ -207,7 +209,7 @@ bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
} }
void update_display() { void update_display() {
static DisplayPage page = PAGE_DRIVER; static DisplayView view = VIEW_DRIVER;
static uint32_t last_cleared; static uint32_t last_cleared;
static bool cleared = true; static bool cleared = true;
@ -226,30 +228,30 @@ void update_display() {
uint32_t now = millis(); uint32_t now = millis();
// Both buttons have to be pressed at the same time, but we also use the // Both buttons have to be pressed at the same time, but we also use the
// debounced rises to ensure we don't keep toggling between the pages // debounced rises to ensure we don't keep toggling between the views
if (Stw_data.buttonState1 && Stw_data.buttonState4 && if (Stw_data.buttonState1 && Stw_data.buttonState4 &&
(Stw_data.button1_rises > 0 || Stw_data.button4_rises > 0)) { (Stw_data.button1_rises > 0 || Stw_data.button4_rises > 0)) {
Stw_data.button1_rises = 0; Stw_data.button1_rises = 0;
Stw_data.button4_rises = 0; Stw_data.button4_rises = 0;
page = (DisplayPage)((page + 1) % DISPLAY_PAGES); view = (DisplayView)((view + 1) % (VIEW_LAST + 1));
tft.clear(); tft.clear();
last_cleared = now; last_cleared = now;
cleared = true; cleared = true;
} }
if (page == PAGE_DRIVER) { if (view == VIEW_DRIVER) {
if (cleared) { if (cleared) {
redraw_page_driver(); redraw_view_driver();
cleared = false; cleared = false;
} else { } else {
update_page_driver(); update_view_driver();
} }
} else { } else {
if (cleared) { if (cleared) {
redraw_page_testing(); redraw_view_testing();
cleared = false; cleared = false;
} else { } else {
update_page_testing(); update_view_testing();
} }
} }
} }
@ -286,7 +288,7 @@ void alarm(String textstr) {
} }
} }
void redraw_page_driver() { void redraw_view_driver() {
// Boxes // Boxes
tft.drawLine(0, 110, 320, 110); tft.drawLine(0, 110, 320, 110);
tft.drawLine(120, 0, 120, 110); tft.drawLine(120, 0, 120, 110);
@ -306,7 +308,7 @@ void redraw_page_driver() {
rr_box.redraw(); rr_box.redraw();
} }
void update_page_driver() { void update_view_driver() {
static Value left_box_value = VAL_FIRST_LEFT_BOX; static Value left_box_value = VAL_FIRST_LEFT_BOX;
if (Stw_data.button4_rises > 0) { if (Stw_data.button4_rises > 0) {
Stw_data.button4_rises--; Stw_data.button4_rises--;
@ -336,24 +338,49 @@ void update_page_driver() {
rr_box.update_value(90); rr_box.update_value(90);
} }
void redraw_page_testing() { void redraw_view_testing() {
tft.clear();
tft.setTextFont(EA_FONT7X12); tft.setTextFont(EA_FONT7X12);
tft.setTextSize(2, 2); tft.setTextSize(2, 2);
for (int i = 0; i <= min(VAL_LAST, 9); i++) { int start = 10 * testing_page;
for (int i = start; i <= min(VAL_LAST, start + 9); i++) {
String text = get_label((Value)i) + ":"; String text = get_label((Value)i) + ":";
int x = (i < 10) ? 10 : 170; int y = (i % 10) * 24;
tft.drawText(x, (i % 10) * 24, 'L', text.c_str()); tft.clearRect(220, y, 320, y + 23);
tft.drawText(10, y, 'L', text.c_str());
} }
update_view_testing();
} }
void update_page_testing() { void update_view_testing() {
// tft.setTextFont(EA_FONT7X12); if (Stw_data.button4_rises > 0) {
// tft.setTextSize(2, 2); Stw_data.button4_rises--;
// for (int i = 0; i < min(VALUES, 20); i++) { testing_page++;
// String text = get_value((Value) i); if (testing_page * 10 > VAL_LAST) {
// int x = (i < 10) ? 10 : 170; testing_page = 0;
// tft.drawText(10, (i % 10) * 24, 'L', text.c_str()); }
// } redraw_view_testing();
}
if (Stw_data.button1_rises > 0) {
Stw_data.button1_rises--;
testing_page--;
if (testing_page < 0) {
testing_page = VAL_LAST / 10;
}
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_value((Value)i);
int y = (i % 10) * 24;
tft.clearRect(220, y, 310, y + 23);
tft.drawText(310, y, 'R', text.c_str());
}
} }
DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y,

View File

@ -21,8 +21,7 @@
#define TOIL_ALARM_TIME 10000 // ms #define TOIL_ALARM_TIME 10000 // ms
#define ENC_DISPLAY_TIME 1000 // ms #define ENC_DISPLAY_TIME 1000 // ms
enum DisplayPage { PAGE_DRIVER, PAGE_TESTING }; enum DisplayView { VIEW_DRIVER, VIEW_TESTING, VIEW_LAST = VIEW_TESTING };
#define DISPLAY_PAGES 2
enum Value { enum Value {
VAL_GEAR, VAL_GEAR,
@ -61,10 +60,10 @@ bool check_enc_displays();
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
uint32_t& begin, const String& title); uint32_t& begin, const String& title);
void redraw_page_driver(); void redraw_view_driver();
void update_page_driver(); void update_view_driver();
void redraw_page_testing(); void redraw_view_testing();
void update_page_testing(); void update_view_testing();
class DataBox { class DataBox {
public: public: