@@ -148,13 +148,23 @@ static uint32_t reverse(uint32_t x)
148
148
149
149
static uint8_t __attribute__ ((aligned)) framebuffer[NUM_LEDS / 8];
150
150
151
+ /* *
152
+ * @brief Class representing an LED matrix for Arduino.
153
+ *
154
+ * This class provides methods to control and manage the LED matrix.
155
+ */
151
156
class ArduinoLEDMatrix
152
157
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
153
158
: public ArduinoGraphics
154
159
#endif
155
160
{
156
161
157
162
public:
163
+ /* *
164
+ * @brief Constructor for the ArduinoLEDMatrix class.
165
+ *
166
+ * Initializes the LED matrix and sets up any necessary configurations.
167
+ */
158
168
ArduinoLEDMatrix ()
159
169
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
160
170
: ArduinoGraphics(canvasWidth, canvasHeight)
@@ -165,12 +175,33 @@ class ArduinoLEDMatrix
165
175
void autoscroll (uint32_t interval_ms) {
166
176
_interval = interval_ms;
167
177
}
178
+
179
+ /* *
180
+ * @brief Turns on the LED at the specified pin.
181
+ *
182
+ * @param `pin` The pin number where the LED is connected.
183
+ */
168
184
void on (size_t pin) {
169
185
turnLed (pin, true );
170
186
}
187
+
188
+ /* *
189
+ * @brief Turns off the LED at the specified pin.
190
+ *
191
+ * @param `pin` The pin number where the LED is connected.
192
+ */
171
193
void off (size_t pin) {
172
194
turnLed (pin, false );
173
195
}
196
+
197
+ /* *
198
+ * @brief Initializes the LED matrix and starts the timer.
199
+ *
200
+ * This function configures and starts a periodic timer for controlling the LED matrix.
201
+ * It searches for an available timer, configures it, and starts it with a default frequency.
202
+ *
203
+ * @return Returns `1` (true) if initialization succeeds, otherwise `0` (false).
204
+ */
174
205
int begin () {
175
206
bool rv = true ;
176
207
uint8_t type;
@@ -185,6 +216,18 @@ class ArduinoLEDMatrix
185
216
rv &= _ledTimer.start ();
186
217
return rv;
187
218
}
219
+
220
+ /* *
221
+ * @brief Advances to the next frame in the LED matrix animation sequence.
222
+ *
223
+ * This function updates the frame buffer by fetching the next frame data from
224
+ * the stored sequence. If the animation reaches the last frame, it either loops
225
+ * or stops based on the loop setting. If a callback function is set, it is
226
+ * triggered when the sequence completes.
227
+ *
228
+ * @note This function also reverses frame data before updating the framebuffer.
229
+ *
230
+ */
188
231
void next () {
189
232
uint32_t frame[3 ];
190
233
frame[0 ] = reverse (*(_frames+(_currentFrame*4 )+0 ));
@@ -203,6 +246,17 @@ class ArduinoLEDMatrix
203
246
}
204
247
memcpy (framebuffer, (uint32_t *)frame, sizeof (frame));
205
248
}
249
+
250
+ /* *
251
+ * @brief Loads a single frame into the LED matrix and updates the display.
252
+ *
253
+ * This function takes a frame buffer containing LED matrix data and loads it
254
+ * as a single-frame animation sequence. It then advances to display the frame
255
+ * immediately and ensures the animation interval is set to 0 to prevent looping.
256
+ *
257
+ * @param `buffer` An array of three 32-bit values representing the frame data.
258
+ *
259
+ */
206
260
void loadFrame (const uint32_t buffer[3 ]){
207
261
uint32_t tempBuffer[][4 ] = {{
208
262
buffer[0 ], buffer[1 ], buffer[2 ], 0
@@ -211,16 +265,47 @@ class ArduinoLEDMatrix
211
265
next ();
212
266
_interval = 0 ;
213
267
}
268
+
269
+ /* *
270
+ * @brief Renders a specific frame from the loaded sequence.
271
+ *
272
+ * This function sets the current frame index to the specified frame number,
273
+ * ensuring it wraps around within the available frame count. It then updates
274
+ * the display to show the selected frame and stops any automatic transitions
275
+ * by setting the interval to 0.
276
+ *
277
+ * @param `frameNumber` The index of the frame to be displayed.
278
+ */
214
279
void renderFrame (uint8_t frameNumber){
215
280
_currentFrame = frameNumber % _framesCount;
216
281
next ();
217
282
_interval = 0 ;
218
283
}
284
+
285
+ /* *
286
+ * @brief Starts playing the loaded frame sequence.
287
+ *
288
+ * This function begins playback of the current sequence, advancing through
289
+ * frames automatically. If looping is enabled, the sequence will restart
290
+ * after reaching the last frame.
291
+ *
292
+ * @param `loop` Set to `true` to enable looping; `false` to play the sequence once. Default is `false`.
293
+ */
219
294
void play (bool loop = false ){
220
295
_loop = loop;
221
296
_sequenceDone = false ;
222
297
next ();
223
298
}
299
+
300
+ /* *
301
+ * @brief Checks if the sequence has finished playing.
302
+ *
303
+ * This function checks if the current frame sequence has completed.
304
+ * If the sequence is done, it will reset the `_sequenceDone` flag
305
+ * and return `true`, otherwise it returns `false`.
306
+ *
307
+ * @return `true` if the sequence is done, `false` otherwise.
308
+ */
224
309
bool sequenceDone (){
225
310
if (_sequenceDone){
226
311
_sequenceDone = false ;
@@ -229,6 +314,18 @@ class ArduinoLEDMatrix
229
314
return false ;
230
315
}
231
316
317
+ /* *
318
+ * @brief Loads pixel data from an array into a buffer.
319
+ *
320
+ * This function takes a byte array (`arr`) containing pixel data and converts it
321
+ * into a `uint32_t` buffer (`dst`). Each byte in the array represents 8 pixels,
322
+ * and the data is packed into the 32-bit buffer accordingly. The function processes
323
+ * the pixel data byte by byte and stores the packed data into the buffer in chunks of 32 bits.
324
+ *
325
+ * @param `arr` The input byte array containing pixel data.
326
+ * @param `size` The number of elements in the array `arr` to process.
327
+ * @param `dst` The destination buffer where the packed pixel data will be stored.
328
+ */
232
329
static void loadPixelsToBuffer (uint8_t * arr, size_t size, uint32_t * dst) {
233
330
uint32_t partialBuffer = 0 ;
234
331
uint8_t pixelIndex = 0 ;
@@ -244,11 +341,36 @@ class ArduinoLEDMatrix
244
341
}
245
342
}
246
343
344
+ /* *
345
+ * @brief Loads pixel data into the frame buffer and prepares it for rendering.
346
+ *
347
+ * This function takes a byte array (`arr`) containing pixel data, converts it
348
+ * into a 32-bit buffer using `loadPixelsToBuffer`, and then loads the buffer
349
+ * into the frame sequence using `loadFrame`. The function ensures that the pixel
350
+ * data is properly formatted and ready for display by converting the data into
351
+ * a suitable format and storing it in the internal frame buffer.
352
+ *
353
+ * @param `arr` The input byte array containing the pixel data to be loaded.
354
+ * @param `size` The number of elements in the array `arr` to process.
355
+ */
247
356
void loadPixels (uint8_t *arr, size_t size){
248
357
loadPixelsToBuffer (arr, size, _frameHolder);
249
358
loadFrame (_frameHolder);
250
359
};
251
360
361
+ /* *
362
+ * @brief Loads a sequence of frames into the frame buffer.
363
+ *
364
+ * This function accepts a 2D array (`frames`) containing frame data and the
365
+ * number of frames (`howMany`). It calculates the total number of frames
366
+ * and sets the appropriate frame pointer for future frame rendering. The
367
+ * function also resets the current frame index to 0, ensuring that frame
368
+ * playback starts from the beginning.
369
+ *
370
+ * @param `frames` A 2D array containing the frame data to be loaded into the
371
+ * frame buffer. Each frame is expected to contain 4 uint32_t values.
372
+ * @param `howMany` The total number of frame elements (in uint32_t) in the `frames` array.
373
+ */
252
374
void loadWrapper (const uint32_t frames[][4 ], uint32_t howMany) {
253
375
_currentFrame = 0 ;
254
376
_frames = (uint32_t *)frames;
@@ -259,6 +381,10 @@ class ArduinoLEDMatrix
259
381
_callBack = callBack;
260
382
}
261
383
384
+ /* *
385
+ * @brief Clears the LED matrix display and resets the canvas buffer.
386
+ *
387
+ */
262
388
void clear () {
263
389
const uint32_t fullOff[] = {
264
390
0x00000000 ,
@@ -273,6 +399,22 @@ class ArduinoLEDMatrix
273
399
274
400
275
401
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
402
+ /* *
403
+ * @brief Sets a pixel at the specified coordinates with a color.
404
+ *
405
+ * This function updates the pixel at position `(x, y)` on the canvas. The pixel is
406
+ * set to on (1) if any of the red (r), green (g), or blue (b) values are greater
407
+ * than 0.
408
+ *
409
+ * @param `x` The x-coordinate (horizontal position) of the pixel to set.
410
+ * Should be between 0 and `canvasWidth - 1`.
411
+ * @param `y` The y-coordinate (vertical position) of the pixel to set.
412
+ * Should be between 0 and `canvasHeight - 1`.
413
+ * @param `r` The red color value (used here for logical presence check).
414
+ * @param `g` The green color value (used here for logical presence check).
415
+ * @param `b` The blue color value (used here for logical presence check).
416
+ *
417
+ */
276
418
virtual void set (int x, int y, uint8_t r, uint8_t g, uint8_t b) {
277
419
if (y >= canvasHeight || x >= canvasWidth || y < 0 || x < 0 ) {
278
420
return ;
@@ -281,6 +423,17 @@ class ArduinoLEDMatrix
281
423
_canvasBuffer[y][x] = (r | g | b) > 0 ? 1 : 0 ;
282
424
}
283
425
426
+ /* *
427
+ * @brief Ends the text rendering and optionally scrolls.
428
+ *
429
+ * This function finalizes the text rendering process and, if scrolling is
430
+ * requested, applies the scroll.
431
+ *
432
+ * @param `scrollDirection` The direction to scroll the text after rendering.
433
+ * Possible values are:
434
+ * - `NO_SCROLL` (default): No scrolling.
435
+ * - A positive value indicates scrolling in a direction.
436
+ */
284
437
void endText (int scrollDirection = NO_SCROLL) {
285
438
ArduinoGraphics::endText (scrollDirection);
286
439
renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
@@ -302,6 +455,22 @@ class ArduinoLEDMatrix
302
455
}
303
456
}
304
457
458
+ /* *
459
+ * @brief Ends the text rendering and captures it into an animation buffer.
460
+ *
461
+ * @param `scrollDirection` The direction to scroll the text after rendering.
462
+ * Typically, the value can specify no scroll or a scroll speed for animation purposes.
463
+ *
464
+ * @param `frames` A 2D array that holds the captured frames, where each frame is
465
+ * represented by a set of 4 32-bit values.
466
+ *
467
+ * @param `howManyMax` The maximum number of frames that can be captured into the
468
+ * `frames` buffer.
469
+ *
470
+ * @param `howManyUsed` A reference that will hold the number of frames actually
471
+ * used to capture the animation.
472
+ *
473
+ */
305
474
void endTextToAnimationBuffer (int scrollDirection, uint32_t frames[][4 ], uint32_t howManyMax, uint32_t & howManyUsed) {
306
475
captureAnimationFrame = &frames[0 ][0 ];
307
476
captureAnimationHowManyRemains = howManyMax;
@@ -315,6 +484,13 @@ class ArduinoLEDMatrix
315
484
howManyUsed = howManyMax - captureAnimationHowManyRemains;
316
485
}
317
486
487
+ /* *
488
+ * @brief Sets the scroll speed for the text rendering.
489
+ *
490
+ * @param `speed` The speed at which the text should scroll, typically in milliseconds
491
+ * or as defined by the graphics library. A higher value will make
492
+ * the text scroll slower, and a lower value will make it scroll faster.
493
+ */
318
494
void textScrollSpeed (unsigned long speed) {
319
495
ArduinoGraphics::textScrollSpeed (speed);
320
496
_textScrollSpeed = speed;
0 commit comments