From fc65d22450bb4bcdb35df6b1dd88c205dfcc95ce Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 14 Mar 2022 14:06:52 +0100 Subject: [PATCH] Rename driver/testing pages to views --- lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp | 71 ++++++++++++++++------- lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h | 11 ++-- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp index 0f38e00..f862cf8 100644 --- a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp +++ b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp @@ -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 rr_box(164, 184, 240, 230, 202, 178, EA_FONT7X12, 3, 5, 'C'); +int testing_page = 0; + void init_display() { pinMode(writeprotect, OUTPUT); digitalWrite(writeprotect, HIGH); @@ -207,7 +209,7 @@ bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, } void update_display() { - static DisplayPage page = PAGE_DRIVER; + static DisplayView view = VIEW_DRIVER; static uint32_t last_cleared; static bool cleared = true; @@ -226,30 +228,30 @@ void update_display() { uint32_t now = millis(); // 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 && (Stw_data.button1_rises > 0 || Stw_data.button4_rises > 0)) { Stw_data.button1_rises = 0; Stw_data.button4_rises = 0; - page = (DisplayPage)((page + 1) % DISPLAY_PAGES); + view = (DisplayView)((view + 1) % (VIEW_LAST + 1)); tft.clear(); last_cleared = now; cleared = true; } - if (page == PAGE_DRIVER) { + if (view == VIEW_DRIVER) { if (cleared) { - redraw_page_driver(); + redraw_view_driver(); cleared = false; } else { - update_page_driver(); + update_view_driver(); } } else { if (cleared) { - redraw_page_testing(); + redraw_view_testing(); cleared = false; } else { - update_page_testing(); + update_view_testing(); } } } @@ -286,7 +288,7 @@ void alarm(String textstr) { } } -void redraw_page_driver() { +void redraw_view_driver() { // Boxes tft.drawLine(0, 110, 320, 110); tft.drawLine(120, 0, 120, 110); @@ -306,7 +308,7 @@ void redraw_page_driver() { rr_box.redraw(); } -void update_page_driver() { +void update_view_driver() { static Value left_box_value = VAL_FIRST_LEFT_BOX; if (Stw_data.button4_rises > 0) { Stw_data.button4_rises--; @@ -336,24 +338,49 @@ void update_page_driver() { rr_box.update_value(90); } -void redraw_page_testing() { +void redraw_view_testing() { + tft.clear(); tft.setTextFont(EA_FONT7X12); 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) + ":"; - int x = (i < 10) ? 10 : 170; - tft.drawText(x, (i % 10) * 24, 'L', text.c_str()); + int y = (i % 10) * 24; + tft.clearRect(220, y, 320, y + 23); + tft.drawText(10, y, 'L', text.c_str()); } + + update_view_testing(); } -void update_page_testing() { - // tft.setTextFont(EA_FONT7X12); - // tft.setTextSize(2, 2); - // for (int i = 0; i < min(VALUES, 20); i++) { - // String text = get_value((Value) i); - // int x = (i < 10) ? 10 : 170; - // tft.drawText(10, (i % 10) * 24, 'L', text.c_str()); - // } +void update_view_testing() { + if (Stw_data.button4_rises > 0) { + Stw_data.button4_rises--; + testing_page++; + if (testing_page * 10 > VAL_LAST) { + testing_page = 0; + } + 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, diff --git a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h index 5f7d4df..eefc34d 100644 --- a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h +++ b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h @@ -21,8 +21,7 @@ #define TOIL_ALARM_TIME 10000 // ms #define ENC_DISPLAY_TIME 1000 // ms -enum DisplayPage { PAGE_DRIVER, PAGE_TESTING }; -#define DISPLAY_PAGES 2 +enum DisplayView { VIEW_DRIVER, VIEW_TESTING, VIEW_LAST = VIEW_TESTING }; enum Value { VAL_GEAR, @@ -61,10 +60,10 @@ bool check_enc_displays(); bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, uint32_t& begin, const String& title); -void redraw_page_driver(); -void update_page_driver(); -void redraw_page_testing(); -void update_page_testing(); +void redraw_view_driver(); +void update_view_driver(); +void redraw_view_testing(); +void update_view_testing(); class DataBox { public: