Screen saver
What should your led matrix do when you do not send anything on the serial port? Wouldn't it be great to have a screen saver, which automatically runs when nothing is sent, and does not get in the way otherwise?
You will have to create a new screensaver task, which will trigger an image change when nothing is being received on the serial port for a while.
Recording image changes
You don't want the screen saver to run if data is being received. Let's record new images arrival.
❎ Declare a static NEW_IMAGE_RECEIVED Signal object containing a Instant.
❎ When a new image is received in serial_receiver, signal the current date to the NEW_IMAGE_RECEIVED queue.
Implementing the screensaver task
❎ Implement a screensaver task and start it on the thread-mode (regular) executor.
In this task, you may for example, in an infinite loop:
- Read the date of the last image received without waiting.
- If any image has been received, wait until one second after this date and
continuethe loop. This way, you effectively do not display anything until the serial port has been idle for one second. - Display your screensaver image (get one from the pool and set it to
NEXT_IMAGE). - Wait for one second.
You can even be more creative and use alternating images every second.
Note that both the serial port code and the screensaver run in thread-mode. The NEW_IMAGE_RECEIVED should only require a ThreadModeRawMutex for its internal synchronization. Check that you haven't used a CriticalSectionRawMutex as it does not require one.