This commit is contained in:
Stephan Mühl
2023-04-09 19:29:08 +02:00
parent 47493062b4
commit 2a8149400b
9 changed files with 735 additions and 1054 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,9 @@
#include "MatrixDisplayUi.h" #include "MatrixDisplayUi.h"
#include "Fonts/AwtrixFont.h" #include "Fonts/AwtrixFont.h"
GifPlayer gif1;
GifPlayer gif2;
MatrixDisplayUi::MatrixDisplayUi(FastLED_NeoMatrix *matrix) MatrixDisplayUi::MatrixDisplayUi(FastLED_NeoMatrix *matrix)
{ {
this->matrix = matrix; this->matrix = matrix;
@@ -41,6 +44,8 @@ void MatrixDisplayUi::init()
this->matrix->setTextWrap(false); this->matrix->setTextWrap(false);
this->matrix->setBrightness(70); this->matrix->setBrightness(70);
this->matrix->setFont(&AwtrixFont); this->matrix->setFont(&AwtrixFont);
gif1.setMatrix(this->matrix);
gif2.setMatrix(this->matrix);
} }
void MatrixDisplayUi::setTargetFPS(uint8_t fps) void MatrixDisplayUi::setTargetFPS(uint8_t fps)
@@ -256,12 +261,12 @@ void MatrixDisplayUi::drawApp()
bool FirstApp = progress < 0.2; bool FirstApp = progress < 0.2;
bool LastApp = progress > 0.8; bool LastApp = progress > 0.8;
this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0)); this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0));
(this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, x, y, FirstApp, LastApp); (this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, x, y, FirstApp, LastApp, &gif1);
(this->AppFunctions[this->getnextAppNumber()])(this->matrix, &this->state, x1, y1, FirstApp, LastApp); (this->AppFunctions[this->getnextAppNumber()])(this->matrix, &this->state, x1, y1, FirstApp, LastApp, &gif2);
break; break;
} }
case FIXED: case FIXED:
(this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, 0, 0, false, false); (this->AppFunctions[this->state.currentApp])(this->matrix, &this->state, 0, 0, false, false, &gif2);
break; break;
} }
} }
@@ -278,7 +283,7 @@ void MatrixDisplayUi::drawOverlays()
{ {
for (uint8_t i = 0; i < this->overlayCount; i++) for (uint8_t i = 0; i < this->overlayCount; i++)
{ {
(this->overlayFunctions[i])(this->matrix, &this->state); (this->overlayFunctions[i])(this->matrix, &this->state, &gif2);
} }
} }

View File

