clean up ledmap names when directly reading from file
This commit is contained in:
@@ -1397,9 +1397,8 @@ void WS2812FX::enumerateLedmaps() {
|
|||||||
|
|
||||||
size_t len = strlen(name);
|
size_t len = strlen(name);
|
||||||
if (len > 0 && len < 33) {
|
if (len > 0 && len < 33) {
|
||||||
if ((len > 0) && (name[len-1] == '\r')) { name[len-1] = '\0'; len--;} // kill trailing `\r` (DOS format: \r\n)
|
(void) cleanUpName(name);
|
||||||
if ((len > 0) && (name[len-1] == ',')) { name[len-1] = '\0'; len--;} // kill trailing `,`
|
len = strlen(name);
|
||||||
if ((len > 0) && (name[len-1] == ' ')) { name[len-1] = '\0'; len--;} // kill trailing ` `
|
|
||||||
ledmapNames[i-1] = new char[len+1]; // +1 to include terminating \0
|
ledmapNames[i-1] = new char[len+1]; // +1 to include terminating \0
|
||||||
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], name, 33);
|
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], name, 33);
|
||||||
}
|
}
|
||||||
@@ -1415,14 +1414,14 @@ void WS2812FX::enumerateLedmaps() {
|
|||||||
char dim[34] = { '\0' };
|
char dim[34] = { '\0' };
|
||||||
f.find("\"width\":");
|
f.find("\"width\":");
|
||||||
f.readBytesUntil('\n', dim, sizeof(dim)-1); //hack: use fileName as we have this allocated already
|
f.readBytesUntil('\n', dim, sizeof(dim)-1); //hack: use fileName as we have this allocated already
|
||||||
uint16_t maxWidth = atoi(dim);
|
uint16_t maxWidth = atoi(cleanUpName(dim));
|
||||||
f.find("\"height\":");
|
f.find("\"height\":");
|
||||||
memset(dim, 0, sizeof(dim)); // clear buffer before reading
|
memset(dim, 0, sizeof(dim)); // clear buffer before reading
|
||||||
f.readBytesUntil('\n', dim, sizeof(dim)-1);
|
f.readBytesUntil('\n', dim, sizeof(dim)-1);
|
||||||
uint16_t maxHeight = atoi(dim);
|
uint16_t maxHeight = atoi(cleanUpName(dim));
|
||||||
ledmapMaxSize = MAX(ledmapMaxSize, maxWidth * maxHeight);
|
ledmapMaxSize = MAX(ledmapMaxSize, maxWidth * maxHeight);
|
||||||
|
|
||||||
USER_PRINTF("enumerateLedmaps %s %s (%dx%d -> %d)\n", fileName, name, maxWidth, maxHeight, ledmapMaxSize);
|
USER_PRINTF("enumerateLedmaps %s \"%s\" (%dx%d -> %d)\n", fileName, name, maxWidth, maxHeight, ledmapMaxSize);
|
||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
USER_FLUSH();
|
USER_FLUSH();
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ uint16_t crc16(const unsigned char* data_p, size_t length);
|
|||||||
um_data_t* simulateSound(uint8_t simulationId);
|
um_data_t* simulateSound(uint8_t simulationId);
|
||||||
// WLEDMM enumerateLedmaps(); moved to FX.h
|
// WLEDMM enumerateLedmaps(); moved to FX.h
|
||||||
CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal); //WLEDMM netmindz ar palette
|
CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal); //WLEDMM netmindz ar palette
|
||||||
|
char *cleanUpName(char *in); // to clean up a name that was read from file
|
||||||
|
|
||||||
#ifdef WLED_ADD_EEPROM_SUPPORT
|
#ifdef WLED_ADD_EEPROM_SUPPORT
|
||||||
//wled_eeprom.cpp
|
//wled_eeprom.cpp
|
||||||
|
|||||||
@@ -537,4 +537,33 @@ CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WLEDMM extended "trim string" function to support enumerateLedmaps
|
||||||
|
// The function takes char* as input, and removes all leading and trailing "decorations" like spaces, tabs, line endings, quotes, colons
|
||||||
|
// The conversion is "in place" (destructive).
|
||||||
|
// example: cleanUpName("\t \"Ring241x 60/9 squeeze \" ,\r") returns "Ring241x 60/9 squeeze"
|
||||||
|
//
|
||||||
|
// Null pointer and zero size "C strings" are handled correctly.
|
||||||
|
// Will not work with flash strings. Unicode encoded multi-byte char strings may get corrupted.
|
||||||
|
//
|
||||||
|
static const char *unwantedChars = "\r\n\t\b ,;:\"\'`´\\"; // list of chars to delete
|
||||||
|
//
|
||||||
|
char *cleanUpName(char *in) {
|
||||||
|
if (nullptr == in) return(in);
|
||||||
|
size_t len = strlen(in);
|
||||||
|
if (len == 0) return(in);
|
||||||
|
|
||||||
|
// delete trailing garbage
|
||||||
|
while ((len > 0) && (strchr(unwantedChars, in[len-1]) != nullptr)) {
|
||||||
|
in[len-1] = '\0'; // deletes last char
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
// delete leading garbage
|
||||||
|
while ((len > 0) && (strchr(unwantedChars, in[0]) != nullptr)) {
|
||||||
|
(void) memmove(in, in+1, len); // shifts string left by one
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(in);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user