Driver for the Seeedstudio RGB OLED module for the xadow M0
Revision 10:ef7440718431, committed 2015-11-17
- Comitter:
- messi1
- Date:
- Tue Nov 17 21:20:37 2015 +0000
- Parent:
- 9:5a7bf0ce8518
- Child:
- 11:162aa3e801df
- Commit message:
- Improved the drawString function; Add setFont function
Changed in this revision
--- a/include/SGL.h Tue Nov 17 19:45:22 2015 +0000 +++ b/include/SGL.h Tue Nov 17 21:20:37 2015 +0000 @@ -40,105 +40,7 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) -const unsigned char simpleFont[][8] = -{ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, - {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, - {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, - {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, - {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, - {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, - {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, - {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, - {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, - {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, - {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, - {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, - {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, - {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, - {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, - {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, - {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, - {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, - {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, - {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, - {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, - {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, - {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, - {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, - {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, - {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, - {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, - {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, - {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, - {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, - {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, - {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, - {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, - {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, - {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, - {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, - {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, - {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, - {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, - {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, - {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, - {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, - {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, - {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, - {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, - {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, - {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, - {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, - {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, - {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, - {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, - {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, - {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, - {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, - {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, - {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, - {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, - {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, - {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, - {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, - {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, - {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, - {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, - {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, - {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, - {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, - {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, - {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, - {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, - {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, - {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, - {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, - {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, - {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, - {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, - {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, - {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, - {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, - {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, - {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, - {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, - {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, - {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, - {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, - {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, - {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, - {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, - {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, - {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} -}; +typedef const unsigned char** FontType; class SGL { @@ -154,10 +56,14 @@ virtual void fillCircle(uint8_t x, uint8_t y, uint8_t r, uint16_t color); virtual void drawTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color); virtual void fillTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color); - virtual void drawChar(uint8_t ascii, uint8_t x, uint8_t y, uint8_t size, uint16_t color); - virtual void drawString(char *string, uint8_t x, uint8_t y, uint8_t size, uint16_t color); + + // The zoom factor works at the moment only with integer values. Float values will create bad fonts + virtual void drawChar(uint8_t ascii, uint8_t x, uint8_t y, float zoom, uint16_t color); + virtual void drawString(const char *string, uint8_t x, uint8_t y, float zoom, uint16_t color, uint8_t fontSpace=6); + virtual void drawBitMap(uint8_t x, uint8_t y, const uint8_t *bitmap, uint8_t width, uint8_t height, uint16_t color); virtual void fillScreen(uint16_t color); + virtual void setFont(FontType font, uint8_t width, uint8_t height, uint8_t start, uint8_t stop); private: void swap(uint8_t* a, uint8_t* b){ @@ -166,6 +72,11 @@ uint8_t _width; uint8_t _height; + FontType _currentFont; + uint8_t _fontWidth; + uint8_t _fontHeight; + uint8_t _fontStart; + uint8_t _fontStop; }; #endif
--- a/include/SSD1331.h Tue Nov 17 19:45:22 2015 +0000 +++ b/include/SSD1331.h Tue Nov 17 21:20:37 2015 +0000 @@ -153,7 +153,7 @@ }; enum PowerMode{ - PM_SleepMode = 0xAE + PM_SleepMode = 0xAE, PM_NormalMode = 0xAF };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SimpleFont.h Tue Nov 17 21:20:37 2015 +0000 @@ -0,0 +1,108 @@ +#ifndef SIMPLE_FONT_H +#define SIMPLE_FONT_H + +#define FONT_SPACE 6 +#define FONT_X 8 +#define FONT_Y 8 + +const unsigned char simpleFont[][8] = +{ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, + {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, + {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, + {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, + {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, + {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, + {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, + {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, + {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, + {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, + {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, + {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, + {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, + {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, + {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, + {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, + {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, + {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, + {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, + {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, + {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, + {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, + {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, + {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, + {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, + {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, + {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, + {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, + {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, + {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, + {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, + {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, + {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, + {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, + {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, + {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, + {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, + {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, + {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, + {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, + {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, + {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, + {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, + {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, + {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, + {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, + {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, + {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, + {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, + {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, + {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, + {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, + {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, + {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, + {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, + {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, + {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, + {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, + {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, + {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, + {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, + {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, + {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, + {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, + {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, + {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, + {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, + {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, + {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, + {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, + {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, + {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, + {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, + {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, + {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, + {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, + {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, + {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, + {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, + {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, + {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, + {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, + {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, + {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, + {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, + {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, + {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, + {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, + {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, + {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, + {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} +}; + +#endif // SIMPLE_FONT_h \ No newline at end of file
--- a/src/SGL.cpp Tue Nov 17 19:45:22 2015 +0000 +++ b/src/SGL.cpp Tue Nov 17 21:20:37 2015 +0000 @@ -29,23 +29,28 @@ */ #include <stdlib.h> #include "SGL.h" +#include "SimpleFont.h" //--------------------------------------------------------------------------------------- -SGL::SGL(uint8_t width, uint8_t height) -{ - _width = width; - _height = height; -} +SGL::SGL(uint8_t width, uint8_t height): + _width(width), _height(height), + _currentFont(0), + _fontWidth(0), + _fontHeight(0), + _fontStart(0), + _fontStop(0) +{} //--------------------------------------------------------------------------------------- void SGL::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_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 dx = abs(x), sx = x0<x1 ? 1 : -1; uint8_t dy = -abs(y), sy = y0<y1 ? 1 : -1; uint8_t err = dx+dy, e2; - for (;;){ + for (;;) + { drawPixel(x0, y0,color); e2 = 2*err; if (e2 >= dy) { @@ -63,7 +68,8 @@ void SGL::drawVLine(uint8_t x, uint8_t y, uint8_t length,uint16_t color) { uint8_t y1 = MIN(y+length,_height-1); - for(uint8_t i = y; i < y1; ++i){ + for(uint8_t i = y; i < y1; ++i) + { drawPixel(x, i, color); } } @@ -72,7 +78,8 @@ void SGL::drawHLine(uint8_t x, uint8_t y, uint8_t length, uint16_t color) { uint8_t x1 = MIN(x+length,_width-1); - for(uint8_t i = x; i < x1; ++i){ + for(uint8_t i = x; i < x1; ++i) + { drawPixel(i, y, color); } } @@ -89,8 +96,10 @@ //--------------------------------------------------------------------------------------- void SGL::fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color) { - for(uint8_t i = 0; i < height; ++i){ - for(uint8_t j = 0; j < width; ++j){ + for(uint8_t i = 0; i < height; ++i) + { + for(uint8_t j = 0; j < width; ++j) + { drawPixel( x+j, y+i, color); } } @@ -100,13 +109,15 @@ void SGL::drawCircle(uint8_t poX, uint8_t poY, uint8_t r, uint16_t color) { int x = -r, y = 0, err = 2-2*r, e2; - do{ + do + { drawPixel(poX-x, poY+y,color); drawPixel(poX+x, poY+y,color); drawPixel(poX+x, poY-y,color); drawPixel(poX-x, poY-y,color); e2 = err; - if(e2 <= y) { + if(e2 <= y) + { err += ++y*2+1; if(-x == y && e2 <= x) e2 = 0; } @@ -118,11 +129,13 @@ void SGL::fillCircle(uint8_t poX, uint8_t poY, uint8_t r, uint16_t color) { int x = -r, y = 0, err = 2-2*r, e2; - do{ + do + { drawVLine(poX-x, poY-y, 2*y, color); drawVLine(poX+x, poY-y, 2*y, color); e2 = err; - if(e2 <= y){ + if(e2 <= y) + { err += ++y*2+1; if(-x == y && e2 <= x) e2 = 0; } @@ -164,7 +177,8 @@ else last = y1-1; - for(y=y0; y<=last; ++y) { + for(y = y0; y <= last; ++y) + { a = x0 + sa / dy01; b = x0 + sb / dy02; sa += dx01; @@ -175,7 +189,8 @@ sa = dx12 * (y - y1); sb = dx02 * (y - y0); - for(; y<=y2; ++y) { + for(; y<=y2; ++y) + { a = x1 + sa / dy12; b = x0 + sb / dy02; sa += dx12; @@ -186,31 +201,41 @@ } //--------------------------------------------------------------------------------------- -void SGL::drawChar(uint8_t ascii, uint8_t x, uint8_t y, uint8_t size, uint16_t color) +void SGL::drawChar(uint8_t ascii, uint8_t x, uint8_t y, float zoom, uint16_t color) { - if((ascii<32)||(ascii>=127)){ + if(!_currentFont && !*_currentFont) + return; + + if((ascii < _fontStart)||(ascii > _fontStop)){ return; } - for (uint8_t i = 0; i < FONT_X; ++i ) { - uint8_t temp = simpleFont[ascii-0x20][i]; - uint8_t inrun = 0; + for(uint8_t i = 0; i < _fontWidth; ++i ) + { + uint8_t temp = simpleFont[ascii-0x20][i]; + uint8_t inrun = 0; uint8_t runlen = 0; uint8_t endrun = 0; - for(uint8_t f = 0; f < FONT_Y; f++){ - if((temp>>f)&0x01){ + for(uint8_t f = 0; f < _fontHeight; ++f) + { + if((temp>>f)&0x01) + { if (inrun) runlen += 1; - else { - inrun = 1; + else + { + inrun = 1; runlen = 1; } - } else if (inrun) { + } + else if (inrun) + { endrun = 1; - inrun = 0; + inrun = 0; } - if (f == FONT_Y - 1 && inrun) { + if (f == _fontHeight - 1 && inrun) + { endrun = 1; // need the +1 b/c we this code is normally // only triggered when f == FONT_Y, due to the @@ -218,8 +243,9 @@ f += 1; } - if (endrun) { - fillRect(x+i*size, y+(f-runlen)*size, size, runlen*size, color); + if (endrun) + { + fillRect(x+i*zoom, y+(f-runlen)*zoom, zoom, runlen*zoom, color); inrun = 0; runlen = 0; endrun = 0; @@ -229,14 +255,19 @@ } //--------------------------------------------------------------------------------------- -void SGL::drawString(char *string, uint8_t x, uint8_t y, uint8_t size, uint16_t color) +void SGL::drawString(const char *string, uint8_t x, uint8_t y, float zoom, uint16_t color, uint8_t fontSpace) { - while(*string){ - drawChar(*string, x, y, size, color); + if(!_currentFont && !*_currentFont) + return; + + while(*string) + { + drawChar(*string, x, y, zoom, color); *string++; - x += FONT_SPACE*size; - if(x >= _width-1){ - y += FONT_Y*size; + x += fontSpace*zoom; + if(x >= _width-1) + { + y += _fontHeight*zoom; x = 0; } } @@ -263,4 +294,17 @@ void SGL::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) +{ + if(!font && !*font) + return; + + _currentFont= font; + _fontWidth = width; + _fontHeight = height; + _fontStart = start; + _fontStop = stop; } \ No newline at end of file
--- a/src/SSD1331.cpp Tue Nov 17 19:45:22 2015 +0000 +++ b/src/SSD1331.cpp Tue Nov 17 21:20:37 2015 +0000 @@ -62,7 +62,10 @@ #include "wait_api.h" SSD1331::SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk) -:SGL(RGB_OLED_WIDTH, RGB_OLED_HEIGHT), _cs(cs), _dc(dc), _spiPort(mosi, miso, sclk) + :SGL(RGB_OLED_WIDTH, RGB_OLED_HEIGHT), + _cs(cs), + _dc(dc), + _spiPort(mosi, miso, sclk) { _spiPort.format(8,3); //8bit frame and POL=1 /PHA=1(UpEdge Sampled) _spiPort.frequency(25000000); // modify later