Skip to content

Commit

Permalink
V0.66
Browse files Browse the repository at this point in the history
- Allows to decide if a notification is stacked. closes #129
- Add indicator3 to http API. closes #130
- Adds some meaningful responses to http api. closes #131
- Fixes a bug where customapp crashes without an icon. closes #132
  • Loading branch information
Blueforcer committed May 17, 2023
1 parent c19546e commit d75fde4
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 87 deletions.
10 changes: 6 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ You can also send a one-time notification with the same JSON format. Simply send
### JSON Properties

The JSON object has the following properties,
All keys are optional, so you can send just the properties you want to use.
**All keys are optional**, so you can send just the properties you want to use.

| Key | Type | Description | Default |
| --- | ---- | ----------- | ------- |
| `text` | string | The text to display on the app. | N/A |
| `text` | string | The text to display. | N/A |
| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 |
| `textOffset` | integer | Sets an offset for the x position of a starting text. | 0 |
| `color` | string or array of integers | The text, bar or line color | |
Expand All @@ -94,13 +94,14 @@ All keys are optional, so you can send just the properties you want to use.
| `sound` | string | The filename of your RTTTL ringtone file (without extension). | N/A |
| `bar` | array of integers | draws a bargraph. Without icon maximum 16 values, with icon 11 values | N/A |
| `line` | array of integers | draws a linechart. Without icon maximum 16 values, with icon 11 values | N/A |
| `autoscale` | boolean | enables or disables autoscaling for bar and linechart | true |
| `autoscale` | boolean | Enables or disables autoscaling for bar and linechart | true |
| `progress` | integer | Shows a progressbar. Value can be 0-100 | -1 |
| `progressC` | string or array of integers | The color of the progressbar | -1 |
| `progressBC` | string or array of integers | The color of the progressbar background | -1 |
| `pos` | number | defines the position of your custompage in the loop, starting at 0 for the first position. This will only apply with your first push. This function is experimental | N/A |
| `pos` | number | Defines the position of your custompage in the loop, starting at 0 for the first position. This will only apply with your first push. This function is experimental | N/A |
| `draw` | array of objects | Array of drawing instructions. Each object represents a drawing command. | See the drawing instructions below |
| `lifetime` | integer | Removes the custom app when there is no update after the given time in seconds | 0 |
| `stack` | integer | Defines if the **notification** will be stacked. false will immediately replace the current notification | true |

Color values can have a hex string or an array of R,G,B values:
`"#FFFFFF" or [255,255,0]`
Expand Down Expand Up @@ -133,6 +134,7 @@ Each drawing instruction is an object with a required command key and an array o
| `dc` | `[x, y, r, cl]` | Draw a circle with center at (`x`, `y`), radius `r`, and color `cl` |
| `dfc` | `[x, y, r, cl]` | Draw a filled circle with center at (`x`, `y`), radius `r`, and color `cl` |
| `dt` | `[x, y, t, cl]` | Draw text `t` with top-left corner at (`x`, `y`) and color `cl` |
| `db` | `[x, y, w, h, [bmp]]` | Draws a RGB565 bitmap array `[bmp]` with top-left corner at (`x`, `y`) and size of (`w`, `h`) |

Color values can be a hex string or an array of R, G, B values:
`"#FFFFFF" or [255, 255, 0]`
Expand Down
5 changes: 3 additions & 2 deletions src/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
currentCustomApp = name;

bool hasIcon = ca->icon;

matrix->fillRect(x, y, 32, 8, ca->background);

// Calculate text and available width
Expand Down Expand Up @@ -459,7 +460,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
{
if (ca->iconWasPushed && ca->pushIcon == 1)
{
ca->scrollposition = 0 + notifications[0].textOffset;
ca->scrollposition = 0 + ca->textOffset;
}
else
{
Expand All @@ -468,7 +469,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
}
else
{
ca->scrollposition = 0 + notifications[0].textOffset;
ca->scrollposition = 0 + ca->textOffset;
}
}
}
Expand Down
58 changes: 39 additions & 19 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,25 @@ bool parseFragmentsText(const String &jsonText, std::vector<uint16_t> &colors, s
return true;
}

