Diff: PCD8544LCD.cpp
- Revision:
- 1:ce391193b822
- Parent:
- 0:6468a28a7b7d
--- a/PCD8544LCD.cpp Sun Apr 17 18:03:24 2011 +0000
+++ b/PCD8544LCD.cpp Thu May 19 18:06:13 2011 +0000
@@ -37,6 +37,8 @@
#include "DebugTrace.h"
#include "sstream"
+#include "stdio.h"
+#include "stringman.h"
DebugTrace pc_PCD8544(ON, TO_SERIAL);
@@ -55,7 +57,7 @@
+-------------------------+
| 1 2 3 4 5 6 7 8 |
| # # # # # # # # |
- | ===#=#=#=#=#=#=#=#=== | Red 1 .. VDD - chip power supply +3.3V
+ | ===#=#=#=#=#=#=#=#=== | Red 1 .. VDD - chip power supply +3.3V
+--=====================--+ Green 2 .. SCLK - serial clock line of LCD
| | Yellow 3 .. SI - serial data input of LCD
| | Gray 4 .. D/C - command/data switch
@@ -68,6 +70,7 @@
*/
+
PCD8544LCD::PCD8544LCD (PinName mosi, PinName miso, PinName sck,
PinName cs, PinName data_cmd, PinName reset):
_spi(mosi, miso, sck),
@@ -83,6 +86,7 @@
void PCD8544LCD::init() {
+ pc_PCD8544.traceOut("Init PCD8544\r\n");
_spi.format(8,0);
_spi.frequency(1000000);
@@ -114,8 +118,11 @@
writeCmd(NORMAL_MODE);
- _LoMark = LCD_CACHE_SIZE; // Reset watermark pointers.
- _HiMark = 0;
+
+ _LoMark = 0;
+ _HiMark = LCD_CACHE_SIZE - 1;
+ //_LoMark = LCD_CACHE_SIZE; // Reset watermark pointers.
+ // _HiMark = 0;
cls();
}
@@ -142,13 +149,14 @@
// GRAPHICAL functions
-void PCD8544LCD::cls() {
+void PCD8544LCD::cls(bool fupdate) {
for (int i = 0; i < LCD_CACHE_SIZE ; i++) {
- _LcdCache[i]=0x00;
+ LcdCache[i]=0x00;
}
_LoMark = 0;
_HiMark = LCD_CACHE_SIZE - 1;
- update();
+ if (fupdate)
+ update();
}
void PCD8544LCD::update() {
@@ -166,7 +174,7 @@
writeCmd(SET_ADDRES_Y | (_LoMark / LCD_X_RES));
for (int i = _LoMark; i <= _HiMark; i++ ) {
- writeData( _LcdCache[i]);
+ writeData( LcdCache[i]);
}
_LoMark = LCD_CACHE_SIZE - 1;
_HiMark = 0;
@@ -175,12 +183,12 @@
void PCD8544LCD::locate(BYTE x0, BYTE y0) {
- _LcdCacheIdx = x0*LCD_BANKS + y0 * LCD_X_RES;
+ LcdCacheIdx = x0*LCD_BANKS + y0 * LCD_X_RES;
}
// Bitmap
-void PCD8544LCD::drawBitmap(BYTE x0, BYTE y0, BYTE* bitmap, BYTE bmpXSize, BYTE bmpYSize,BYTE fupdate) {
+void PCD8544LCD::drawBitmap(BYTE x0, BYTE y0, const unsigned char* bitmap, BYTE bmpXSize, BYTE bmpYSize,BYTE fupdate) {
BYTE row;
if (0 == bmpYSize % 8)
@@ -195,7 +203,7 @@
locate(x0, y0);
for (BYTE i = 0; i < bmpXSize; i++) {
- _LcdCache[_LcdCacheIdx+ i]=bitmap[i + (n * bmpXSize)];
+ LcdCache[LcdCacheIdx+ i]=bitmap[i + (n * bmpXSize)];
}
y0++;
}
@@ -203,13 +211,15 @@
update();
}
-void PCD8544LCD::writeString(BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode mode,BYTE fupdate) {
+void PCD8544LCD::writeString(BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode dmode,eSpaceMode smode, BYTE fupdate) {
locate(x0, y0);
chooseFont(font);
while (*string) {
- writeChar(x0,y0,*string++,font, mode, FALSE);
+ writeChar(x0,y0,*string++,font, dmode, FALSE);
x0+=_font_width; // width +1;
+ if (smode==SPACE_NORMAL)
+ x0++;
}
if (fupdate==TRUE)
update();
@@ -336,7 +346,7 @@
index = ((y0 / 8) * LCD_X_RES) + x0;
offset = y0 - ((y0 / 8) * 8);
- data = _LcdCache[index];
+ data = LcdCache[index];
if ( mode == PIXEL_OFF ) {
data &= (~(0x01 << offset));
@@ -345,7 +355,7 @@
} else if ( mode == PIXEL_XOR ) {
data ^= (0x01 << offset);
}
- _LcdCache[index] = data;
+ LcdCache[index] = data;
if ( index < _LoMark ) {
_LoMark = index;
@@ -446,119 +456,130 @@
}
void PCD8544LCD::drawchart(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE unitx, BYTE unity,
- eRasterMode rmode,signed char * val, int start, int count) {
- BYTE miny,endy,maxy;
-
- drawrectangle(x0,y0-h,x0+w,y0,FILL_OFF,PIXEL_ON,FALSE);
+ eRasterMode rMode, eChartMode cMode,eDrawMode dMode, int16_t * val, int size, int t) {
+ int maxy;
+ int _scale=1;
+ int prescale=1;
- for (int i=0;i<h;i++) {
- if ((i % unity) == 0) {
- drawpixel(x0-2,y0-i,PIXEL_ON,FALSE);
- drawpixel(x0+w+2,y0-i,PIXEL_ON,FALSE);
+ signed char v1,v2;
+ char buffer[4];
- if (rmode==RASTER_ON) {
- for (int r=0;r<w;r++) {
- if ((r % 2) ==0)
- drawpixel(x0+r,y0-i,PIXEL_ON,FALSE);
- }
- }
- }
- if ((i % 2) == 0) {
- drawpixel(x0-1,y0-i,PIXEL_ON,FALSE);
- drawpixel(x0+w+1,y0-i,PIXEL_ON,FALSE);
- }
- }
+ if (size>w)
+ size=w;
- for (int i=0;i<w;i++) {
- if ((i % unitx) == 0) {
- drawpixel(x0+i,y0-1,PIXEL_ON,FALSE);
+ // search maximum value to calculate scale
+ if (dMode==DRAW_OVERWRITE) {
+ maxy=0;
+ for (int i=0; i<size;i++) {
+ if (val[i]>maxy)
+ maxy=val[i];
- if (rmode==RASTER_ON) {
- for (int r=0;r<h;r++) {
- if ((r % 2) ==0)
- drawpixel(x0+i,y0-r,PIXEL_ON,FALSE);
- }
- }
- }
- if ((i % 2) == 0) {
- drawpixel(x0+i,y0+1,PIXEL_ON,FALSE);
- }
- }
-/*
- // clear axis area
- drawrectangle(x0-9,y0-1,x0-3,y0-h,FILL_ON,PIXEL_OFF,FALSE);
- drawrectangle(x0-4,y0+3,x0+w+2,y0+7,FILL_ON,PIXEL_OFF,FALSE);
- */
- //write labels Axis X
+ }
- //draw data values
- //axisy halen uit minimum ans maximum value van timeframe
-
+ if (maxy>h) { //scale can be 1,2,5 *10i
+ prescale= ((maxy-1)/((h/unity)*unity));
+ _scale=1;
+ while (prescale>10) {
+ _scale=_scale*10;
+ prescale=prescale/10;
+ }
+ if (prescale>1)
+ _scale=_scale*5;
+ else
+ if (prescale==1)
+ _scale =_scale*2;
- endy = ((val[start+count] / unity))*unity;
- maxy=0;
- miny =10;
- for ( int i=start; i<start+count-1;i++) {
- if (maxy < ((val[start+count] / unity)+1)*unity)
- maxy=(((val[start+count] / unity)+1)*unity);
- if (miny > ((val[start+count] / unity))*unity)
- miny=((val[start+count] / unity)*unity);
+ }
+ Scale=_scale;
}
- // TODO check this
- // if ((maxy-miny)>h) // problems screen is not high enough
- miny =10; //(h- (maxy-endy));
+ if (dMode==DRAW_OVERWRITE) {
+ drawrectangle(x0-11,y0-h,x0+w,y0+4+7,FILL_ON,PIXEL_OFF,FALSE);
+ drawline(x0,y0,x0,y0-h,PIXEL_ON,FALSE);
+ drawline(x0,y0,x0+w,y0,PIXEL_ON,FALSE);
+
+ //drawrectangle(x0,y0-h,x0+w,y0,FILL_OFF,PIXEL_ON,FALSE);
+
+ for (int i=0;i<=h;i++) {
+ if ((i % unity) == 0) {
+ drawpixel(x0-2,y0-i,PIXEL_ON,FALSE);
+ // drawpixel(x0+w+2,y0-i,PIXEL_ON,FALSE);
- signed char v1,v2;
-
- if (count>w)
- count=w;
+ if (rMode==RASTER_ON) {
+ for (int r=0;r<=w;r++) {
+ if ((r % 2) ==0)
+ drawpixel(x0+r,y0-i,PIXEL_ON,FALSE);
+ }
+ }
+ // draw vertical axis labels
- for (int i=0; i<count-1;i++) {
- v1 = val[i+start]*0.5;
-
-
- /*if ((v1-miny)<=0)
- v1=miny;
+ itostr(buffer,i*Scale);
+
+ // pc_PCD8544.traceOut(" %i %s |",i*Scale,buffer);
+ writeString(x0-11,y0-i+1,buffer,VERYSMALLFONT,NORMAL,SPACE_NONE,FALSE);
- if ((v1-miny)>=h)
- v1=v1*0.5;*/
-
- //pc_PCD8544.traceOut("v1=%i ",v1);
-
- v2 = val[i+start+1]*0.5;
-
- //pc_PCD8544.traceOut("v2=%i",v2);
-/*
- if ((v2-miny)<=0)
- v2=miny;
+ }
+ if ((i % 2) == 0) {
+ drawpixel(x0-1,y0-i,PIXEL_ON,FALSE);
+ // drawpixel(x0+w+1,y0-i,PIXEL_ON,FALSE);
+ }
+ }
+
+ for (int i=0;i<=w;i++) {
+ if (((i+(t % unitx)) % unitx) == 0) {
+ drawpixel(x0+i,y0+2,PIXEL_ON,FALSE);
- if ((v2-miny)>=h)
- v2=h;*/
-
- //drawpixel(x0+i,y0-v1,PIXEL_ON,FALSE);
-
- drawline(x0+i,y0-v1,x0+i+1,y0-v2,PIXEL_ON,FALSE);
+ if (rMode==RASTER_ON) {
+ for (int r=0;r<=h;r++) {
+ if ((r % 2) ==0)
+ drawpixel(x0+i,y0-r,PIXEL_ON,FALSE);
+ }
+ }
+ if (((t-w+i)/unitx)>=0)
+ snprintf(buffer,3,"%i",((t-w+i)/unitx));
+ else
+ snprintf(buffer,3,"%i",24+((t-w+i)/unitx));
+
+ // pc_PCD8544.traceOut(" %i %s ",(t-w+i)/unitx,buffer);
+ writeString(x0+i-3,y0+4,buffer,VERYSMALLFONT,NORMAL,SPACE_NORMAL,FALSE);
+ }
+ if ((i % 2) == 0) {
+ drawpixel(x0+i,y0+1,PIXEL_ON,FALSE);
+ }
+ }
+ // update();
}
- /*
+ for (int i=0;i<size;i++) {
+ // pc_PCD8544.traceOut(" %i ",val[i]);
+ v1 = val[i] / Scale;
+ if (v1>h)
+ v1=h;
- BYTE V;
- char s[2];
+ if (i!=(size-1)) {
+ v2 = val[i+1] / Scale;
+ if (v2>h)
+ v2=h;
+ } else
+ v2=v1;
- for (int i=0;i<unitx;i++){
- V=axisx+i*axisunitx;
- std::string s;
- std::stringstream out;
- out << V;
- s = out.str();
-
- if (B>10)
- writeString(x0-4,0,"Hallo Pieter-Jan",TINYFONT,NORMAL,TRUE);
- }
- }*/
+ switch (cMode) {
+ case C_POINT: {
+ drawpixel(x0+i,y0-v1,PIXEL_ON,FALSE);
+ break;
+ }
+ case C_LINE: {
+ drawline(x0+i,y0-v1,x0+i+1,y0-v2,PIXEL_ON,FALSE);
+ break;
+ }
+ case C_VLINE: {
+ drawline(x0+i,y0-v1,x0+i,y0,PIXEL_ON,FALSE);
+ break;
+ }
+ }
+ }
update();
}