This commit is contained in:
Elfish
2023-04-02 12:06:17 +02:00
44 changed files with 1677 additions and 1155 deletions

View File

@@ -36,6 +36,7 @@ struct CustomApp
bool isGif;
bool rainbow;
bool soundPlayed;
uint16_t duration = 0;
String sound;
int16_t repeat = 0;
int16_t currentRepeat = 0;
@@ -61,7 +62,7 @@ struct Notification
bool isGif;
bool flag = false;
unsigned long startime = 0;
unsigned long duration = 0;
uint16_t duration = 0;
int16_t repeat = -1;
bool hold = false;
byte pushIcon = 0;
@@ -104,7 +105,7 @@ int findAppIndexByName(const String &name)
return -1;
}
void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
@@ -152,7 +153,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 firstApp, bool lastApp)
void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
@@ -180,7 +181,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 firstApp, bool lastApp)
void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
@@ -201,7 +202,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 firstApp, bool lastApp)
void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
@@ -215,7 +216,7 @@ void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
}
#ifdef ULANZI
void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
@@ -287,7 +288,7 @@ else
}
}
void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
// Abort if notify.flag is set
if (notify.flag)
@@ -304,8 +305,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
return;
}
// reset custom App properties if last App
if (lastApp)
// reset custom App properties if last frame
if (lastFrame)
{
ca->iconWasPushed = false;
ca->scrollposition = 9;
@@ -313,6 +314,14 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
ca->scrollDelay = 0;
}
if (!DisplayManager.appIsSwitching)
{
if (ca->duration > 0)
{
DisplayManager.setAppTime(ca->duration);
}
}
CURRENT_APP = ca->name;
currentCustomApp = name;
@@ -634,64 +643,126 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
DisplayManager.getInstance().resetTextColor();
}
void CApp1(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
// 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)
{
String name = getAppNameByFunction(CApp1);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp2(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp2(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp2);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp3(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp3(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp3);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp4(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp4(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp4);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp5(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp5(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp5);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp6(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp6(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp6);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp7(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp7(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp7);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp8(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp8(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp8);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp9(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp9(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp9);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp10(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void CApp10(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp10);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp11(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp11);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp12(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp12);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp13(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp13);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp14(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp14);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp15(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp15);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp16(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp16);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp17(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp17);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp18(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp18);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp19(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp19);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
String name = getAppNameByFunction(CApp20);
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame);
}
const uint16_t *getWeatherIcon(int code)
@@ -708,7 +779,7 @@ const uint16_t *getWeatherIcon(int code)
}
}
void WeatherApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
void WeatherApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;

View File

@@ -69,6 +69,17 @@ const char HAtransID[] PROGMEM = {"%s_tra"};
const char HAtransName[] PROGMEM = {"Transition"};
const char HAtransIcon[] PROGMEM = {"mdi:swap-vertical"};
const char HAupdateID[] PROGMEM = {"%s_upd"};
const char HAupdateName[] PROGMEM = {"Update"};
const char HAupdateClass[] PROGMEM = {"update"};
const char HAupdateIcon[] PROGMEM = {"mdi:update"};
const char HAdoUpID[] PROGMEM = {"%s_doupd"};
const char HAdoUpName[] PROGMEM = {"Start Update"};
const char HAdoUpIcon[] PROGMEM = {"mdi:update"};
const char HAsigID[] PROGMEM = {"%s_sig"};
const char HAsigIcon[] PROGMEM = {"mdi:sun-wireless"};
const char HAsigName[] PROGMEM = {"WiFi strength"};
@@ -104,3 +115,4 @@ const char TempKey[] PROGMEM = {"temp"};
const char HumKey[] PROGMEM = {"hum"};
const char UpTimeKey[] PROGMEM = {"uptime"};
const char SignalStrengthKey[] PROGMEM = {"wifi_signal"};
const char UpdateKey[] PROGMEM = {"up_available"};

View File

@@ -77,10 +77,19 @@ extern const char HAupID[];
extern const char HAupName[];
extern const char HAupClass[];
extern const char HAdoUpID[];
extern const char HAdoUpName[];
extern const char HAdoUpIcon[];
extern const char HAtransID[];
extern const char HAtransName[];
extern const char HAtransIcon[];
extern const char HAupdateID[];
extern const char HAupdateName[];
extern const char HAupdateClass[];
extern const char HAupdateIcon[];
extern const char HAbtnLID[];
extern const char HAbtnLName[];
@@ -106,5 +115,5 @@ extern const char TempKey[];
extern const char HumKey[];
extern const char UpTimeKey[];
extern const char SignalStrengthKey[];
extern const char UpdateKey[];
#endif

View File

@@ -13,6 +13,7 @@
#include "ServerManager.h"
#include "MenuManager.h"
#include "Apps.h"
#include "Dictionary.h"
Ticker AlarmTicker;
Ticker TimerTicker;
@@ -26,8 +27,6 @@ Ticker TimerTicker;
#define MATRIX_WIDTH 32
#define MATRIX_HEIGHT 8
bool appIsSwitching;
GifPlayer gif;
CRGB leds[MATRIX_WIDTH * MATRIX_HEIGHT];
@@ -214,7 +213,7 @@ void pushCustomApp(String name, int position)
if (customApps.count(name) == 0)
{
++customPagesCount;
void (*customApps[10])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10};
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};
if (position < 0) // Insert at the end of the vector
{
@@ -230,6 +229,7 @@ void pushCustomApp(String name, int position)
}
ui.setApps(Apps); // Add Apps
DisplayManager.getInstance().setAutoTransition(true);
}
}
@@ -238,17 +238,15 @@ void removeCustomApp(const String &name)
auto it = std::find_if(Apps.begin(), Apps.end(), [&name](const std::pair<String, AppCallback> &appPair)
{ return appPair.first == name; });
if (it != Apps.end())
{
Apps.erase(it);
ui.setApps(Apps);
}
Apps.erase(it);
ui.setApps(Apps);
}
void DisplayManager_::generateCustomPage(String name, const char *json)
{
if (json == "" && customApps.count(name))
if (strcmp(json, "") == 0 && customApps.count(name))
{
Serial.println("delete");
customApps.erase(customApps.find(name));
removeCustomApp(name);
return;
@@ -295,6 +293,7 @@ void DisplayManager_::generateCustomPage(String name, const char *json)
customApp.barSize = 0;
}
customApp.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : 0;
int pos = doc.containsKey("pos") ? doc["pos"].as<uint8_t>() : -1;
customApp.rainbow = doc.containsKey("rainbow") ? doc["rainbow"] : false;
customApp.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
@@ -519,6 +518,7 @@ void DisplayManager_::loadNativeApps()
void DisplayManager_::setup()
{
TJpgDec.setCallback(jpg_output);
FastLED.addLeds<NEOPIXEL, MATRIX_PIN>(leds, MATRIX_WIDTH * MATRIX_HEIGHT);
gif.setMatrix(&matrix);
@@ -536,17 +536,17 @@ void DisplayManager_::tick()
}
else
{
ui.update();
if (ui.getUiState()->appState == IN_TRANSITION && !appIsSwitching)
{
appIsSwitching = true;
MQTTManager.setCurrentApp(CURRENT_APP);
}
else if (ui.getUiState()->appState == FIXED && appIsSwitching)
{
appIsSwitching = false;
MQTTManager.setCurrentApp(CURRENT_APP);
setAppTime(TIME_PER_APP);
}
ui.update();
}
}
@@ -788,7 +788,8 @@ void DisplayManager_::updateAppVector(const char *json)
bool show = true;
int position = -1;
if (app.containsKey("show"))
if (app.containsKey("show"))
{
show = app["show"].as<bool>();
}
@@ -819,13 +820,17 @@ void DisplayManager_::updateAppVector(const char *json)
callback = HumApp;
SHOW_HUM = show;
}
#ifdef ULANZI
else if (name == "bat")
{
callback = BatApp;
SHOW_BAT = show;
}
#endif
else
{
// If the app is not one of the built-in apps, check if it's already in the vector
@@ -884,4 +889,33 @@ void DisplayManager_::updateAppVector(const char *json)
Apps = std::move(newApps);
ui.setApps(Apps);
saveSettings();
}
String DisplayManager_::getStat()
{
StaticJsonDocument<200> doc;
char buffer[5];
#ifdef ULANZI
doc[BatKey] = BATTERY_PERCENT;
doc[BatRawKey] = BATTERY_RAW;
#endif
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
doc[LuxKey] = buffer;
doc[LDRRawKey] = LDR_RAW;
doc[BrightnessKey] = BRIGHTNESS;
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
doc[TempKey] = buffer;
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
doc[HumKey] = buffer;
doc[UpTimeKey] = PeripheryManager.readUptime();
doc[SignalStrengthKey] = WiFi.RSSI();
doc[UpdateKey] = UPDATE_AVAILABLE;
String jsonString;
serializeJson(doc, jsonString);
return jsonString;
}
void DisplayManager_::setAppTime(uint16_t duration)
{
ui.setTimePerApp(duration);
}

View File

@@ -26,6 +26,7 @@ private:
public:
static DisplayManager_ &getInstance();
bool appIsSwitching;
void setup();
void tick();
void clear();
@@ -48,7 +49,7 @@ public:
void setFPS(uint8_t);
void MatrixState(bool);
void generateNotification(const char *json);
void generateCustomPage(String, const char *json);
void generateCustomPage(String name, const char *json);
void printText(int16_t x, int16_t y, const char *text, bool centered, bool ignoreUppercase);
bool setAutoTransition(bool active);
void switchToApp(const char *json);
@@ -60,6 +61,9 @@ public:
void drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h);
void drawBarChart(int16_t x, int16_t y, const int data[], byte dataSize, bool withIcon, uint16_t color);
void updateAppVector(const char *json);
void setMatrixLayout(int layout);
void setAppTime(uint16_t duration);
String getStat();
};
extern DisplayManager_ &DisplayManager;