void DisplayManager_::parseCustomPage(const String &name, const char *json)
bool DisplayManager_::parseCustomPage(const String &name, const char *json)
{

if ((strcmp(json, "") == 0) || (strcmp(json, "{}") == 0))
{
removeCustomAppFromApps(name, true);
return;
return true;
}
DynamicJsonDocument doc(4096);
DeserializationError error = deserializeJson(doc, json);
if (error)
{
doc.clear();
return;
return false;
}

if (doc.is<JsonObject>())
{
generateCustomPage(name, json);
return generateCustomPage(name, json);
}
else if (doc.is<JsonArray>())
{
Expand All @@ -358,23 +358,24 @@ void DisplayManager_::parseCustomPage(const String &name, const char *json)
JsonObject customPageObject = customPage.as<JsonObject>();
String customPageJson;
serializeJson(customPageObject, customPageJson);
generateCustomPage(name + String(cpIndex), customPageJson.c_str());
if (generateCustomPage(name + String(cpIndex), customPageJson.c_str()))
return false;
++cpIndex;
}
}

doc.clear();
}

void DisplayManager_::generateCustomPage(const String &name, const char *json)
bool DisplayManager_::generateCustomPage(const String &name, const char *json)
{

DynamicJsonDocument doc(4096);
DeserializationError error = deserializeJson(doc, json);
if (error)
{
doc.clear();
return;
return false;
}

CustomApp customApp;
Expand Down Expand Up @@ -586,16 +587,17 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json)
pushCustomApp(name, pos - 1);
customApps[name] = customApp;
doc.clear();
return true;
}

void DisplayManager_::generateNotification(const char *json)
bool DisplayManager_::generateNotification(const char *json)
{
StaticJsonDocument<4096> doc;
DeserializationError error = deserializeJson(doc, json);
if (error)
{
doc.clear();
return;
return false;
}

Notification newNotification;
Expand Down Expand Up @@ -757,13 +759,11 @@ void DisplayManager_::generateNotification(const char *json)
{
newNotification.isGif = false;
newNotification.icon = LittleFS.open("/ICONS/" + iconFileName + ".jpg");

}
else if (LittleFS.exists("/ICONS/" + iconFileName + ".gif"))
{
newNotification.isGif = true;
newNotification.icon = LittleFS.open("/ICONS/" + iconFileName + ".gif");

}
else
{
Expand All @@ -777,7 +777,25 @@ void DisplayManager_::generateNotification(const char *json)
newNotification.icon = nullPointer;
}

notifications.push_back(newNotification);
bool stack = doc.containsKey("stack") ? doc["stack"] : true;

if (stack)
{
notifications.push_back(newNotification);
}
else
{
if (notifications.empty())
{
notifications.push_back(newNotification);
}
else
{
notifications[0] = newNotification;
}
}
doc.clear();
return true;
}

void DisplayManager_::loadNativeApps()
Expand Down Expand Up @@ -1463,7 +1481,7 @@ void DisplayManager_::setIndicator3State(bool state)
ui->setIndicator3State(state);
}

void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
bool DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
{

if (strcmp(json, "") == 0)
Expand All @@ -1485,13 +1503,13 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
default:
break;
}
return;
return true;
}

DynamicJsonDocument doc(128);
DeserializationError error = deserializeJson(doc, json);
if (error)
return;
return false;

if (doc.containsKey("color"))
{
Expand Down Expand Up @@ -1573,6 +1591,7 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
}
}
MQTTManager.setIndicatorState(indicator, ui->indicator1State, ui->indicator1Color);
return true;
}

