From 1fdadd8b8574d79d1bbac5b5a8b7f7030adccfb5 Mon Sep 17 00:00:00 2001 From: Jasper Date: Thu, 17 Mar 2022 00:10:41 +0100 Subject: [PATCH] Reduce flicker --- lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp | 31 ++++++++++++++++------- lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h | 3 ++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp index a415c9c..c4cb73b 100644 --- a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp +++ b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.cpp @@ -22,9 +22,9 @@ String bezeichnungen[] = {"T_mot", "T_oil", "P_oil", "% fa", int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10, led11, led12, led13, led14, led15, led16}; -DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C'); -DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R'); -DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R'); +DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C', true); +DataBox left_box(0, 25, 119, 94, 110, 25, EA_FONT6X8, 3, 8, 'R', false); +DataBox right_box(201, 25, 320, 94, 310, 25, EA_FONT6X8, 3, 8, 'R', false); TireTempBox fl_box(80, 130, 156, 176, 118, 124, EA_FONT7X12, 3, 5, 'C'); 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'); @@ -354,9 +354,18 @@ void update_view_driver() { left_box.update_label(get_label(left_box_value)); } + // These can change rapidly, which would lead to a lot of flickering if + // rendered in the clear-redraw method. So instead, they're simply overwritten + // with a black background. + tft.setTextColor(EA_WHITE, EA_BLACK); + left_box.update_value(pad_left(get_value(left_box_value), 5)); + right_box.update_value(pad_left(get_value(VAL_RPM), 5)); + // These don't change as rapidly, and would overwrite adjacent elements + // (lines/labels) if rendered with a background because of the empty pixels + // above/below the characters. So they're rendered using the clear-redraw + // method.0 + tft.setTextColor(EA_WHITE, EA_TRANSPARENT); gear_box.update_value(get_value(VAL_GEAR)); - left_box.update_value(get_value(left_box_value)); - right_box.update_value(get_value(VAL_RPM)); fl_box.update_value(get_value(VAL_TT_FL).toInt()); fr_box.update_value(get_value(VAL_TT_FR).toInt()); rl_box.update_value(get_value(VAL_TT_RL).toInt()); @@ -428,10 +437,11 @@ void update_value_testing(int i) { } DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, - int font, int size_x, int size_y, uint8_t justification) + int font, int size_x, int size_y, uint8_t justification, + bool do_clear) : x1{x1}, y1{y1}, x2{x2}, y2{y2}, text_x{text_x}, text_y{text_y}, font{font}, size_x{size_x}, size_y{size_y}, - justification{justification}, value{""}, label{""} {} + justification{justification}, do_clear{do_clear}, value{""}, label{""} {} void DataBox::update_value(String val_new) { if (!val_new.equals(value)) { @@ -456,7 +466,9 @@ void DataBox::redraw_value() { tft.setTextFont(font); tft.setTextSize(size_x, size_y); Serial.println("Redrawing value:"); - tft.clearRect(x1, y1, x2, y2); + if (do_clear) { + tft.clearRect(x1, y1, x2, y2); + } tft.drawText(text_x, text_y, justification, value.c_str()); } @@ -472,7 +484,8 @@ TireTempBox::TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font, int size_x, int size_y, uint8_t justification) : DataBox{x1, y1, x2, y2, text_x, - text_y, font, size_x, size_y, justification}, + text_y, font, size_x, size_y, justification, + false}, num_value{-1} {} void TireTempBox::update_value(int val_new) { diff --git a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h index eb44785..9eacb5b 100644 --- a/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h +++ b/lib/FT18_STW_DISPLAY/FT18_STW_DISPLAY.h @@ -73,7 +73,7 @@ void update_value_testing(int i); class DataBox { public: DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font, - int size_x, int size_y, uint8_t justification); + int size_x, int size_y, uint8_t justification, bool do_clear); void update_value(String val_new); void update_label(String label_new); @@ -85,6 +85,7 @@ public: protected: int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y; uint8_t justification; + bool do_clear; String value; String label; };