View File

@@ -1,6 +1,8 @@
#include "Globals.h"
#include "Preferences.h"
#include <WiFi.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
Preferences Settings;
@@ -13,8 +15,53 @@ char *getID()
return macStr;
}
void startLittleFS()
{
if (LittleFS.begin())
{
LittleFS.mkdir("/MELODIES");
LittleFS.mkdir("/ICONS");
}
else
{
Serial.println("ERROR on mounting LittleFS. It will be formmatted!");
LittleFS.format();
ESP.restart();
}
}
void loadDevSettings()
{
Serial.println("laodSettings");
File file = LittleFS.open("/dev.json", "r");
if (!file)
{
return;
}
DynamicJsonDocument doc(128);
DeserializationError error = deserializeJson(doc, file);
if (error)
{
Serial.println(F("Failed to read dev settings"));
return;
}
if (doc.containsKey("bootsound"))
{
BOOT_SOUND = doc["bootsound"].as<String>();
}
if (doc.containsKey("bootsound"))
{
UPPERCASE_LETTERS = doc["uppercase"].as<bool>();
}
file.close();
}
void loadSettings()
{
startLittleFS();
Settings.begin("awtrix", false);
MATRIX_FPS = Settings.getUChar("FPS", 23);
BRIGHTNESS = Settings.getUChar("BRI", 120);
@@ -31,12 +78,15 @@ void loadSettings()
SHOW_DATE = Settings.getBool("DAT", true);
SHOW_TEMP = Settings.getBool("TEMP", true);
SHOW_HUM = Settings.getBool("HUM", true);
MATRIX_LAYOUT = Settings.getUInt("MAT", 0);
#ifdef ULANZI
SHOW_BAT = Settings.getBool("BAT", true);
#endif
SOUND_ACTIVE = Settings.getBool("SOUND", true);
Settings.end();
uniqueID = getID();
MQTT_PREFIX = String(uniqueID);
loadDevSettings();
}
void saveSettings()
@@ -57,9 +107,11 @@ void saveSettings()
Settings.putBool("DAT", SHOW_DATE);
Settings.putBool("TEMP", SHOW_TEMP);
Settings.putBool("HUM", SHOW_HUM);
Settings.putUInt("MAT", MATRIX_LAYOUT);
#ifdef ULANZI
Settings.putBool("BAT", SHOW_BAT);
#endif
Settings.putBool("SOUND", SOUND_ACTIVE);
Settings.end();
}
@@ -69,7 +121,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.45";
const char *VERSION = "0.47";
String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
String MQTT_USER;
@@ -130,4 +182,10 @@ bool AP_MODE;
bool MATRIX_OFF;
bool TIMER_ACTIVE;
bool ALARM_ACTIVE;
uint16_t TEXTCOLOR_565 = 0xFFFF;
uint16_t TEXTCOLOR_565 = 0xFFFF;
bool SOUND_ACTIVE;
String BOOT_SOUND = "";
uint8_t VOLUME;
uint8_t VOLUME_PERCENT;
int MATRIX_LAYOUT;
bool UPDATE_AVAILABLE = false;

