diff options
Diffstat (limited to 'glcddrivers/simlcd.c')
-rw-r--r-- | glcddrivers/simlcd.c | 114 |
1 files changed, 74 insertions, 40 deletions
diff --git a/glcddrivers/simlcd.c b/glcddrivers/simlcd.c index 6dc1dfe..d1da90f 100644 --- a/glcddrivers/simlcd.c +++ b/glcddrivers/simlcd.c @@ -9,6 +9,8 @@ * to the COPYING file distributed with this package. * * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de> + * (c) 2011 Dirk Heiser + * (c) 2011 Wolfgang Astleitner <mrwastl AT users.sourceforge.net> */ #include <stdio.h> @@ -19,22 +21,22 @@ #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" -namespace GLCD -{ +#define FG_CHAR "#" +#define BG_CHAR "." -cDriverSimLCD::cDriverSimLCD(cDriverConfig * config) -: config(config) +namespace GLCD { - oldConfig = new cDriverConfig(*config); -} -cDriverSimLCD::~cDriverSimLCD() +cDriverSimLCD::cDriverSimLCD(cDriverConfig * config) : cDriver(config) { - delete oldConfig; } -int cDriverSimLCD::Init() +int cDriverSimLCD::Init(void) { width = config->width; if (width <= 0) @@ -51,13 +53,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 +72,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 +87,7 @@ int cDriverSimLCD::DeInit() return 0; } -int cDriverSimLCD::CheckSetup() +int cDriverSimLCD::CheckSetup(void) { if (config->width != oldConfig->width || config->height != oldConfig->height) @@ -105,29 +107,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] = GRAPHLCD_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 +137,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] == GRAPHLCD_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,"."); + fprintf(fp,BG_CHAR); + } else + { + fprintf(fp,FG_CHAR); } - c = c << 1; } } fprintf(fp,"\n"); @@ -172,7 +179,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 +188,31 @@ void cDriverSimLCD::Refresh(bool refreshAll) } } +uint32_t cDriverSimLCD::GetBackgroundColor(void) +{ + return GRAPHLCD_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 |