A simple library for SSH1106 controlled GLCDs

Dependents:   SSH1106_OLED

Files at this revision

API Documentation at this revision

Comitter:
Anaesthetix
Date:
Thu Dec 22 23:15:46 2016 +0000
Parent:
1:ac9efaadd666
Commit message:
Made universal for different resolutions.

Changed in this revision

SSH1106.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SSH1106.cpp	Mon Dec 19 23:23:41 2016 +0000
+++ b/SSH1106.cpp	Thu Dec 22 23:15:46 2016 +0000
@@ -91,9 +91,9 @@
     _lcd_cs->write(0);
     _lcd_cd->write(1);
 
-    for(unsigned short j = 0; j < 8; j++) {
+    for(unsigned short j = 0; j < LCDPAGES; j++) {
         SSH1106::setCursor(0, j);
-        for(unsigned short i = 0; i < 128 ; i++) {
+        for(unsigned short i = 0; i < LCDWIDTH ; i++) {
             _lcd->write(0x00);
         }
     }
@@ -186,9 +186,9 @@
     _lcd_cs->write(0);
     _lcd_cd->write(1);
     SSH1106::setCursor(0,0);
-    for(int row=0; row<8; row++) {
+    for(int row=0; row<LCDPAGES; row++) {
         SSH1106::setCursor(0, row);
-        for(int column=0; column<128; column++) {
+        for(int column=0; column<LCDWIDTH; column++) {
             _lcd->write(data[cnt]);
             cnt++;
         }
@@ -264,9 +264,9 @@
     _lcd_cs->write(0);
     _lcd_cd->write(1);
     SSH1106::setCursor(0,0);
-    for(int row=0; row<8; row++) {
+    for(int row=0; row<LCDPAGES; row++) {
         SSH1106::setCursor(0, row);
-        for(int column=0; column<128; column++) {
+        for(int column=0; column<LCDWIDTH; column++) {
             _lcd->write(buff[cnt]);
             cnt++;
         }
@@ -282,8 +282,8 @@
 
     if(width+posx > LCDWIDTH) width = (LCDWIDTH-posx); // keep inside display area
 
-    page = posy/8;
-    offset = posy - (page*8);
+    page = posy/LCDPAGES;
+    offset = posy - (page*LCDPAGES);
     buffer[0] = buffer[0] >> (8-height);
     buffer[0] = buffer[0] << offset;
 
@@ -292,12 +292,12 @@
         buffer[1] = buffer[1] - (0xFF << (offset2));
     }
 
-    cursor = posx + (page*128);
+    cursor = posx + (page*LCDWIDTH);
 
     for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= buffer[0];
 
-    if(buffer[1] != 0xFF && (page+1) < 8) {         // only write if line takes up > 1 page & keep inside display area
-        for(int i=0; i<width; i++) SSH1106::buff[cursor+i+128] |= buffer[1];
+    if(buffer[1] != 0xFF && (page+1) < LCDPAGES) {         // only write if line takes up > 1 page & keep inside display area
+        for(int i=0; i<width; i++) SSH1106::buff[cursor+i+LCDWIDTH] |= buffer[1];
     }
 }
 
@@ -306,19 +306,19 @@
     char page, pagecount, offset, offset2;
     int cursor;
 
-    page = posy/8;
-    pagecount = height/8;
-    offset2 = height - (pagecount*8);
-    cursor = posx + (page*128); // LCDWIDTH
+    page = posy/LCDPAGES;
+    pagecount = height/LCDPAGES;
+    offset2 = height - (pagecount*LCDPAGES);
+    cursor = posx + (page*LCDWIDTH); // LCDWIDTH
 
     for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= (0xFF>>offset);
 
     for(; pagecount > 1; pagecount--) {
         page++;
-        cursor += 128;
+        cursor += LCDWIDTH;
         for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= 0xFF;
     }
 
-    cursor += 128;
+    cursor += LCDWIDTH;
     for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= (0xFF >> offset2);
 }
\ No newline at end of file