mirror of
https://github.com/revspace/operame
synced 2024-12-04 21:57:30 +00:00
Tiny refactor
This commit is contained in:
parent
5889fcdaa5
commit
d2177e450f
21
operame.ino
21
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<String>& 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<String>& 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user