Skip to content

Commit

Permalink
V0.36
Browse files Browse the repository at this point in the history
  • Loading branch information
Blueforcer committed Mar 23, 2023
1 parent 04c9b5a commit a3584ce
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 12 deletions.
Binary file modified docs/flasher/firmware/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/flasher/firmware/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AWTRIX Light",
"version": "0.35",
"version": "0.36",
"home_assistant_domain": "AwtrixLight",
"funding_url": "https://blueforcer.de",
"new_install_prompt_erase": true,
Expand Down
28 changes: 24 additions & 4 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# MQTT Commands

### Switch to app
**Topic**
### Switch apps
##### Topic
`[PREFIX]/nextapp`
`[PREFIX]/previousapp`

### Switch to specific app
##### Topic
`[PREFIX]/switch`
**Payload**
##### Payload
`{"name":"time"}`

Build-in app names are
Expand All @@ -15,4 +20,19 @@ Build-in app names are

For custompages you need to call the name you set in the topic:
If `[PREFIX]/custom/test` is your topic,
then `test` is the name.
then `test` is the name.

## Change Settings
##### Topic
`[PREFIX]/settings`

##### JSON Properties
| Key | Type | Description | Value Range |
| ----------- | ------- | --------------------------------------------------------------------------- | ------------------------------------------ |
| `apptime` | number | Determines the duration an app is displayed in milliseconds. | Any positive integer value. Default 7000 |
| `transition`| number | The time the transition to the next app takes in milliseconds. | Any positive integer value. Default 500 |
| `textcolor` | string | A color in hexadecimal format. | Any valid 6-digit hexadecimal color value, e.g. "#FF0000" for red |
| `fps` | number | Determines the frame rate at which the matrix is updated. | Any positive integer value. Default 23 |
| `brightness`| number | Determines the brightness of the matrix. | An integer between 0 and 255 |
| `autobrightness`| boolean | Determines if automatic brightness control is active. | `true` or `false` |
| `autotransition`| boolean | Determines if automatic switching to the next app is active. | `true` or `false` |
22 changes: 21 additions & 1 deletion src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile)
TJpgDec.drawFsJpg(x, y, jpgFile);
}

void DisplayManager_::setSettings()
void DisplayManager_::applyAllSettings()
{
ui.setTargetFPS(MATRIX_FPS);
ui.setTimePerApp(TIME_PER_APP);
ui.setTimePerTransition(TIME_PER_TRANSITION);
setBrightness(BRIGHTNESS);
setTextColor(TEXTCOLOR_565);
setAutoTransition(AUTO_TRANSITION);
}

void DisplayManager_::resetTextColor()
Expand Down Expand Up @@ -492,4 +495,21 @@ void DisplayManager_::switchToApp(String Payload)
int index = findAppIndexByName(name);
if (index > -1)
ui.transitionToApp(index);
}

void DisplayManager_::setNewSettings(String Payload)
{
DynamicJsonDocument doc(512);
DeserializationError error = deserializeJson(doc, Payload);
if (error)
return;
TIME_PER_APP = doc.containsKey("apptime") ? doc["apptime"] : TIME_PER_APP;
TIME_PER_TRANSITION = doc.containsKey("transition") ? doc["transition"] : TIME_PER_TRANSITION;
TEXTCOLOR_565 = doc.containsKey("textcolor") ? hexToRgb565(doc["textcolor"]) : TEXTCOLOR_565;
MATRIX_FPS = doc.containsKey("fps") ? doc["fps"] : MATRIX_FPS;
BRIGHTNESS = doc.containsKey("brightness") ? doc["brightness"] : BRIGHTNESS;
AUTO_BRIGHTNESS = doc.containsKey("autobrightness") ? doc["autobrightness"] : AUTO_BRIGHTNESS;
AUTO_TRANSITION = doc.containsKey("autotransition") ? doc["autotransition"] : AUTO_TRANSITION;
applyAllSettings();
saveSettings();
}
3 changes: 2 additions & 1 deletion src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DisplayManager_
static DisplayManager_ &getInstance();
void setup();
void tick();
void setSettings();
void applyAllSettings();
void rightButton();
void dismissNotify();
void HSVtext(int16_t, int16_t, const char *, bool);
Expand All @@ -48,6 +48,7 @@ class DisplayManager_
void printText(int16_t x, int16_t y, const char *text, bool centered, bool ignoreUppercase);
bool setAutoTransition(bool active);
void switchToApp(String Payload);
void setNewSettings(String Payload);
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
};
Expand Down
3 changes: 3 additions & 0 deletions src/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ uint16_t hexToRgb565(String hexValue)
uint8_t r = strtol(hexValue.substring(0, 2).c_str(), NULL, 16);
uint8_t g = strtol(hexValue.substring(2, 4).c_str(), NULL, 16);
uint8_t b = strtol(hexValue.substring(4, 6).c_str(), NULL, 16);
if ((errno == ERANGE) || (r > 255) || (g > 255) || (b > 255)) {
return 0xFFFF;
}
uint16_t color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
return color;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.35";
const char *VERSION = "0.36";
String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
String MQTT_USER;
Expand Down
23 changes: 22 additions & 1 deletion src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,30 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
return;
}

if (strTopic == MQTT_PREFIX + "/switch")
if (strTopic == MQTT_PREFIX + "/switch")
{
DisplayManager.switchToApp(strPayload);
return;
}

if (strTopic == MQTT_PREFIX + "/settings")
{
DisplayManager.setNewSettings(strPayload);
return;
}

if (strTopic == MQTT_PREFIX + "/nextapp")
{
DisplayManager.nextApp();
return;
}

if (strTopic == MQTT_PREFIX + "/previousapp")
{
DisplayManager.previousApp();
return;
}

else if (strTopic.startsWith(MQTT_PREFIX + "/custom"))
{
String topic_str = topic;
Expand All @@ -161,6 +179,9 @@ void onMqttConnected()
mqtt.subscribe((prefix + String("/timer")).c_str());
mqtt.subscribe((prefix + String("/custom/#")).c_str());
mqtt.subscribe((prefix + String("/switch")).c_str());
mqtt.subscribe((prefix + String("/settings")).c_str());
mqtt.subscribe((prefix + String("/previousapp")).c_str());
mqtt.subscribe((prefix + String("/nextapp")).c_str());
Serial.println("MQTT Connected");
}

Expand Down
4 changes: 2 additions & 2 deletions src/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ void MenuManager_::selectButtonLong()
}
else if (currentState == TspeedMenu)
{
DisplayManager.setSettings();
DisplayManager.applyAllSettings();
saveSettings();
}
else if (currentState == AppTimeMenu)
{
DisplayManager.setSettings();
DisplayManager.applyAllSettings();
saveSettings();
}
currentState = MainMenu;
Expand Down
2 changes: 1 addition & 1 deletion src/ServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void ServerManager_::loadSettings()
SHOW_HUM = doc["Show humidity"];
SHOW_BATTERY = doc["Show battery"];
file.close();
DisplayManager.setSettings();
DisplayManager.applyAllSettings();
Serial.println(F("Configuration loaded"));
return;
}
Expand Down

0 comments on commit a3584ce

Please sign in to comment.