From c1cd201603ed460c93da8f8d7a7681ffabfbb04a Mon Sep 17 00:00:00 2001 From: Thokoop <11939567+Thokoop@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:30:00 +0200 Subject: [PATCH 1/5] Added support for 48 flaps per module --- src/SplitFlapDisplay.cpp | 5 +++-- src/SplitFlapDisplay.h | 8 ++++--- src/SplitFlapDisplay.ino | 1 + src/SplitFlapModule.cpp | 45 ++++++++++++++++++++-------------------- src/SplitFlapModule.h | 14 ++++++++----- src/web/settings.html | 27 ++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/SplitFlapDisplay.cpp b/src/SplitFlapDisplay.cpp index 355a4a7..988d0e3 100644 --- a/src/SplitFlapDisplay.cpp +++ b/src/SplitFlapDisplay.cpp @@ -12,6 +12,7 @@ void SplitFlapDisplay::init() { displayOffset = settings.getInt("displayOffset"); magnetPosition = settings.getInt("magnetPosition"); maxVel = settings.getFloat("maxVel"); + charSetSize = settings.getInt("charset"); std::vector settingAddresses = settings.getIntVector("moduleAddresses"); for (int i = 0; i < numModules; i++) { @@ -31,7 +32,7 @@ void SplitFlapDisplay::init() { Serial.println(); for (uint8_t i = 0; i < numModules; i++) { - modules[i] = SplitFlapModule(moduleAddresses[i], stepsPerRot, moduleOffsets[i] + displayOffset, magnetPosition); + modules[i] = SplitFlapModule(moduleAddresses[i], stepsPerRot, moduleOffsets[i] + displayOffset, magnetPosition, charSetSize); } SDAPin = settings.getInt("sdaPin"); @@ -314,4 +315,4 @@ void SplitFlapDisplay::stopMotors() { void SplitFlapDisplay::setMqtt(SplitFlapMqtt *mqttHandler) { mqtt = mqttHandler; -} +} \ No newline at end of file diff --git a/src/SplitFlapDisplay.h b/src/SplitFlapDisplay.h index f235ca4..201e87c 100644 --- a/src/SplitFlapDisplay.h +++ b/src/SplitFlapDisplay.h @@ -33,6 +33,7 @@ class SplitFlapDisplay { void testCount(); void testRandom(float speed = MAX_RPM); int getNumModules() { return numModules; } + int getCharsetSize() const { return charSetSize; } void setMqtt(SplitFlapMqtt *mqttHandler); private: @@ -48,9 +49,10 @@ class SplitFlapDisplay { int moduleOffsets[MAX_MODULES]; int displayOffset; - float maxVel; // Max Velocity In RPM - int stepsPerRot; // number of motor steps per full rotation of character - // drum + float maxVel; // Max Velocity In RPM + int charSetSize; // 37 for standard, 48 for extended + int stepsPerRot; // number of motor steps per full rotation of character + // drum int magnetPosition; // position of drum wheel when magnet is detected int SDAPin; // SDA pin int SCLPin; // SCL pin diff --git a/src/SplitFlapDisplay.ino b/src/SplitFlapDisplay.ino index bf2eec5..b27d393 100644 --- a/src/SplitFlapDisplay.ino +++ b/src/SplitFlapDisplay.ino @@ -37,6 +37,7 @@ JsonSettings settings = JsonSettings("config", { {"sclPin", JsonSetting(9)}, {"stepsPerRot", JsonSetting(2048)}, {"maxVel", JsonSetting(15.0f)}, + {"charset", JsonSetting(37)}, // Operational States {"mode", JsonSetting(0)} }); diff --git a/src/SplitFlapModule.cpp b/src/SplitFlapModule.cpp index 22b4473..6f6afff 100644 --- a/src/SplitFlapModule.cpp +++ b/src/SplitFlapModule.cpp @@ -2,28 +2,30 @@ // Array of characters, in order, the first item is located on the magnet on the // character drum -const char SplitFlapModule::chars[37] = {' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', +const char SplitFlapModule::StandardChars[37] = {' ', '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'}; -const int SplitFlapModule::numChars = sizeof(SplitFlapModule::chars) / sizeof(SplitFlapModule::chars[0]); -int SplitFlapModule::charPositions[37]; // to be written in init function -bool hasErrored = false; +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', '5', '6', '7', '8', '9', + '\'', ':', '?', '!', '.', '-', '/', '$', '@', '#', '%',}; -// Not used but useful to have -// const int SplitFlapModule::motorPins[] = {P06, P05, P04, P03}; // List of -// pins to set as OUTPUT const int SplitFlapModule::HallEffectPIN = P17; //Input -// pin for Hall effect sensor + +bool hasErrored = false; // Default Constructor -SplitFlapModule::SplitFlapModule() : address(0), position(0), stepNumber(0), stepsPerRot(0) { // default values - magnetPosition = 710; // sort of guessing +SplitFlapModule::SplitFlapModule() : address(0), position(0), stepNumber(0), stepsPerRot(0), chars(StandardChars), numChars(37), charSetSize(37) { + magnetPosition = 710; } // Constructor implementation -SplitFlapModule::SplitFlapModule(uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos) - : address(I2Caddress), position(0), stepNumber(0), stepsPerRot(stepsPerFullRotation) { - magnetPosition = magnetPos + stepOffset; +SplitFlapModule::SplitFlapModule(uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos, int charsetSize) + : address(I2Caddress), position(0), stepNumber(0), stepsPerRot(stepsPerFullRotation), charSetSize(charsetSize) { + magnetPosition = magnetPos + stepOffset; + + chars = (charsetSize == 48) ? ExtendedChars : StandardChars; + numChars = (charsetSize == 48) ? 48 : 37; } void SplitFlapModule::writeIO(uint16_t data) { @@ -49,6 +51,13 @@ void SplitFlapModule::writeIO(uint16_t data) { // Init Module, Setup IO Board void SplitFlapModule::init() { + float stepSize = (float)stepsPerRot / (float)numChars; + float currentPosition = 0; + for (int i = 0; i < numChars; i++) { + charPositions[i] = (int)currentPosition; + currentPosition += stepSize; + } + uint16_t initState = 0b1111111111100001; // Pin 15 (17) as INPUT, Pins 1-4 as OUTPUT writeIO(initState); @@ -67,19 +76,11 @@ void SplitFlapModule::init() { delay(initDelay); stop(); - - // Generate Character Position Array - float stepSize = (float) stepsPerRot / (float) numChars; - float currentPosition = 0; - for (int i = 0; i < numChars; i++) { - charPositions[i] = (int) currentPosition; - currentPosition += stepSize; - } } int SplitFlapModule::getCharPosition(char inputChar) { inputChar = toupper(inputChar); - for (int i = 0; i < numChars; i++) { + for (int i = 0; i < charSetSize; i++) { if (chars[i] == inputChar) { return charPositions[i]; } diff --git a/src/SplitFlapModule.h b/src/SplitFlapModule.h index 945aa68..07dc9e5 100644 --- a/src/SplitFlapModule.h +++ b/src/SplitFlapModule.h @@ -8,7 +8,7 @@ class SplitFlapModule { // Constructor declarationS SplitFlapModule(); // default constructor required to allocate memory for // SplitFlapDisplay class - SplitFlapModule(uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos); + SplitFlapModule(uint8_t I2Caddress, int stepsPerFullRotation, int stepOffset, int magnetPos, int charSetSize); void init(); @@ -19,6 +19,7 @@ class SplitFlapModule { int getMagnetPosition() const { return magnetPosition; } // position where magnet is detected int getCharPosition(char inputChar); // get integer position given single character int getPosition() const { return position; } // get integer position + int getCharsetSize() const { return numChars; } // getter for charset size bool readHallEffectSensor(); // return the value read by the hall effect // sensor @@ -41,10 +42,13 @@ class SplitFlapModule { static const int motorPins[]; // Array of motor pins static const int HallEffectPIN; // Hall Effect Sensor Pin (On PCF8575) - static const char chars[37]; // all characters in order - static int charPositions[37]; // will be generated based on the characters and - // the magnetPosition variable - static const int numChars; // number of characters in module + const char* chars; // pointer to active character set + int charPositions[48]; // support up to 48 characters + int numChars; // current number of characters + int charSetSize; + + 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 ee0a28f..186a190 100644 --- a/src/web/settings.html +++ b/src/web/settings.html @@ -42,6 +42,7 @@

@@ -58,6 +59,7 @@

@@ -74,6 +76,7 @@

@@ -91,6 +94,7 @@