diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-28 11:12:15 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-28 11:12:15 +0200 |
commit | 219dd7dd5d52d07032b4129a96499c7cbe7a4ab3 (patch) | |
tree | 9002f86bc372c390743d149d6be79c2cdaef8a75 | |
parent | 84efb00f6b7b30ddbfd0551aae3130e86c90562c (diff) | |
download | graphlcd-base-219dd7dd5d52d07032b4129a96499c7cbe7a4ab3.tar.gz graphlcd-base-219dd7dd5d52d07032b4129a96499c7cbe7a4ab3.tar.bz2 |
updated simlcd-driver (diff contributed by user 'Keine_Ahnung')
-rw-r--r-- | glcddrivers/simlcd.c | 105 | ||||
-rw-r--r-- | glcddrivers/simlcd.h | 6 |
2 files changed, 76 insertions, 35 deletions
diff --git a/glcddrivers/simlcd.c b/glcddrivers/simlcd.c index 6dc1dfe..787648a 100644 --- a/glcddrivers/simlcd.c +++ b/glcddrivers/simlcd.c @@ -19,6 +19,13 @@ #include "config.h" #include "simlcd.h" +#define DISPLAY_REFRESH_FILE "/tmp/simlcd.sem" +#define DISPLAY_DATA_FILE "/tmp/simlcd.dat" +#define TOUCH_REFRESH_FILE "/tmp/simtouch.sem" +#define TOUCH_DATA_FILE "/tmp/simtouch.dat" + +#define FG_CHAR "#" +#define BG_CHAR "." namespace GLCD { @@ -29,12 +36,12 @@ cDriverSimLCD::cDriverSimLCD(cDriverConfig * config) oldConfig = new cDriverConfig(*config); } -cDriverSimLCD::~cDriverSimLCD() +cDriverSimLCD::~cDriverSimLCD(void) { delete oldConfig; } -int cDriverSimLCD::Init() +int cDriverSimLCD::Init(void) { width = config->width; if (width <= 0) @@ -51,13 +58,13 @@ int cDriverSimLCD::Init() } // setup lcd array - LCD = new unsigned char *[(width + 7) / 8]; + LCD = new uint32_t *[width]; if (LCD) { - for (int x = 0; x < (width + 7) / 8; x++) + for (int x = 0; x < width; x++) { - LCD[x] = new unsigned char[height]; - memset(LCD[x], 0, height); + LCD[x] = new uint32_t[height]; + //memset(LCD[x], 0, height); } } @@ -70,12 +77,12 @@ int cDriverSimLCD::Init() return 0; } -int cDriverSimLCD::DeInit() +int cDriverSimLCD::DeInit(void) { // free lcd array if (LCD) { - for (int x = 0; x < (width + 7) / 8; x++) + for (int x = 0; x < width; x++) { delete[] LCD[x]; } @@ -85,7 +92,7 @@ int cDriverSimLCD::DeInit() return 0; } -int cDriverSimLCD::CheckSetup() +int cDriverSimLCD::CheckSetup(void) { if (config->width != oldConfig->width || config->height != oldConfig->height) @@ -105,29 +112,29 @@ int cDriverSimLCD::CheckSetup() return 0; } -void cDriverSimLCD::Clear() +void cDriverSimLCD::Clear(void) { - for (int x = 0; x < (width + 7) / 8; x++) - memset(LCD[x], 0, height); + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + LCD[x][y] = GLCD::cColor::White; + } + } } -void cDriverSimLCD::Set8Pixels(int x, int y, unsigned char data) +void cDriverSimLCD::SetPixel(int x, int y, uint32_t data) { if (x >= width || y >= height) return; - if (!config->upsideDown) - { - // normal orientation - LCD[x / 8][y] = LCD[x / 8][y] | data; - } - else + if (config->upsideDown) { // upside down orientation x = width - 1 - x; y = height - 1 - y; - LCD[x / 8][y] = LCD[x / 8][y] | ReverseBits(data); } + LCD[x][y] = data; } void cDriverSimLCD::Refresh(bool refreshAll) @@ -135,36 +142,41 @@ void cDriverSimLCD::Refresh(bool refreshAll) FILE * fp = NULL; int x; int y; - int i; - unsigned char c; if (CheckSetup() > 0) refreshAll = true; - fp = fopen("/tmp/simlcd.sem", "r"); + fp = fopen(DISPLAY_REFRESH_FILE, "r"); if (!fp || refreshAll) { if (fp) fclose(fp); - fp = fopen("/tmp/simlcd.dat", "w"); + fp = fopen(DISPLAY_DATA_FILE, "w"); if (fp) { for (y = 0; y < height; y++) { - for (x = 0; x < (width + 7) / 8; x++) + for (x = 0; x < width; x++) { - c = LCD[x][y] ^ (config->invert ? 0xff : 0x00); - for (i = 0; i < 8; i++) + if (LCD[x][y] == GLCD::cColor::Black) { - if (c & 0x80) + if (!config->invert) { - fprintf(fp,"#"); + fprintf(fp,FG_CHAR); + } else + { + fprintf(fp,BG_CHAR); } - else + } + else + { + if (!config->invert) + { + fprintf(fp,BG_CHAR); + } else { - fprintf(fp,"."); + fprintf(fp,FG_CHAR); } - c = c << 1; } } fprintf(fp,"\n"); @@ -172,7 +184,7 @@ void cDriverSimLCD::Refresh(bool refreshAll) fclose(fp); } - fp = fopen("/tmp/simlcd.sem", "w"); + fp = fopen(DISPLAY_REFRESH_FILE, "w"); fclose(fp); } else @@ -181,4 +193,31 @@ void cDriverSimLCD::Refresh(bool refreshAll) } } +GLCD::cColor cDriverSimLCD::GetBackgroundColor(void) +{ + return GLCD::cColor::White; +} + +bool cDriverSimLCD::GetDriverFeature(const std::string & Feature, int & value) +{ + if (strcasecmp(Feature.c_str(), "depth") == 0) { + value = 1; + return true; + } else if (strcasecmp(Feature.c_str(), "ismonochrome") == 0) { + value = true; + return true; + } else if (strcasecmp(Feature.c_str(), "isgreyscale") == 0 || strcasecmp(Feature.c_str(), "isgrayscale") == 0) { + value = false; + return true; + } else if (strcasecmp(Feature.c_str(), "iscolour") == 0 || strcasecmp(Feature.c_str(), "iscolor") == 0) { + value = false; + return true; + } else if (strcasecmp(Feature.c_str(), "touch") == 0 || strcasecmp(Feature.c_str(), "touchscreen") == 0) { + value = false; + return true; + } + value = 0; + return false; +} + } // end of namespace diff --git a/glcddrivers/simlcd.h b/glcddrivers/simlcd.h index 8b2aca8..750fa81 100644 --- a/glcddrivers/simlcd.h +++ b/glcddrivers/simlcd.h @@ -25,7 +25,7 @@ class cDriverConfig; class cDriverSimLCD : public cDriver { private: - unsigned char ** LCD; + uint32_t ** LCD; cDriverConfig * config; cDriverConfig * oldConfig; @@ -39,8 +39,10 @@ public: virtual int DeInit(); virtual void Clear(); - virtual void Set8Pixels(int x, int y, unsigned char data); + virtual void SetPixel(int x, int y, uint32_t data); virtual void Refresh(bool refreshAll = false); + virtual GLCD::cColor GetBackgroundColor(void); + virtual bool GetDriverFeature (const std::string & Feature, int & value); }; } // end of namespace |