Reduce flicker

This commit is contained in:
Jasper Blanckenburg 2022-03-17 00:10:41 +01:00
parent 130a0dde2f
commit 1fdadd8b85
2 changed files with 24 additions and 10 deletions

View File

@ -22,9 +22,9 @@ String bezeichnungen[] = {"T_mot", "T_oil", "P_oil", "% fa",
int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8, int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16}; led9, led10, led11, led12, led13, led14, led15, led16};
DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C'); DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C', true);
DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R'); DataBox left_box(0, 25, 119, 94, 110, 25, EA_FONT6X8, 3, 8, 'R', false);
DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R'); 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 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 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');
@ -354,9 +354,18 @@ void update_view_driver() {
left_box.update_label(get_label(left_box_value)); 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)); 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()); fl_box.update_value(get_value(VAL_TT_FL).toInt());
fr_box.update_value(get_value(VAL_TT_FR).toInt()); fr_box.update_value(get_value(VAL_TT_FR).toInt());
rl_box.update_value(get_value(VAL_TT_RL).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, 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}, : 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}, 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) { void DataBox::update_value(String val_new) {
if (!val_new.equals(value)) { if (!val_new.equals(value)) {
@ -456,7 +466,9 @@ void DataBox::redraw_value() {
tft.setTextFont(font); tft.setTextFont(font);
tft.setTextSize(size_x, size_y); tft.setTextSize(size_x, size_y);
Serial.println("Redrawing value:"); Serial.println("Redrawing value:");
if (do_clear) {
tft.clearRect(x1, y1, x2, y2); tft.clearRect(x1, y1, x2, y2);
}
tft.drawText(text_x, text_y, justification, value.c_str()); 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, int font, int size_x, int size_y,
uint8_t justification) uint8_t justification)
: DataBox{x1, y1, x2, y2, text_x, : 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} {} num_value{-1} {}
void TireTempBox::update_value(int val_new) { void TireTempBox::update_value(int val_new) {

View File

@ -73,7 +73,7 @@ void update_value_testing(int i);
class DataBox { class DataBox {
public: public:
DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font, 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_value(String val_new);
void update_label(String label_new); void update_label(String label_new);
@ -85,6 +85,7 @@ public:
protected: protected:
int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y; int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y;
uint8_t justification; uint8_t justification;
bool do_clear;
String value; String value;
String label; String label;
}; };