Driver for the Seeedstudio RGB OLED module for the xadow M0

Files at this revision

API Documentation at this revision

Comitter:
messi1
Date:
Sat Dec 10 22:51:06 2016 +0000
Parent:
16:7984718638fc
Commit message:
removed wait(0.05); Add boundingRect function

Changed in this revision

include/Point.h Show annotated file Show diff for this revision Revisions of this file
include/SGL.h Show annotated file Show diff for this revision Revisions of this file
src/SGL.cpp Show annotated file Show diff for this revision Revisions of this file
src/SSD1331.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7984718638fc -r 1bcdc92af126 include/Point.h
--- a/include/Point.h	Thu Dec 08 22:08:16 2016 +0000
+++ b/include/Point.h	Sat Dec 10 22:51:06 2016 +0000
@@ -8,23 +8,25 @@
     Point():
     _x(0),
     _y(0)
-    {};
+    {}
     
     Point(T x, T y):
     _x(x),
     _y(y)
-    {};
+    {}
     
-    T x(){reurn _x;}
+    T x(){return _x;}
     T y(){return _y;}
     T& rx(){return _x;}
     T& ry(){return _y;}
     void setX(T x){_x = x;}
     void setY(T y){_y = y;}
     bool isNull()const{return (_x==0 && _y==0);}
+
     Point& operator*=(T factor){_x*=factor; _y*=factor; return *this;}
     Point& operator+=(const Point& point){_x+=p._x; _y+=p._y; return *this;}
     Point& operator-=(const Point& point){_x-=p._x; _y-=p._y; return *this;}
+
     friend inline bool   operator==( const Point &p1, const Point &p2 ){ return p1._x == p2._x && p1._y == p2._y; }
     friend inline bool   operator!=( const Point &p1, const Point &p2 ){ return p1._x != p2._x || p1._y != p2._y; }
     friend inline const Point operator+( const Point &p1, const Point &p2 ){ return Point(p1._x+p2._x, p1._y+p2._y); }
diff -r 7984718638fc -r 1bcdc92af126 include/SGL.h
--- a/include/SGL.h	Thu Dec 08 22:08:16 2016 +0000
+++ b/include/SGL.h	Sat Dec 10 22:51:06 2016 +0000
@@ -45,6 +45,7 @@
  
 public:
     SGL(T width, T height);
+    virtual void clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) = 0;
     virtual void drawPixel(T x, T y, uint16_t color) = 0; // implemented by subclass
     virtual void drawLine(T x0, T y0, T x1, T y1, uint16_t color);
     virtual void drawVLine(T x, T y, T length,uint16_t color);
@@ -58,8 +59,8 @@
     
     // The zoom factor works at the moment only with integer values. Float values will create bad fonts 
     virtual void drawChar(uint8_t ascii, T x, T y, uint16_t color, float zoom=1);
-/*    virtual void drawString(const char *string, T x, T y, uint16_t color, float zoom=1, uint8_t fontSpace=6);*/
-    virtual Rect<T> drawString(const char *string, T x, T y, uint16_t color, float zoom=1, uint8_t fontSpace=6);
+    virtual void drawString(const char *string, T x, T y, uint16_t color, float zoom=1, int8_t fontSpace=0);
+    virtual Rect<T> boundingRect(const char *string, T x, T y, float zoom=1, int8_t fontSpace=0);
     
     virtual void drawBitMap(T x, T y, const uint8_t *bitmap, T width, T height, uint16_t color);
     virtual void fillScreen(uint16_t color);
@@ -70,8 +71,8 @@
         T t = *a; *a = *b; *b = t; 
     };
     
-    T _width;
-    T _height;
+    T _displayWidth;
+    T _displayHeight;
     FontType _currentFont;
     uint8_t _fontWidth;
     uint8_t _fontHeight;
diff -r 7984718638fc -r 1bcdc92af126 src/SGL.cpp
--- a/src/SGL.cpp	Thu Dec 08 22:08:16 2016 +0000
+++ b/src/SGL.cpp	Sat Dec 10 22:51:06 2016 +0000
@@ -37,7 +37,7 @@
 //---------------------------------------------------------------------------------------
 template <class T>
 SGL<T>::SGL(T width, T height):
-    _width(width), _height(height),
+    _displayWidth(width), _displayHeight(height),
     _currentFont(0),     
     _fontWidth(0),
     _fontHeight(0),