View File

@@ -66,7 +66,12 @@ extern String TIME_FORMAT;
extern String DATE_FORMAT;
extern bool START_ON_MONDAY;
extern bool IS_CELSIUS;
extern bool SOUND_ACTIVE;
extern String BOOT_SOUND;
extern uint8_t VOLUME;
extern uint8_t VOLUME_PERCENT;
extern int MATRIX_LAYOUT;
extern bool UPDATE_AVAILABLE;
void loadSettings();
void saveSettings();
#endif // Globals_H

View File

@@ -6,8 +6,8 @@
#include <WiFi.h>
#include <ArduinoJson.h>
#include "Dictionary.h"
unsigned long startTime;
#include "PeripheryManager.h"
#include "UpdateManager.h"
WiFiClient espClient;
uint8_t lastBrightness;
@@ -37,6 +37,8 @@ HASensor *ram = nullptr;
HABinarySensor *btnleft = nullptr;
HABinarySensor *btnmid = nullptr;
HABinarySensor *btnright = nullptr;
HABinarySensor *update = nullptr;
HAButton *doUpdate = nullptr;
// The getter for the instantiated singleton instance
MQTTManager_ &MQTTManager_::getInstance()
@@ -62,6 +64,11 @@ void onButtonCommand(HAButton *sender)
{
DisplayManager.previousApp();
}
else if (sender == doUpdate)
{
if (UPDATE_AVAILABLE)
UpdateManager.updateFirmware();
}
}
void onSwitchCommand(bool state, HASwitch *sender)
@@ -184,6 +191,12 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
DisplayManager.previousApp();
return;
}
if (strTopic == MQTT_PREFIX + "/doupdate")
{
if (UPDATE_AVAILABLE)
UpdateManager.updateFirmware();
return;
}
else if (strTopic.startsWith(MQTT_PREFIX + "/custom"))
{
@@ -203,7 +216,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
void onMqttConnected()
{
String prefix = MQTT_PREFIX;
const char* topics[] PROGMEM = {
const char *topics[] PROGMEM = {
"/brightness",
"/notify/dismiss",
"/notify",
@@ -213,15 +226,17 @@ void onMqttConnected()
"/settings",
"/previousapp",
"/nextapp",
"/doupdate",
"/nextapp",
"/apps"
};
for (const char* topic : topics) {
"/apps"};
for (const char *topic : topics)
{
String fullTopic = prefix + topic;
mqtt.subscribe(fullTopic.c_str());
}
Serial.println(F("MQTT Connected"));
}
void connect()
{
mqtt.onMessage(onMqttMessage);
@@ -240,14 +255,14 @@ void connect()
}
char matID[40], briID[40];
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40];
char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], updateID[40], doUpdateID[40];
#ifdef ULANZI
char batID[40];
#endif
void MQTTManager_::setup()
{
startTime = millis();
if (HA_DISCOVERY)
{
Serial.println(F("Starting Homeassistant discorvery"));
@@ -262,6 +277,8 @@ void MQTTManager_::setup()
device.setManufacturer(HAmanufacturer);
device.setModel(HAmodel);
device.setAvailability(true);
device.enableSharedAvailability();
device.enableLastWill();
String uniqueIDWithSuffix;
@@ -296,6 +313,12 @@ void MQTTManager_::setup()
dismiss->setIcon(HAbtnaIcon);
dismiss->setName(HAbtnaName);
sprintf(doUpdateID, HAdoUpID, macStr);
doUpdate = new HAButton(doUpdateID);
doUpdate->setIcon(HAdoUpIcon);
doUpdate->setName(HAdoUpName);
doUpdate->onCommand(onButtonCommand);
sprintf(transID, HAtransID, macStr);
transition = new HASwitch(transID);
transition->setIcon(HAtransIcon);
@@ -370,6 +393,12 @@ void MQTTManager_::setup()
btnleft = new HABinarySensor(btnLID);
btnleft->setName(HAbtnLName);
sprintf(updateID, HAupdateID, macStr);
update = new HABinarySensor(updateID);
update->setIcon(HAupdateIcon);
update->setName(HAupdateName);
update->setDeviceClass(HAupdateClass);
sprintf(btnMID, HAbtnMID, macStr);
btnmid = new HABinarySensor(btnMID);
btnmid->setName(HAbtnMName);
@@ -418,22 +447,6 @@ void MQTTManager_::setCurrentApp(String value)
curApp->setValue(value.c_str());
}
const char *readUptime()
{
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned long uptimeSeconds = elapsedTime / 1000;
unsigned long uptimeMinutes = uptimeSeconds / 60;
unsigned long uptimeHours = uptimeMinutes / 60;
unsigned long uptimeDays = uptimeHours / 24;
unsigned long hours = uptimeHours % 24;
unsigned long minutes = uptimeMinutes % 60;
unsigned long seconds = uptimeSeconds % 60;
sprintf(uptime, "P%dDT%dH%dM%dS", uptimeDays, hours, minutes, seconds);
return uptime;
}
void MQTTManager_::sendStats()
{
if (HA_DISCOVERY)
@@ -466,33 +479,17 @@ void MQTTManager_::sendStats()
int freeHeapBytes = ESP.getFreeHeap();
itoa(freeHeapBytes, rambuffer, 10);
ram->setValue(rambuffer);
uptime->setValue(readUptime());
uptime->setValue(PeripheryManager.readUptime());
version->setValue(VERSION);
transition->setState(AUTO_TRANSITION, false);
update->setState(UPDATE_AVAILABLE, false);
}
else
{
}
StaticJsonDocument<200> doc;
char buffer[5];
#ifdef ULANZI
doc[BatKey] = BATTERY_PERCENT;
doc[BatRawKey] = BATTERY_RAW;
#endif
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
doc[LuxKey] = buffer;
doc[LDRRawKey] = LDR_RAW;
doc[BrightnessKey] = BRIGHTNESS;
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
doc[TempKey] = buffer;
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
doc[HumKey] = buffer;
doc[UpTimeKey] = readUptime();
doc[SignalStrengthKey] = WiFi.RSSI();
String jsonString;
serializeJson(doc, jsonString);
publish(StatsTopic, jsonString.c_str());
publish(StatsTopic, DisplayManager.getStat().c_str());
}
void MQTTManager_::sendButton(byte btn, bool state)

