Updated usermods for WLED-SR FX mode names.

This commit is contained in:
Blaž Kristan 2021-11-02 13:12:14 +01:00
parent 73c75635b1
commit 10fc9fe268
9 changed files with 71 additions and 299 deletions

View File

@ -148,58 +148,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -191,58 +191,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -285,33 +285,9 @@ class St7789DisplayUsermod : public Usermod {
// mode name // mode name
tft.setTextColor(TFT_CYAN); tft.setTextColor(TFT_CYAN);
tft.setCursor(0, 144); tft.setCursor(0, 144);
uint8_t qComma = 0; char lineBuffer[tftcharwidth+1];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, tftcharwidth);
uint8_t printedChars = 0; tft.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++)
{
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol)
{
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > tftcharwidth - 1))
break;
}
// palette name // palette name
tft.setTextColor(TFT_YELLOW); tft.setTextColor(TFT_YELLOW);

View File

@ -177,58 +177,15 @@ void userLoop() {
// Third row with mode name // Third row with mode name
tft.setCursor(1, 68); tft.setCursor(1, 68);
uint8_t qComma = 0; char lineBuffer[tftcharwidth+1];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, tftcharwidth);
uint8_t printedChars = 0; tft.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > tftcharwidth - 1))
break;
}
// Fourth row with palette name // Fourth row with palette name
tft.setCursor(1, 90); tft.setCursor(1, 90);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, tftcharwidth);
insideQuotes = false; tft.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
// The following is modified from the code from the u8g2/u8g8 based code (knownPalette was knownMode)
if ((qComma > knownPalette) || (printedChars > tftcharwidth - 1))
break;
}
// Fifth row with estimated mA usage // Fifth row with estimated mA usage
tft.setCursor(1, 112); tft.setCursor(1, 112);
// Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate). // Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate).

View File

@ -185,58 +185,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -191,58 +191,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -470,30 +470,8 @@ class FourLineDisplayUsermod : public Usermod {
*/ */
void showCurrentEffectOrPalette(int knownMode, const char *qstring, uint8_t row) { void showCurrentEffectOrPalette(int knownMode, const char *qstring, uint8_t row) {
char lineBuffer[LINE_BUFFER_SIZE]; char lineBuffer[LINE_BUFFER_SIZE];
uint8_t qComma = 0; extractModeName(knownMode, qstring, lineBuffer, LINE_BUFFER_SIZE-1);
bool insideQuotes = false; uint8_t printedChars = strlen(lineBuffer);
uint8_t printedChars = 0;
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(qstring); i++) {
singleJsonSymbol = pgm_read_byte_near(qstring + i);
if (singleJsonSymbol == '\0') break;
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode)) break;
lineBuffer[printedChars++] = singleJsonSymbol;
}
if ((qComma > knownMode) || (printedChars >= getCols()-2) || printedChars >= sizeof(lineBuffer)-2) break;
}
for (;printedChars < getCols()-2 && printedChars < sizeof(lineBuffer)-2; printedChars++) lineBuffer[printedChars]=' '; for (;printedChars < getCols()-2 && printedChars < sizeof(lineBuffer)-2; printedChars++) lineBuffer[printedChars]=' ';
lineBuffer[printedChars] = 0; lineBuffer[printedChars] = 0;
drawString(2, row*lineHeight, lineBuffer); drawString(2, row*lineHeight, lineBuffer);

View File

@ -128,6 +128,8 @@ bool deserializeState(JsonObject root, byte callMode = CALL_MODE_DIRECT_CHANGE,
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true); void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true);
void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true); void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true);
void serializeInfo(JsonObject root); void serializeInfo(JsonObject root);
void serializeSRNames(JsonArray arr, const char *qstring);
void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
void serveJson(AsyncWebServerRequest* request); void serveJson(AsyncWebServerRequest* request);
bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0); bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0);

View File

@ -796,7 +796,9 @@ void serializeNodes(JsonObject root)
} }
} }
void serializeSRNames(JsonVariant arr, const char *qstring) { // deserializes mode names string into JsonArray
// also removes WLED-SR extensions (@...) from deserialised names
void deserializeModeNames(JsonArray arr, const char *qstring) {
String lineBuffer; String lineBuffer;
bool insideQuotes = false; bool insideQuotes = false;
char singleJsonSymbol; char singleJsonSymbol;
@ -827,6 +829,39 @@ void serializeSRNames(JsonVariant arr, const char *qstring) {
} }
} }
// extracts effect mode (or palette) name from names serialized string
// caller must provide large enough buffer!
void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
{
uint8_t qComma = 0;
bool insideQuotes = false;
uint8_t printedChars = 0;
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(src); i++) {
singleJsonSymbol = pgm_read_byte_near(src + i);
if (singleJsonSymbol == '\0') break;
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != mode)) break;
dest[printedChars++] = singleJsonSymbol;
}
if ((qComma > mode) || (printedChars >= maxLen)) break;
}
dest[printedChars] = '\0';
char *p = strchr(dest,'@');
if (p != nullptr) *p = '\0';
}
void serveJson(AsyncWebServerRequest* request) void serveJson(AsyncWebServerRequest* request)
{ {
byte subJson = 0; byte subJson = 0;
@ -879,7 +914,7 @@ void serveJson(AsyncWebServerRequest* request)
{ {
//doc[F("effects")] = serialized((const __FlashStringHelper*)JSON_mode_names); //doc[F("effects")] = serialized((const __FlashStringHelper*)JSON_mode_names);
JsonArray effects = doc.createNestedArray(F("effects")); JsonArray effects = doc.createNestedArray(F("effects"));
serializeSRNames(effects, JSON_mode_names); // remove WLED-SR extensions from effect names deserializeModeNames(effects, JSON_mode_names); // remove WLED-SR extensions from effect names
doc[F("palettes")] = serialized((const __FlashStringHelper*)JSON_palette_names); doc[F("palettes")] = serialized((const __FlashStringHelper*)JSON_palette_names);
} }
} }