-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
pixie_chroma_internal.cpp
2929 lines (2358 loc) · 106 KB
/
pixie_chroma_internal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* @file pixie_chroma_internal.cpp
*
* Designed specifically to work with Pixie Chroma:
* ----> https://connornishijima.github.io/PixieChroma
*
* Last Updated by Connor Nishijima on 10/21/21
*/
#include "Pixie_Chroma.h"
#include "utility/pixie_utility.h"
// ---------------------------------------------------------------------------------------------------------|
// -- PUBLIC CLASS FUNCTIONS -------------------------------------------------------------------------------|
// ---------------------------------------------------------------------------------------------------------|
/*! ############################################################################
@brief
Used to initialize the PixieChroma library.
@details
Example usage before `setup()` would be:
#include "Pixie_Chroma.h"
PixieChroma pix;
Because each of these functions are contained in the PixieChroma class
object, you'll use them like this:
pix.print( "Hello!" );
*///............................................................................
PixieChroma::PixieChroma(){}
// TODO: Fix "first led" being on in the mask upon initialization
// This is most visible using begin_quad(). (The color of the erroneous
// LED is from the color map.)
/*! ############################################################################
@brief
Initializes the display buffer, populates the XY coordinate table, defaults
the display colors to green, loads the default CRGBPalette, initializes
FastLED, and sets the default power budget.
@details
Pixie Chroma allows for multi-row displays, which are wired in reading
order (left to right, top to bottom) and their shape is defined here. For
example, a 16-Pixie display with two rows of eight:
data_pin
|
+--+-+ +----+ +----+ +----+ +----+ +----+ +----+ +----+
| 1 |-->| 2 |-->| 3 |-->| 4 |-->| 5 |-->| 6 |-->| 7 |-->| 8 |
+----+ +----+ +----+ +----+ +----+ +----+ +----+ +--+-+
|
+--------------------------------------------------------------+
|
+--+-+ +----+ +----+ +----+ +----+ +----+ +----+ +----+
| 9 |-->| 10 |-->| 11 |-->| 12 |-->| 13 |-->| 14 |-->| 15 |-->| 16 |
+----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+
The corresponding setup for this display layout would be:
#include "Pixie_Chroma.h"
PixieChroma pix;
#define DATA_PIN 5
#define PIXIES_X 8
#define PIXIES_Y 2
void setup() {
pix.begin( DATA_PIN, PIXIES_X, PIXIES_Y );
}
For faster performance on large displays, see begin_quad().
@param data_pin GPIO pin to use for FastLED output
@param pixies_x Number of Pixie PCBs in the X axis of your display
@param pixies_y Number of Pixie PCBs in the Y axis of your display
*///............................................................................
void PixieChroma::begin( const uint8_t data_pin, uint8_t pixies_x, uint8_t pixies_y ){
pixie_pin = data_pin;
chars_x = pixies_x * 2; // Pixies have two chars each
chars_y = pixies_y;
matrix_width = display_width * chars_x;
matrix_height = display_height * chars_y;
NUM_PIXELS = matrix_width * matrix_height;
color_map = new CRGB[ NUM_PIXELS + 1 ]; // Hidden extra LED to write to if we call an out-of-bounds XY coordinate for color or mask
mask = new uint8_t[ NUM_PIXELS + 1 ];
xy_table = new int16_t[ NUM_PIXELS ];
calc_xy(); // NUM_LEDS is calculated here
color_map_out = new CRGB[ NUM_LEDS ];
mask_out = new uint8_t[ NUM_LEDS ];
for( uint16_t i = 0; i < NUM_LEDS; i++ ){
color_map[i] = CRGB( 0, 255, 0 );
}
current_palette.loadDynamicGradientPalette( GREEN_SOLID );
build_controller( pixie_pin ); // ----- Initialize FastLED
set_animation( ANIMATION_NULL ); // --- Set animation function to an empty one
clear(); // --------------------------- Clear anything in mask (should be empty anyways), reset cursor
set_max_power( 5.0, 500 ); // --------- Set default power budget in volts and milliamps (5.0V, 500mA)
}
/*! ############################################################################
@brief
Initializes the display buffer, populates the XY coordinate table, defaults
the display colors to green, loads the default CRGBPalette, initializes
FastLED **for Quad Mode**, and sets the default power budget.
@details
This version of begin() is special, in that it will send your image data to
the LEDs in 4 parallel streams to increase speed.
Unfortunately, this requires hard-coded pins on the ESP8266 and ESP32 to
function *due to FastLED limitations*:
- DATA_OUT_1: **GPIO 12 / D6**
- DATA_OUT_2: **GPIO 13 / D7**
- DATA_OUT_3: **GPIO 14 / D5**
- DATA_OUT_4: **GPIO 15 / D8**
On each data line, you'll wire `pixies_per_pin` number of Pixie
Chromas, with the final image being seamlessly spread across these
four lines.
For example, if you have 16 Pixie Chromas (in two rows of eight) and
have Quad Mode enabled, then each of the 4 data lines will have 4
Pixie Chromas like so:
- **DATA_OUT_1** GPIO
- Pixie 1
- Pixie 2
- Pixie 3
- Pixie 4
- **DATA_OUT_2** GPIO
- Pixie 5
- Pixie 6
- Pixie 7
- Pixie 8
- **DATA_OUT_3** GPIO
- Pixie 9
- Pixie 10
- Pixie 11
- Pixie 12
- **DATA_OUT_4** GPIO
- Pixie 13
- Pixie 14
- Pixie 15
- Pixie 16
The corresponding setup for this display layout would be:
#include "Pixie_Chroma.h"
PixieChroma pix;
#define PIXIES_PER_PIN 4
#define PIXIES_X 8
#define PIXIES_Y 2
void setup() {
pix.begin_quad( PIXIES_PER_PIN, PIXIES_X, PIXIES_Y );
}
Then, with the displays physically arranged in reading order ( left to right,
top to bottom ) you're ready to begin!
DATA_OUT_1 --+ DATA_OUT_2 ----+
| |
+--+-+ +----+ +----+ +----+ || +--+-+ +----+ +----+ +----+
| 1 |-->| 2 |-->| 3 |-->| 4 | || | 5 |-->| 6 |-->| 7 |-->| 8 |
+----+ +----+ +----+ +----+ || +----+ +----+ +----+ +----+
DATA_OUT_3 --+ DATA_OUT_4 ----+
| |
+--+-+ +----+ +----+ +----+ || +--+-+ +----+ +----+ +----+
| 9 |-->| 10 |-->| 11 |-->| 12 | || | 13 |-->| 14 |-->| 15 |-->| 16 |
+----+ +----+ +----+ +----+ || +----+ +----+ +----+ +----+
Using begin_quad() to enable the Quad Mode driver will
always send the 4 lines of data in parallel, saving on time per frame.
begin_quad() ideally **should not be used with less than 4 Pixie Chromas**,
and with at least one on each line. Even if only two lines are physically
used, all 4 pins are still occupied by Quad Mode.
@param pixies_per_pin Pixies per data pin
@param pixies_x Number of Pixie PCBs in the X axis of your display
@param pixies_y Number of Pixie PCBs in the Y axis of your display
*///............................................................................
void PixieChroma::begin_quad( uint8_t pixies_per_pin, uint8_t pixies_x, uint8_t pixies_y ){
chars_x = pixies_x * 2; // Pixies have two chars each
chars_y = pixies_y;
matrix_width = display_width * chars_x;
matrix_height = display_height * chars_y;
NUM_PIXELS = matrix_width * matrix_height;
color_map = new CRGB[ NUM_PIXELS + 1 ]; // Hidden extra LED to write to if we call an out-of-bounds XY coordinate for color or mask
mask = new uint8_t[ NUM_PIXELS + 1 ];
xy_table = new int16_t[ NUM_PIXELS ];
calc_xy();
color_map_out = new CRGB[ NUM_LEDS ];
mask_out = new uint8_t[ NUM_LEDS ];
for( uint16_t i = 0; i < NUM_LEDS; i++ ){
color_map[i] = CRGB( 0,255,0 );
}
current_palette.loadDynamicGradientPalette( GREEN_SOLID );
#if defined( ARDUINO_ARCH_ESP8266 )
// WS2811_PORTA on ESP8266 takes up GPIO 12, GPIO 13, GPIO 14 and GPIO 15 for Quad Mode
FastLED.addLeds<WS2811_PORTA,4>( color_map_out, pixies_per_pin * leds_per_pixie ).setCorrection( TypicalLEDStrip ); // Initialize FastLED
#endif
#if defined( ARDUINO_ARCH_ESP32 )
// Quad Mode on ESP32 takes up GPIO 12, GPIO 13, GPIO 14 and GPIO 27
FastLED.addLeds<NEOPIXEL, 13>( // Initialize FastLED Data Out 1
color_map_out,
( pixies_per_pin*leds_per_pixie ) * 0,
( pixies_per_pin*leds_per_pixie )
).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, 12>( // Initialize FastLED Data Out 2
color_map_out,
( pixies_per_pin*leds_per_pixie ) * 1,
( pixies_per_pin*leds_per_pixie )
).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, 14>( // Initialize FastLED Data Out 3
color_map_out,
( pixies_per_pin*leds_per_pixie ) * 2,
( pixies_per_pin*leds_per_pixie )
).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, 27>( // Initialize FastLED Data Out 4
color_map_out,
( pixies_per_pin*leds_per_pixie ) * 3,
( pixies_per_pin*leds_per_pixie )
).setCorrection( TypicalLEDStrip );
#endif
set_animation( ANIMATION_NULL ); // --- Set animation function to an empty one
clear(); // --------------------------- Clear anything in mask ( should be empty anyways ), reset cursor
set_max_power( 5, 500 ); // ----------- Set default power budget in volts and milliamps
}
/*! ############################################################################
@brief
Takes an 8-bit brightness value and passes it to FastLED internally, to
provide global brightness control with temporal dithering.
@param level 8-bit global brightness value ( 0-255 )
*///............................................................................
void PixieChroma::set_brightness( uint8_t level ){
brightness_level = level;
}
/*! ############################################################################
@brief
Accepts a const uint8_t (8-bit) array to generate a FastLED Gradient
Palette at runtime:
const uint8_t* my_gradient_palette[] = {
[INDEX], [R_VAL], [G_VAL], [B_VAL],
0, 255, 0, 0,
127, 0, 255, 0,
255, 0, 0, 255,
};
On each line is the index of the color ( 0-255 ) to express the position in
the gradient this color occurs. So in the given example, it is a gradient
from red at 0, to green at 127, to blue at 255.
@param pal FastLED "Gradient Palette" array
*///............................................................................
void PixieChroma::set_palette( const uint8_t* pal ){
current_palette.loadDynamicGradientPalette( pal ); // GRADIENT PALETTE
}
/*! ############################################################################
@brief
Accepts a FastLED CRGBPalette16 object to set the current color palette for
animation.
@param pal FastLED CRGBPalette16 object to use
*///............................................................................
void PixieChroma::set_palette( CRGBPalette16 pal ){ // STANDARD PALETTE
current_palette = pal;
}
/*! ############################################################################
@brief
Accepts a preset or custom function to use for the animation ISR.
@details
For a list of predefined animations, see pixie_animations.h.
@param action Function to set as an animation ISR
*///............................................................................
void PixieChroma::set_animation( void ( *action )(PixieChroma*, float) ) {
anim_func = action;
}
/*! ############################################################################
@brief
Used to scale the animation speed of animation ISRs that can use
pix.animation_speed() to scale their speeds or for other effects
@param speed Floating point value: 1.0 = 100%, 3.2 = 320%, 0.5 = 50%
*///............................................................................
void PixieChroma::set_animation_speed( float speed ){
animation_speed = speed;
}
/*! ############################################################################
@brief
Allows you to enable built-in automatic gamma correction, using a fast LUT
in pixie_utility.h. (Not enabled by default)
@param enabled Whether or not to apply gamma correction
*///............................................................................
void PixieChroma::set_gamma_correction( bool enabled ){
correct_gamma = enabled;
}
/*! ############################################################################
@brief
Sets the cursor position in a 2D context, in whole displays.
@details
Wherever the cursor is, is where the next call to print() or write() will
originate. Position is counted from zero. Remember: each Pixie Chroma has
two "displays" on it.
+-----------------+ +-----------------+ +-----------------+
| + + + | | + + + | | + + + |
|+-----+ +-----+| |+-----+ +-----+| |+-----+ +-----+|
|| | | || || | | || || | | ||
|| | | || || | | || || | | ||
|| 0,0 | | 1,0 ||-->|| 2,0 | | 3,0 ||-->|| 4,0 | | 5,0 ||
|| | | || || | | || || | | ||
|| | | || || | | || || | | ||
|+-----+ +-----+| |+-----+ +-----+| |+-----+ +-----+|
| + + + | | + + + | | + + + |
+-----------------+ +-----------------+ +-----------------+
|
+-------------------------------------------+
|
V
+-----------------+ +-----------------+ +-----------------+
| + + + | | + + + | | + + + |
|+-----+ +-----+| |+-----+ +-----+| |+-----+ +-----+|
|| | | || || | | || || | | ||
|| | | || || | | || || | | ||
|| 0,1 | | 1,1 ||-->|| 2,1 | | 3,1 ||-->|| 4,0 | | 5,1 ||
|| | | || || | | || || | | ||
|| | | || || | | || || | | ||
|+-----+ +-----+| |+-----+ +-----+| |+-----+ +-----+|
| + + + | | + + + | | + + + |
+-----------------+ +-----------------+ +-----------------+
For example:
`set_cursor( 1,0 )` sets the cursor to the second display in the first row.
`set_cursor( 3,1 )` sets the cursor to the fourth display in the second row.
@param x_position New cursor position on the X-axis, in whole displays
@param y_position New cursor position on the Y-axis, in whole displays
*///............................................................................
void PixieChroma::set_cursor( uint8_t x_position, uint8_t y_position ){
cursor_x = display_padding_x + ( display_width * x_position );
cursor_y = display_padding_y + ( display_height * y_position );
}
/*! ############################################################################
@brief
Sets the maximum power budget in volts and milliamps.
@details
Knowing the average power consumption of these LEDs at any given color,
FastLED will automatically globally scale down the output values with
temporal dithering to lower power usage until it is within the budget
defined here. Defaults to 5.0V / 500mA to protect PC USB ports if the
Pixies are not independently powered. ( 2000mA = 2A, 500mA = 0.5A, etc. )
@param volts Total LED power budget in volts. ( default: 5.0 )
@param milliamps Total LED power budget in milliamps ( default 500 )
*///............................................................................
void PixieChroma::set_max_power( float volts, uint16_t milliamps ){
max_V = volts;
max_mA = milliamps;
}
/*! ############################################################################
@brief
Sets the target frame rate for animation. This target frame rate is only
used to calculate `delta` in custom/preset animation functions.
@details
This does not change your real frame rate, or even govern it: it is left up
to the user to use frequent show() calls or auto_update(). The "target frame
rate" here is used to calculate `delta` for the animation functions, and
should be set as close as possible to the rate at which you are expecting to
call show().
This function is automatically called with a matching FPS when you use
`set_update_mode( AUTOMATIC, FPS )`.
@param target Target frame rate for animation.
*///............................................................................
void PixieChroma::set_frame_rate_target( uint16_t target ){
fps_target = target;
}
/*! ############################################################################
@brief
Sets the line wrapping behavior
@details
`set_line_wrap( true );` will automatically enter next line when the edge of
the display is reached, and `set_line_wrap( false );` will not.
@param enabled Enable or disable auto line-wrapping
*///............................................................................
void PixieChroma::set_line_wrap( bool enabled ){
line_wrap = enabled;
}
/*! ############################################################################
@brief
Allows for automatic show() calls at a specified frames per second if
AUTOMATIC is used. (uses Ticker.attach_ms() internally)
@details
This lets you use things like print() as infrequently as you'd like, since
show() will automatically run in the background to keep the current
animation function running smoothly.
Use in conjunction with hold() and free() to prevent show() calls during
text/image construction, leading to unintended partial frames being shown.
Be aware, hold() does not prevent animation / palette updates (only mask
updates) so animations will still run smoothly during hold() times until
free() is called and the mask is finally updated.
@param mode AUTOMATIC or MANUAL. AUTOMATIC will call show() at `FPS`
using an ISR, MANUAL allows you call show() when you like.
@param FPS Update *this* many times per second (Default: 60) Only
applicable when mode is AUTOMATIC
*///............................................................................
void PixieChroma::set_update_mode( t_update_mode mode, uint16_t FPS ){
if( mode == AUTOMATIC && ticker_running == false ){
set_frame_rate_target( FPS );
animate.attach_ms<typeof this>(
round(1000 / float(FPS)),
[](typeof this _p){ _p->show(); },
// This. ^ This is the magic sauce
// right here. This is apparently how
// you add a non-static class member to
// Ticker from within a class and I
// hate it. Readability sucks, oh well.
this
);
ticker_running = true;
}
else if( mode == MANUAL && ticker_running == true ){
animate.detach();
ticker_running = false;
}
}
/*! ############################################################################
@brief
Writes an icon* to a specified X and Y cursor position
@param icon The icon to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( const uint8_t* icon, uint8_t x_pos, uint8_t y_pos ){
write_pix(
icon,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes an icon to a specified X and Y cursor position, taking five uint8_t
as input for the column data.
@details
Example:
pix.write( B00101111, B01001001, B01001001, B01001001, B00110001 );
OR, WRITTEN VERTICALLY:
pix.write( , , , , );
1 1 1 1 1 LSB
1 0 0 0 0
1 0 0 0 0
1 1 1 1 0
0 0 0 0 1
1 0 0 0 1
0 1 1 1 0
0 0 0 0 0 MSB (unused)
B B B B B
This writes a "5" to the display, seen above in the "1" bits of each column.
The MSB (highest bit) is not used in icons.
@param icon_col_1 Column 1 data of this icon
@param icon_col_2 Column 2 data of this icon
@param icon_col_3 Column 3 data of this icon
@param icon_col_4 Column 4 data of this icon
@param icon_col_5 Column 5 data of this icon
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( uint8_t icon_col_1, uint8_t icon_col_2, uint8_t icon_col_3, uint8_t icon_col_4, uint8_t icon_col_5, uint8_t x_pos, uint8_t y_pos ){
uint8_t icon[5] = {
icon_col_1,
icon_col_2,
icon_col_3,
icon_col_4,
icon_col_5
};
write( icon, x_pos, y_pos );
}
/*! ############################################################################
@brief
Writes a char* string to a specified X and Y cursor position.
@param message char* string to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( char* message, uint8_t x_pos, uint8_t y_pos ){
write_pix(
message,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes a signed 16-bit integer to a specified X and Y cursor position.
@param input Signed integer to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( int16_t input, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
itoa( input, char_buf, 10 );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes an unsigned 16-bit integer to a specified X and Y cursor position.
@param input Unsigned integer to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( uint16_t input, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
utoa( input, char_buf, 10 );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes a signed 32-bit integer to a specified X and Y cursor position.
@param input Signed integer to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( int32_t input, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
ltoa( input, char_buf, 10 );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes an unsigned 32-bit integer to a specified X and Y cursor position.
@param input Unsigned integer to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( uint32_t input, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
ultoa( input, char_buf, 10 );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes an unsigned 32-bit integer to a specified X and Y cursor position.
( Stupid ESP-specific type )
@param input Unsigned integer to write
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( long unsigned int input, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
ultoa( input, char_buf, 10 );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes a double-precision floating point value to a specified X and Y cursor
position, to a specified number of decimal places.
@param input Double-precision float to write
@param places Number of decimal places to show **[optional]**
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( double input, uint8_t places, uint8_t x_pos, uint8_t y_pos ){
char char_buf[32];
dtoa( input, char_buf, places );
write_pix(
char_buf,
display_padding_x + ( display_width * x_pos ),
display_padding_y + ( display_height * y_pos )
);
}
/*! ############################################################################
@brief
Writes a single-precision floating point value to a specified X and Y cursor
position, to a specified number of decimal places.
@param input Single-precision float to write
@param places Number of decimal places to show **[optional]**
@param x_pos X cursor position of write **[optional]**
@param y_pos Y cursor position of write **[optional]**
*///............................................................................
void PixieChroma::write( float input, uint8_t places, uint8_t x_pos, uint8_t y_pos ){
write(
double( input ),
places,
x_pos,
y_pos
);
}
/*! ############################################################################
@brief
Internal function for rendering icons to the mask buffer.
@details
This can also be used to write Icons that are not aligned to whole display
positions, such as during smooth scrolling.
@param icon Icon to render
@param x_dest X pixel position of write **[optional]**
@param y_dest Y pixel position of write **[optional]**
*///............................................................................
void PixieChroma::write_pix( const uint8_t* icon, int16_t x_dest, int16_t y_dest ){
add_char(
icon,
x_dest,
y_dest
);
cursor_x_temp = x_dest+display_width;
if( cursor_x_temp >= ( display_width * chars_x ) ){
cursor_x_temp = display_padding_x;
cursor_y_temp += display_height;
}
}
/*! ############################################################################
@brief
Internal function for rendering char* strings to the mask buffer.
@details
All other write() function overloads eventually end up casted to char*
strings and passed to this function for rendering. This can also be used to
write char* strings that are not aligned to whole display positions, such
as during smooth scrolling.
@param message char* of text to render
@param x_dest X pixel position of write **[optional]**
@param y_dest Y pixel position of write **[optional]**
*///............................................................................
void PixieChroma::write_pix( char* message, int16_t x_dest, int16_t y_dest ){
int16_t offset_x = 0;
int16_t offset_y = 0;
uint8_t len = strlen( message );
for( uint8_t i = 0; i < len; i++ ){
if( message[i] == '\n' ){ // Newline, force line break
x_dest = display_padding_x;
offset_x = 0;
offset_y = display_height;
}
else if( line_wrap == true && x_dest+offset_x >= ( display_width * chars_x ) ){ // End of line reached, wrap to new line if line_wrap enabled
x_dest = display_padding_x;
offset_x = 0;
offset_y = display_height;
add_char(
message[i],
x_dest + offset_x,
y_dest + offset_y
);
offset_x += display_width;
}
else if( message[i] == 0 || message[i] == '\0' ){ // end of string
return;
}
else{ // Normal char
add_char(
message[i],
x_dest + offset_x,
y_dest + offset_y
);
offset_x += display_width;
}
}
cursor_x_temp = x_dest+offset_x;
cursor_y_temp = y_dest+offset_y;
}
/*! ############################################################################
@brief
Internal function for rendering a single char to the mask buffer.
@details
All other write() function overloads eventually end up casted to char*
strings and passed to this function one character at a time for rendering.
@param chr char to render
@param x_dest X pixel position of write
@param y_dest Y pixel position of write
*///............................................................................
void PixieChroma::add_char( char chr, int16_t x_dest, int16_t y_dest ){
if ( chr >= printable_ascii_offset ) {
chr -= printable_ascii_offset;
}
for( uint8_t x = 0; x < font_col_width; x++ ){
uint8_t column = pgm_read_byte( font + ( chr * font_col_width + x ) );
uint16_t row1_index = xy( x_dest+x, y_dest+0 );
uint16_t row2_index = xy( x_dest+x, y_dest+1 );
uint16_t row3_index = xy( x_dest+x, y_dest+2 );
uint16_t row4_index = xy( x_dest+x, y_dest+3 );
uint16_t row5_index = xy( x_dest+x, y_dest+4 );
uint16_t row6_index = xy( x_dest+x, y_dest+5 );
uint16_t row7_index = xy( x_dest+x, y_dest+6 );
// "Subtract" from mask transparency with saturating function
mask[row1_index] = qadd8( mask[row1_index], bit_table[bitRead( column, 0 )] );
mask[row2_index] = qadd8( mask[row2_index], bit_table[bitRead( column, 1 )] );
mask[row3_index] = qadd8( mask[row3_index], bit_table[bitRead( column, 2 )] );
mask[row4_index] = qadd8( mask[row4_index], bit_table[bitRead( column, 3 )] );
mask[row5_index] = qadd8( mask[row5_index], bit_table[bitRead( column, 4 )] );
mask[row6_index] = qadd8( mask[row6_index], bit_table[bitRead( column, 5 )] );
mask[row7_index] = qadd8( mask[row7_index], bit_table[bitRead( column, 6 )] );
}
}
/*! ############################################################################
@brief
Internal function for rendering a single icon to the mask buffer.
@param icon Icon column data to render
@param x_dest X pixel position of write
@param y_dest Y pixel position of write
*///............................................................................
void PixieChroma::add_char( const uint8_t* icon, int16_t x_dest, int16_t y_dest ){
for( uint8_t x = 0; x < font_col_width; x++ ){
uint8_t column = pgm_read_byte_far( icon+x );
uint16_t row1_index = xy( x_dest+x, y_dest+0 );
uint16_t row2_index = xy( x_dest+x, y_dest+1 );
uint16_t row3_index = xy( x_dest+x, y_dest+2 );
uint16_t row4_index = xy( x_dest+x, y_dest+3 );
uint16_t row5_index = xy( x_dest+x, y_dest+4 );
uint16_t row6_index = xy( x_dest+x, y_dest+5 );
uint16_t row7_index = xy( x_dest+x, y_dest+6 );
// "Subtract" from mask transparency with saturating function
mask[row1_index] = qadd8( mask[row1_index], bit_table[bitRead( column,0 )] );
mask[row2_index] = qadd8( mask[row2_index], bit_table[bitRead( column,1 )] );
mask[row3_index] = qadd8( mask[row3_index], bit_table[bitRead( column,2 )] );
mask[row4_index] = qadd8( mask[row4_index], bit_table[bitRead( column,3 )] );
mask[row5_index] = qadd8( mask[row5_index], bit_table[bitRead( column,4 )] );
mask[row6_index] = qadd8( mask[row6_index], bit_table[bitRead( column,5 )] );
mask[row7_index] = qadd8( mask[row7_index], bit_table[bitRead( column,6 )] );
}
}
/*! ############################################################################
@brief
Prints an Icon to the displays, at the current cursor position.
@param icon Icon column data to render
*///............................................................................
void PixieChroma::print( const uint8_t* icon ){
write_pix( icon, cursor_x, cursor_y );
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
}
/*! ############################################################################
@brief
Prints an icon to the displays at the current cursor position, taking five
uint8_t as input for the column data.
@details
Example:
pix.print( B00101111, B01001001, B01001001, B01001001, B00110001 );
OR, WRITTEN VERTICALLY:
pix.print( , , , , );
1 1 1 1 1 LSB
1 0 0 0 0
1 0 0 0 0
1 1 1 1 0
0 0 0 0 1
1 0 0 0 1
0 1 1 1 0
0 0 0 0 0 MSB ( unused )
B B B B B
This writes a "5" to the display, seen above in the "1" bits of
each column. The MSB ( highest bit ) is not used in icons.
@param icon_col_1 Column 1 data of this icon
@param icon_col_2 Column 2 data of this icon
@param icon_col_3 Column 3 data of this icon
@param icon_col_4 Column 4 data of this icon
@param icon_col_5 Column 5 data of this icon
*///............................................................................
void PixieChroma::print( uint8_t icon_col_1, uint8_t icon_col_2, uint8_t icon_col_3, uint8_t icon_col_4, uint8_t icon_col_5 ){
cursor_x_temp = cursor_x;
cursor_y_temp = cursor_y;
const uint8_t icon[5] = {
icon_col_1,
icon_col_2,
icon_col_3,
icon_col_4,
icon_col_5,
};
write_pix( icon, cursor_x, cursor_y );
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
}
/*! ############################################################################
@brief
Prints a char* string to the displays at the current cursor position.
@param message char* string to print
*///............................................................................
void PixieChroma::print( char* message ){
write_pix( message, cursor_x, cursor_y );
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
}
/*! ############################################################################
@brief
Prints a signed 16-bit integer to the displays at the current cursor
position.
@param input Signed integer to print
*///............................................................................
void PixieChroma::print( int16_t input ){
char char_buf[32];
itoa( input, char_buf, 10 );
write_pix( char_buf, cursor_x, cursor_y );
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
}
/*! ############################################################################
@brief
Prints an unsigned 16-bit integer to the displays at the current cursor
position.
@param input Unsigned integer to print
*///............................................................................
void PixieChroma::print( uint16_t input ){
char char_buf[32];
utoa( input, char_buf, 10 );
write_pix( char_buf, cursor_x, cursor_y );
// Store cursor changes
cursor_x = cursor_x_temp;
cursor_y = cursor_y_temp;
}
/*! ############################################################################