root@4
|
1 |
/*
|
root@4
|
2 |
* GraphLCD driver library
|
root@4
|
3 |
*
|
root@4
|
4 |
* serdisp.h - include support for displays supported by serdisplib (if library is installed)
|
root@4
|
5 |
* http://serdisplib.sourceforge.net
|
root@4
|
6 |
*
|
root@4
|
7 |
* This file is released under the GNU General Public License. Refer
|
root@4
|
8 |
* to the COPYING file distributed with this package.
|
root@4
|
9 |
*
|
root@4
|
10 |
* (c) 2003-2005 Wolfgang Astleitner <mrwastl AT users.sourceforge.net>
|
root@4
|
11 |
*/
|
root@4
|
12 |
|
root@4
|
13 |
#include <stdio.h>
|
root@4
|
14 |
#include <stdlib.h>
|
root@4
|
15 |
#include <syslog.h>
|
root@4
|
16 |
#include <dlfcn.h>
|
root@4
|
17 |
|
root@4
|
18 |
#include "common.h"
|
root@4
|
19 |
#include "config.h"
|
root@4
|
20 |
#include "serdisp.h"
|
root@4
|
21 |
|
root@4
|
22 |
#define SERDISP_VERSION(a,b) ((long)(((a) << 8) + (b)))
|
root@4
|
23 |
#define SERDISP_VERSION_GET_MAJOR(_c) ((int)( (_c) >> 8 ))
|
root@4
|
24 |
#define SERDISP_VERSION_GET_MINOR(_c) ((int)( (_c) & 0xFF ))
|
root@4
|
25 |
|
root@4
|
26 |
// taken from serdisp_control.h
|
root@4
|
27 |
#define FEATURE_CONTRAST 0x01
|
root@4
|
28 |
#define FEATURE_REVERSE 0x02
|
root@4
|
29 |
#define FEATURE_BACKLIGHT 0x03
|
root@4
|
30 |
#define FEATURE_ROTATE 0x04
|
root@4
|
31 |
|
root@4
|
32 |
#define SD_COL_BLACK 0xFF000000
|
root@4
|
33 |
|
root@4
|
34 |
namespace GLCD
|
root@4
|
35 |
{
|
root@4
|
36 |
|
root@4
|
37 |
cDriverSerDisp::cDriverSerDisp(cDriverConfig * config)
|
root@4
|
38 |
: config(config)
|
root@4
|
39 |
{
|
root@4
|
40 |
oldConfig = new cDriverConfig(*config);
|
root@4
|
41 |
|
root@4
|
42 |
dd = (void *) NULL;
|
root@4
|
43 |
}
|
root@4
|
44 |
|
root@4
|
45 |
cDriverSerDisp::~cDriverSerDisp(void)
|
root@4
|
46 |
{
|
root@4
|
47 |
delete oldConfig;
|
root@4
|
48 |
}
|
root@4
|
49 |
|
root@4
|
50 |
int cDriverSerDisp::Init(void)
|
root@4
|
51 |
{
|
root@4
|
52 |
char* errmsg; // error message returned by dlerror()
|
root@4
|
53 |
|
root@4
|
54 |
std::string controller;
|
root@4
|
55 |
std::string optionstring = "";
|
root@4
|
56 |
std::string wiringstring;
|
root@4
|
57 |
|
root@4
|
58 |
|
root@4
|
59 |
// dynamically load serdisplib using dlopen() & co.
|
root@4
|
60 |
|
root@4
|
61 |
sdhnd = dlopen("libserdisp.so", RTLD_LAZY);
|
root@4
|
62 |
if (!sdhnd) { // try /usr/local/lib
|
root@4
|
63 |
sdhnd = dlopen("/usr/local/lib/libserdisp.so", RTLD_LAZY);
|
root@4
|
64 |
}
|
root@4
|
65 |
|
root@4
|
66 |
if (!sdhnd) { // serdisplib seems not to be installed
|
root@4
|
67 |
syslog(LOG_ERR, "%s: error: unable to dynamically load library '%s'. Err: %s (cDriver::Init)\n",
|
root@4
|
68 |
config->name.c_str(), "libserdisp.so", "not found");
|
root@4
|
69 |
return -1;
|
root@4
|
70 |
}
|
root@4
|
71 |
|
root@4
|
72 |
dlerror(); // clear error code
|
root@4
|
73 |
|
root@4
|
74 |
/* pre-init some flags, function pointers, ... */
|
root@4
|
75 |
supports_options = 0;
|
root@4
|
76 |
fg_colour = 1;
|
root@4
|
77 |
bg_colour = -1;
|
root@4
|
78 |
|
root@4
|
79 |
// get serdisp version
|
root@4
|
80 |
fp_serdisp_getversioncode = (long int (*)()) dlsym(sdhnd, "serdisp_getversioncode");
|
root@4
|
81 |
|
root@4
|
82 |
if (dlerror()) { // no serdisp_getversioncode() -> version of serdisplib is < 1.95
|
root@4
|
83 |
syslog(LOG_DEBUG, "%s: INFO: symbol serdisp_getversioncode unknown: autodetecting pre 1.95 serdisplib version (cDriver::Init)\n",
|
root@4
|
84 |
config->name.c_str());
|
root@4
|
85 |
|
root@4
|
86 |
fp_SDCONN_open = (void*(*)(const char*)) dlsym(sdhnd, "SDCONN_open");
|
root@4
|
87 |
if (dlerror()) { // no SDCONN_open() -> version of serdisplib is < 1.93
|
root@4
|
88 |
serdisp_version = SERDISP_VERSION(1,92);
|
root@4
|
89 |
syslog(LOG_DEBUG, "%s: INFO: detected serdisplib version <= 1.92 (cDriver::Init)\n", config->name.c_str());
|
root@4
|
90 |
|
root@4
|
91 |
fp_PP_open = (void*(*)(const char*))dlsym(sdhnd, "PP_open");
|
root@4
|
92 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
93 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
94 |
config->name.c_str(), "PP_open", errmsg);
|
root@4
|
95 |
return -1;
|
root@4
|
96 |
}
|
root@4
|
97 |
fp_PP_close = (void*(*)(void*))dlsym(sdhnd, "PP_close");
|
root@4
|
98 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
99 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
100 |
config->name.c_str(), "PP_close", errmsg);
|
root@4
|
101 |
return -1;
|
root@4
|
102 |
}
|
root@4
|
103 |
} else {
|
root@4
|
104 |
serdisp_version = SERDISP_VERSION(1,94); // no serdisp_getversioncode, but SDCONN_open: 1.93 or 1.94
|
root@4
|
105 |
syslog(LOG_DEBUG, "%s: INFO: detected serdisplib version 1.93 or 1.94 (cDriver::Init)\n", config->name.c_str());
|
root@4
|
106 |
|
root@4
|
107 |
fp_serdisp_quit = (void (*)(void*)) dlsym(sdhnd, "serdisp_quit");
|
root@4
|
108 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
109 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
110 |
config->name.c_str(), "serdisp_quit", errmsg);
|
root@4
|
111 |
return -1;
|
root@4
|
112 |
}
|
root@4
|
113 |
}
|
root@4
|
114 |
|
root@4
|
115 |
fp_serdisp_setpixcol = (void (*)(void*, int, int, long int)) dlsym(sdhnd, "serdisp_setpixel");
|
root@4
|
116 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
117 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
118 |
config->name.c_str(), "serdisp_setpixel", errmsg);
|
root@4
|
119 |
return -1;
|
root@4
|
120 |
}
|
root@4
|
121 |
fg_colour = 1; /* set foreground to 'pixel on' */
|
root@4
|
122 |
|
root@4
|
123 |
} else { // serdisp version >= 1.95
|
root@4
|
124 |
serdisp_version = fp_serdisp_getversioncode();
|
root@4
|
125 |
syslog(LOG_DEBUG, "%s: INFO: detected serdisplib version %d.%d (cDriver::Init)\n",
|
root@4
|
126 |
config->name.c_str(), SERDISP_VERSION_GET_MAJOR(serdisp_version), SERDISP_VERSION_GET_MINOR(serdisp_version));
|
root@4
|
127 |
|
root@4
|
128 |
|
root@4
|
129 |
fp_SDCONN_open = (void*(*)(const char*)) dlsym(sdhnd, "SDCONN_open");
|
root@4
|
130 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
131 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
132 |
config->name.c_str(), "SDCONN_open", errmsg);
|
root@4
|
133 |
return -1;
|
root@4
|
134 |
}
|
root@4
|
135 |
fp_serdisp_quit = (void (*)(void*)) dlsym(sdhnd, "serdisp_quit");
|
root@4
|
136 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
137 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
138 |
config->name.c_str(), "serdisp_quit", errmsg);
|
root@4
|
139 |
return -1;
|
root@4
|
140 |
}
|
root@4
|
141 |
fp_serdisp_setpixcol = (void (*)(void*, int, int, long int)) dlsym(sdhnd, "serdisp_setcolour");
|
root@4
|
142 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
143 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
144 |
config->name.c_str(), "serdisp_setcolour", errmsg);
|
root@4
|
145 |
return -1;
|
root@4
|
146 |
}
|
root@4
|
147 |
fg_colour = SD_COL_BLACK; /* set foreground colour to black */
|
root@4
|
148 |
|
root@4
|
149 |
if (serdisp_version >= SERDISP_VERSION(1,96) ) {
|
root@4
|
150 |
supports_options = 1;
|
root@4
|
151 |
|
root@4
|
152 |
fp_serdisp_isoption = (int (*)(void*, const char*)) dlsym(sdhnd, "serdisp_isoption");
|
root@4
|
153 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
154 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
155 |
config->name.c_str(), "serdisp_isoption", errmsg);
|
root@4
|
156 |
return -1;
|
root@4
|
157 |
}
|
root@4
|
158 |
fp_serdisp_setoption = (void (*)(void*, const char*, long int)) dlsym(sdhnd, "serdisp_setoption");
|
root@4
|
159 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
160 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
161 |
config->name.c_str(), "serdisp_setoption", errmsg);
|
root@4
|
162 |
return -1;
|
root@4
|
163 |
}
|
root@4
|
164 |
} /* >= 1.96 */
|
root@4
|
165 |
}
|
root@4
|
166 |
|
root@4
|
167 |
// load other symbols that will be required
|
root@4
|
168 |
fp_serdisp_init = (void*(*)(void*, const char*, const char*)) dlsym(sdhnd, "serdisp_init");
|
root@4
|
169 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
170 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
171 |
config->name.c_str(), "serdisp_init", errmsg);
|
root@4
|
172 |
return -1;
|
root@4
|
173 |
}
|
root@4
|
174 |
|
root@4
|
175 |
fp_serdisp_rewrite = (void (*)(void*)) dlsym(sdhnd, "serdisp_rewrite");
|
root@4
|
176 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
177 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
178 |
config->name.c_str(), "serdisp_rewrite", errmsg);
|
root@4
|
179 |
return -1;
|
root@4
|
180 |
}
|
root@4
|
181 |
|
root@4
|
182 |
fp_serdisp_update = (void (*)(void*)) dlsym(sdhnd, "serdisp_update");
|
root@4
|
183 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
184 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
185 |
config->name.c_str(), "serdisp_update", errmsg);
|
root@4
|
186 |
return -1;
|
root@4
|
187 |
}
|
root@4
|
188 |
|
root@4
|
189 |
fp_serdisp_clearbuffer = (void (*)(void*)) dlsym(sdhnd, "serdisp_clearbuffer");
|
root@4
|
190 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
191 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
192 |
config->name.c_str(), "serdisp_clearbuffer", errmsg);
|
root@4
|
193 |
return -1;
|
root@4
|
194 |
}
|
root@4
|
195 |
|
root@4
|
196 |
fp_serdisp_feature = (int (*)(void*, int, int)) dlsym(sdhnd, "serdisp_feature");
|
root@4
|
197 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
198 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
199 |
config->name.c_str(), "serdisp_feature", errmsg);
|
root@4
|
200 |
return -1;
|
root@4
|
201 |
}
|
root@4
|
202 |
|
root@4
|
203 |
fp_serdisp_close = (void (*)(void*))dlsym(sdhnd, "serdisp_close");
|
root@4
|
204 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
205 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
206 |
config->name.c_str(), "serdisp_close", errmsg);
|
root@4
|
207 |
return -1;
|
root@4
|
208 |
}
|
root@4
|
209 |
|
root@4
|
210 |
fp_serdisp_getwidth = (int (*)(void*)) dlsym(sdhnd, "serdisp_getwidth");
|
root@4
|
211 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
212 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
213 |
config->name.c_str(), "serdisp_getwidth", errmsg);
|
root@4
|
214 |
return -1;
|
root@4
|
215 |
}
|
root@4
|
216 |
|
root@4
|
217 |
fp_serdisp_getheight = (int (*)(void*)) dlsym(sdhnd, "serdisp_getheight");
|
root@4
|
218 |
if ( (errmsg = dlerror()) != NULL ) { // should not happen
|
root@4
|
219 |
syslog(LOG_ERR, "%s: error: cannot load symbol %s. Err:%s (cDriver::Init)\n",
|
root@4
|
220 |
config->name.c_str(), "serdisp_getheight", errmsg);
|
root@4
|
221 |
return -1;
|
root@4
|
222 |
}
|
root@4
|
223 |
|
root@4
|
224 |
// done loading all required symbols
|
root@4
|
225 |
|
root@4
|
226 |
|
root@4
|
227 |
// setting up the display
|
root@4
|
228 |
width = 0;
|
root@4
|
229 |
height = 0;
|
root@4
|
230 |
|
root@4
|
231 |
for (unsigned int i = 0; i < config->options.size(); i++)
|
root@4
|
232 |
{
|
root@4
|
233 |
if (config->options[i].name == "Controller") {
|
root@4
|
234 |
controller = config->options[i].value;
|
root@4
|
235 |
} else if (config->options[i].name == "Options") {
|
root@4
|
236 |
optionstring = config->options[i].value;
|
root@4
|
237 |
} else if (config->options[i].name == "Wiring") {
|
root@4
|
238 |
wiringstring = config->options[i].value;
|
root@4
|
239 |
} else if (config->options[i].name == "FGColour") {
|
root@4
|
240 |
fg_colour = strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
|
root@4
|
241 |
fg_colour |= 0xFF000000L; /* force alpha to 0xFF */
|
root@4
|
242 |
} else if (config->options[i].name == "BGColour") {
|
root@4
|
243 |
bg_colour = strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
|
root@4
|
244 |
bg_colour |= 0xFF000000L; /* force alpha to 0xFF */
|
root@4
|
245 |
}
|
root@4
|
246 |
}
|
root@4
|
247 |
|
root@4
|
248 |
if (wiringstring.length()) {
|
root@4
|
249 |
optionstring = "WIRING=" + wiringstring + ((optionstring != "") ? ";" + optionstring : "");
|
root@4
|
250 |
}
|
root@4
|
251 |
|
root@4
|
252 |
if (controller == "")
|
root@4
|
253 |
{
|
root@4
|
254 |
syslog(LOG_ERR, "%s error: no controller given!\n", config->name.c_str());
|
root@4
|
255 |
return -1;
|
root@4
|
256 |
}
|
root@4
|
257 |
|
root@4
|
258 |
|
root@4
|
259 |
if (config->device == "")
|
root@4
|
260 |
{
|
root@4
|
261 |
// use DirectIO
|
root@4
|
262 |
|
root@4
|
263 |
// neither device nor port is set
|
root@4
|
264 |
if (config->port == 0)
|
root@4
|
265 |
return -1;
|
root@4
|
266 |
|
root@4
|
267 |
char temp[10];
|
root@4
|
268 |
snprintf(temp, 8, "0x%x", config->port);
|
root@4
|
269 |
|
root@4
|
270 |
if (serdisp_version < SERDISP_VERSION(1,93) ) {
|
root@4
|
271 |
sdcd = fp_PP_open(temp);
|
root@4
|
272 |
} else {
|
root@4
|
273 |
sdcd = fp_SDCONN_open(temp);
|
root@4
|
274 |
}
|
root@4
|
275 |
|
root@4
|
276 |
if (sdcd == 0) {
|
root@4
|
277 |
syslog(LOG_ERR, "%s: error: unable to open port 0x%x for display %s. (cDriver::Init)\n",
|
root@4
|
278 |
config->name.c_str(), config->port, controller.c_str());
|
root@4
|
279 |
return -1;
|
root@4
|
280 |
}
|
root@4
|
281 |
|
root@4
|
282 |
uSleep(10);
|
root@4
|
283 |
}
|
root@4
|
284 |
else
|
root@4
|
285 |
{
|
root@4
|
286 |
// use ppdev
|
root@4
|
287 |
if (serdisp_version < SERDISP_VERSION(1,93) ) {
|
root@4
|
288 |
sdcd = fp_PP_open(config->device.c_str());
|
root@4
|
289 |
} else {
|
root@4
|
290 |
sdcd = fp_SDCONN_open(config->device.c_str());
|
root@4
|
291 |
}
|
root@4
|
292 |
|
root@4
|
293 |
if (sdcd == 0) {
|
root@4
|
294 |
syslog(LOG_ERR, "%s: error: unable to open device %s for display %s. (cDriver::Init)\n",
|
root@4
|
295 |
config->name.c_str(), config->device.c_str(), controller.c_str());
|
root@4
|
296 |
return -1;
|
root@4
|
297 |
}
|
root@4
|
298 |
}
|
root@4
|
299 |
|
root@4
|
300 |
if (serdisp_version < SERDISP_VERSION(1,95) )
|
root@4
|
301 |
dd = fp_serdisp_init(sdcd, controller.c_str(), "");
|
root@4
|
302 |
else
|
root@4
|
303 |
dd = fp_serdisp_init(sdcd, controller.c_str(), optionstring.c_str());
|
root@4
|
304 |
|
root@4
|
305 |
if (!dd)
|
root@4
|
306 |
{
|
root@4
|
307 |
syslog(LOG_ERR, "%s: error: cannot open display %s. Err:%s (cDriver::Init)\n",
|
root@4
|
308 |
config->name.c_str(), controller.c_str(), "no handle");
|
root@4
|
309 |
return -1;
|
root@4
|
310 |
}
|
root@4
|
311 |
|
root@4
|
312 |
width = config->width;
|
root@4
|
313 |
if (width <= 0)
|
root@4
|
314 |
width = fp_serdisp_getwidth(dd);
|
root@4
|
315 |
height = config->height;
|
root@4
|
316 |
if (height <= 0)
|
root@4
|
317 |
height = fp_serdisp_getheight(dd);
|
root@4
|
318 |
|
root@4
|
319 |
if (serdisp_version < SERDISP_VERSION(1,96) ) {
|
root@4
|
320 |
fp_serdisp_feature(dd, FEATURE_ROTATE, config->upsideDown);
|
root@4
|
321 |
fp_serdisp_feature(dd, FEATURE_CONTRAST, config->contrast);
|
root@4
|
322 |
fp_serdisp_feature(dd, FEATURE_BACKLIGHT, config->backlight);
|
root@4
|
323 |
fp_serdisp_feature(dd, FEATURE_REVERSE, config->invert);
|
root@4
|
324 |
} else {
|
root@4
|
325 |
/* standard options */
|
root@4
|
326 |
fp_serdisp_setoption(dd, "ROTATE", config->upsideDown);
|
root@4
|
327 |
fp_serdisp_setoption(dd, "CONTRAST", config->contrast);
|
root@4
|
328 |
fp_serdisp_setoption(dd, "BACKLIGHT", config->backlight);
|
root@4
|
329 |
fp_serdisp_setoption(dd, "INVERT", config->invert);
|
root@4
|
330 |
|
root@4
|
331 |
/* driver dependend options */
|
root@4
|
332 |
for (unsigned int i = 0; i < config->options.size(); i++) {
|
root@4
|
333 |
std::string optionname = config->options[i].name;
|
root@4
|
334 |
if (optionname != "UpsideDown" && optionname != "Contrast" &&
|
root@4
|
335 |
optionname != "Backlight" && optionname != "Invert") {
|
root@4
|
336 |
|
root@4
|
337 |
if ( fp_serdisp_isoption(dd, optionname.c_str()) == 1 ) /* if == 1: option is existing AND r/w */
|
root@4
|
338 |
fp_serdisp_setoption(dd, optionname.c_str(), strtol(config->options[i].value.c_str(), NULL, 0));
|
root@4
|
339 |
}
|
root@4
|
340 |
}
|
root@4
|
341 |
|
root@4
|
342 |
}
|
root@4
|
343 |
|
root@4
|
344 |
*oldConfig = *config;
|
root@4
|
345 |
|
root@4
|
346 |
// clear display
|
root@4
|
347 |
Clear();
|
root@4
|
348 |
|
root@4
|
349 |
syslog(LOG_INFO, "%s: SerDisp with %s initialized.\n", config->name.c_str(), controller.c_str());
|
root@4
|
350 |
return 0;
|
root@4
|
351 |
}
|
root@4
|
352 |
|
root@4
|
353 |
int cDriverSerDisp::DeInit(void)
|
root@4
|
354 |
{
|
root@4
|
355 |
if (serdisp_version < SERDISP_VERSION(1,93) ) {
|
root@4
|
356 |
fp_serdisp_close(dd);
|
root@4
|
357 |
fp_PP_close(sdcd);
|
root@4
|
358 |
sdcd = NULL;
|
root@4
|
359 |
} else {
|
root@4
|
360 |
//fp_serdisp_quit(dd);
|
root@4
|
361 |
/* use serdisp_close instead of serdisp_quit so that showpic and showtext are usable together with serdisplib */
|
root@4
|
362 |
fp_serdisp_close(dd);
|
root@4
|
363 |
}
|
root@4
|
364 |
(int) dlclose(sdhnd);
|
root@4
|
365 |
sdhnd = NULL;
|
root@4
|
366 |
|
root@4
|
367 |
return 0;
|
root@4
|
368 |
}
|
root@4
|
369 |
|
root@4
|
370 |
int cDriverSerDisp::CheckSetup()
|
root@4
|
371 |
{
|
root@4
|
372 |
bool update = false;
|
root@4
|
373 |
|
root@4
|
374 |
if (config->device != oldConfig->device ||
|
root@4
|
375 |
config->port != oldConfig->port ||
|
root@4
|
376 |
config->width != oldConfig->width ||
|
root@4
|
377 |
config->height != oldConfig->height)
|
root@4
|
378 |
{
|
root@4
|
379 |
DeInit();
|
root@4
|
380 |
Init();
|
root@4
|
381 |
return 0;
|
root@4
|
382 |
}
|
root@4
|
383 |
|
root@4
|
384 |
if (config->contrast != oldConfig->contrast)
|
root@4
|
385 |
{
|
root@4
|
386 |
fp_serdisp_feature(dd, FEATURE_CONTRAST, config->contrast);
|
root@4
|
387 |
oldConfig->contrast = config->contrast;
|
root@4
|
388 |
update = true;
|
root@4
|
389 |
}
|
root@4
|
390 |
if (config->backlight != oldConfig->backlight)
|
root@4
|
391 |
{
|
root@4
|
392 |
fp_serdisp_feature(dd, FEATURE_BACKLIGHT, config->backlight);
|
root@4
|
393 |
oldConfig->backlight = config->backlight;
|
root@4
|
394 |
update = true;
|
root@4
|
395 |
}
|
root@4
|
396 |
if (config->upsideDown != oldConfig->upsideDown)
|
root@4
|
397 |
{
|
root@4
|
398 |
fp_serdisp_feature(dd, FEATURE_ROTATE, config->upsideDown);
|
root@4
|
399 |
oldConfig->upsideDown = config->upsideDown;
|
root@4
|
400 |
update = true;
|
root@4
|
401 |
}
|
root@4
|
402 |
if (config->invert != oldConfig->invert)
|
root@4
|
403 |
{
|
root@4
|
404 |
fp_serdisp_feature(dd, FEATURE_REVERSE, config->invert);
|
root@4
|
405 |
oldConfig->invert = config->invert;
|
root@4
|
406 |
update = true;
|
root@4
|
407 |
}
|
root@4
|
408 |
|
root@4
|
409 |
/* driver dependend options */
|
root@4
|
410 |
for (unsigned int i = 0; i < config->options.size(); i++) {
|
root@4
|
411 |
std::string optionname = config->options[i].name;
|
root@4
|
412 |
if (optionname != "UpsideDown" && optionname != "Contrast" &&
|
root@4
|
413 |
optionname != "Backlight" && optionname != "Invert") {
|
root@4
|
414 |
|
root@4
|
415 |
if ( fp_serdisp_isoption(dd, optionname.c_str()) == 1 ) /* if == 1: option is existing AND r/w */
|
root@4
|
416 |
fp_serdisp_setoption(dd, optionname.c_str(), strtol(config->options[i].value.c_str(), NULL, 0));
|
root@4
|
417 |
oldConfig->options[i] = config->options[i];
|
root@4
|
418 |
update = true;
|
root@4
|
419 |
}
|
root@4
|
420 |
}
|
root@4
|
421 |
|
root@4
|
422 |
|
root@4
|
423 |
if (update)
|
root@4
|
424 |
return 1;
|
root@4
|
425 |
return 0;
|
root@4
|
426 |
}
|
root@4
|
427 |
|
root@4
|
428 |
void cDriverSerDisp::Clear(void)
|
root@4
|
429 |
{
|
root@4
|
430 |
if (bg_colour == -1)
|
root@4
|
431 |
fp_serdisp_clearbuffer(dd);
|
root@4
|
432 |
else { /* if bg_colour is set, draw background 'by hand' */
|
root@4
|
433 |
int x,y;
|
root@4
|
434 |
for (y = 0; y < fp_serdisp_getheight(dd); y++)
|
root@4
|
435 |
for (x = 0; x < fp_serdisp_getwidth(dd); x++)
|
root@4
|
436 |
fp_serdisp_setpixcol(dd, x, y, bg_colour); /* >= 1.95: serdisp_setcolour(), < 1.95: serdisp_setpixel() */
|
root@4
|
437 |
}
|
root@4
|
438 |
}
|
root@4
|
439 |
|
root@4
|
440 |
void cDriverSerDisp::Set8Pixels(int x, int y, unsigned char data) {
|
root@4
|
441 |
int i, start, pixel;
|
root@4
|
442 |
|
root@4
|
443 |
data = ReverseBits(data);
|
root@4
|
444 |
|
root@4
|
445 |
start = (x >> 3) << 3;
|
root@4
|
446 |
|
root@4
|
447 |
for (i = 0; i < 8; i++) {
|
root@4
|
448 |
pixel = data & (1 << i);
|
root@4
|
449 |
if (pixel)
|
root@4
|
450 |
fp_serdisp_setpixcol(dd, start + i, y, fg_colour); /* >= 1.95: serdisp_setcolour(), < 1.95: serdisp_setpixel() */
|
root@4
|
451 |
else if (!pixel && bg_colour != -1) /* if bg_colour is set: use it if pixel is not set */
|
root@4
|
452 |
fp_serdisp_setpixcol(dd, start + i, y, bg_colour); /* >= 1.95: serdisp_setcolour(), < 1.95: serdisp_setpixel() */
|
root@4
|
453 |
}
|
root@4
|
454 |
}
|
root@4
|
455 |
|
root@4
|
456 |
void cDriverSerDisp::Refresh(bool refreshAll)
|
root@4
|
457 |
{
|
root@4
|
458 |
if (CheckSetup() == 1)
|
root@4
|
459 |
refreshAll = true;
|
root@4
|
460 |
|
root@4
|
461 |
if (refreshAll)
|
root@4
|
462 |
fp_serdisp_rewrite(dd);
|
root@4
|
463 |
else
|
root@4
|
464 |
fp_serdisp_update(dd);
|
root@4
|
465 |
}
|
root@4
|
466 |
|
root@4
|
467 |
} // end of namespace
|