void DisplayManager_::gammaCorrection()
Expand Down Expand Up @@ -1932,18 +1951,18 @@ void DisplayManager_::processDrawInstructions(int16_t xOffset, int16_t yOffset,
}
}

void DisplayManager_::moodlight(const char *json)
bool DisplayManager_::moodlight(const char *json)
{
if (strcmp(json, "") == 0)
{
MOODLIGHT_MODE = false;
return;
return true;
}

DynamicJsonDocument doc(512);
DeserializationError error = deserializeJson(doc, json);
if (error)
return;
return false;

int brightness = doc["brightness"] | BRIGHTNESS;
matrix->setBrightness(brightness);
Expand All @@ -1967,10 +1986,11 @@ void DisplayManager_::moodlight(const char *json)
}
else
{
return;
return true;
}

MOODLIGHT_MODE = true;

matrix->show();
return true;
}
10 changes: 5 additions & 5 deletions src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class DisplayManager_
void setBrightness(int);
void setTextColor(uint16_t color);
void setFPS(uint8_t);
void generateNotification(const char *json);
void generateCustomPage(const String &name, const char *json);
bool generateNotification(const char *json);
bool generateCustomPage(const String &name, const char *json);
void printText(int16_t x, int16_t y, const char *text, bool centered, byte textCase);
bool setAutoTransition(bool active);
void switchToApp(const char *json);
Expand All @@ -78,16 +78,16 @@ class DisplayManager_
void setIndicator3State(bool state);
void reorderApps(const String &jsonString);
void gammaCorrection();
void indicatorParser(uint8_t indicator, const char *json);
bool indicatorParser(uint8_t indicator, const char *json);
void showSleepAnimation();
void showCurtainEffect();
void sendAppLoop();
void processDrawInstructions(int16_t x, int16_t y, String &drawInstructions);
String ledsAsJson();
String getAppsWithIcon();
void startArtnet();
void parseCustomPage(const String &name, const char *json);
void moodlight(const char *json);
bool parseCustomPage(const String &name, const char *json);
bool moodlight(const char *json);
};

extern DisplayManager_ &DisplayManager;
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.65";
const char *VERSION = "0.66";

String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
Expand Down
25 changes: 17 additions & 8 deletions src/PeripheryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,34 +222,43 @@ void PeripheryManager_::setVolume(uint8_t vol)
}
#endif

void PeripheryManager_::parseSound(const char *json)
bool PeripheryManager_::parseSound(const char *json)
{

StaticJsonDocument<128> doc;
DeserializationError error = deserializeJson(doc, json);
if (error)
{
playFromFile(String(json));
return;
return playFromFile(String(json));
}
if (doc.containsKey("sound"))
{
playFromFile(doc["sound"].as<String>());
return playFromFile(doc["sound"].as<String>());
}
}

void PeripheryManager_::playFromFile(String file)
bool PeripheryManager_::playFromFile(String file)
{
if (!SOUND_ACTIVE)
return;
return true;

#ifdef ULANZI
DEBUG_PRINTLN(F("Playing RTTTL sound file"));
Melody melody = MelodyFactory.loadRtttlFile("/MELODIES/" + String(file) + ".txt");
player.playAsync(melody);
if (LittleFS.exists("/MELODIES/" + String(file) + ".txt"))
{
Melody melody = MelodyFactory.loadRtttlFile("/MELODIES/" + String(file) + ".txt");
player.playAsync(melody);
return true;
}
else
{
return false;
}

#else
dfmp3.playMp3FolderTrack(file.toInt());
#endif
return true;
}

bool PeripheryManager_::isPlaying()
Expand Down
4 changes: 2 additions & 2 deletions src/PeripheryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PeripheryManager_
void setup();
void tick();
void playBootSound();
void playFromFile(String file);
void parseSound(const char *json);
bool playFromFile(String file);
bool parseSound(const char *json);
bool isPlaying();
void stopSound();
#ifndef ULANZI
Expand Down
Loading

0 comments on commit d75fde4

Please sign in to comment.