root/tags/0.10.0/drv_serdisplib.c

Revision 554, 8.8 kB (checked in by reinelt, 4 years ago)

[lcd4linux @ 2005-05-28 09:06:14 by reinelt]
serdisplib cosmetics

Line 
1/* $Id: drv_serdisplib.c,v 1.5 2005/05/28 09:06:14 reinelt Exp $
2 *
3 * driver for serdisplib displays
4 *
5 * Copyright (C) 2005 Michael Reinelt <reinelt@eunet.at>
6 * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
7 *
8 * This file is part of LCD4Linux.
9 *
10 * LCD4Linux is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * LCD4Linux is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *
25 * $Log: drv_serdisplib.c,v $
26 * Revision 1.5  2005/05/28 09:06:14  reinelt
27 * serdisplib cosmetics
28 *
29 * Revision 1.4  2005/05/12 14:55:47  reinelt
30 * plugins for serdisplib driver
31 *
32 * Revision 1.3  2005/05/12 05:52:43  reinelt
33 * serdisplib GET_VERSION_MAJOR macro
34 *
35 * Revision 1.2  2005/05/11 04:27:49  reinelt
36 * small serdisplib bugs fixed
37 *
38 * Revision 1.1  2005/05/10 13:20:14  reinelt
39 * added serdisplib driver
40 *
41 */
42
43/*
44 *
45 * exported fuctions:
46 *
47 * struct DRIVER drv_serdisplib
48 *
49 */
50
51#include "config.h"
52
53#include <stdlib.h>
54#include <stdio.h>
55#include <string.h>
56#include <unistd.h>
57
58#include <serdisplib/serdisp.h>
59
60/* Fixme: This should be removed as soon as serdisp.h
61 * contains this macros
62 */
63#ifndef SERDISP_VERSION_GET_MAJOR
64#define SERDISP_VERSION_GET_MAJOR(_c)  ((int)( (_c) >> 8 ))
65#define SERDISP_VERSION_GET_MINOR(_c)  ((int)( (_c) & 0xFF ))
66#endif
67
68
69#include "debug.h"
70#include "cfg.h"
71#include "qprintf.h"
72#include "plugin.h"
73#include "widget.h"
74#include "widget_text.h"
75#include "widget_icon.h"
76#include "widget_bar.h"
77#include "drv.h"
78#include "drv_generic_graphic.h"
79
80#ifdef WITH_DMALLOC
81#include <dmalloc.h>
82#endif
83
84static char Name[] = "serdisplib";
85
86static serdisp_CONN_t *sdcd;
87static serdisp_t *dd;
88
89
90/****************************************/
91/***  hardware dependant functions    ***/
92/****************************************/
93
94static void drv_SD_blit(const int row, const int col, const int height, const int width)
95{
96    int r, c;
97    long color;
98
99    for (r = row; r < row + height; r++) {
100  for (c = col; c < col + width; c++) {
101      color = drv_generic_graphic_FB[r * LCOLS + c] ? SD_COL_BLACK : SD_COL_WHITE;
102      serdisp_setcolour(dd, c, r, color);
103  }
104    }
105
106    serdisp_update(dd);
107}
108
109
110static int drv_SD_contrast(int contrast)
111{
112    if (contrast < 0)
113  contrast = 0;
114    if (contrast > MAX_CONTRASTSTEP)
115  contrast = MAX_CONTRASTSTEP;
116
117    serdisp_feature(dd, FEATURE_CONTRAST, contrast);
118
119    return contrast;
120}
121
122
123static int drv_SD_backlight(int backlight)
124{
125    if (backlight < FEATURE_NO)
126  backlight = FEATURE_NO;
127    if (backlight > FEATURE_YES)
128  backlight = FEATURE_YES;
129
130    serdisp_feature(dd, FEATURE_BACKLIGHT, backlight);
131
132    return backlight;
133}
134
135
136static int drv_SD_reverse(int reverse)
137{
138    if (reverse < FEATURE_NO)
139  reverse = FEATURE_NO;
140    if (reverse > FEATURE_YES)
141  reverse = FEATURE_YES;
142
143    serdisp_feature(dd, FEATURE_REVERSE, reverse);
144
145    return reverse;
146}
147
148
149static int drv_SD_rotate(int rotate)
150{
151    if (rotate < 0)
152  rotate = 0;
153    if (rotate > 3)
154  rotate = 3;
155
156    serdisp_feature(dd, FEATURE_ROTATE, rotate);
157
158    return rotate;
159}
160
161
162
163static int drv_SD_start(const char *section)
164{
165    long version;
166    char *port, *model, *options, *s;
167    int contrast, backlight, reverse, rotate;
168
169    version = serdisp_getversioncode();
170    info("%s: header  version %d.%d", Name, SERDISP_VERSION_MAJOR, SERDISP_VERSION_MINOR);
171    info("%s: library version %d.%d", Name, SERDISP_VERSION_GET_MAJOR(version), SERDISP_VERSION_GET_MINOR(version));
172
173    port = cfg_get(section, "Port", NULL);
174    if (port == NULL || *port == '\0') {
175  error("%s: no '%s.Port' entry from %s", Name, section, cfg_source());
176  return -1;
177    }
178
179    /* opening the output device */
180    sdcd = SDCONN_open(port);
181    if (sdcd == NULL) {
182  error("%s: open(%s) failed: %s", Name, port, sd_geterrormsg());
183  return -1;
184    }
185
186
187    model = cfg_get(section, "Model", "");
188    if (model == NULL || *model == '\0') {
189  error("%s: no '%s.Model' entry from %s", Name, section, cfg_source());
190  return -1;
191    }
192    info("%s: using model '%s'", Name, model);
193
194    options = cfg_get(section, "Options", "");
195    info("%s: using options '%s'", Name, options);
196
197    /* opening and initialising the display */
198    dd = serdisp_init(sdcd, model, options);
199    if (dd == NULL) {
200  error("%s: init(%s, %s, %s) failed: %s", Name, port, model, options, sd_geterrormsg());
201  SDCONN_close(sdcd);
202  return -1;
203    }
204
205    DROWS = serdisp_getheight(dd);
206    DCOLS = serdisp_getwidth(dd);
207    info("%s: display size %dx%d", Name, DCOLS, DROWS);
208
209    XRES = -1;
210    YRES = -1;
211    s = cfg_get(section, "Font", "6x8");
212    if (s == NULL || *s == '\0') {
213  error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
214  return -1;
215    }
216    if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
217  error("%s: bad Font '%s' from %s", Name, s, cfg_source());
218  return -1;
219    }
220
221    /* Fixme: provider other fonts someday... */
222    if (XRES != 6 && YRES != 8) {
223  error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
224  return -1;
225    }
226
227    /* clear display */
228    serdisp_clear(dd);
229
230    if (cfg_number(section, "Contrast", 0, 0, MAX_CONTRASTSTEP, &contrast) > 0) {
231  drv_SD_contrast(contrast);
232    }
233
234    if (cfg_number(section, "Backlight", 0, 0, 1, &backlight) > 0) {
235  drv_SD_backlight(backlight);
236    }
237
238    if (cfg_number(section, "Reverse", 0, 0, 1, &reverse) > 0) {
239  drv_SD_reverse(reverse);
240    }
241
242    if (cfg_number(section, "Rotate", 0, 0, 3, &rotate) > 0) {
243  drv_SD_rotate(rotate);
244    }
245
246    return 0;
247}
248
249
250/****************************************/
251/***            plugins               ***/
252/****************************************/
253
254static void plugin_contrast(RESULT * result, RESULT * arg1)
255{
256    double contrast;
257
258    contrast = drv_SD_contrast(R2N(arg1));
259    SetResult(&result, R_NUMBER, &contrast);
260}
261
262
263static void plugin_backlight(RESULT * result, RESULT * arg1)
264{
265    double backlight;
266
267    backlight = drv_SD_backlight(R2N(arg1));
268    SetResult(&result, R_NUMBER, &backlight);
269}
270
271
272static void plugin_reverse(RESULT * result, RESULT * arg1)
273{
274    double reverse;
275
276    reverse = drv_SD_reverse(R2N(arg1));
277    SetResult(&result, R_NUMBER, &reverse);
278}
279
280
281static void plugin_rotate(RESULT * result, RESULT * arg1)
282{
283    double rotate;
284
285    rotate = drv_SD_rotate(R2N(arg1));
286    SetResult(&result, R_NUMBER, &rotate);
287}
288
289
290/****************************************/
291/***        widget callbacks          ***/
292/****************************************/
293
294
295/* using drv_generic_graphic_draw(W) */
296/* using drv_generic_graphic_icon_draw(W) */
297/* using drv_generic_graphic_bar_draw(W) */
298
299
300/****************************************/
301/***        exported functions        ***/
302/****************************************/
303
304
305/* list models */
306int drv_SD_list(void)
307{
308    printf("%s", "any");
309    return 0;
310}
311
312
313/* initialize driver & display */
314int drv_SD_init(const char *section, const int quiet)
315{
316    WIDGET_CLASS wc;
317    int ret;
318
319    /* real worker functions */
320    drv_generic_graphic_real_blit = drv_SD_blit;
321
322    /* start display */
323    if ((ret = drv_SD_start(section)) != 0)
324  return ret;
325
326    /* initialize generic graphic driver */
327    if ((ret = drv_generic_graphic_init(section, Name)) != 0)
328  return ret;
329
330    if (!quiet) {
331  char buffer[40];
332  qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
333  if (drv_generic_graphic_greet(buffer, NULL)) {
334      sleep(3);
335      drv_generic_graphic_clear();
336  }
337    }
338
339    /* register text widget */
340    wc = Widget_Text;
341    wc.draw = drv_generic_graphic_draw;
342    widget_register(&wc);
343
344    /* register icon widget */
345    wc = Widget_Icon;
346    wc.draw = drv_generic_graphic_icon_draw;
347    widget_register(&wc);
348
349    /* register bar widget */
350    wc = Widget_Bar;
351    wc.draw = drv_generic_graphic_bar_draw;
352    widget_register(&wc);
353
354    /* register plugins */
355    AddFunction("LCD::contrast",  1, plugin_contrast);
356    AddFunction("LCD::backlight", 1, plugin_backlight);
357    AddFunction("LCD::reverse",   1, plugin_reverse);
358    AddFunction("LCD::rotate",    1, plugin_rotate);
359
360    return 0;
361}
362
363
364/* close driver & display */
365int drv_SD_quit(const int quiet)
366{
367
368    info("%s: shutting down.", Name);
369
370    drv_generic_graphic_clear();
371
372    if (!quiet) {
373  drv_generic_graphic_greet("goodbye!", NULL);
374    }
375
376    drv_generic_graphic_quit();
377
378    serdisp_quit(dd);
379
380    return (0);
381}
382
383
384DRIVER drv_serdisplib = {
385  name:Name,
386  list:drv_SD_list,
387  init:drv_SD_init,
388  quit:drv_SD_quit,
389};
Note: See TracBrowser for help on using the browser.