longer segment names
* introducing WLED_MAX_SEGNAME_LEN from upstream * default: max name length = 48 * hopefully found all places where the segment name length was hardcoded (32, 33, 34) * some comments still refer to "32" but wtf
This commit is contained in:
@@ -6814,8 +6814,8 @@ uint16_t mode_2Dscrollingtext(void) {
|
||||
case 5: letterWidth = 5; letterHeight = 12; break;
|
||||
}
|
||||
const int yoffset = map(SEGMENT.intensity, 0, 255, -rows/2, rows/2) + (rows-letterHeight)/2;
|
||||
char text[33] = {'\0'}; // ToDO use WLED_MAX_SEGNAME_LEN + 1
|
||||
unsigned maxLen = (SEGMENT.name) ? min(32, (int)strlen(SEGMENT.name)) : 0; // WLEDMM make it robust against too long segment names, ToDO use WLED_MAX_SEGNAME_LEN
|
||||
char text[WLED_MAX_SEGNAME_LEN+1] = {'\0'};
|
||||
unsigned maxLen = (SEGMENT.name) ? min(WLED_MAX_SEGNAME_LEN, (int)strlen(SEGMENT.name)) : 0; // WLEDMM make it robust against too long segment names
|
||||
|
||||
#if !defined(WLED_ENABLE_FULL_FONTS)
|
||||
if (SEGMENT.name) for (size_t i=0,j=0; i<maxLen; i++) if (SEGMENT.name[i]>31 && SEGMENT.name[i]<128) text[j++] = SEGMENT.name[i]; // unicode killer
|
||||
|
||||
@@ -842,7 +842,7 @@ void Segment::drawArc(unsigned x0, unsigned y0, int radius, uint32_t color, uint
|
||||
//WLEDMM for artifx
|
||||
bool Segment::jsonToPixels(char * name, uint8_t fileNr) {
|
||||
if (!isActive()) return true; // segment not active, nothing to do
|
||||
char fileName[42] = { '\0' }; // we need up to 40 bytes (seg.name is 32 bytes max)
|
||||
char fileName[WLED_MAX_SEGNAME_LEN+12] = { '\0' }; // we need up to 40 bytes (seg.name is 32 bytes max)
|
||||
//WLEDMM: als support segment name ledmaps
|
||||
bool isFile = false;
|
||||
// strcpy_P(fileName, PSTR("/mario"));
|
||||
@@ -886,11 +886,6 @@ bool Segment::jsonToPixels(char * name, uint8_t fileNr) {
|
||||
#include "src/font/codepages.h"
|
||||
#endif
|
||||
|
||||
//upstream compatibility
|
||||
#if !defined(WLED_MAX_SEGNAME_LEN)
|
||||
#define WLED_MAX_SEGNAME_LEN 32 // ToDO: inrease default to 48
|
||||
#endif
|
||||
|
||||
// unicode-aware wrapper for drawCharacter(), to be called from mode_2Dscrollingtext()
|
||||
void Segment::drawText(const unsigned char* text, size_t maxLen, int maxLetters, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2, bool drawShadow) {
|
||||
if (!isActive()) return; // not active
|
||||
|
||||
@@ -698,7 +698,7 @@ struct ArrayAndSize {
|
||||
};
|
||||
class JMapC {
|
||||
public:
|
||||
char previousSegmentName[50] = "";
|
||||
char previousSegmentName[WLED_MAX_SEGNAME_LEN+12] = "";
|
||||
|
||||
~JMapC() {
|
||||
DEBUG_PRINTLN("~JMapC");
|
||||
@@ -751,7 +751,7 @@ class JMapC {
|
||||
uint32_t dataSize = 0;
|
||||
deletejVectorMap();
|
||||
DEBUG_PRINT("New "); DEBUG_PRINTLN(SEGMENT.name);
|
||||
char jMapFileName[50] = {'\0'}; // we need at most 32 + 7 bytes
|
||||
char jMapFileName[WLED_MAX_SEGNAME_LEN+12] = {'\0'}; // we need at most 32 + 7 bytes
|
||||
strcpy(jMapFileName, "/");
|
||||
strcat(jMapFileName, SEGMENT.name);
|
||||
strcat(jMapFileName, ".json");
|
||||
@@ -1728,22 +1728,22 @@ void WS2812FX::enumerateLedmaps() {
|
||||
f = WLED_FS.open(fileName, "r");
|
||||
if (f) {
|
||||
f.find("\"n\":");
|
||||
char name[34] = { '\0' }; // ensure string termination
|
||||
char name[WLED_MAX_SEGNAME_LEN+2] = { '\0' }; // ensure string termination
|
||||
f.readBytesUntil('\n', name, sizeof(name)-1);
|
||||
|
||||
size_t len = strlen(name);
|
||||
if (len > 0 && len < 33) {
|
||||
if (len > 0 && len < (sizeof(name)-1)) {
|
||||
(void) cleanUpName(name);
|
||||
len = strlen(name);
|
||||
ledmapNames[i-1] = new(std::nothrow) 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, sizeof(name));
|
||||
}
|
||||
if (!ledmapNames[i-1]) {
|
||||
char tmp[33];
|
||||
snprintf_P(tmp, 32, PSTR("ledmap%d.json"), i);
|
||||
len = strlen(tmp);
|
||||
ledmapNames[i-1] = new(std::nothrow) char[len+1];
|
||||
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], tmp, 33);
|
||||
size_t tmplen = strlen(tmp);
|
||||
ledmapNames[i-1] = new(std::nothrow) char[tmplen+1];
|
||||
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], tmp, tmplen);
|
||||
}
|
||||
|
||||
USER_PRINTF("enumerateLedmaps %s \"%s\"", fileName, name);
|
||||
@@ -1779,7 +1779,7 @@ void WS2812FX::enumerateLedmaps() {
|
||||
uint8_t segment_index = 0;
|
||||
for (segment &seg : _segments) {
|
||||
if (seg.name != nullptr && strlen(seg.name) > 0) {
|
||||
char fileName[33+11] = { '\0' }; // segment name is 32 chars max, so we need 43 chars in worst case
|
||||
char fileName[WLED_MAX_SEGNAME_LEN+12] = { '\0' }; // segment name is 32 chars max, so we need 43 chars in worst case
|
||||
snprintf_P(fileName, sizeof(fileName)-1, PSTR("/lm%s.json"), seg.name);
|
||||
bool isFile = WLED_FS.exists(fileName);
|
||||
if (isFile) ledMaps |= 1 << (10+segment_index);
|
||||
@@ -2587,7 +2587,7 @@ void WS2812FX::loadCustomPalettes() {
|
||||
bool WS2812FX::deserializeMap(uint8_t n) {
|
||||
// 2D support creates its own ledmap (on the fly) if a ledmap.json exists it will overwrite built one.
|
||||
|
||||
char fileName[42] = {'\0'}; // WLEDMM we need at least 32 + 7 bytes
|
||||
char fileName[WLED_MAX_SEGNAME_LEN+10] = {'\0'}; // WLEDMM we need at least 32 + 7 bytes
|
||||
//WLEDMM: als support segment name ledmaps
|
||||
bool isFile = false;;
|
||||
if (n<10) {
|
||||
|
||||
@@ -91,6 +91,22 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef WLED_MAX_SEGNAME_LEN
|
||||
#ifdef ESP8266
|
||||
#define WLED_MAX_SEGNAME_LEN 32
|
||||
#else
|
||||
#define WLED_MAX_SEGNAME_LEN 48 // WLEDMM upstream uses 64, but 48 seems to be a good compromise between flexibility and memory needed
|
||||
#endif
|
||||
#else
|
||||
#if WLED_MAX_SEGNAME_LEN<32
|
||||
#undef WLED_MAX_SEGNAME_LEN
|
||||
#define WLED_MAX_SEGNAME_LEN 32
|
||||
#else
|
||||
#warning WLED UI does not support your modified maximum segment name length!
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//Usermod IDs
|
||||
#define USERMOD_ID_RESERVED 0 //Unused. Might indicate no usermod present
|
||||
#define USERMOD_ID_UNSPECIFIED 1 //Default value for a general user mod that does not specify a custom ID
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
#include "GifDecoder.h"
|
||||
|
||||
|
||||
//upstream compatibility
|
||||
#if !defined(WLED_MAX_SEGNAME_LEN)
|
||||
#define WLED_MAX_SEGNAME_LEN 32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Functions to render images from filesystem to segments, used by the "Image" effect
|
||||
*/
|
||||
|
||||
@@ -151,8 +151,8 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
if (name != nullptr) len = strlen(name);
|
||||
if (len > 0) {
|
||||
// WLEDMM: truncate segment name, instead of silently deleting
|
||||
if (len > 32) { // ToDO: use WLED_MAX_SEGNAME_LEN
|
||||
len = 32; // cut to max segment name length
|
||||
if (len > WLED_MAX_SEGNAME_LEN) {
|
||||
len = WLED_MAX_SEGNAME_LEN; // cut to max segment name length
|
||||
#if defined(WLED_ENABLE_FULL_FONTS)
|
||||
if (name[len] > 127) // UTF-8 => don't cut in the middle of a multi-byte char
|
||||
len = cutUnicodeAt((unsigned char*)name, len-1) +1; // +1 to convert between index and length
|
||||
|
||||
Reference in New Issue
Block a user