EPD display library. Check this version (it should work)
Fork of GDEP015OC1 by
Diff: GDEP015OC1.cpp
- Revision:
- 3:dc7b794b59b7
- Parent:
- 2:1c8f73aa2a16
- Child:
- 4:86114342ce8f
--- a/GDEP015OC1.cpp Thu Sep 15 09:19:30 2016 +0000 +++ b/GDEP015OC1.cpp Thu Sep 15 12:12:34 2016 +0000 @@ -1,5 +1,9 @@ +/** + * Created by Filip Hormot (f.hormot@gmail.com) on 14/09/16. + */ #include "mbed.h" #include "GDEP015OC1.h" +#include "5x7.h" static const unsigned char _lutFull[] = { 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, @@ -7,6 +11,7 @@ }; GDEP015OC1::GDEP015OC1(SPI& spi, PinName cs=p5, PinName dc=p6, PinName rst=p7, PinName busy=p8) : _spi(spi), _cs(cs), _dc(dc), _rst(rst), _busy(busy){ + _bold = _italic = false; _init(); } @@ -27,7 +32,7 @@ void GDEP015OC1::_init(void){ _rst = _cs = 1; - //empty(); + empty(); } void GDEP015OC1::_wakeUp(void){ @@ -130,7 +135,7 @@ for(uint8_t x = 0; x < 8; x++){ pix |= ((*(data + (i*200)%5000 + (24-i/200) + x*25)>>((i/25)%8))&(0x01))<<(7-x); } - return pix; + return pix^0xFF; } uint8_t GDEP015OC1::_mirrorData(uint8_t data){ @@ -194,4 +199,127 @@ if (e2 >-dx) { err -= dy; startX += sx; } if (e2 < dy) { err += dx; startY += sy; } } +} + +void GDEP015OC1::drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool color=0){ + drawLine(x1, y1, x2, y2, color); + drawLine(x2, y2, x3, y3, color); + drawLine(x3, y3, x1, y1, color); +} + +void GDEP015OC1::drawRectangle(uint16_t startX, uint16_t startY, uint16_t stopX, uint16_t stopY, bool color=0){ + drawLine(startX, startY, stopX, startY, color); + drawLine(stopX, startY, stopX, stopY, color); + drawLine(stopX, stopY, startX, stopY, color); + drawLine(startX, stopY, startX, startY, color); +} + +void GDEP015OC1::drawCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){ + int d,x,y; + + d=3-2*radius; + x=0; + y=radius; + while(x<=y){ + drawPixel(startX+x,startY+y,color); + drawPixel(startX-y,startY-x,color); + drawPixel(startX+y,startY-x,color); + drawPixel(startX-y,startY+x,color); + drawPixel(startX+y,startY+x,color); + drawPixel(startX-x,startY-y,color); + drawPixel(startX+x,startY-y,color); + drawPixel(startX-x,startY+y,color); + + if(d<=0) + d=d+4*x+6; + else{ + d=d+4*x-4*y+10; + y--; + } + x++; + } +} + +void GDEP015OC1::fillCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){ + for(uint16_t r = 1;r<=radius; r++){ + drawCircle(startX, startY, r, color); + drawCircle(startX+1, startY, r-1, color); + drawCircle(startX-1, startY, r-1, color); + } +} + +void GDEP015OC1::drawEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color){ + int a2 = width*width; + int b2 = height*height; + int fa2 = 4*a2, fb2 = 4*b2; + int x, y, sigma; + + //First half + for(int x = 0, y = height, sigma = 2*b2+a2*(1-2*height); b2*x <= a2*y; x++){ + drawPixel(startX+x,startY+y,color); + drawPixel(startX-x,startY+y,color); + drawPixel(startX+x,startY-y,color); + drawPixel(startX-x,startY-y,color); + if(sigma >= 0){ + sigma += fa2 * (1-y); + y--; + } + sigma += b2 * ((4 * x) + 6); + } + //Second half + for (x = width, y = 0, sigma = 2*a2+b2*(1-2*width); a2*y <= b2*x; y++){ + drawPixel(startX+x,startY+y,color); + drawPixel(startX-x,startY+y,color); + drawPixel(startX+x,startY-y,color); + drawPixel(startX-x,startY-y,color); + if (sigma >= 0){ + sigma += fb2 * (1 - x); + x--; + } + sigma += a2 * ((4 * y) + 6); + } +} + +void GDEP015OC1::fillEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color=0){ + for(uint16_t w = width; w > 0; w--){ + drawEllipse(startX, startX, w, height, color); + } + drawLine(startX, startY-height, startX, startY+height, color); +} + +void GDEP015OC1::writeChar(char character, uint16_t startX, uint16_t startY, bool color=0){ + unsigned char letter[FONT_WIDTH]; + + //Grab data for the corresponding font + for(uint8_t i = 0; i<FONT_WIDTH; i++) + letter[i] = Font5x7[(character - ' ') * FONT_WIDTH + i]; + + for(uint8_t i = 0; i<FONT_WIDTH; i++){ + for(uint8_t j = 0; j<FONT_HEIGHT; j++){ + if((letter[i]>>j)&0x01){ + if(_italic){ + drawPixel(startX+i+(FONT_HEIGHT/3 - j/3), startY+j, color); + if(_bold){ + for(uint8_t z=0; z<2; z++) + drawPixel(startX+i-z+(FONT_HEIGHT/3- j/3), startY+j, color); + } + } + else{ + drawPixel(startX+i, startY+j, color); + if(_bold){ + for(uint8_t z=0; z<2; z++) + drawPixel(startX+i-z, startY+j, color); + } + } + } + } + } +} + +void GDEP015OC1::writeString(char *string, uint16_t startX, uint16_t startY, bool color=0){ + uint8_t length = 0; + while(*(string+length) != '\0') length++; + + for(uint8_t x=0; x<length; x++) + writeChar(*(string+x), startX+(FONT_WIDTH)*x, startY, color); } \ No newline at end of file