@@ -69,13 +69,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
69
69
#define TOTALFONTS 4
70
70
#endif
71
71
72
- #define swapOLED (a, b ) \
73
- { \
74
- uint8_t t = a; \
75
- a = b; \
76
- b = t; \
77
- }
78
-
79
72
// Add the font name as declared in the header file. Remove as many as possible to conserve FLASH memory.
80
73
const unsigned char *MicroOLED::fontsPointer[] = {
81
74
font5x7, font8x16, sevensegment, fontlargenumber
@@ -272,6 +265,14 @@ void MicroOLED::begin()
272
265
clear (ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
273
266
}
274
267
268
+ // Calling this function with nothing sets the debug port to Serial
269
+ // You can also call it with other streams like Serial1, SerialUSB, etc.
270
+ void MicroOLED::enableDebugging (Stream &debugPort)
271
+ {
272
+ _debugPort = &debugPort;
273
+ _printDebug = true ;
274
+ }
275
+
275
276
/* * \brief Send the display a command byte
276
277
277
278
Send a command via SPI, I2C or parallel to SSD1306 controller.
@@ -556,26 +557,70 @@ Draw line using color and mode from x0,y0 to x1,y1 of the screen buffer.
556
557
*/
557
558
void MicroOLED::line (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode)
558
559
{
560
+ if (_printDebug == true )
561
+ {
562
+ _debugPort->print (F (" line: line coords: (" ));
563
+ _debugPort->print (x0);
564
+ _debugPort->print (F (" ," ));
565
+ _debugPort->print (y0);
566
+ _debugPort->print (F (" ) (" ));
567
+ _debugPort->print (x1);
568
+ _debugPort->print (F (" ," ));
569
+ _debugPort->print (y1);
570
+ _debugPort->println (F (" )" ));
571
+ }
572
+
559
573
uint8_t steep = abs (y1 - y0) > abs (x1 - x0);
560
574
if (steep)
561
575
{
562
- swapOLED (x0, y0);
563
- swapOLED (x1, y1);
564
- }
576
+ swapOLED (&x0, &y0);
577
+ swapOLED (&x1, &y1);
578
+ if (_printDebug == true )
579
+ _debugPort->println (F (" line: line is steep" ));
580
+ }
565
581
566
582
if (x0 > x1)
567
583
{
568
- swapOLED (x0, x1);
569
- swapOLED (y0, y1);
584
+ swapOLED (&x0, &x1);
585
+ swapOLED (&y0, &y1);
586
+ if (_printDebug == true )
587
+ _debugPort->println (F (" line: x0 > x1" ));
570
588
}
571
589
590
+ // if (_printDebug == true)
591
+ // {
592
+ // _debugPort->print(F("line: line coords: ("));
593
+ // _debugPort->print(x0);
594
+ // _debugPort->print(F(","));
595
+ // _debugPort->print(y0);
596
+ // _debugPort->print(F(") ("));
597
+ // _debugPort->print(x1);
598
+ // _debugPort->print(F(","));
599
+ // _debugPort->print(y1);
600
+ // _debugPort->println(F(")"));
601
+ // }
602
+
572
603
uint8_t dx, dy;
573
604
dx = x1 - x0;
574
605
dy = abs (y1 - y0);
575
606
607
+ if (_printDebug == true )
608
+ {
609
+ _debugPort->print (F (" line: dx: " ));
610
+ _debugPort->print (dx);
611
+ _debugPort->print (F (" dy: " ));
612
+ _debugPort->println (dy);
613
+ }
614
+
576
615
int8_t err = dx / 2 ;
577
616
int8_t ystep;
578
617
618
+ if (_printDebug == true )
619
+ {
620
+ _debugPort->print (F (" line: err: " ));
621
+ _debugPort->println (err);
622
+ }
623
+
579
624
if (y0 < y1)
580
625
{
581
626
ystep = 1 ;
@@ -585,15 +630,37 @@ void MicroOLED::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t col
585
630
ystep = -1 ;
586
631
}
587
632
588
- for (; x0 < x1; x0++)
633
+ if (_printDebug == true )
634
+ {
635
+ _debugPort->print (F (" line: ystep: " ));
636
+ _debugPort->println (ystep);
637
+ }
638
+
639
+ for (; x0 <= x1; x0++)
589
640
{
590
641
if (steep)
591
642
{
592
643
pixel (y0, x0, color, mode);
644
+ if (_printDebug == true )
645
+ {
646
+ _debugPort->print (F (" line: steep pixel: (" ));
647
+ _debugPort->print (y0);
648
+ _debugPort->print (F (" ," ));
649
+ _debugPort->print (x0);
650
+ _debugPort->println (F (" )" ));
651
+ }
593
652
}
594
653
else
595
654
{
596
655
pixel (x0, y0, color, mode);
656
+ if (_printDebug == true )
657
+ {
658
+ _debugPort->print (F (" line: pixel: (" ));
659
+ _debugPort->print (x0);
660
+ _debugPort->print (F (" ," ));
661
+ _debugPort->print (y0);
662
+ _debugPort->println (F (" )" ));
663
+ }
597
664
}
598
665
err -= dy;
599
666
if (err < 0 )
@@ -1193,3 +1260,10 @@ uint8_t MicroOLED::getI2CTransactionSize(void)
1193
1260
{
1194
1261
return (i2cTransactionSize);
1195
1262
}
1263
+
1264
+ void MicroOLED::swapOLED (uint8_t *x, uint8_t *y)
1265
+ {
1266
+ uint8_t t = *x;
1267
+ *x = *y;
1268
+ *y = t;
1269
+ }
0 commit comments