View File

@@ -3,8 +3,10 @@
#include <Globals.h>
#include <ServerManager.h>
#include <DisplayManager.h>
#include <updater.h>
#include <PeripheryManager.h>
//#include <update.h>
#include <icons.h>
#include <UpdateManager.h>
String menuText;
int menuSelection;
@@ -26,6 +28,8 @@ enum MenuState
WeekdayMenu,
TempMenu,
Appmenu,
SoundMenu,
VolumeMenu
};
const char *menuItems[] PROGMEM = {
@@ -40,10 +44,11 @@ const char *menuItems[] PROGMEM = {
"WEEKDAY",
"TEMP",
"APPS",
"SOUND",
"UPDATE"};
int8_t menuIndex = 0;
uint8_t menuItemCount = 12;
uint8_t menuItemCount = 13;
const char *timeFormat[] PROGMEM = {
"%H:%M:%S",
@@ -75,14 +80,13 @@ const char *appsItems[][2] PROGMEM = {
{"13", "time"},
{"1158", "date"},
{"234", "temp"},
#ifdef ULANZI
#ifdef ULANZI
{"2075", "hum"},
{"1486", "bat"}};
#else
#else
{"2075", "hum"}};
#endif
int8_t appsIndex;
uint8_t appsCount = 5;
@@ -134,6 +138,8 @@ String MenuManager_::menutext()
return "0x" + String(textColors[currentColor], HEX);
case SwitchMenu:
return AUTO_TRANSITION ? "ON" : "OFF";
case SoundMenu:
return SOUND_ACTIVE ? "ON" : "OFF";
case TspeedMenu:
return String(TIME_PER_TRANSITION / 1000.0, 1) + "s";
case AppTimeMenu:
@@ -238,9 +244,16 @@ void MenuManager_::rightButton()
case WeekdayMenu:
START_ON_MONDAY = !START_ON_MONDAY;
break;
case SoundMenu:
SOUND_ACTIVE = !SOUND_ACTIVE;
break;
case TempMenu:
IS_CELSIUS = !IS_CELSIUS;
break;
case VolumeMenu:
VOLUME_PERCENT = (VOLUME_PERCENT % 100) + 1;
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
PeripheryManager.setVolume(VOLUME);
default:
break;
}
@@ -298,6 +311,13 @@ void MenuManager_::leftButton()
case TempMenu:
IS_CELSIUS = !IS_CELSIUS;
break;
case SoundMenu:
SOUND_ACTIVE = !SOUND_ACTIVE;
break;
case VolumeMenu:
VOLUME_PERCENT = (VOLUME_PERCENT % 100) + 1;
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
PeripheryManager.setVolume(VOLUME);
default:
break;
}
@@ -349,9 +369,18 @@ void MenuManager_::selectButton()
currentState = Appmenu;
break;
case 11:
if (FirmwareVersionCheck())
currentState = SoundMenu;
break;
case 12:
#ifdef AWTRIX_UPGRADE
currentState = VolumeMenu;
break;
#endif
case 13:
if (UpdateManager.checkUpdate(true))
{
updateFirmware();
UpdateManager.updateFirmware();
}
break;
default:
@@ -425,6 +454,12 @@ void MenuManager_::selectButtonLong()
DisplayManager.applyAllSettings();
saveSettings();
break;
case VolumeMenu:
#ifdef AWTRIX_UPGRADE
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
saveSettings();
#endif
break;
case TimeFormatMenu:
TIME_FORMAT = timeFormat[timeFormatIndex];
saveSettings();
@@ -433,6 +468,7 @@ void MenuManager_::selectButtonLong()
DATE_FORMAT = dateFormat[dateFormatIndex];
saveSettings();
case WeekdayMenu:
case SoundMenu:
case TempMenu:
saveSettings();
break;

