From cc6fba8d6042218be7ef3b51833d024863fac2b6 Mon Sep 17 00:00:00 2001 From: Thokoop <11939567+Thokoop@users.noreply.github.com> Date: Mon, 14 Apr 2025 21:11:28 +0200 Subject: [PATCH 1/4] Work in progress: Added custom charset field --- src/SplitFlapDisplay.cpp | 33 ++++++++++++++++++++- src/SplitFlapDisplay.h | 2 ++ src/SplitFlapDisplay.ino | 3 +- src/SplitFlapModule.cpp | 63 +++++++++++++++++++++++++++++++++------- src/SplitFlapModule.h | 13 ++++++++- src/web/settings.html | 36 +++++++++++++++++++++++ 6 files changed, 137 insertions(+), 13 deletions(-) diff --git a/src/SplitFlapDisplay.cpp b/src/SplitFlapDisplay.cpp index ebe0fe2..1fd967a 100644 --- a/src/SplitFlapDisplay.cpp +++ b/src/SplitFlapDisplay.cpp @@ -13,6 +13,17 @@ void SplitFlapDisplay::init() { magnetPosition = settings.getInt("magnetPosition"); maxVel = settings.getFloat("maxVel"); charSetSize = settings.getInt("charset"); + String customCharsetString = settings.getString("custom_charset"); + const char* customCharsetPtr = nullptr; + + memset(customCharsetPersistent, 0, sizeof(customCharsetPersistent)); + if (customCharsetString.length() == charSetSize) { + for (int i = 0; i < charSetSize; i++) { + customCharsetPersistent[i] = customCharsetString[i]; + } + customCharsetPersistent[charSetSize] = '\0'; + customCharsetPtr = customCharsetPersistent; + } std::vector settingAddresses = settings.getIntVector("moduleAddresses"); for (int i = 0; i < numModules; i++) { @@ -31,9 +42,29 @@ void SplitFlapDisplay::init() { } Serial.println(); + + for (uint8_t i = 0; i < numModules; i++) { + const char* customCharsetPtr = nullptr; + + static char moduleCharset[MAX_MODULES][49]; + memset(moduleCharset[i], 0, sizeof(moduleCharset[i])); + + if (customCharsetString.length() == charSetSize) { + for (int c = 0; c < charSetSize; c++) { + moduleCharset[i][c] = customCharsetString[c]; + } + moduleCharset[i][charSetSize] = '\0'; + customCharsetPtr = moduleCharset[i]; + } + modules[i] = SplitFlapModule( - moduleAddresses[i], stepsPerRot, moduleOffsets[i] + displayOffset, magnetPosition, charSetSize + moduleAddresses[i], + stepsPerRot, + moduleOffsets[i] + displayOffset, + magnetPosition, + charSetSize, + customCharsetPtr ); } diff --git a/src/SplitFlapDisplay.h b/src/SplitFlapDisplay.h index 201e87c..3137008 100644 --- a/src/SplitFlapDisplay.h +++ b/src/SplitFlapDisplay.h @@ -57,5 +57,7 @@ class SplitFlapDisplay { int SDAPin; // SDA pin int SCLPin; // SCL pin + char customCharsetPersistent[49]; + SplitFlapMqtt *mqtt = nullptr; }; diff --git a/src/SplitFlapDisplay.ino b/src/SplitFlapDisplay.ino index c8cb9ae..4b0303b 100644 --- a/src/SplitFlapDisplay.ino +++ b/src/SplitFlapDisplay.ino @@ -39,7 +39,8 @@ JsonSettings settings = JsonSettings("config", { {"sclPin", JsonSetting(9)}, {"stepsPerRot", JsonSetting(2048)}, {"maxVel", JsonSetting(15.0f)}, - {"charset", JsonSetting(37)}, + {"charset", JsonSetting(48)}, + {"custom_charset", JsonSetting("")}, // Operational States {"mode", JsonSetting(0)} }); diff --git a/src/SplitFlapModule.cpp b/src/SplitFlapModule.cpp index bd7fc25..cfdf3d7 100644 --- a/src/SplitFlapModule.cpp +++ b/src/SplitFlapModule.cpp @@ -7,8 +7,8 @@ const char SplitFlapModule::StandardChars[37] = {' ', 'A', 'B', 'C', 'D', 'E', ' 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; const char SplitFlapModule::ExtendedChars[48] = { - ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', + ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\'', ':', '?', '!', '.', '-', '/', '$', '@', '#', '%', }; @@ -16,19 +16,51 @@ bool hasErrored = false; // Default Constructor SplitFlapModule::SplitFlapModule() - : address(0), position(0), stepNumber(0), stepsPerRot(0), chars(StandardChars), numChars(37), charSetSize(37) { + : SplitFlapModule(0x20, 2048, 0, 710, 37, nullptr) { magnetPosition = 710; } // Constructor implementation SplitFlapModule::SplitFlapModule( - uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos, int charsetSize -) - : address(I2Caddress), position(0), stepNumber(0), stepsPerRot(stepsPerFullRotation), charSetSize(charsetSize) { + uint8_t I2Caddress, + int stepsPerFullRotation, + int stepOffset, + int magnetPos, + int charsetSize, + const char* customCharset +) : address(I2Caddress), + position(0), + stepNumber(0), + stepsPerRot(stepsPerFullRotation), + charSetSize(charsetSize) { + magnetPosition = magnetPos + stepOffset; - chars = (charsetSize == 48) ? ExtendedChars : StandardChars; - numChars = (charsetSize == 48) ? 48 : 37; + if (customCharset != nullptr && strlen(customCharset) == charsetSize) { + usingCustomChars = true; + numChars = charsetSize; + + // Copy safely and log + for (int i = 0; i < numChars; i++) { + customChars[i] = customCharset[i]; + Serial.print("["); + Serial.print(i); + Serial.print(": '"); + Serial.print(customChars[i]); + Serial.print("' ("); + Serial.print((int)customChars[i]); + Serial.println(")]"); + } + customChars[numChars] = '\0'; // null-terminate + chars = customChars; + + Serial.println("Custom chars assigned."); + Serial.println(chars); + } else { + usingCustomChars = false; + chars = (charsetSize == 48) ? ExtendedChars : StandardChars; + numChars = (charsetSize == 48) ? 48 : 37; + } } void SplitFlapModule::writeIO(uint16_t data) { @@ -82,13 +114,24 @@ void SplitFlapModule::init() { } int SplitFlapModule::getCharPosition(char inputChar) { - inputChar = toupper(inputChar); + if (!usingCustomChars) { + inputChar = toupper(inputChar); + } + for (int i = 0; i < charSetSize; i++) { + + Serial.print("TEST:'"); + Serial.println(chars[i]); if (chars[i] == inputChar) { return charPositions[i]; } } - return 0; // Character not found, return blank + + Serial.print("Character not found: '"); + Serial.print(inputChar); + Serial.println("' — returning 0"); + + return 0; // fallback: space } void SplitFlapModule::stop() { diff --git a/src/SplitFlapModule.h b/src/SplitFlapModule.h index 3eed10f..6bcb8dc 100644 --- a/src/SplitFlapModule.h +++ b/src/SplitFlapModule.h @@ -8,7 +8,14 @@ class SplitFlapModule { // Constructor declarationS SplitFlapModule(); // default constructor required to allocate memory for // SplitFlapDisplay class - SplitFlapModule(uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos, int charSetSize); + SplitFlapModule( + uint8_t I2Caddress, + int stepsPerFullRotation, + int stepOffset, + int magnetPos, + int charsetSize, + const char* customCharset = nullptr + ); void init(); @@ -46,9 +53,13 @@ class SplitFlapModule { int charPositions[48]; // support up to 48 characters int numChars; // current number of characters int charSetSize; + char customCharsetPersistent[49] = {0}; + bool usingCustomChars = false; + char customChars[49]; static const char StandardChars[37]; static const char ExtendedChars[48]; + }; // //PINs on the PCF8575 Board diff --git a/src/web/settings.html b/src/web/settings.html index 1979ae8..791928d 100644 --- a/src/web/settings.html +++ b/src/web/settings.html @@ -482,6 +482,42 @@ + +
+ +
+ + +
+
+