@@ -31,7 +31,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "FastLED_NeoMatrix.h" #include "FastLED_NeoMatrix.h"
#include <vector> #include <vector>
#include "GifPlayer.h"
// #define DEBUG_MatrixDisplayUi(...) Serial.printf( __VA_ARGS__ ) // #define DEBUG_MatrixDisplayUi(...) Serial.printf( __VA_ARGS__ )
#ifndef DEBUG_MatrixDisplayUi #ifndef DEBUG_MatrixDisplayUi
@@ -53,6 +53,7 @@ enum AppState
// Structure of the UiState // Structure of the UiState
struct MatrixDisplayUiState struct MatrixDisplayUiState
{ {
u_int64_t lastUpdate = 0; u_int64_t lastUpdate = 0;
uint16_t ticksSinceLastStateSwitch = 0; uint16_t ticksSinceLastStateSwitch = 0;
@@ -68,17 +69,17 @@ struct MatrixDisplayUiState
void *userData = NULL; void *userData = NULL;
}; };
typedef void (*AppCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp); typedef void (*AppCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer);
typedef void (*OverlayCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state); typedef void (*OverlayCallback)(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer);
class MatrixDisplayUi class MatrixDisplayUi
{ {
private: private:
FastLED_NeoMatrix *matrix; FastLED_NeoMatrix *matrix;
// Values for the Apps // Values for the Apps
AnimationDirection appAnimationDirection = SLIDE_DOWN; AnimationDirection appAnimationDirection = SLIDE_DOWN;
int8_t lastTransitionDirection = 1; int8_t lastTransitionDirection = 1;
uint16_t ticksPerApp = 151; // ~ 5000ms at 30 FPS uint16_t ticksPerApp = 151; // ~ 5000ms at 30 FPS
@@ -86,7 +87,7 @@ private:
bool setAutoTransition = true; bool setAutoTransition = true;
bool lastFrameShown; bool lastFrameShown;
AppCallback *AppFunctions; AppCallback *AppFunctions = nullptr;
// Internally used to transition to a specific app // Internally used to transition to a specific app
int8_t nextAppNumber = -1; int8_t nextAppNumber = -1;
@@ -114,7 +115,6 @@ public:
* Initialise the display * Initialise the display
*/ */
void init(); void init();
void show();
/** /**
* Configure the internal used target FPS * Configure the internal used target FPS

View File

@@ -25,8 +25,6 @@ lib_deps =
marcmerlin/FastLED NeoMatrix@^1.2 marcmerlin/FastLED NeoMatrix@^1.2
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8
plerup/EspSoftwareSerial@^8.0.1 plerup/EspSoftwareSerial@^8.0.1
h2zero/NimBLE-Arduino@^1.4.1
[env:awtrix_upgrade] [env:awtrix_upgrade]
platform = https://github.com/platformio/platform-espressif32.git platform = https://github.com/platformio/platform-espressif32.git
@@ -45,4 +43,3 @@ lib_deps =
marcmerlin/FastLED NeoMatrix@^1.2 marcmerlin/FastLED NeoMatrix@^1.2
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8
plerup/EspSoftwareSerial@^8.0.1 plerup/EspSoftwareSerial@^8.0.1
h2zero/NimBLE-Arduino@^1.4.1

View File

@@ -107,7 +107,7 @@ int findAppIndexByName(const String &name)
return -1; return -1;
} }
void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
if (notify.flag) if (notify.flag)
return; return;
@@ -155,7 +155,7 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
} }
} }
void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
if (notify.flag) if (notify.flag)
return; return;
@@ -183,7 +183,7 @@ void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
} }
} }
void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
if (notify.flag) if (notify.flag)
return; return;
@@ -209,7 +209,7 @@ void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
} }
} }
void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
if (notify.flag) if (notify.flag)
return; return;
@@ -222,10 +222,8 @@ void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
matrix->print("%"); matrix->print("%");
} }
#ifdef ULANZI #ifdef ULANZI
void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
if (notify.flag) if (notify.flag)
return; return;
@@ -238,7 +236,7 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
} }
#endif #endif
void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state) void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{ {
if (!MenuManager.inMenu) if (!MenuManager.inMenu)
return; return;
@@ -246,7 +244,7 @@ void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
DisplayManager.printText(0, 6, utf8ascii(MenuManager.menutext()).c_str(), true, true); DisplayManager.printText(0, 6, utf8ascii(MenuManager.menutext()).c_str(), true, true);
} }
void AlarmApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state) void AlarmApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{ {
if (ALARM_ACTIVE) if (ALARM_ACTIVE)
{ {
@@ -271,7 +269,7 @@ void AlarmApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
} }
} }
void TimerApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state) void TimerApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{ {
if (TIMER_ACTIVE) if (TIMER_ACTIVE)
{ {
@@ -297,7 +295,7 @@ void TimerApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
} }
} }
void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
// Abort if notify.flag is set // Abort if notify.flag is set
if (notify.flag) if (notify.flag)
@@ -457,10 +455,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
// Display animated GIF if enabled and App is fixed, since we have only one gifplayer instance, it looks weird when 2 apps want to draw a different gif // Display animated GIF if enabled and App is fixed, since we have only one gifplayer instance, it looks weird when 2 apps want to draw a different gif
if (ca->isGif) if (ca->isGif)
{ {
if (state->appState == FIXED)
{ gifPlayer->playGif(x + ca->iconPosition, y, &ca->icon);
DisplayManager.drawGIF(x + ca->iconPosition, y, ca->icon);
}
} }
else else
{ {
@@ -478,7 +474,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
DisplayManager.getInstance().resetTextColor(); DisplayManager.getInstance().resetTextColor();
} }
void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state) void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{ {
// Check if notification flag is set // Check if notification flag is set
if (!notify.flag) if (!notify.flag)
@@ -634,7 +630,8 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
if (notify.isGif) if (notify.isGif)
{ {
// Display GIF if present // Display GIF if present
DisplayManager.drawGIF(notify.iconPosition, 0, notify.icon);
gifPlayer->playGif(notify.iconPosition, 0, &notify.icon);
} }
else else
{ {
@@ -655,124 +652,124 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
// Unattractive to have a function for every customapp wich does the same, but currently still no other option found TODO // Unattractive to have a function for every customapp wich does the same, but currently still no other option found TODO
void CApp1(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp1(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp1); String name = getAppNameByFunction(CApp1);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp2(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp2(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp2); String name = getAppNameByFunction(CApp2);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp3(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp3(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp3); String name = getAppNameByFunction(CApp3);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp4(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp4(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp4); String name = getAppNameByFunction(CApp4);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp5(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp5(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp5); String name = getAppNameByFunction(CApp5);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp6(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp6(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp6); String name = getAppNameByFunction(CApp6);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp7(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp7(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp7); String name = getAppNameByFunction(CApp7);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp8(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp8(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp8); String name = getAppNameByFunction(CApp8);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp9(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp9(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp9); String name = getAppNameByFunction(CApp9);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp10(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp10(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp10); String name = getAppNameByFunction(CApp10);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp11(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp11(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp11); String name = getAppNameByFunction(CApp11);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp12(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp12(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp12); String name = getAppNameByFunction(CApp12);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp13(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp13(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp13); String name = getAppNameByFunction(CApp13);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp14(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp14(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp14); String name = getAppNameByFunction(CApp14);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp15(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp15(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp15); String name = getAppNameByFunction(CApp15);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp16(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp16(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp16); String name = getAppNameByFunction(CApp16);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp17(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp17(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp17); String name = getAppNameByFunction(CApp17);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp18(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp18(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp18); String name = getAppNameByFunction(CApp18);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp19(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp19(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp19); String name = getAppNameByFunction(CApp19);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame) void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{ {
String name = getAppNameByFunction(CApp20); String name = getAppNameByFunction(CApp20);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame); ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
} }
const uint16_t *getWeatherIcon(int code) const uint16_t *getWeatherIcon(int code)

View File

@@ -1,292 +0,0 @@
#include <BeaconScanner.h>
#include <NimBLEDevice.h>
#include <Ticker.h>
#include "MQTTManager.h"
#include <ArduinoJson.h>
#include <LittleFS.h>
#include <DisplayManager.h>
float triggerDistance = 0.6;
String room = "Büro";
std::vector<String> allowedIds;
Ticker scanTicker;
// The getter for the instantiated singleton instance
BeaconScanner_ &BeaconScanner_::getInstance()
{
static BeaconScanner_ instance;
return instance;
}
// Initialize the global shared instance
BeaconScanner_ &BeaconScanner = BeaconScanner.getInstance();
static const int scanTime = 5; // In Sekunden
NimBLEScan *pBLEScan;
uint32_t fnv1a_32(const String &input)
{
const uint32_t FNV_PRIME = 0x01000193;
const uint32_t FNV_OFFSET_BASIS = 0x811C9DC5;
uint32_t hash = FNV_OFFSET_BASIS;
for (unsigned int i = 0; i < input.length(); ++i)
{
hash ^= static_cast<uint8_t>(input[i]);
hash *= FNV_PRIME;
}
return hash;
}
String getManufacturerName(uint16_t manufacturerID)
{
switch (manufacturerID)
{
case 0x004C: // Apple, Inc.
return "Apple";
case 0x0118: // Google, Inc.
return "Google";
case 0x000F: // Microsoft Corporation
return "Microsoft";
case 0x0030: // Ericsson Technology Licensing
return "Ericsson";
case 0x0039: // Intel Corp.
return "Intel";
case 0x0059: // Samsung Electronics Co., Ltd.
return "Samsung";
case 0x000D: // Nokia Corporation
return "Nokia";
case 0x0100: // Broadcom Corporation
return "Broadcom";
case 0x0034: // Texas Instruments Inc.
return "Texas Instruments";
case 0x0075: // Sony Ericsson Mobile Communications AB
return "Sony Ericsson";
case 0x0089: // Panasonic Corporation
return "Panasonic";
default:
return "Unknown";
}
}
bool isIdAllowed(const char *id)
{
if (allowedIds.size() == 0)
return true;
for (const String &allowedId : allowedIds)
{
if (strcmp(id, allowedId.c_str()) == 0)
{
return true;
}
}
Serial.println("Not allowed");
return false;
}
double calculateDistance(int rssi, int8_t txPower)
{
if (rssi == 0)
{
return -1.0;
}
double pathLoss = txPower - rssi;
// Path Loss Exponent (n) ist eine Umgebungsspezifische Konstante und liegt normalerweise zwischen 2 und 4.
// 2 entspricht Freiraum, während 4 dichtere Umgebungen repräsentiert.
double pathLossExponent = 3.0;
return pow(10, pathLoss / (10 * pathLossExponent));
}
String toHexString(const std::string &input)
{
String hexString = "";
for (unsigned char c : input)
{
char hexChar[3];
snprintf(hexChar, sizeof(hexChar), "%02X", c);
hexString += hexChar;
}
return hexString;
}
bool isIBeacon(NimBLEAdvertisedDevice *advertisedDevice, uint16_t *major, uint16_t *minor, int8_t *txPower, String *uuid, String *manufacturerName)
{
std::string payload = advertisedDevice->getManufacturerData();
if (payload.size() == 25 && static_cast<uint8_t>(payload[0]) == 0x4C && static_cast<uint8_t>(payload[1]) == 0x00 && static_cast<uint8_t>(payload[2]) == 0x02 && static_cast<uint8_t>(payload[3]) == 0x15)
{
uint16_t manufacturerID = (static_cast<uint8_t>(payload[0]) << 8) | static_cast<uint8_t>(payload[1]);
*uuid = toHexString(payload.substr(4, 16));
*major = (static_cast<uint8_t>(payload[20]) << 8) | static_cast<uint8_t>(payload[21]);
*minor = (static_cast<uint8_t>(payload[22]) << 8) | static_cast<uint8_t>(payload[23]);
*txPower = static_cast<int8_t>(payload[24]);
*manufacturerName = getManufacturerName(manufacturerID);
return true;
}
return false;
}
bool isEddystoneUID(NimBLEAdvertisedDevice *advertisedDevice, String *namespaceID, String *instanceID)
{
std::string serviceData = advertisedDevice->getServiceData();
if (serviceData.size() >= 20 && static_cast<uint8_t>(serviceData[0]) == 0xAA && static_cast<uint8_t>(serviceData[1]) == 0xFE && static_cast<uint8_t>(serviceData[2]) == 0x00)
{
*namespaceID = toHexString(serviceData.substr(4, 10));
*instanceID = toHexString(serviceData.substr(14, 6));
return true;
}
return false;
}
class MyAdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
{
void onResult(NimBLEAdvertisedDevice *advertisedDevice)
{
StaticJsonDocument<512> doc;
uint16_t major;
uint16_t minor;
int8_t txPower;
String uuid;
String manufacturer;
uint32_t hashedUUID = fnv1a_32(uuid);
char compressedUUID[9];
snprintf(compressedUUID, sizeof(compressedUUID), "%08X", hashedUUID);
int rssi = advertisedDevice->getRSSI();
doc["id"] = compressedUUID;
doc["rssi"] = rssi;
String topic;
bool sendToMQTT = false;
topic = String("rooms/") + room;
if (isIBeacon(advertisedDevice, &major, &minor, &txPower, &uuid, &manufacturer))
{
double BeaconDistance = calculateDistance(rssi, txPower);
doc["txPower"] = txPower;
doc["distance"] = BeaconDistance;
if (advertisedDevice->haveName())
{
String nameBLE = String(advertisedDevice->getName().c_str());
doc["name"] = nameBLE;
}
Serial.print("iBeacon UUID: ");
Serial.print(compressedUUID);
Serial.print(" Distance: ");
Serial.print(BeaconDistance);
Serial.print(" Manufacturer: ");
Serial.print(manufacturer);
Serial.print(" TxPower: ");
Serial.println(txPower);
if (BeaconDistance < 0.2)
{
char jsonString[100];
memset(jsonString, 0, sizeof(jsonString));
std::snprintf(jsonString, sizeof(jsonString), "{\"text\":\"%s\",\"duration\":\"%d\",\"color\":%s\"}", compressedUUID, 4,"#00ff00");
DisplayManager.generateNotification(jsonString);
return;
}
if ((BeaconDistance <= triggerDistance) && isIdAllowed(compressedUUID))
{
char JSONmessageBuffer[512];
serializeJson(doc, JSONmessageBuffer);
MQTTManager.publish(topic.c_str(), JSONmessageBuffer);
}
}
}
};
void BeaconScanner_::startScan()
{
Serial.println(F("---------------"));
Serial.println(F("Scan BLE"));
Serial.println(F("---------------"));
pBLEScan->start(scanTime, [](NimBLEScanResults results)
{ scanTicker.once(scanTime, []()
{ BeaconScanner.startScan(); }); });
}
void printAllowedIds()
{
Serial.println("Allowed IDs:");
for (const String &allowedId : allowedIds)
{
Serial.println(allowedId);
}
}
bool loadBeaconSettings()
{
Serial.println("loadSettings");
if (LittleFS.exists("/beacons.json"))
{
File file = LittleFS.open("/beacons.json", "r");
DynamicJsonDocument doc(128);
DeserializationError error = deserializeJson(doc, file);
if (error)
{
Serial.println(F("Failed to read beacon settings"));
return false;
}
if (doc.containsKey("room"))
{
room = doc["room"].as<String>();
Serial.println(room);
}
else
{
return false;
}
if (doc.containsKey("trigger_distance"))
{
triggerDistance = doc["trigger_distance"].as<float>();
Serial.println(triggerDistance);
}
else
{
return false;
}
if (doc.containsKey("allowed_ids"))
{
JsonArray allowedIdsJsonArray = doc["allowed_ids"];
for (const char *id : allowedIdsJsonArray)
{
allowedIds.push_back(String(id));
}
printAllowedIds();
}
return true;
file.close();
}
else
{
return false;
}
}
void BeaconScanner_::setup()
{
if (!loadBeaconSettings())
return;
NimBLEDevice::init("");
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
pBLEScan = NimBLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
pBLEScan->setActiveScan(true);
pBLEScan->setMaxResults(0);
startScan();
}

View File

@@ -1,18 +0,0 @@
#ifndef BeaconScanner_h
#define BeaconScanner_h
#include <Arduino.h>
class BeaconScanner_
{
private:
BeaconScanner_() = default;
public:
static BeaconScanner_ &getInstance();
void setup();
void startScan();
};
extern BeaconScanner_ &BeaconScanner;
#endif

View File

@@ -15,6 +15,7 @@
#include "Apps.h" #include "Apps.h"
#include "Dictionary.h" #include "Dictionary.h"
#include <set> #include <set>
#include "GifPlayer.h"
Ticker AlarmTicker; Ticker AlarmTicker;
Ticker TimerTicker; Ticker TimerTicker;
@@ -93,12 +94,6 @@ bool DisplayManager_::setAutoTransition(bool active)
showGif = false; showGif = false;
} }
void DisplayManager_::drawGIF(uint16_t x, uint16_t y, fs::File gFile)
{
gif.setFile(gFile);
gif.drawFrame(x, y);
}
void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile) void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile)
{ {
TJpgDec.drawFsJpg(x, y, jpgFile); TJpgDec.drawFsJpg(x, y, jpgFile);
@@ -211,7 +206,7 @@ void pushCustomApp(String name, int position)
if (customApps.count(name) == 0) if (customApps.count(name) == 0)
{ {
++customPagesCount; ++customPagesCount;
void (*customApps[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20}; void (*customApps[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool, GifPlayer *) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20};
if (position < 0) // Insert at the end of the vector if (position < 0) // Insert at the end of the vector
{ {
@@ -307,7 +302,7 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json)
customApp.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0; customApp.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
customApp.textCase = doc.containsKey("textCase") ? doc["textCase"] : 0; customApp.textCase = doc.containsKey("textCase") ? doc["textCase"] : 0;
customApp.name = name; customApp.name = name;
customApp.text = utf8ascii(doc["text"].as<String>()); customApp.text = doc.containsKey("text") ? utf8ascii(doc["text"].as<String>()) : "";
if (doc.containsKey("color")) if (doc.containsKey("color"))
{ {
@@ -386,7 +381,7 @@ void DisplayManager_::generateNotification(const char *json)
deserializeJson(doc, json); deserializeJson(doc, json);
notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_APP; notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_APP;
notify.text = utf8ascii(doc["text"].as<String>()); notify.text = doc.containsKey("text") ? utf8ascii(doc["text"].as<String>()) : "";
notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint16_t>() : -1; notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint16_t>() : -1;
notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as<bool>() : false; notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as<bool>() : false;
notify.hold = doc.containsKey("hold") ? doc["hold"].as<bool>() : false; notify.hold = doc.containsKey("hold") ? doc["hold"].as<bool>() : false;
@@ -551,10 +546,6 @@ void DisplayManager_::setup()
ui->init(); ui->init();
} }
void ShowGif()
{
}
void DisplayManager_::tick() void DisplayManager_::tick()
{ {
if (AP_MODE) if (AP_MODE)
@@ -577,9 +568,6 @@ void DisplayManager_::tick()
MQTTManager.setCurrentApp(CURRENT_APP); MQTTManager.setCurrentApp(CURRENT_APP);
setAppTime(TIME_PER_APP); setAppTime(TIME_PER_APP);
} }
// if (showGif && !MenuManager.inMenu)
//
// matrix->show();
} }
} }

View File

@@ -37,7 +37,6 @@
#include "ServerManager.h" #include "ServerManager.h"
#include "Globals.h" #include "Globals.h"
#include "UpdateManager.h" #include "UpdateManager.h"
#include "BeaconScanner.h"
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
volatile bool StopTask = false; volatile bool StopTask = false;
@@ -85,7 +84,7 @@ void setup()
DisplayManager.HSVtext(x, 6, ("AWTRIX " + ServerManager.myIP.toString()).c_str(), true, 0); DisplayManager.HSVtext(x, 6, ("AWTRIX " + ServerManager.myIP.toString()).c_str(), true, 0);
x -= 0.18; x -= 0.18;
} }
BeaconScanner.setup(); // BeaconScanner.setup();
} }
else else
{ {
@@ -94,6 +93,7 @@ void setup()
} }
delay(200); delay(200);
DisplayManager.setBrightness(BRIGHTNESS);
DisplayManager.clearMatrix(); DisplayManager.clearMatrix();
} }