2 * GraphLCD driver library
4 * simlcd.c - SimLCD driver class
5 * Output goes to a file instead of lcd.
6 * Use SimLCD tool to view this file.
8 * This file is released under the GNU General Public License. Refer
9 * to the COPYING file distributed with this package.
11 * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de>
25 cDriverSimLCD::cDriverSimLCD(cDriverConfig * config)
28 oldConfig = new cDriverConfig(*config);
31 cDriverSimLCD::~cDriverSimLCD()
36 int cDriverSimLCD::Init()
38 width = config->width;
41 height = config->height;
45 for (unsigned int i = 0; i < config->options.size(); i++)
47 if (config->options[i].name == "")
53 LCD = new unsigned char *[(width + 7) / 8];
56 for (int x = 0; x < (width + 7) / 8; x++)
58 LCD[x] = new unsigned char[height];
59 memset(LCD[x], 0, height);
68 syslog(LOG_INFO, "%s: SIMLCD initialized.\n", config->name.c_str());
72 int cDriverSimLCD::DeInit()
77 for (int x = 0; x < (width + 7) / 8; x++)
87 int cDriverSimLCD::CheckSetup()
89 if (config->width != oldConfig->width ||
90 config->height != oldConfig->height)
97 if (config->upsideDown != oldConfig->upsideDown ||
98 config->invert != oldConfig->invert)
100 oldConfig->upsideDown = config->upsideDown;
101 oldConfig->invert = config->invert;
107 void cDriverSimLCD::Clear()
109 for (int x = 0; x < (width + 7) / 8; x++)
110 memset(LCD[x], 0, height);
113 void cDriverSimLCD::Set8Pixels(int x, int y, unsigned char data)
115 if (x >= width || y >= height)
118 if (!config->upsideDown)
120 // normal orientation
121 LCD[x / 8][y] = LCD[x / 8][y] | data;
125 // upside down orientation
128 LCD[x / 8][y] = LCD[x / 8][y] | ReverseBits(data);
132 void cDriverSimLCD::Refresh(bool refreshAll)
140 if (CheckSetup() > 0)
143 fp = fopen("/tmp/simlcd.sem", "r");
144 if (!fp || refreshAll)
148 fp = fopen("/tmp/simlcd.dat", "w");
151 for (y = 0; y < height; y++)
153 for (x = 0; x < (width + 7) / 8; x++)
155 c = LCD[x][y] ^ (config->invert ? 0xff : 0x00);
156 for (i = 0; i < 8; i++)
174 fp = fopen("/tmp/simlcd.sem", "w");
183 } // end of namespace