diff --git a/lib/NoiascaHt16k33/src/NoiascaHt16k33.cpp b/lib/NoiascaHt16k33/src/NoiascaHt16k33.cpp index a651eae9c..881ce45d0 100644 --- a/lib/NoiascaHt16k33/src/NoiascaHt16k33.cpp +++ b/lib/NoiascaHt16k33/src/NoiascaHt16k33.cpp @@ -221,6 +221,11 @@ uint16_t Noiasca_ht16k33_hw_7::getCharacterBitmap(uint8_t value) { } +void Noiasca_ht16k33_hw_7::setZeroSlash(bool state) { + return; // _zeroSlash = state; // Ignored for 7-segment +} + + // general write method for 7 segment size_t Noiasca_ht16k33_hw_7::write(uint8_t value) { if (value == '.' || value == ',' || value == ':' || value == ';') // dots need a special handling @@ -301,6 +306,12 @@ uint16_t Noiasca_ht16k33_hw_14::getCharacterBitmap(uint8_t value) { return 0u; } + +void Noiasca_ht16k33_hw_14::setZeroSlash(bool state) { + _zeroSlash = state; +} + + size_t Noiasca_ht16k33_hw_14::write(uint8_t value) { if (value == 35) value = 127; // MISSING: I don't remember why this is of any sence. This mapping costs 6 byte. DEPRECATED //if (value==167 || value == 248) value = 42; // degree @@ -317,6 +328,9 @@ size_t Noiasca_ht16k33_hw_14::write(uint8_t value) { else if (value > 31 && value < FONTFILE14_MAX_CHAR) // write printable ASCII characters to display { _lastBitmap = pgm_read_word_near(charTable14 + value - 32); // the table starts with the first printable character at 32 + if (_zeroSlash && ('0' == value)) { + _lastBitmap |= (SEG14_M | SEG14_N); + } #ifdef HT16K33_BUFFERSIZE displaybuffer[_currentPosition] = _lastBitmap; #endif diff --git a/lib/NoiascaHt16k33/src/NoiascaHt16k33.h b/lib/NoiascaHt16k33/src/NoiascaHt16k33.h index 56217d183..ad5ac42d3 100644 --- a/lib/NoiascaHt16k33/src/NoiascaHt16k33.h +++ b/lib/NoiascaHt16k33/src/NoiascaHt16k33.h @@ -222,6 +222,7 @@ const uint16_t SEG14_DP = (1<<14); virtual uint16_t getCharacterBitmap(uint8_t value); + virtual void setZeroSlash(bool state); // not supported LCD API 1.0 functions // =================================== @@ -253,6 +254,7 @@ const uint16_t SEG14_DP = (1<<14); #endif uint8_t _currentPosition; // current position of cursor uint8_t _lastPosition; // last position of cursor + bool _zeroSlash = false; // Apply / to the 0 for readability }; /** \brief class for HT16K33 displays with 7 segment LEDs @@ -271,6 +273,7 @@ class Noiasca_ht16k33_hw_7 : public Noiasca_ht16k33 { // 7 segment display using Print::write; uint16_t getCharacterBitmap(uint8_t value); // using Noiasca_ht16k33::getCharacterBitmap; + void setZeroSlash(bool state); protected: uint8_t _hasColonDigit; // is set to 1 if display has a separate colon digit at digit 2 (the third column). Is on this level to have one common .write() method uint8_t _lastBitmap; // last written bitmap (if we have to reprint for the decimal point) @@ -305,6 +308,7 @@ class Noiasca_ht16k33_hw_14 : public Noiasca_ht16k33 { // 14 Segment Display using Print::write; uint16_t getCharacterBitmap(uint8_t value); // using Noiasca_ht16k33::getCharacterBitmap; + void setZeroSlash(bool state); protected: uint16_t _lastBitmap; // last written bitmap (if we have to reprint for the decimal point) }; diff --git a/src/_P157_14DGT.ino b/src/_P157_14DGT.ino index 45eea4944..5382c6aad 100644 --- a/src/_P157_14DGT.ino +++ b/src/_P157_14DGT.ino @@ -30,6 +30,9 @@ // /** History + * 2026-06-13 tonhuisman: Add Scroll Always option to also scroll content <= display width + * Add Zero with slash option + * Add Delay to next scroll-start option * 2026-05-25 tonhuisman: Add 7digit,, command for writing content from a specific digit 1..len * Remove right-align option, as this isn't implemented * Clean up source @@ -67,9 +70,12 @@ boolean Plugin_157(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_SET_DEFAULTS: { # if P157_SCROLL_TEXT - P157_CFG_SCROLLSPEED = 10; // Default 10 * 0.1 sec scroll speed + P157_CFG_SCROLLSPEED = 10; // Default 10 * 0.1 sec scroll speed # endif // if P157_SCROLL_TEXT - P157_CFG_DISPLAYS = 1; // Default number of displays + P157_CFG_DISPLAYS = 1; // Default number of displays + uint32_t lSettings{}; + bitWrite(lSettings, P157_OPTION_ZEROSLASH, true); // Enable zero with slash by default + P157_CFG_FLAGS = lSettings; break; } @@ -148,13 +154,20 @@ boolean Plugin_157(uint8_t function, struct EventStruct *event, String& string) addFormCheckBox(F("Suppress leading 0 on day/hour"), F("supp0"), bitRead(P157_CFG_FLAGS, P157_OPTION_SUPPRESS0)); # endif // if P157_SUPPRESS_ZERO + if (!P157_is7SegmentDisplay(P157_CFG_DISPLAYTYPE)) { + addFormCheckBox(F("Use 0 with slash"), F("zero_slash"), bitRead(P157_CFG_FLAGS, P157_OPTION_ZEROSLASH)); + } + # if P157_SCROLL_TEXT - addFormCheckBox(F("Scroll text > display width"), F("scroll_text"), bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLTEXT)); - addFormCheckBox(F("Scroll text in from right"), F("scroll_full"), bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLFULL)); + addFormCheckBox(F("Scroll text > display width"), F("scroll_text"), bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLTEXT)); + addFormCheckBox(F("Scroll text also <= display width"), F("scroll_always"), bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLL_ALL)); + addFormCheckBox(F("Scroll text in from right"), F("scroll_full"), bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLFULL)); if (P157_CFG_SCROLLSPEED == 0) { P157_CFG_SCROLLSPEED = 10; } addFormNumericBox(F("Scroll speed (0.1 sec/step)"), F("scrollspeed"), P157_CFG_SCROLLSPEED, 1, 600); addUnit(F("1..600 = 0.1..60 sec/step")); + addFormNumericBox(F("Delay to next scroll-start"), F("scrolldelay"), P157_CFG_SCROLLDELAY, 0, 6000); + addUnit(F("0.1 sec")); # endif // if P157_SCROLL_TEXT // addFormCheckBox(F("Right-align Temperature (7dt)"), F("temp_rightalign"), bitRead(P157_CFG_FLAGS, P157_OPTION_RIGHTALIGN)); @@ -182,14 +195,16 @@ boolean Plugin_157(uint8_t function, struct EventStruct *event, String& string) } uint32_t lSettings = 0; - // bitWrite(lSettings, P157_OPTION_PERIOD, isFormItemChecked(F("periods"))); + bitWrite(lSettings, P157_OPTION_ZEROSLASH, isFormItemChecked(F("zero_slash"))); bitWrite(lSettings, P157_OPTION_HIDEDEGREE, isFormItemChecked(F("hide_degree"))); // bitWrite(lSettings, P157_OPTION_RIGHTALIGN, isFormItemChecked(F("temp_rightalign"))); # if P157_SCROLL_TEXT bitWrite(lSettings, P157_OPTION_SCROLLTEXT, isFormItemChecked(F("scroll_text"))); + bitWrite(lSettings, P157_OPTION_SCROLL_ALL, isFormItemChecked(F("scroll_always"))); bitWrite(lSettings, P157_OPTION_SCROLLFULL, isFormItemChecked(F("scroll_full"))); P157_CFG_SCROLLSPEED = getFormItemInt(F("scrollspeed")); + P157_CFG_SCROLLDELAY = getFormItemInt(F("scrolldelay")); # endif // if P157_SCROLL_TEXT # if P157_SUPPRESS_ZERO bitWrite(lSettings, P157_OPTION_SUPPRESS0, isFormItemChecked(F("supp0"))); diff --git a/src/src/PluginStructs/P157_data_struct.cpp b/src/src/PluginStructs/P157_data_struct.cpp index 378443965..b6e60ccb0 100644 --- a/src/src/PluginStructs/P157_data_struct.cpp +++ b/src/src/PluginStructs/P157_data_struct.cpp @@ -71,10 +71,13 @@ bool P157_data_struct::init(struct EventStruct *event) # if P157_SCROLL_TEXT txtScrolling = bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLTEXT); scrollFull = bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLLFULL); + scrollAll = bitRead(P157_CFG_FLAGS, P157_OPTION_SCROLL_ALL); + scrollDelay = P157_CFG_SCROLLDELAY; setScrollSpeed(P157_CFG_SCROLLSPEED); # endif // if P157_SCROLL_TEXT suppressLeading0 = bitRead(P157_CFG_FLAGS, P157_OPTION_SUPPRESS0); timesep = true; + zeroSlash = bitRead(P157_CFG_FLAGS, P157_OPTION_ZEROSLASH); # if P157_EXTRA_FONTS fontSet = P157_CFG_FONTSET; @@ -92,6 +95,7 @@ bool P157_data_struct::init(struct EventStruct *event) if (!P157_is7SegmentDisplay(displayModel)) { ht16k33 = new (std::nothrow) Noiasca_ht16k33_hw_14(); // 14 segment + ht16k33->setZeroSlash(zeroSlash); } else { ht16k33 = new (std::nothrow) Noiasca_ht16k33_hw_7(); // 7 segment } @@ -382,6 +386,10 @@ int P157_data_struct::getEffectiveTextLength(const String& text) { bool P157_data_struct::nextScroll() { bool result = false; + if (scrollWait && (--scrollWait > 0)) { + return result; + } + if (isScrollEnabled() && (!_textToScroll.isEmpty() # if P157_7DBIN_COMMAND || binData.size() > 0 @@ -399,7 +407,8 @@ bool P157_data_struct::nextScroll() { scrollPos++; if (scrollPos > (binData.size() - bufLen)) { - scrollPos = 0; // Redisplay + scrollPos = 0; // Redisplay + scrollWait = scrollDelay; // Restart delay counter } scrollCount = _scrollSpeed; // Restart countdown } else @@ -424,7 +433,8 @@ bool P157_data_struct::nextScroll() { scrollPos++; if (scrollPos > _textToScroll.length() - bufLen) { - scrollPos = 0; // Restart when all text displayed + scrollPos = 0; // Restart when all text displayed + scrollWait = scrollDelay; // Restart delay counter } scrollCount = _scrollSpeed; // Restart countdown # ifdef P157_DEBUG @@ -466,22 +476,6 @@ void P157_data_struct::setScrollSpeed(uint8_t speed) { # endif // if P157_SCROLL_TEXT -// # if P157_7DBIN_COMMAND - -// void P157_data_struct::setBinaryData(const String& data) { -// binaryData = true; -// # if P157_SCROLL_TEXT -// setTextToScroll(data); -// binaryData = true; // is reset in setTextToScroll -// scrollCount = _scrollSpeed; -// scrollPos = 0; -// # else // if P157_SCROLL_TEXT -// _textToScroll = data; -// # endif // if P157_SCROLL_TEXT -// } - -// # endif // if P157_7DBIN_COMMAND - # ifdef P157_DEBUG void P157_data_struct::logBufferContent(String prefix) { @@ -887,7 +881,7 @@ bool P157_data_struct::plugin_write_7dt(const String& text) { return false; } - float P157_temptemp = 0.0f; + float P157_temptemp = 0.0f; if (!text.isEmpty()) { validFloatFromString(text, P157_temptemp); @@ -916,7 +910,7 @@ bool P157_data_struct::plugin_write_7dt(const String& text) { fillBufferWithDash(); } else { if ((P157_temptemp < uLimitDec) && (P157_temptemp > lLimitDec)) { - P157_temptemp = roundf(P157_temptemp * 10.0f); + P157_temptemp = roundf(P157_temptemp * 10.0f); } fillBufferWithTemp(P157_temptemp); } @@ -936,8 +930,8 @@ bool P157_data_struct::plugin_write_7ddt(const String& text) { return false; } - float P157_lefttemp = 0.0f; - float P157_righttemp = 0.0f; + float P157_lefttemp = 0.0f; + float P157_righttemp = 0.0f; if (!text.isEmpty()) { validFloatFromString(parseString(text, 1), P157_lefttemp); @@ -1057,7 +1051,7 @@ bool P157_data_struct::plugin_write_7dtext(const String& text) { # if P157_SCROLL_TEXT setTextToScroll(EMPTY_STRING); - setScrollEnabled(getEffectiveTextLength(text) > bufLen); + setScrollEnabled(scrollAll || getEffectiveTextLength(text) > bufLen); if (isScrollEnabled()) { setTextToScroll(text); @@ -1148,6 +1142,10 @@ bool P157_data_struct::plugin_write_7dbin(const String& text, # endif // if P157_EXTRA_FONTS { bitmap = ht16k33->getCharacterBitmap(argValue.charAt(i)); + + if (zeroSlash && ('0' == argValue.charAt(i)) && !P157_is7SegmentDisplay(displayModel)) { + bitmap |= (SEG14_M | SEG14_N); + } } if ((i < argValue.length()) && isPeriodChar(argValue.charAt(i + 1))) { @@ -1164,7 +1162,7 @@ bool P157_data_struct::plugin_write_7dbin(const String& text, if (binData.size() > 0) { # if P157_SCROLL_TEXT - setScrollEnabled(binData.size() > bufLen); + setScrollEnabled(scrollAll || binData.size() > bufLen); if (isScrollEnabled()) { uint8_t i = 0; diff --git a/src/src/PluginStructs/P157_data_struct.h b/src/src/PluginStructs/P157_data_struct.h index 6209112c3..334b51863 100644 --- a/src/src/PluginStructs/P157_data_struct.h +++ b/src/src/PluginStructs/P157_data_struct.h @@ -14,6 +14,7 @@ # define P157_CFG_I2C_ADDRESS PCONFIG(4) # define P157_CFG_DISPLAYS PCONFIG(5) # define P157_CFG_FONTSET PCONFIG(6) +# define P157_CFG_SCROLLDELAY PCONFIG(7) # define P157_CFG_FLAGS PCONFIG_ULONG(0) # define P157_DISP_MANUAL 0 @@ -31,9 +32,9 @@ # define P157_CHAR_EURO 128 # define P157_CHAR_DEGREE 129 -// # define P157_OPTION_PERIOD 0 // Period as dot +# define P157_OPTION_ZEROSLASH 0 // Use zero with slash (14-segment only) # define P157_OPTION_HIDEDEGREE 1 // Hide degree symbol for temperatures -// # define P157_OPTION_RIGHTALIGN 2 // Align 7dt output to the right +# define P157_OPTION_SCROLL_ALL 2 // Scroll also when text not linger than display width # define P157_OPTION_SCROLLTEXT 3 // Scroll text > display width # define P157_OPTION_SCROLLFULL 4 // Scroll text from the right in, starting with a blank display # define P157_OPTION_SUPPRESS0 5 // Suppress leading zero on day/hour of Date/Time display @@ -195,7 +196,11 @@ public: bool scrollAllowed = false; uint16_t scrollCount = 0; uint16_t scrollPos = 0; + uint16_t scrollDelay = 0; + uint16_t scrollWait = 0; bool scrollFull = false; + bool scrollAll = false; + bool zeroSlash = false; private: