kopia lustrzana https://github.com/Aircoookie/WLED
Minor change in handling mode names.
rodzic
10fc9fe268
commit
f66fcfbe6d
|
@ -292,33 +292,8 @@ class St7789DisplayUsermod : public Usermod {
|
|||
// palette name
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
tft.setCursor(0, 168);
|
||||
qComma = 0;
|
||||
insideQuotes = false;
|
||||
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;
|
||||
}
|
||||
extractModeName(knownPalette, JSON_palette_names, lineBuffer, tftcharwidth);
|
||||
tft.print(lineBuffer);
|
||||
|
||||
tft.setCursor(0, 192);
|
||||
tft.setTextColor(TFT_SILVER);
|
||||
|
|
|
@ -438,6 +438,7 @@ class FourLineDisplayUsermod : public Usermod {
|
|||
|
||||
void drawLine(uint8_t line, Line4Type lineType) {
|
||||
char lineBuffer[LINE_BUFFER_SIZE];
|
||||
uint8_t printedChars;
|
||||
switch(lineType) {
|
||||
case FLD_LINE_BRIGHTNESS:
|
||||
sprintf_P(lineBuffer, PSTR("Brightness %3d"), bri);
|
||||
|
@ -452,10 +453,16 @@ class FourLineDisplayUsermod : public Usermod {
|
|||
drawString(2, line*lineHeight, lineBuffer);
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
case FLD_LINE_TIME:
|
||||
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,
|
||||
* 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 serializeInfo(JsonObject root);
|
||||
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);
|
||||
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
|
||||
// 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;
|
||||
bool insideQuotes = false;
|
||||
bool atFound = false;
|
||||
uint8_t printedChars = 0;
|
||||
char singleJsonSymbol;
|
||||
|
||||
|
@ -845,7 +846,10 @@ void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
|||
switch (singleJsonSymbol) {
|
||||
case '"':
|
||||
insideQuotes = !insideQuotes;
|
||||
if (!insideQuotes && atFound) atFound = false;
|
||||
break;
|
||||
case '@':
|
||||
if (insideQuotes) atFound = true;
|
||||
case '[':
|
||||
case ']':
|
||||
break;
|
||||
|
@ -853,13 +857,12 @@ void extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
|||
qComma++;
|
||||
default:
|
||||
if (!insideQuotes || (qComma != mode)) break;
|
||||
dest[printedChars++] = singleJsonSymbol;
|
||||
if (!atFound) dest[printedChars++] = singleJsonSymbol;
|
||||
}
|
||||
if ((qComma > mode) || (printedChars >= maxLen)) break;
|
||||
}
|
||||
dest[printedChars] = '\0';
|
||||
char *p = strchr(dest,'@');
|
||||
if (p != nullptr) *p = '\0';
|
||||
return printedChars;
|
||||
}
|
||||
|
||||
void serveJson(AsyncWebServerRequest* request)
|
||||
|
@ -878,6 +881,13 @@ void serveJson(AsyncWebServerRequest* request)
|
|||
else if (url.indexOf(F("eff")) > 0) {
|
||||
// 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);
|
||||
// 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;
|
||||
}
|
||||
else if (url.indexOf("pal") > 0) {
|
||||
|
@ -923,6 +933,8 @@ void serveJson(AsyncWebServerRequest* request)
|
|||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
|
||||
delete response;
|
||||
}
|
||||
|
||||
#define MAX_LIVE_LEDS 180
|
||||
|
|
Ładowanie…
Reference in New Issue