2022-08-03 13:19:25 +02:00
|
|
|
#ifndef LED_DISPLAY
|
|
|
|
#define LED_DISPLAY
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ArduinoJson.h>
|
2020-10-15 22:54:20 +02:00
|
|
|
#include "mbedtls/md.h"
|
|
|
|
#include "EepromManager.h"
|
2020-10-13 17:01:29 +02:00
|
|
|
#include "BluetoothLeUartServer.h"
|
|
|
|
#include "LedDisplayController.h"
|
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
|
2022-08-03 13:19:25 +02:00
|
|
|
class LedDisplay : protected BluetoothLeUartServerCallbacks
|
2020-10-14 23:54:54 +02:00
|
|
|
{
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
public:
|
2020-10-17 23:06:55 +02:00
|
|
|
template<typename T_COLOR_FEATURE, typename T_METHOD>
|
2022-08-03 13:19:25 +02:00
|
|
|
explicit LedDisplay(String deviceName, NeoPixelBrightnessBusGfx<T_COLOR_FEATURE, T_METHOD> *ledDisplayMatrix)
|
2020-10-17 23:06:55 +02:00
|
|
|
{
|
|
|
|
this->lastKeepAlive = -1;
|
|
|
|
this->sessionAuthorized = false;
|
|
|
|
|
|
|
|
// init eeprom manager
|
|
|
|
this->eepromManager = new EepromManager();
|
|
|
|
|
|
|
|
// init led display controller
|
|
|
|
this->ledDisplayController = new LedDisplayController(ledDisplayMatrix);
|
|
|
|
this->ledDisplayController->registerEepromUnit(this->eepromManager);
|
|
|
|
|
2020-10-17 23:20:15 +02:00
|
|
|
// register eeprom for this class
|
|
|
|
this->eepromUnit = this->eepromManager->registerEempromUnit(sizeof(DisplayProperties));
|
|
|
|
this->loadProperties();
|
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
// init ble server
|
2020-10-17 23:20:15 +02:00
|
|
|
this->bleServer = new BluetoothLeUartServer(this->properties.deviceName, "92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
|
2020-10-17 23:06:55 +02:00
|
|
|
this->bleServer->setCallbacks(this);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// befriend for callbacks
|
|
|
|
friend class BluetoothLeUartServer;
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-15 16:58:06 +02:00
|
|
|
void loop();
|
|
|
|
|
2020-10-13 17:01:29 +02:00
|
|
|
protected:
|
2020-10-14 23:54:54 +02:00
|
|
|
// calbacks for BluetoothLeUartServerCallbacks
|
|
|
|
void onDeviceConnectedChanged(bool deviceConnected) override;
|
2020-10-13 17:01:29 +02:00
|
|
|
void onDataReceived(String data) override;
|
|
|
|
|
|
|
|
private:
|
2022-07-28 10:11:12 +02:00
|
|
|
|
2022-08-03 13:19:25 +02:00
|
|
|
enum DisplayCommand
|
2020-10-14 23:54:54 +02:00
|
|
|
{
|
2020-10-18 01:40:24 +02:00
|
|
|
AuthenticateCommand = 0,
|
2020-10-15 16:58:06 +02:00
|
|
|
KeepAliveCommand = 1,
|
2020-10-14 23:54:54 +02:00
|
|
|
GetAllTextSetsCommand = 10,
|
|
|
|
GetTextSetParameterCommand = 11,
|
|
|
|
GetDisplayBrightnessCommand = 12,
|
|
|
|
SetTextSetParameterCommand = 20,
|
2020-10-17 03:22:37 +02:00
|
|
|
SetDisplayBrightnessCommand = 21,
|
|
|
|
SetDisplayCodeCommand = 22,
|
|
|
|
SetDisplayNameCommand = 23
|
2020-10-14 23:54:54 +02:00
|
|
|
};
|
|
|
|
|
2022-08-03 13:19:25 +02:00
|
|
|
enum DisplayStatusCode
|
2020-10-14 23:54:54 +02:00
|
|
|
{
|
|
|
|
Success = 200,
|
2020-10-17 03:22:37 +02:00
|
|
|
BadRequestError = 400,
|
2020-10-15 22:54:20 +02:00
|
|
|
Unauthorized = 401,
|
2020-10-14 23:54:54 +02:00
|
|
|
InternalError = 500,
|
|
|
|
DisplayControllerError = 501
|
|
|
|
};
|
|
|
|
|
2020-10-15 16:58:06 +02:00
|
|
|
unsigned long lastKeepAlive;
|
|
|
|
const int maximumKeepAliveDelay = 10000;
|
2020-10-15 22:54:20 +02:00
|
|
|
bool sessionAuthorized;
|
2020-10-15 16:58:06 +02:00
|
|
|
|
2020-10-15 22:54:20 +02:00
|
|
|
typedef struct {
|
|
|
|
char deviceName[50];
|
|
|
|
char deviceCode[5];
|
|
|
|
char valid[3];
|
|
|
|
} DisplayProperties;
|
|
|
|
|
|
|
|
DisplayProperties properties;
|
|
|
|
|
|
|
|
EepromManager* eepromManager;
|
|
|
|
EepromUnit* eepromUnit;
|
|
|
|
LedDisplayController* ledDisplayController;
|
|
|
|
BluetoothLeUartServer* bleServer;
|
|
|
|
|
|
|
|
bool loadProperties();
|
|
|
|
bool storeProperties();
|
|
|
|
|
|
|
|
String sha256(String payload);
|
2020-10-13 17:01:29 +02:00
|
|
|
};
|
|
|
|
|
2022-08-03 13:19:25 +02:00
|
|
|
#endif // LED_DISPLAY
|