ESPresense/lib/BleFingerprint/GUI.cpp

140 lines
2.9 KiB
C++
Raw Normal View History

2021-08-23 15:48:40 +02:00
#include "GUI.h"
GUI Display;
void GUI::seenStart()
{
2021-09-17 00:18:15 +02:00
#ifdef M5ATOM
M5.dis.drawpix(0, CRGB(15, 15, 15));
#else
digitalWrite(LED_BUILTIN, LED_BUILTIN_ON);
2021-09-17 00:18:15 +02:00
#endif
}
void GUI::seenEnd()
{
2021-09-17 00:18:15 +02:00
#ifdef M5ATOM
M5.dis.drawpix(0, CRGB(0, 0, 0));
#else
digitalWrite(LED_BUILTIN, !LED_BUILTIN_ON);
2021-09-17 00:18:15 +02:00
#endif
}
void GUI::erasing()
{
status("Erasing...");
Serial.println(F("Resetting back to defaults..."));
}
void GUI::erased()
{
}
void GUI::connecting()
{
status("Connecting...");
connected(false, false);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
#endif
}
2021-08-23 15:48:40 +02:00
void GUI::connected(bool wifi = false, bool mqtt = false)
{
2021-09-17 00:18:15 +02:00
#ifdef M5ATOM
if (!wifi)
M5.dis.drawpix(0, CRGB(0, 128, 0));
else if (!mqtt)
M5.dis.drawpix(0, CRGB(0, 0, 128));
else
M5.dis.drawpix(0, CRGB(0, 0, 0));
#else
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, !LED_BUILTIN_ON);
#endif
2021-08-23 15:48:40 +02:00
status("Wifi: %s Mqtt: %s", (wifi ? "no" : "yes"), (wifi ? "no" : "yes"));
2021-09-17 00:18:15 +02:00
#endif
2021-08-23 15:48:40 +02:00
}
2021-09-15 18:11:32 +02:00
void GUI::close(BleFingerprint *f)
2021-08-23 15:48:40 +02:00
{
2021-09-15 18:11:32 +02:00
Serial.printf("%d Close | MAC: %s, ID: %-50s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str());
2021-09-19 04:40:43 +02:00
status("C: %s", f->getId().c_str());
2021-08-23 15:48:40 +02:00
}
2021-09-15 18:11:32 +02:00
void GUI::added(BleFingerprint *f)
2021-08-23 15:48:40 +02:00
{
2021-09-15 18:11:32 +02:00
Serial.printf("%d New | MAC: %s, ID: %-50s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str());
}
void GUI::removed(BleFingerprint *f)
{
Serial.printf("%d Del | MAC: %s, ID: %-50s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str());
}
void GUI::left(BleFingerprint *f)
{
Serial.printf("%d Left | MAC: %s, ID: %-50s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str());
2021-09-19 04:40:43 +02:00
status("L: %s", f->getId().c_str());
2021-08-23 15:48:40 +02:00
}
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()
{
if (!init)
{
2021-09-17 00:18:15 +02:00
#ifdef M5STICK
2021-09-18 14:24:15 +02:00
M5.begin(true, true, false);
2021-08-23 15:48:40 +02:00
M5.Lcd.setRotation(3);
sprite.createSprite(M5.Lcd.width(), M5.Lcd.height());
sprite.setSwapBytes(true);
2021-09-17 00:18:15 +02:00
#elif defined M5ATOM
M5.begin(false, false, true);
M5.dis.drawpix(0, CRGB(64, 0, 0));
#endif
2021-08-23 15:48:40 +02:00
init = true;
}
2021-09-17 00:18:15 +02:00
#ifdef M5STICK
2021-08-23 15:48:40 +02:00
if (dirty)
{
sprite.pushSprite(0, 0);
M5.Axp.ScreenBreath(12);
dirty = false;
}
#endif
}
2021-09-17 00:18:15 +02:00
void GUI::updateProgress(unsigned int percent)
{
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, percent % 2);
#endif
}
void GUI::updateEnd()
{
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, !LED_BUILTIN_ON);
#endif
}