@@ -73,7 +73,7 @@
 template <class T>
 void SGL<T>::drawVLine(T x, T y, T length,uint16_t color)
 {
-    T y1 = MIN(y+length,_height-1);
+    T y1 = MIN(y+length,_displayHeight-1);
     for(T i = y; i < y1; ++i)
     {
         drawPixel(x, i, color);
@@ -84,7 +84,7 @@
 template <class T>
 void SGL<T>::drawHLine(T x, T y, T length, uint16_t color)
 {
-    T x1 = MIN(x+length,_width-1);
+    T x1 = MIN(x+length,_displayWidth-1);
     for(T i = x; i < x1; ++i)
     {
         drawPixel(i, y, color);
@@ -223,6 +223,8 @@
     if((ascii < _fontStart)||(ascii > _fontStop)){
         return;
     }
+    
+    clearArea(x, y, x+_fontWidth, y+_fontHeight);
 
     for(uint8_t i = 0; i < _fontWidth; ++i )
     {
@@ -269,28 +271,33 @@
 }
 
 //---------------------------------------------------------------------------------------
-/*template <class T>
-void SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, uint8_t fontSpace)
+template <class T>
+void SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, int8_t fontSpace)
 {
     if(!_currentFont && !*_currentFont)
         return;
         
+    T tempX = x;
+    T tempY = y;
+        
     while(*string)
-    {
-        drawChar(*string, x, y, color, zoom);
+    {  
+        drawChar(*string, tempX, tempY, color, zoom);
         *string++;
-        x += fontSpace*zoom;
-        if(x >= _width-1)
+        tempX += _fontWidth+fontSpace;
+        
+        // New line when end of display reached 
+        if(tempX >= _displayWidth-1)
         {
-            y += _fontHeight*zoom;
-            x = 0;
+            tempY += _fontHeight*zoom;
+            tempX = 0;
         }
     }
-}*/
+}
 
 //---------------------------------------------------------------------------------------
 template <class T>
-Rect<T> SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, uint8_t fontSpace)
+Rect<T> SGL<T>::boundingRect(const char *string, T x, T y, float zoom, int8_t fontSpace)
 {
     if(!_currentFont && !*_currentFont)
         return Rect<T>();
@@ -299,18 +306,20 @@
         
     while(*string)
     {
-        boundingWidth += _fontWidth;
-        drawChar(*string, x, y, color, zoom);
+        boundingWidth += (_fontWidth+fontSpace*zoom);        
         *string++;
-        x += fontSpace*zoom;
-        if(x >= _width-1)
-        {
-            y += _fontHeight*zoom;
-            x = 0;
-        }
     }
     
-    return Rect<T>(x, y, boundingWidth, _fontHeight );
+    T rectX = x-2;
+    T rectY = y-2;
+    
+    if(rectX > _displayWidth)
+        rectX = 0;
+        
+    if(rectY > _displayHeight)
+        rectY = 0;
+    
+    return Rect<T>(rectX, rectY, boundingWidth, _fontHeight+3 );
 }
 
 //---------------------------------------------------------------------------------------
@@ -335,7 +344,7 @@
 template <class T>
 void SGL<T>::fillScreen(uint16_t color)
 {
-    fillRect(0, 0, _width, _height, color);
+    fillRect(0, 0, _displayWidth, _displayHeight, color);
 }
 
 //---------------------------------------------------------------------------------------
diff -r 7984718638fc -r 1bcdc92af126 src/SSD1331.cpp
--- a/src/SSD1331.cpp	Thu Dec 08 22:08:16 2016 +0000
+++ b/src/SSD1331.cpp	Sat Dec 10 22:51:06 2016 +0000
@@ -157,7 +157,6 @@
 
     sendCmd(CMD_FILL_WINDOW, ENABLE_FILL);//fill window
     sendCmd(cmd, 11);
-    wait(0.05); 
 }
 
 //------------------------------------------------------------------------------------
@@ -172,7 +171,6 @@
     
     uint8_t cmd[7] = { CMD_COPY_WINDOW, x0, y0, x1, y1, x2, y2};
     sendCmd(cmd, 7);
-    wait(0.05); 
 }
 
 //------------------------------------------------------------------------------------
@@ -185,7 +183,6 @@
     
     uint8_t cmdBuffer[5] = { CMD_DIM_WINDOW, x0, y0, x1, y1 };
     sendCmd(cmdBuffer, 5); //Send buffer
-    wait(0.05); 
 }
 
 //------------------------------------------------------------------------------------
@@ -197,8 +194,7 @@
     if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
     
     uint8_t cmdBuffer[5] = { CMD_CLEAR_WINDOW, x0, y0, x1, y1 };
-    sendCmd(cmdBuffer, 5); //Send buffer
-    wait(0.05);  
+    sendCmd(cmdBuffer, 5); //Send buffer 
 }
 
 //------------------------------------------------------------------------------------
@@ -218,7 +214,7 @@
 void SSD1331::setScrolling(ScrollDirection direction, uint8_t rowAddr, uint8_t rowNum, ScrollInterval interval)
 {
     uint8_t scolling_horizontal = 0x0;
-    uint8_t scolling_vertical = 0x0;
+    uint8_t scolling_vertical   = 0x0;
     switch(direction){
         case SD_Horizontal:
             scolling_horizontal = 0x01;