Skip to content

FAQ: Why do the sketch authors have to provide the notification class?

Michael Miller edited this page Jan 7, 2024 · 2 revisions

There really is two parts, why you need it, and why is it done this way.

Why you need it:
The Wiki mentions it here right at the top as to why you need it but doesn't go into detail.
It will notify you so you can react to events. Not every sketch will use it, but at least from a debugging perspective its handy for the sketch author to understand errors. A normal use of it is to handle when one MP3 file has finished so that you can pick (randomly, scripted, or reactive) the next and play it. Another is if you want to react to a SD card being removed and inserted. Further, even when inserted, the chip takes time before you can use it, so there is a notification of when its online and ready. As the sketch author, you may inform the user through a display screen or color LED. You may also disable certain controls like play and stop based on these notifications.

Why is it done this way:
These events and errors are asynchronous to the calls you make. When you ask to play a song, it doesn't block waiting for the chip to state that song is not available, as that may take some time for the chip to reply. Further, the chip may have stopped playing another song during the time it took to make the call to play another. These notifications all come from the chip sent out of order of anything you request, thus asynchronous. The only way to easily manage this is to have a callback mechanism for them.
Using a template model (C++ nomenclature, C# calls it generics) is very memory efficient way to provide the notification callbacks. In the end using less RAM and less code space than other models as this library is targeted at some small uC (microcontrollers) with limited memory and processing speed. This helps keep it useful for smaller low powered projects.

Clone this wiki locally