mirror of
https://github.com/wled/WLED.git
synced 2025-07-17 07:46:32 +00:00
Minor change in handling mode names.
This commit is contained in:
parent
10fc9fe268
commit
f66fcfbe6d
@ -292,33 +292,8 @@ class St7789DisplayUsermod : public Usermod {
|
|||||||
// palette name
|
// palette name
|
||||||
tft.setTextColor(TFT_YELLOW);
|
tft.setTextColor(TFT_YELLOW);
|
||||||
tft.setCursor(0, 168);
|
tft.setCursor(0, 168);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
tft.setCursor(0, 192);
|
tft.setCursor(0, 192);
|
||||||
tft.setTextColor(TFT_SILVER);
|
tft.setTextColor(TFT_SILVER);
|
||||||
|
@ -438,6 +438,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
|
|
||||||
void drawLine(uint8_t line, Line4Type lineType) {
|
void drawLine(uint8_t line, Line4Type lineType) {
|
||||||
char lineBuffer[LINE_BUFFER_SIZE];
|
char lineBuffer[LINE_BUFFER_SIZE];
|
||||||
|
uint8_t printedChars;
|
||||||
switch(lineType) {
|
switch(lineType) {
|
||||||
case FLD_LINE_BRIGHTNESS:
|
case FLD_LINE_BRIGHTNESS:
|
||||||
sprintf_P(lineBuffer, PSTR("Brightness %3d"), bri);
|
sprintf_P(lineBuffer, PSTR("Brightness %3d"), bri);
|
||||||
@ -452,10 +453,16 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
drawString(2, line*lineHeight, lineBuffer);
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_MODE:
|
case FLD_LINE_MODE:
|
||||||
showCurrentEffectOrPalette(knownMode, JSON_mode_names, line);
|
printedChars = extractModeName(knownMode, JSON_mode_names, lineBuffer, LINE_BUFFER_SIZE-1);
|
||||||
|
for (;printedChars < getCols()-2 && printedChars < LINE_BUFFER_SIZE-3; printedChars++) lineBuffer[printedChars]=' ';
|
||||||
|
lineBuffer[printedChars] = 0;
|
||||||
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_PALETTE:
|
case FLD_LINE_PALETTE:
|
||||||
showCurrentEffectOrPalette(knownPalette, JSON_palette_names, line);
|
printedChars = extractModeName(knownPalette, JSON_palette_names, lineBuffer, LINE_BUFFER_SIZE-1);
|
||||||
|
for (;printedChars < getCols()-2 && printedChars < LINE_BUFFER_SIZE-3; printedChars++) lineBuffer[printedChars]=' ';
|
||||||
|
lineBuffer[printedChars] = 0;
|
||||||
|
drawString(2, line*lineHeight, lineBuffer);
|
||||||
break;
|
break;
|
||||||
case FLD_LINE_TIME:
|
case FLD_LINE_TIME:
|
||||||
default:
|
default:
|
||||||
@ -464,19 +471,6 @@ class FourLineDisplayUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the current effect or palette (desiredEntry)
|
|
||||||
* on the appropriate line (row).
|
|
||||||
*/
|
|
||||||
void showCurrentEffectOrPalette(int knownMode, const char *qstring, uint8_t row) {
|
|
||||||
char lineBuffer[LINE_BUFFER_SIZE];
|
|
||||||
extractModeName(knownMode, qstring, lineBuffer, LINE_BUFFER_SIZE-1);
|
|
||||||
uint8_t printedChars = strlen(lineBuffer);
|
|
||||||
for (;printedChars < getCols()-2 && printedChars < sizeof(lineBuffer)-2; printedChars++) lineBuffer[printedChars]=' ';
|
|
||||||
lineBuffer[printedChars] = 0;
|
|
||||||
drawString(2, row*lineHeight, lineBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there screen is off or in clock is displayed,
|
* If there screen is off or in clock is displayed,
|
||||||
* this will return true. This allows us to throw away
|
* this will return true. This allows us to throw away
|
||||||
|
@ -129,7 +129,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
|
|||||||
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 serializeSRNames(JsonArray arr, const char *qstring);
|
||||||
void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
|
uint8_t 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);
|
||||||
|
|
||||||
|
@ -831,10 +831,11 @@ void deserializeModeNames(JsonArray arr, const char *qstring) {
|
|||||||
|
|
||||||
// extracts effect mode (or palette) name from names serialized string
|
// extracts effect mode (or palette) name from names serialized string
|
||||||
// caller must provide large enough buffer!
|
// caller must provide large enough buffer!
|
||||||
void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
||||||
{
|
{
|
||||||
uint8_t qComma = 0;
|
uint8_t qComma = 0;
|
||||||
bool insideQuotes = false;
|
bool insideQuotes = false;
|
||||||
|
bool atFound = false;
|
||||||
uint8_t printedChars = 0;
|
uint8_t printedChars = 0;
|
||||||
char singleJsonSymbol;
|
char singleJsonSymbol;
|
||||||
|
|
||||||
@ -845,7 +846,10 @@ void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
|||||||
switch (singleJsonSymbol) {
|
switch (singleJsonSymbol) {
|
||||||
case '"':
|
case '"':
|
||||||
insideQuotes = !insideQuotes;
|
insideQuotes = !insideQuotes;
|
||||||
|
if (!insideQuotes && atFound) atFound = false;
|
||||||
break;
|
break;
|
||||||
|
case '@':
|
||||||
|
if (insideQuotes) atFound = true;
|
||||||
case '[':
|
case '[':
|
||||||
case ']':
|
case ']':
|
||||||
break;
|
break;
|
||||||
@ -853,13 +857,12 @@ void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
|||||||
qComma++;
|
qComma++;
|
||||||
default:
|
default:
|
||||||
if (!insideQuotes || (qComma != mode)) break;
|
if (!insideQuotes || (qComma != mode)) break;
|
||||||
dest[printedChars++] = singleJsonSymbol;
|
if (!atFound) dest[printedChars++] = singleJsonSymbol;
|
||||||
}
|
}
|
||||||
if ((qComma > mode) || (printedChars >= maxLen)) break;
|
if ((qComma > mode) || (printedChars >= maxLen)) break;
|
||||||
}
|
}
|
||||||
dest[printedChars] = '\0';
|
dest[printedChars] = '\0';
|
||||||
char *p = strchr(dest,'@');
|
return printedChars;
|
||||||
if (p != nullptr) *p = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void serveJson(AsyncWebServerRequest* request)
|
void serveJson(AsyncWebServerRequest* request)
|
||||||
@ -878,6 +881,13 @@ void serveJson(AsyncWebServerRequest* request)
|
|||||||
else if (url.indexOf(F("eff")) > 0) {
|
else if (url.indexOf(F("eff")) > 0) {
|
||||||
// this is going to serve raw effect names which will include WLED-SR extensions in names
|
// this is going to serve raw effect names which will include WLED-SR extensions in names
|
||||||
request->send_P(200, "application/json", JSON_mode_names);
|
request->send_P(200, "application/json", JSON_mode_names);
|
||||||
|
// if we want parsed effect names use this (warning, this will prevent UI from receiving this extension making it useless)
|
||||||
|
//AsyncJsonResponse* response = new AsyncJsonResponse(JSON_BUFFER_SIZE, true); // array document
|
||||||
|
//JsonArray doc = response->getRoot();
|
||||||
|
//deserializeModeNames(doc, JSON_mode_names); // remove WLED-SR extensions from effect names
|
||||||
|
//response->setLength();
|
||||||
|
//request->send(response);
|
||||||
|
//delete response;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (url.indexOf("pal") > 0) {
|
else if (url.indexOf("pal") > 0) {
|
||||||
@ -923,6 +933,8 @@ void serveJson(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
|
delete response;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_LIVE_LEDS 180
|
#define MAX_LIVE_LEDS 180
|
||||||
|
Loading…
x
Reference in New Issue
Block a user