ESPresense/lib/GUI/GUI.cpp

62 lines
1.3 KiB
C++
Raw Normal View History

2021-08-23 15:48:40 +02:00
#include "GUI.h"
GUI Display;
void GUI::connected(bool wifi = false, bool mqtt = false)
{
status("Wifi: %s Mqtt: %s", (wifi ? "no" : "yes"), (wifi ? "no" : "yes"));
}
void GUI::close(const char *mac, const char *id)
{
Serial.printf("%d Close | MAC: %s, ID: %-50s\n", xPortGetCoreID(), mac, id);
status("C: %s", id);
}
void GUI::left(const char *mac, const char *id)
{
Serial.printf("%d Left | MAC: %s, ID: %-50s\n", xPortGetCoreID(), mac, id);
status("L: %s", id);
}
void GUI::status(const char *format, ...)
{
#ifdef M5STICK
sprite.fillSprite(TFT_BLACK);
sprite.setTextDatum(MC_DATUM);
2021-08-24 01:32:19 +02:00
2021-08-23 15:48:40 +02:00
char *message;
va_list args;
va_start(args, format);
vasprintf(&message, format, args);
va_end(args);
2021-08-24 01:32:19 +02:00
#ifdef PLUS
2021-08-23 15:48:40 +02:00
sprite.drawString(message, sprite.width() / 2, sprite.height() / 2, 4);
#else
sprite.drawString(message, sprite.width() / 2, sprite.height() / 2, 1);
#endif
free(message);
dirty = true;
#endif
}
void GUI::update()
{
#ifdef M5STICK
if (!init)
{
M5.begin(true, true, false);
M5.Lcd.setRotation(3);
sprite.createSprite(M5.Lcd.width(), M5.Lcd.height());
sprite.setSwapBytes(true);
init = true;
}
if (dirty)
{
sprite.pushSprite(0, 0);
M5.Axp.ScreenBreath(12);
dirty = false;
}
#endif
}