Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

Revision:
11:162aa3e801df
Parent:
10:ef7440718431
Child:
12:8e27450eb391
--- a/src/SGL.cpp	Tue Nov 17 21:20:37 2015 +0000
+++ b/src/SGL.cpp	Wed Nov 18 09:28:05 2015 +0000
@@ -31,8 +31,12 @@
 #include "SGL.h"
 #include "SimpleFont.h"
 
+//template class SGL<uint8_t>;
+//template class SGL<uint16_t>;
+
 //---------------------------------------------------------------------------------------
-SGL::SGL(uint8_t width, uint8_t height):
+template <class T>
+SGL<T>::SGL(T width, T height):
     _width(width), _height(height),
     _currentFont(0),     
     _fontWidth(0),
@@ -42,13 +46,14 @@
 {}
 
 //---------------------------------------------------------------------------------------
-void SGL::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color)
+template <class T>
+void SGL<T>::drawLine(T x0, T y0, T x1, T y1, uint16_t color)
 {
-    uint8_t x   = x1-x0;
-    uint8_t y   = y1-y0;
-    uint8_t dx  = abs(x),  sx = x0<x1 ? 1 : -1;
-    uint8_t dy  = -abs(y), sy = y0<y1 ? 1 : -1;
-    uint8_t err = dx+dy, e2;
+    T x   = x1-x0;
+    T y   = y1-y0;
+    T dx  = abs(x),  sx = x0<x1 ? 1 : -1;
+    T dy  = -abs(y), sy = y0<y1 ? 1 : -1;
+    T err = dx+dy, e2;
     for (;;)
     {
         drawPixel(x0, y0,color);
@@ -65,27 +70,30 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawVLine(uint8_t x, uint8_t y, uint8_t length,uint16_t color)
+template <class T>
+void SGL<T>::drawVLine(T x, T y, T length,uint16_t color)
 {
-    uint8_t y1 = MIN(y+length,_height-1);
-    for(uint8_t i = y; i < y1; ++i)
+    T y1 = MIN(y+length,_height-1);
+    for(T i = y; i < y1; ++i)
     {
         drawPixel(x, i, color);
     }
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawHLine(uint8_t x, uint8_t y, uint8_t length, uint16_t color)
+template <class T>
+void SGL<T>::drawHLine(T x, T y, T length, uint16_t color)
 {
-    uint8_t x1 = MIN(x+length,_width-1);
-    for(uint8_t i = x; i < x1; ++i)
+    T x1 = MIN(x+length,_width-1);
+    for(T i = x; i < x1; ++i)
     {
         drawPixel(i, y, color);
     }
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color)
+template <class T>
+void SGL<T>::drawRect(T x, T y, T width, T height, uint16_t color)
 {
     drawHLine(x, y, width, color);
     drawHLine(x, y+height, width, color);
@@ -94,7 +102,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color)
+template <class T>
+void SGL<T>::fillRect(T x, T y, T width, T height, uint16_t color)
 {
     for(uint8_t i = 0; i < height; ++i)
     {
@@ -106,7 +115,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawCircle(uint8_t poX, uint8_t poY, uint8_t r, uint16_t color)
+template <class T>
+void SGL<T>::drawCircle(T poX, T poY, T r, uint16_t color)
 {
     int x = -r, y = 0, err = 2-2*r, e2;
     do
@@ -126,7 +136,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::fillCircle(uint8_t poX, uint8_t poY, uint8_t r, uint16_t color)
+template <class T>
+void SGL<T>::fillCircle(T poX, T poY, T r, uint16_t color)
 {
     int x = -r, y = 0, err = 2-2*r, e2;
     do
@@ -144,7 +155,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color)
+template <class T>
+void SGL<T>::drawTraingle(T x0, T y0, T x1, T y1, T x2, T y2, uint16_t color)
 {
     drawLine(x0, y0, x1, y1,color);
     drawLine(x1, y1, x2, y2,color);
@@ -152,9 +164,10 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::fillTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color)
+template <class T>
+void SGL<T>::fillTraingle(T x0, T y0, T x1, T y1, T x2, T y2, uint16_t color)
 {
-    uint8_t a, b, y, last;
+    T a, b, y, last;
 
     if(y0 > y1){ swap(&y0, &y1); swap(&x0, &x1); }
     if(y1 > y2){ swap(&y2, &y1); swap(&x2, &x1); }
@@ -201,7 +214,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawChar(uint8_t ascii, uint8_t x, uint8_t y, float zoom, uint16_t color)
+template <class T>
+void SGL<T>::drawChar(uint8_t ascii, T x, T y, uint16_t color, float zoom)
 {
     if(!_currentFont && !*_currentFont)
         return;
@@ -255,7 +269,8 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawString(const char *string, uint8_t x, uint8_t y, float zoom, uint16_t color, uint8_t fontSpace)
+template <class T>
+void SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, uint8_t fontSpace)
 {
     if(!_currentFont && !*_currentFont)
         return;
@@ -274,13 +289,14 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::drawBitMap(uint8_t x, uint8_t y, const uint8_t *bitmap, uint8_t width, uint8_t height, uint16_t color)
+template <class T>
+void SGL<T>::drawBitMap(T x, T y, const uint8_t *bitmap, T width, T height, uint16_t color)
 {
-    uint8_t byteWidth = (width + 7) / 8;
+    T byteWidth = (width + 7) / 8;
     
-    for(uint8_t j = 0; j < height; ++j)
+    for(T j = 0; j < height; ++j)
     {
-        for(uint8_t i = 0; i < width; ++i ) 
+        for(T i = 0; i < width; ++i ) 
         {
             if( *(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7)) ) 
             {
@@ -291,13 +307,15 @@
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::fillScreen(uint16_t color)
+template <class T>
+void SGL<T>::fillScreen(uint16_t color)
 {
     fillRect(0, 0, _width, _height, color);
 }
 
 //---------------------------------------------------------------------------------------
-void SGL::setFont(FontType font, uint8_t width, uint8_t height, uint8_t start, uint8_t stop)
+template <class T>
+void SGL<T>::setFont(FontType font, uint8_t width, uint8_t height, uint8_t asciiStart, uint8_t asciiStop)
 {
     if(!font && !*font)
         return;
@@ -305,6 +323,6 @@
     _currentFont= font;
     _fontWidth  = width;
     _fontHeight = height;
-    _fontStart  = start;
-    _fontStop   = stop;    
+    _fontStart  = asciiStart;
+    _fontStop   = asciiStop;    
 }
\ No newline at end of file