Simple line-by-line way to use SSD1306 screens.

Files at this revision

API Documentation at this revision

Comitter:
austinbrown124
Date:
Mon May 25 17:31:00 2020 +0000
Parent:
2:574d1b329593
Commit message:
Fixed uint16 problem and added in protection against overflows on framebuf.

Changed in this revision

SSD1306_simple.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 574d1b329593 -r b9855e428053 SSD1306_simple.cpp
--- a/SSD1306_simple.cpp	Sun May 24 17:32:24 2020 +0000
+++ b/SSD1306_simple.cpp	Mon May 25 17:31:00 2020 +0000
@@ -253,7 +253,7 @@
 
 } 
 
-void SSD1306::writeInt( uint8_t col, int16_t num) {
+void SSD1306::writeInt( uint8_t col, int32_t num) {
     //GPIOA->ODR |= GPIO_ODR_8;
     if(num<0)
     {
@@ -267,6 +267,8 @@
     int base = 10;
     int mult = 10000;  // can print maximum of 5 digits
     
+    num = num%100000;
+    
     while (mult > num) { mult /= base; }
     
     int num2print = 0;
@@ -312,16 +314,19 @@
     
     if (_font == FONT_8x8) {
         for (uint8_t i = 0; i < FONT8x8_WIDTH; i++) {
+            if (k >= (COLUMNS+FRAME_BUF_OFFSET)) { break; }
             framebuf[k] = font_8x8[char_index][i];
             k++;
         }
     } else if (_font == FONT_16x12_0) {
         for (uint8_t i = 0; i < FONT16x12_WIDTH; i++) {
+            if (k >= (COLUMNS+FRAME_BUF_OFFSET)) { break; }
             framebuf[k] = font_16x12_0[char_index][i];
             k++;
         }
     } else if (_font == FONT_16x12_1) {
         for (uint8_t i = 0; i < FONT16x12_WIDTH; i++) {
+            if (k >= (COLUMNS+FRAME_BUF_OFFSET)) { break; }
             framebuf[k] = font_16x12_1[char_index][i];
             k++;
         }