Qrome / marquee-scroller

Marquee Scroller Clock News Weather and More
https://www.thingiverse.com/thing:2867294
MIT License
328 stars 158 forks source link

Request for enhancement: set Marquee Message via rest API or MQTT #187

Open woody4165 opened 3 years ago

woody4165 commented 3 years ago

Hi

Do you think it's possible to set the Marquee Message via REST API ? It could be nice to update or empty the message from outside the configuration.

Regarding MQTT, I'm testing now this project that uses MQTT to show a message and it's really useful and fast. I use it via NodeRed to update some Hassio entities value and it would be GREAT to add to this project.

Thanks

sprior commented 2 years ago

MQTT has some timing requirements so the existing implementation of scrollMessage with a call to delay() can be an issue. Based on this code I'm starting to play with integrating max72xx into my own (not currently public) project which supports MQTT and I refactored the scrollMessage code so it can be called in a loop and doesn't block - I got the inspiration for this from the ws2812fx library. Here's how I did it: `static String scrollingMessage; static int scrollingMessageIndex; static int scrollingMessageFinalIndex; static bool scrollingMessageActive = false; static unsigned long next_time = 0;

define SPEED_MIN (uint16_t)2

define SPEED_MAX (uint16_t)65535

define SPEED (uint16_t)25

void scrollMessage(String msg) { scrollingMessage = msg + " "; // add a space at the end scrollingMessageIndex = 0; scrollingMessageFinalIndex = width * scrollingMessage.length() + matrix.width() - 1 - spacer; scrollingMessageActive = true; Serial.println("start scrolling message"); }

void scrollMessageLoop() { if (!scrollingMessageActive) { //Serial.println("scrolling message not active"); return; } if (! (scrollingMessageIndex < scrollingMessageFinalIndex) ) { scrollingMessageActive = false; matrix.setCursor(0, 0); Serial.println("end scrolling message"); return; } bool doShow = false; unsigned long now = millis(); // Be aware, millis() rolls over every 49 days if(now > next_time) { doShow = true; uint16_t delay = SPEED; // same as speed next_time = now + max(delay, SPEED_MIN); } if (doShow){ if (refresh == 1) scrollingMessageIndex = 0; refresh = 0; matrix.fillScreen(LOW);

  int letter = scrollingMessageIndex / width;
  int x = (matrix.width() - 1) - scrollingMessageIndex % width;
  int y = (matrix.height() - 8) / 2; // center the text vertically

  while ( x + width - spacer >= 0 && letter >= 0 ) {
     if ( letter < scrollingMessage.length() ) {
        matrix.drawChar(x, y, scrollingMessage[letter], HIGH, LOW, 1);
     }

     letter--;
     x -= width;
  }

  matrix.write(); // Send bitmap to display

  scrollingMessageIndex++;  

} }`