- fixes a bug with special-chars in rainbow mode
- adds a new key "pos" to the custompage api where you can define the position of your page in the loop.

closes #13
This commit is contained in:
Stephan Mühl
2023-03-25 14:09:00 +01:00
parent 8fd80f40b6
commit 5d0967068b
8 changed files with 29 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ The JSON object has the following properties:
| Key | Type | Description | Default | | Key | Type | Description | Default |
| --- | ---- | ----------- | ------- | | --- | ---- | ----------- | ------- |
| `pos` | number | defines the position of your custompage in the loop, starting at 1 for the first position. This will only apply with your first push. You cant change the position afterwards. For that you need to delete it and add it again. | At the end of the loop |
| `text` | string | The text to display on the page. | | | `text` | string | The text to display on the page. | |
| `icon` | string | The icon ID or filename (without extension) to display on the page. | | | `icon` | string | The icon ID or filename (without extension) to display on the page. | |
| `repeat` | number | Sets how many times the text should be scrolled through the matrix before the display ends. | 1 | | `repeat` | number | Sets how many times the text should be scrolled through the matrix before the display ends. | 1 |

Binary file not shown.

View File

@@ -1,6 +1,6 @@
{ {
"name": "AWTRIX Light", "name": "AWTRIX Light",
"version": "0.38", "version": "0.39",
"home_assistant_domain": "AwtrixLight", "home_assistant_domain": "AwtrixLight",
"funding_url": "https://blueforcer.de", "funding_url": "https://blueforcer.de",
"new_install_prompt_erase": true, "new_install_prompt_erase": true,

View File

@@ -154,11 +154,11 @@ void DisplayManager_::printText(int16_t x, int16_t y, const char *text, bool cen
} }
upperText[length] = '\0'; // Null terminator upperText[length] = '\0'; // Null terminator
matrix.print(utf8ascii(upperText)); matrix.print(upperText);
} }
else else
{ {
matrix.print(utf8ascii(text)); matrix.print(text);
} }
} }
@@ -178,11 +178,11 @@ void DisplayManager_::HSVtext(int16_t x, int16_t y, const char *text, bool clear
matrix.setCursor(xpos + x, y); matrix.setCursor(xpos + x, y);
if (UPPERCASE_LETTERS) if (UPPERCASE_LETTERS)
{ {
matrix.print(utf8ascii((char)toupper(text[i]))); matrix.print((char)toupper(text[i]));
} }
else else
{ {
matrix.print(utf8ascii(&text[i])); matrix.print(&text[i]);
} }
char temp_str[2] = {'\0', '\0'}; char temp_str[2] = {'\0', '\0'};
temp_str[0] = text[i]; temp_str[0] = text[i];
@@ -193,22 +193,27 @@ void DisplayManager_::HSVtext(int16_t x, int16_t y, const char *text, bool clear
matrix.show(); matrix.show();
} }
void pushCustomFrame(String name) void pushCustomFrame(String name, int position)
{ {
if (customFrames.count(name) == 0) if (customFrames.count(name) == 0)
{ {
++customPagesCount; ++customPagesCount;
void (*customFrames[10])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CFrame1, CFrame2, CFrame3, CFrame4, CFrame5, CFrame6, CFrame7, CFrame8, CFrame9, CFrame10}; void (*customFrames[10])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CFrame1, CFrame2, CFrame3, CFrame4, CFrame5, CFrame6, CFrame7, CFrame8, CFrame9, CFrame10};
if (customFrames[customPagesCount] != NULL)
if (position < 0) // Insert at the end of the vector
{ {
Apps.push_back(std::make_pair(name, customFrames[customPagesCount])); Apps.push_back(std::make_pair(name, customFrames[customPagesCount]));
ui.setApps(Apps); // Add frames
} }
else else if (position < Apps.size()) // Insert at a specific position
{ {
++customPagesCount; Apps.insert(Apps.begin() + position, std::make_pair(name, customFrames[customPagesCount]));
} }
else // Invalid position, Insert at the end of the vector
{
Apps.push_back(std::make_pair(name, customFrames[customPagesCount]));
}
ui.setApps(Apps); // Add frames
} }
} }
@@ -255,7 +260,7 @@ void DisplayManager_::generateCustomPage(String name, String payload)
customFrame.rainbow = doc.containsKey("rainbow") ? doc["rainbow"] : false; customFrame.rainbow = doc.containsKey("rainbow") ? doc["rainbow"] : false;
customFrame.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0; customFrame.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
customFrame.name = name; customFrame.name = name;
customFrame.text = doc["text"].as<String>(); customFrame.text = utf8ascii(doc["text"].as<String>());
customFrame.color = doc.containsKey("color") ? doc["color"].is<String>() ? hexToRgb565(doc["color"]) : doc["color"].is<JsonArray>() ? hexToRgb565(doc["color"].as<String>()) customFrame.color = doc.containsKey("color") ? doc["color"].is<String>() ? hexToRgb565(doc["color"]) : doc["color"].is<JsonArray>() ? hexToRgb565(doc["color"].as<String>())
: TEXTCOLOR_565 : TEXTCOLOR_565
@@ -284,7 +289,9 @@ void DisplayManager_::generateCustomPage(String name, String payload)
} }
} }
pushCustomFrame(name); int pos = doc.containsKey("pos") ? doc["pos"].as<uint8_t>() : -1;
pushCustomFrame(name, pos - 1);
customFrames[name] = customFrame; customFrames[name] = customFrame;
} }
@@ -294,7 +301,7 @@ void DisplayManager_::generateNotification(String payload)
deserializeJson(doc, payload); deserializeJson(doc, payload);
notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_APP; notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_APP;
notify.text = doc["text"].as<String>(); notify.text = utf8ascii(doc["text"].as<String>());
notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint16_t>() : -1; notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint16_t>() : -1;
notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as<bool>() : false; notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as<bool>() : false;
notify.hold = doc.containsKey("hold") ? doc["hold"].as<bool>() : false; notify.hold = doc.containsKey("hold") ? doc["hold"].as<bool>() : false;

View File

@@ -167,7 +167,7 @@ void TempFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x
matrix->setCursor(12 + x, 6 + y); matrix->setCursor(12 + x, 6 + y);
if (IS_CELSIUS) if (IS_CELSIUS)
{ {
matrix->print((int)CURRENT_TEMP); matrix->print((int)CURRENT_TEMP);
matrix->print(utf8ascii("°C")); matrix->print(utf8ascii("°C"));
} }
else else
@@ -208,7 +208,7 @@ void MenuFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
if (!MenuManager.inMenu) if (!MenuManager.inMenu)
return; return;
matrix->fillScreen(0); matrix->fillScreen(0);
DisplayManager.printText(0, 6, MenuManager.menutext().c_str(), true, true); DisplayManager.printText(0, 6, utf8ascii(MenuManager.menutext()).c_str(), true, true);
} }
void AlarmFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state) void AlarmFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)

View File

@@ -42,7 +42,7 @@ IPAddress gateway;
IPAddress subnet; IPAddress subnet;
IPAddress primaryDNS; IPAddress primaryDNS;
IPAddress secondaryDNS; IPAddress secondaryDNS;
const char *VERSION = "0.38"; const char *VERSION = "0.39";
String MQTT_HOST = ""; String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883; uint16_t MQTT_PORT = 1883;
String MQTT_USER; String MQTT_USER;

View File

@@ -189,14 +189,15 @@ void connect()
{ {
mqtt.onMessage(onMqttMessage); mqtt.onMessage(onMqttMessage);
mqtt.onConnected(onMqttConnected); mqtt.onConnected(onMqttConnected);
if (MQTT_USER == "" || MQTT_PASS == "") if (MQTT_USER == "" || MQTT_PASS == "")
{ {
Serial.println("Connecting to MQTT"); Serial.println("Connecting to MQTT w/o login");
mqtt.begin(MQTT_HOST.c_str(), MQTT_PORT, nullptr, nullptr, MQTT_PREFIX.c_str()); mqtt.begin(MQTT_HOST.c_str(), MQTT_PORT, nullptr, nullptr, MQTT_PREFIX.c_str());
} }
else else
{ {
Serial.println("Connecting to MQTT"); Serial.println("Connecting to MQTT with login");
mqtt.begin(MQTT_HOST.c_str(), MQTT_PORT, MQTT_USER.c_str(), MQTT_PASS.c_str(), MQTT_PREFIX.c_str()); mqtt.begin(MQTT_HOST.c_str(), MQTT_PORT, MQTT_USER.c_str(), MQTT_PASS.c_str(), MQTT_PREFIX.c_str());
} }
} }

View File

@@ -1 +1 @@
0.38 0.39