View File

@@ -16,8 +16,6 @@
#include <LightDependentResistor.h>
#include <MenuManager.h>
#define SOUND_OFF false
#ifdef ULANZI
// Pinouts für das ULANZI-Environment
#define BATTERY_PIN 34
@@ -43,8 +41,16 @@
#ifdef ULANZI
Adafruit_SHT31 sht31;
#else
class Mp3Notify
{
};
Adafruit_BME280 bme280;
SoftwareSerial mySoftwareSerial(D7, D5); // RX, TX
typedef DFMiniMp3<SoftwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(mySoftwareSerial);
#endif
EasyButton button_left(BUTTON_UP_PIN);
EasyButton button_right(BUTTON_DOWN_PIN);
EasyButton button_select(BUTTON_SELECT_PIN);
@@ -74,6 +80,7 @@ unsigned long previousMillis_LDR = 0;
const unsigned long interval_BatTempHum = 10000;
const unsigned long interval_LDR = 100;
int total = 0;
unsigned long startTime;
const int LDRReadings = 10;
int TotalLDRReadings[LDRReadings];
@@ -81,6 +88,11 @@ float sampleSum = 0.0;
float sampleAverage = 0.0;
float brightnessPercent = 0.0;
#ifdef awrtrix_upgrade
class Mp3Notify;
SoftwareSerial mySoftwareSerial(D7, D5); // RX, TX
#endif
// The getter for the instantiated singleton instance
PeripheryManager_ &PeripheryManager_::getInstance()
{
@@ -93,14 +105,36 @@ PeripheryManager_ &PeripheryManager = PeripheryManager.getInstance();
void left_button_pressed()
{
DisplayManager.leftButton();
MenuManager.leftButton();
if (AP_MODE)
{
--MATRIX_LAYOUT;
if (MATRIX_LAYOUT < 0)
MATRIX_LAYOUT = 2;
saveSettings();
ESP.restart();
}
else
{
DisplayManager.leftButton();
MenuManager.leftButton();
}
}
void right_button_pressed()
{
DisplayManager.rightButton();
MenuManager.rightButton();
if (AP_MODE)
{
++MATRIX_LAYOUT;
if (MATRIX_LAYOUT > 2)
MATRIX_LAYOUT = 0;
saveSettings();
ESP.restart();
}
else
{
DisplayManager.rightButton();
MenuManager.rightButton();
}
}
void select_button_pressed()
@@ -129,17 +163,28 @@ void select_button_tripple()
void PeripheryManager_::playBootSound()
{
if (SOUND_OFF)
if (!SOUND_ACTIVE)
return;
if (BOOT_SOUND == "")
{
#ifdef ULANZI
const int nNotes = 6;
String notes[nNotes] = {"E5", "C5", "G4", "E4", "G4", "C5"};
const int timeUnit = 150;
Melody melody = MelodyFactory.load("Nice Melody", timeUnit, notes, nNotes);
player.playAsync(melody);
const int nNotes = 6;
String notes[nNotes] = {"E5", "C5", "G4", "E4", "G4", "C5"};
const int timeUnit = 150;
Melody melody = MelodyFactory.load("Bootsound", timeUnit, notes, nNotes);
player.playAsync(melody);
#else
playFromFile(DFMINI_MP3_BOOT);
// no standardsound
#endif
}
else
{
#ifdef ULANZI
playFromFile("/MELODIES/" + BOOT_SOUND + ".txt");
#else
dfmp3.playMp3FolderTrack(BOOT_SOUND.toInt());
#endif
}
}
void PeripheryManager_::stopSound()
@@ -153,10 +198,16 @@ void PeripheryManager_::stopSound()
#endif
}
void PeripheryManager_::setVolume(uint8_t vol)
{
#ifdef AWTRIX_UPGRADE
dfmp3.setVolume(vol);
#endif
}
void PeripheryManager_::playFromFile(String file)
{
if (SOUND_OFF)
if (!SOUND_ACTIVE)
return;
#ifdef ULANZI
Melody melody = MelodyFactory.loadRtttlFile(file);
@@ -188,7 +239,7 @@ void firstStart()
CURRENT_TEMP -= 9.0;
#else
CURRENT_TEMP = bme280.readTemperature();
CURRENT_HUM = 0;
CURRENT_HUM = bme280.readHumidity();
#endif
uint16_t LDRVALUE = analogRead(LDR_PIN);
@@ -199,6 +250,7 @@ void firstStart()
void PeripheryManager_::setup()
{
startTime = millis();
pinMode(LDR_PIN, INPUT);
#ifdef ULANZI
pinMode(BUZZER_PIN, OUTPUT);
@@ -221,6 +273,7 @@ void PeripheryManager_::setup()
sht31.begin(0x44);
#else
bme280.begin();
dfmp3.begin();
#endif
photocell.setPhotocellPositionOnGround(false);
firstStart();
@@ -340,3 +393,19 @@ void PeripheryManager_::checkAlarms()
}
}
}
const char *PeripheryManager_::readUptime()
{
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned long uptimeSeconds = elapsedTime / 1000;
unsigned long uptimeMinutes = uptimeSeconds / 60;
unsigned long uptimeHours = uptimeMinutes / 60;
unsigned long uptimeDays = uptimeHours / 24;
unsigned long hours = uptimeHours % 24;
unsigned long minutes = uptimeMinutes % 60;
unsigned long seconds = uptimeSeconds % 60;
sprintf(uptime, "P%dDT%dH%dM%dS", uptimeDays, hours, minutes, seconds);
return uptime;
}

