From b8625588cdbb4fd9bdfce0fa2b048a80164e4829 Mon Sep 17 00:00:00 2001
From: DTTerastar
Date: Mon, 23 Aug 2021 09:48:40 -0400
Subject: [PATCH] WIP
---
lib/BleFingerprint/BleFingerprint.cpp | 16 +++----
lib/BleFingerprint/BleFingerprint.h | 3 +-
lib/GUI/GUI.cpp | 60 +++++++++++++++++++++++++++
lib/GUI/GUI.h | 33 +++++++++++++++
platformio.ini | 10 +++++
src/main.cpp | 9 +---
src/main.h | 8 ----
7 files changed, 115 insertions(+), 24 deletions(-)
create mode 100644 lib/GUI/GUI.cpp
create mode 100644 lib/GUI/GUI.h
diff --git a/lib/BleFingerprint/BleFingerprint.cpp b/lib/BleFingerprint/BleFingerprint.cpp
index 238c14b..68884b5 100644
--- a/lib/BleFingerprint/BleFingerprint.cpp
+++ b/lib/BleFingerprint/BleFingerprint.cpp
@@ -90,9 +90,9 @@ BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmi
int major = ENDIAN_CHANGE_U16(oBeacon.getMajor());
int minor = ENDIAN_CHANGE_U16(oBeacon.getMinor());
- id = "iBeacon:" + proximityUUID + "-" + String(major) + "-" + String(minor);
+ id = "iBeacon:" + proximityUUID;
Serial.printf(", ID: %s", id.c_str());
- calRssi = oBeacon.getSignalPower();
+ calRssi = -oBeacon.getSignalPower();
}
else
{
@@ -197,16 +197,16 @@ bool BleFingerprint::report(JsonDocument *doc, int maxDistance)
String mac = SMacf(address);
if (output.value.position < 0.5)
{
- if (!enroll)
+ if (!close)
{
- Serial.printf("%d Enter | MAC: %s, ID: %-50s %lu %5.1f %5.1f %5.1f\n", xPortGetCoreID(), mac.c_str(), id.c_str(), output.timestamp, output.value.position, output.value.speed * 1e6, output.value.acceleration * 1e12);
- enroll = true;
+ Display.close(mac.c_str(), id.c_str());
+ close = true;
}
}
- else if (enroll && output.value.position > 1.5)
+ else if (close && output.value.position > 1.5)
{
- Serial.printf("%d Left | MAC: %s, ID: %-50s %lu %5.1f %5.1f %5.1f\n", xPortGetCoreID(), mac.c_str(), id.c_str(), output.timestamp, output.value.position, output.value.speed * 1e6, output.value.acceleration * 1e12);
- enroll = false;
+ Display.left(mac.c_str(), id.c_str());
+ close = false;
}
if (id != nullptr)
diff --git a/lib/BleFingerprint/BleFingerprint.h b/lib/BleFingerprint/BleFingerprint.h
index f878143..6e93012 100644
--- a/lib/BleFingerprint/BleFingerprint.h
+++ b/lib/BleFingerprint/BleFingerprint.h
@@ -2,6 +2,7 @@
#define _BLEFINGERPRINT_
#include
+#include
#include
#include
#include
@@ -30,7 +31,7 @@ public:
long getLastSeen() { return lastSeenMicros; };
private:
- bool hasValue = false, enroll = false, reported = false;
+ bool hasValue = false, close = false, reported = false;
NimBLEAddress address;
String id, name, url;
int rssi = -100, calRssi = 0;
diff --git a/lib/GUI/GUI.cpp b/lib/GUI/GUI.cpp
new file mode 100644
index 0000000..ed7a3fc
--- /dev/null
+++ b/lib/GUI/GUI.cpp
@@ -0,0 +1,60 @@
+#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);
+#ifdef PLUS
+ char *message;
+ va_list args;
+ va_start(args, format);
+ vasprintf(&message, format, args);
+ va_end(args);
+ 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
+}
diff --git a/lib/GUI/GUI.h b/lib/GUI/GUI.h
new file mode 100644
index 0000000..8d17dd3
--- /dev/null
+++ b/lib/GUI/GUI.h
@@ -0,0 +1,33 @@
+#ifndef GUI_h
+#define GUI_h
+
+#include
+
+#ifdef M5STICK
+#ifdef PLUS
+#include
+#else
+#include
+#endif
+#endif
+
+class GUI
+{
+public:
+ void close(const char *mac, const char *id);
+ void left(const char *mac, const char *id);
+ void status(const char *message, ...);
+ void connected(bool wifi, bool mqtt);
+ void update();
+
+private:
+ bool init;
+ bool dirty;
+#ifdef M5STICK
+ TFT_eSprite sprite = TFT_eSprite(&M5.Lcd);
+#endif
+};
+
+#endif
+
+extern GUI Display;
diff --git a/platformio.ini b/platformio.ini
index 00eb5e4..d6b8037 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -28,9 +28,11 @@ board = esp32dev
lib_deps = ${common_env_data.lib_deps_external}
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
build_flags =
-D FIRMWARE='"esp32"'
-Wall
+
[env:esp32-noupdate]
platform = espressif32
framework = arduino
@@ -42,6 +44,7 @@ build_flags =
-D FIRMWARE='"esp32-noupdate"'
-D NOUPDATE
-Wall
+
[env:esp32-verbose]
platform = espressif32
framework = arduino
@@ -49,10 +52,12 @@ board = esp32dev
lib_deps = ${common_env_data.lib_deps_external}
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
build_flags =
-D FIRMWARE='"esp32-verbose"'
-D VERBOSE
-Wall
+
[env:m5stickc]
platform = espressif32
framework = arduino
@@ -62,10 +67,12 @@ lib_deps =
${common_env_data.lib_deps_external}
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
build_flags =
-D M5STICK
-D FIRMWARE='"m5stickc"'
-Wall
+
[env:m5stickc-plus]
platform = espressif32
framework = arduino
@@ -75,11 +82,13 @@ lib_deps =
${common_env_data.lib_deps_external}
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
build_flags =
-D M5STICK
-D PLUS
-D FIRMWARE='"m5stickc-plus"'
-Wall
+
[env:m5atom-matrix]
platform = espressif32
framework = arduino
@@ -88,6 +97,7 @@ lib_deps =
${common_env_data.lib_deps_external}
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
build_flags =
-D M5ATOM
-D MATRIX
diff --git a/src/main.cpp b/src/main.cpp
index 8ce4547..78f4287 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -39,7 +39,7 @@ bool sendTelemetry(int totalSeen = -1, int totalReported = -1, int totalAdverts
initial = false;
if (mqttClient.publish(availabilityTopic.c_str(), 0, 1, "online") == true)
{
- Serial.println("Connected to MQTT");
+ Display.status("Connected to MQTT");
reconnectTries = 0;
}
else
@@ -295,12 +295,6 @@ void setup()
setClock();
connectToMqtt();
xTaskCreatePinnedToCore(scanForDevices, "BLE Scan", 4096, nullptr, 1, &scannerTask, 1);
-
-#ifdef M5STICK
- M5.begin();
- M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
-#endif
-
configureOTA();
}
@@ -308,4 +302,5 @@ void loop()
{
ArduinoOTA.handle();
firmwareUpdate();
+ Display.update();
}
diff --git a/src/main.h b/src/main.h
index 16ad637..b88e1d3 100644
--- a/src/main.h
+++ b/src/main.h
@@ -22,14 +22,6 @@
#include "BleFingerprint.h"
#include "Settings.h"
-#ifdef M5STICK
-#ifdef PLUS
-#include
-#else
-#include
-#endif
-#endif
-
AsyncMqttClient mqttClient;
TimerHandle_t reconnectTimer;
TaskHandle_t scannerTask;