diff --git a/operame.ino b/operame.ino index 2477e33..7b94488 100644 --- a/operame.ino +++ b/operame.ino @@ -56,7 +56,15 @@ void retain(String topic, String message) { mqtt.publish(topic, message, true, 0); } +void clear_sprite(int bg = TFT_BLACK) { + sprite.fillSprite(bg); + if (WiFi.status() == WL_CONNECTED) { + sprite.drawRect(0, 0, display.width(), display.height(), TFT_BLUE); + } +} + void display_big(const String& text, int fg = TFT_WHITE, int bg = TFT_BLACK) { + clear_sprite(bg); sprite.setTextSize(1); bool nondigits = false; for (int i = 0; i < text.length(); i++) { @@ -67,22 +75,18 @@ void display_big(const String& text, int fg = TFT_WHITE, int bg = TFT_BLACK) { sprite.setTextSize(nondigits && text.length() < 10 ? 2 : 1); sprite.setTextDatum(MC_DATUM); sprite.setTextColor(fg, bg); - sprite.fillSprite(bg); - if (WiFi.status() == WL_CONNECTED) - sprite.drawRect(0, 0, display.width(), display.height(), TFT_BLUE); sprite.drawString(text, display.width()/2, display.height()/2); sprite.pushSprite(0, 0); } void display_lines(const std::list& lines, int fg = TFT_WHITE, int bg = TFT_BLACK) { + clear_sprite(bg); sprite.setTextSize(1); sprite.setTextFont(4); sprite.setTextDatum(MC_DATUM); sprite.setTextColor(fg, bg); - sprite.fillSprite(bg); - if (WiFi.status() == WL_CONNECTED) - sprite.drawRect(0, 0, display.width(), display.height(), TFT_BLUE); + const int line_height = 32; int y = display.height()/2 - (lines.size()-1) * line_height/2; for (auto line : lines) { @@ -93,12 +97,9 @@ void display_lines(const std::list& lines, int fg = TFT_WHITE, int bg = } void display_logo() { + clear_sprite(); sprite.setSwapBytes(true); - sprite.fillSprite(TFT_BLACK); sprite.pushImage(12, 30, 215, 76, OPERAME_LOGO); - if (WiFi.status() == WL_CONNECTED) - sprite.drawRect(0, 0, display.width(), display.height(), TFT_BLUE); - sprite.pushSprite(0, 0); }