View File

@@ -35,6 +35,8 @@ public:
void playFromFile(String file);
bool isPlaying();
void stopSound();
void setVolume(uint8_t);
const char *readUptime();
};
extern PeripheryManager_ &PeripheryManager;

View File

@@ -9,26 +9,11 @@
#include <LittleFS.h>
#include <WiFi.h>
#include "DisplayManager.h"
#include "UpdateManager.h"
WebServer server(80);
FSWebServer mws(LittleFS, server);
bool FSOPEN;
void startLittleFS()
{
if (LittleFS.begin())
{
LittleFS.mkdir("/MELODIES");
LittleFS.mkdir("/ICONS");
FSOPEN = true;
}
else
{
Serial.println("ERROR on mounting LittleFS. It will be formmatted!");
LittleFS.format();
ESP.restart();
}
}
// The getter for the instantiated singleton instance
ServerManager_ &ServerManager_::getInstance()
@@ -49,26 +34,26 @@ void versionHandler()
void saveHandler()
{
WebServerClass *webRequest = mws.getRequest();
Serial.println("Save");
ServerManager.getInstance().loadSettings();
webRequest->send(200);
}
void ServerManager_::setup()
{
if (!local_IP.fromString(NET_IP) || !gateway.fromString(NET_GW) || !subnet.fromString(NET_SN) || !primaryDNS.fromString(NET_PDNS) || !secondaryDNS.fromString(NET_SDNS))
NET_STATIC = false;
if (NET_STATIC)
{
WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);
}
IPAddress myIP = mws.startWiFi(10000, uniqueID, "12345678");
myIP = mws.startWiFi(10000, uniqueID, "12345678");
isConnected = !(myIP == IPAddress(192, 168, 4, 1));
Serial.println(myIP.toString());
if (isConnected)
{
mws.addOptionBox("Network");
mws.addOption("Static IP", NET_STATIC);
mws.addOption("Local IP", NET_IP);
@@ -91,11 +76,32 @@ void ServerManager_::setup()
mws.addHTML(custom_html, "icon_html");
mws.addCSS(custom_css);
mws.addJavascript(custom_script);
mws.addOptionBox("General");
mws.addOption("Uppercase letters", UPPERCASE_LETTERS);
mws.addHandler("/save", HTTP_GET, saveHandler);
mws.addHandler("/save", HTTP_POST, saveHandler);
mws.addHandler("/api/notify", HTTP_POST, []()
{DisplayManager.generateNotification(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/nextapp", HTTP_POST, []()
{DisplayManager.nextApp(); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/previousapp", HTTP_POST, []()
{DisplayManager.previousApp(); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/timer", HTTP_POST, []()
{ DisplayManager.gererateTimer(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/notify/dismiss", HTTP_POST, []()
{ DisplayManager.dismissNotify(); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/apps", HTTP_POST, []()
{ DisplayManager.updateAppVector(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/switch", HTTP_POST, []()
{ DisplayManager.switchToApp(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/settings", HTTP_POST, []()
{ DisplayManager.setNewSettings(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/custom", HTTP_POST, []()
{ DisplayManager.generateCustomPage(mws.webserver->arg("name"),mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
mws.addHandler("/api/stats", HTTP_GET, []()
{ mws.webserver->sendContent(DisplayManager.getStat()); });
mws.addHandler("/api/doupdate", HTTP_POST, []()
{ if (UPDATE_AVAILABLE)
UpdateManager.updateFirmware(); mws.webserver->send(200,"OK"); });
Serial.println("Webserver loaded");
}
mws.addHandler("/version", HTTP_GET, versionHandler);
mws.begin();
@@ -129,12 +135,10 @@ uint16_t stringToColor(const String &str)
String gStr = str.substring(comma1 + 1, comma2);
String bStr = str.substring(comma2 + 1);
int r = rStr.toInt();
int g = gStr.toInt();
int b = bStr.toInt();
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
{
return 0xFFFF;
@@ -164,9 +168,6 @@ String colorToString(uint16_t color)
void ServerManager_::loadSettings()
{
if (!FSOPEN)
startLittleFS();
if (LittleFS.exists("/config.json"))
{
File file = LittleFS.open("/config.json", "r");
@@ -189,7 +190,6 @@ void ServerManager_::loadSettings()
NET_SN = doc["Subnet"].as<String>();
NET_PDNS = doc["Primary DNS"].as<String>();
NET_SDNS = doc["Secondary DNS"].as<String>();
UPPERCASE_LETTERS = doc["Uppercase letters"];
file.close();
DisplayManager.applyAllSettings();
Serial.println(F("Configuration loaded"));

View File

@@ -14,9 +14,9 @@ public:
void tick();
void loadSettings();
bool isConnected;
void SaveSettings();
IPAddress myIP;
};
extern ServerManager_ &ServerManager;
#endif
#endif

View File

@@ -1,20 +1,34 @@
#include <UpdateManager.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <WiFiClientSecure.h>
#include "cert.h"
#include "DisplayManager.h"
#include <Ticker.h>
#include "Globals.h"
#define URL_fw_Version "https://raw.githubusercontent.com/Blueforcer/awtrix-light/main/version"
#define URL_fw_Bin "https://raw.githubusercontent.com/Blueforcer/awtrix-light/main/docs/flasher/firmware/firmware.bin"
Ticker UpdateTicker;
// The getter for the instantiated singleton instance
UpdateManager_ &UpdateManager_::getInstance()
{
static UpdateManager_ instance;
return instance;
}
// Initialize the global shared instance
UpdateManager_ &UpdateManager = UpdateManager.getInstance();
void update_started()
{
}
void update_finished()
{
}
void update_progress(int cur, int total)
@@ -29,7 +43,7 @@ void update_error(int err)
DisplayManager.show();
}
void updateFirmware()
void UpdateManager_::updateFirmware()
{
WiFiClientSecure client;
client.setCACert(rootCACertificate);
@@ -56,13 +70,15 @@ void updateFirmware()
}
}
bool FirmwareVersionCheck()
bool UpdateManager_::checkUpdate(bool withScreen)
{
if (withScreen)
{
DisplayManager.clear();
DisplayManager.printText(0, 6, "CHECK", true, true);
DisplayManager.show();
}
DisplayManager.clear();
DisplayManager.printText(0, 6, "CHECK", true, true);
DisplayManager.show();
String payload;
int httpCode;
String fwurl = "";
@@ -103,20 +119,34 @@ bool FirmwareVersionCheck()
payload.trim();
if (payload.equals(VERSION))
{
Serial.printf("\nDevice already on latest firmware version:%s\n", VERSION);
DisplayManager.clear();
DisplayManager.printText(0, 6, "NO UP :(", true, true);
DisplayManager.show();
delay(1000);
UPDATE_AVAILABLE = false;
Serial.printf("\nDevice already on latest firmware version: %s\n", VERSION);
if (withScreen)
{
DisplayManager.clear();
DisplayManager.printText(0, 6, "NO UP :(", true, true);
DisplayManager.show();
delay(1000);
}
return 0;
}
else
{
Serial.println(payload);
Serial.println("New firmware detected");
DisplayManager.printText(0, 6, payload.c_str(), true, true);
UPDATE_AVAILABLE = true;
return 1;
}
}
UPDATE_AVAILABLE = false;
return 0;
}
void checkUpdateNoReturn()
{
Serial.println("Check Update");
UpdateManager.getInstance().checkUpdate(false);
}
void UpdateManager_::setup()
{
UpdateTicker.attach(3600, checkUpdateNoReturn);
}

18
src/UpdateManager.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef UpdateManager_h
#define UpdateManager_h
#include <Arduino.h>
class UpdateManager_
{
private:
UpdateManager_() = default;
public:
static UpdateManager_ &getInstance();
void setup();
bool checkUpdate(bool);
void updateFirmware();
};
extern UpdateManager_ &UpdateManager;
#endif

View File

@@ -36,6 +36,7 @@
#include "MQTTManager.h"
#include "ServerManager.h"
#include "Globals.h"
#include "UpdateManager.h"
TaskHandle_t taskHandle;
volatile bool StopTask = false;
@@ -73,13 +74,23 @@ void setup()
{
MQTTManager.setup();
DisplayManager.loadNativeApps();
UpdateManager.setup();
UpdateManager.checkUpdate(false);
StopTask = true;
float x = 4;
while (x >= -85)
{
DisplayManager.HSVtext(x, 6, ("AWTRIX " + ServerManager.myIP.toString()).c_str(), true);
x -= 0.18;
}
}
else
{
AP_MODE = true;
StopTask = true;
}
StopTask = true;
delay(200);
DisplayManager.clearMatrix();
}
@@ -88,9 +99,9 @@ void loop()
{
ServerManager.tick();
DisplayManager.tick();
PeripheryManager.tick();
if (ServerManager.isConnected)
{
PeripheryManager.tick();
MQTTManager.tick();
}
}