Skip to content

Commit

Permalink
v0.47
Browse files Browse the repository at this point in the history
-Add update sensor to HA. AWL search for an update every hour.
- Fixes duration in custom apps
  • Loading branch information
Blueforcer committed Apr 1, 2023
1 parent 8808559 commit bc72069
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 70 deletions.
1 change: 0 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- Features
- [Apps](apps.md)
- [Alarm clock](alarm.md)
- [Timer](timer.md)
- [Icons](icons.md)
- [Sounds](sounds.md)
- [Hidden features](dev.md)
Expand Down
31 changes: 0 additions & 31 deletions docs/timer.md
Original file line number Diff line number Diff line change
@@ -1,31 +0,0 @@
# Timer

With AWTRIX Light, you can set a timer using MQTT. Simply send a JSON object to the topic **[PREFIX]/timer** to start a timer.

When the timer goes off, the display will show a notification, and you can dismiss the timer by pressing the middle button.

## JSON Properties

The JSON object has the following properties:

| Key | Type | Description |
| --- | ---- | ----------- |
| `hours` | number | The number of hours after midnight when the timer should be triggered. |
| `minutes` | number | The number of minutes after the hour when the timer should be triggered. |
| `seconds` | number | The number of seconds after the minute when the timer should be triggered. |
| `sound` | string | The name of the sound file (without extension) to play when the timer is triggered. |

Each value is optional, so you can set a timer for just minutes, or any combination of hours, minutes, and seconds. If you only want to start a timer in some minutes, just send the minutes.

## Example

Here's an example JSON object to start a timer for 1 hour, 30 minutes, and 10 seconds, with the sound "friends":

```json
{
"hours": 1,
"minutes": 30,
"seconds": 10,
"sound": "friends"
}
```
6 changes: 3 additions & 3 deletions src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <ArduinoJson.h>
#include "Dictionary.h"
#include "PeripheryManager.h"
#include "Updater.h"
#include "UpdateManager.h"

WiFiClient espClient;
uint8_t lastBrightness;
Expand Down Expand Up @@ -67,7 +67,7 @@ void onButtonCommand(HAButton *sender)
else if (sender == doUpdate)
{
if (UPDATE_AVAILABLE)
Updater.updateFirmware();
UpdateManager.updateFirmware();
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
if (strTopic == MQTT_PREFIX + "/doupdate")
{
if (UPDATE_AVAILABLE)
Updater.updateFirmware();
UpdateManager.updateFirmware();
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <ServerManager.h>
#include <DisplayManager.h>
#include <PeripheryManager.h>
#include <updater.h>
//#include <update.h>
#include <icons.h>
#include <Updater.h>
#include <UpdateManager.h>

String menuText;
int menuSelection;
Expand Down Expand Up @@ -378,9 +378,9 @@ void MenuManager_::selectButton()
#endif

case 13:
if (Updater.checkUpdate(true))
if (UpdateManager.checkUpdate(true))
{
Updater.updateFirmware();
UpdateManager.updateFirmware();
}
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/ServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <LittleFS.h>
#include <WiFi.h>
#include "DisplayManager.h"
#include "Updater.h"
#include "UpdateManager.h"

WebServer server(80);
FSWebServer mws(LittleFS, server);
Expand Down Expand Up @@ -99,7 +99,7 @@ void ServerManager_::setup()
{ mws.webserver->sendContent(DisplayManager.getStat()); });
mws.addHandler("/api/doupdate", HTTP_POST, []()
{ if (UPDATE_AVAILABLE)
Updater.updateFirmware(); mws.webserver->send(200,"OK"); });
UpdateManager.updateFirmware(); mws.webserver->send(200,"OK"); });
Serial.println("Webserver loaded");
}
mws.addHandler("/version", HTTP_GET, versionHandler);
Expand Down
16 changes: 8 additions & 8 deletions src/Updater.cpp → src/UpdateManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Updater.h>
#include <UpdateManager.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
Expand All @@ -14,14 +14,14 @@
Ticker UpdateTicker;

// The getter for the instantiated singleton instance
Updater_ &Updater_::getInstance()
UpdateManager_ &UpdateManager_::getInstance()
{
static Updater_ instance;
static UpdateManager_ instance;
return instance;
}

// Initialize the global shared instance
Updater_ &Updater = Updater.getInstance();
UpdateManager_ &UpdateManager = UpdateManager.getInstance();

void update_started()
{
Expand All @@ -43,7 +43,7 @@ void update_error(int err)
DisplayManager.show();
}

void Updater_::updateFirmware()
void UpdateManager_::updateFirmware()
{
WiFiClientSecure client;
client.setCACert(rootCACertificate);
Expand All @@ -70,7 +70,7 @@ void Updater_::updateFirmware()
}
}

bool Updater_::checkUpdate(bool withScreen)
bool UpdateManager_::checkUpdate(bool withScreen)
{
if (withScreen)
{
Expand Down Expand Up @@ -143,10 +143,10 @@ bool Updater_::checkUpdate(bool withScreen)
void checkUpdateNoReturn()
{
Serial.println("Check Update");
Updater.getInstance().checkUpdate(false);
UpdateManager.getInstance().checkUpdate(false);
}

void Updater_::setup()
void UpdateManager_::setup()
{
UpdateTicker.attach(3600, checkUpdateNoReturn);
}
18 changes: 18 additions & 0 deletions src/UpdateManager.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "MQTTManager.h"
#include "ServerManager.h"
#include "Globals.h"
#include "Updater.h"
#include "UpdateManager.h"

TaskHandle_t taskHandle;
volatile bool StopTask = false;
Expand Down Expand Up @@ -74,8 +74,8 @@ void setup()
{
MQTTManager.setup();
DisplayManager.loadNativeApps();
Updater.setup();
Updater.checkUpdate(false);
UpdateManager.setup();
UpdateManager.checkUpdate(false);
StopTask = true;
float x = 4;
while (x >= -85)
Expand Down
18 changes: 0 additions & 18 deletions src/updater.h

This file was deleted.

0 comments on commit bc72069

Please sign in to comment.