aboutsummaryrefslogtreecommitdiffstats
path: root/drv_serdisplib.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-10 13:20:14 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-10 13:20:14 +0000
commit424c378dd92c9ba92ba258689a0358c3cc3010b5 (patch)
tree931aae247949c64b7173d2344146a76df150c5cc /drv_serdisplib.c
parentdbf5d92605a9db10e3e3cb154d03a515c5d5c5af (diff)
downloadlcd4linux-424c378dd92c9ba92ba258689a0358c3cc3010b5.tar.gz
[lcd4linux @ 2005-05-10 13:20:10 by reinelt]
added serdisplib driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@548 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'drv_serdisplib.c')
-rw-r--r--drv_serdisplib.c272
1 files changed, 272 insertions, 0 deletions
diff --git a/drv_serdisplib.c b/drv_serdisplib.c
new file mode 100644
index 0000000..6b44139
--- /dev/null
+++ b/drv_serdisplib.c
@@ -0,0 +1,272 @@
+/* $Id: drv_serdisplib.c,v 1.1 2005/05/10 13:20:14 reinelt Exp $
+ *
+ * driver for serdisplib displays
+ *
+ * Copyright (C) 2005 Michael Reinelt <reinelt@eunet.at>
+ * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: drv_serdisplib.c,v $
+ * Revision 1.1 2005/05/10 13:20:14 reinelt
+ * added serdisplib driver
+ *
+ */
+
+/*
+ *
+ * exported fuctions:
+ *
+ * struct DRIVER drv_serdisplib
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+//#include <stdio.h>
+#include <string.h>
+//#include <errno.h>
+#include <unistd.h>
+//#include <termios.h>
+//#include <fcntl.h>
+//#include <sys/time.h>
+
+#include <serdisplib/serdisp.h>
+
+#include "debug.h"
+#include "cfg.h"
+#include "qprintf.h"
+#include "plugin.h"
+#include "widget.h"
+#include "widget_text.h"
+#include "widget_icon.h"
+#include "widget_bar.h"
+#include "drv.h"
+#include "drv_generic_graphic.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+static char Name[] = "serdisplib";
+
+static serdisp_CONN_t *sdcd;
+static serdisp_t *dd;
+
+
+/****************************************/
+/*** hardware dependant functions ***/
+/****************************************/
+
+static void drv_SD_blit(const int row, const int col, const int height, const int width)
+{
+ int r, c;
+ long color;
+
+ for (r = row; r < row + height; r++) {
+ for (c = col; c < col + width; c++) {
+ color = drv_generic_graphic_FB[r * LCOLS + c] ? SD_COL_BLACK : SD_COL_WHITE;
+ serdisp_setcolour(dd, r, c, color);
+ }
+ }
+
+ serdisp_update(dd);
+}
+
+
+static int drv_SD_start(const char *section)
+{
+ long version;
+ char *port, *model, *options, *s;
+ int TROWS, TCOLS;
+
+ version = serdisp_getversioncode();
+ info ("%s: header version %d.%d", Name, SERDISP_VERSION_MAJOR, SERDISP_VERSION_MINOR);
+ info ("%s: library version %d.%d", Name, version>>8, version & 0xff);
+
+ port = cfg_get(section, "Port", NULL);
+ if (port == NULL || *port == '\0') {
+ error("%s: no '%s.Port' entry from %s", Name, section, cfg_source());
+ return -1;
+ }
+
+ /* opening the output device */
+ sdcd = SDCONN_open(port);
+ if (sdcd == NULL) {
+ error ("%s: open(%s) failed: %s", Name, port, sd_geterrormsg());
+ return -1;
+ }
+
+
+ model = cfg_get(section, "Model", "");
+ if (model == NULL || *model == '\0') {
+ error("%s: no '%s.Model' entry from %s", Name, section, cfg_source());
+ return -1;
+ }
+ info("%s: using model '%s'", Name, model);
+
+ options = cfg_get(section, "Options", "");
+ info("%s: using options '%s'", Name, options);
+
+ /* opening and initialising the display */
+ dd = serdisp_init(sdcd, model, options);
+ if (dd == NULL) {
+ error ("%s: init(%s, %s, %s) failed: %s", Name, port, model, options, sd_geterrormsg());
+ SDCONN_close(sdcd);
+ return -1;
+ }
+
+ DROWS = serdisp_getheight(dd);
+ DCOLS = serdisp_getwidth(dd);
+ info ("%s: display size %dx%d", Name, DCOLS, DROWS);
+
+ XRES = -1;
+ YRES = -1;
+ s = cfg_get(section, "Font", "6x8");
+ if (s == NULL || *s == '\0') {
+ error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
+ return -1;
+ }
+ if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
+ error("%s: bad Font '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+
+ /* Fixme: provider other fonts someday... */
+ if (XRES != 6 && YRES != 8) {
+ error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
+ return -1;
+ }
+
+ TROWS = DROWS / YRES; /* text rows */
+ TCOLS = DCOLS / XRES; /* text cols */
+
+ /* clear display */
+ serdisp_clear(dd);
+
+ return 0;
+}
+
+
+/****************************************/
+/*** plugins ***/
+/****************************************/
+
+/* none at the moment... */
+/* Fixme: SD_FEATURE's */
+
+
+/****************************************/
+/*** widget callbacks ***/
+/****************************************/
+
+
+/* using drv_generic_graphic_draw(W) */
+/* using drv_generic_graphic_icon_draw(W) */
+/* using drv_generic_graphic_bar_draw(W) */
+
+
+/****************************************/
+/*** exported functions ***/
+/****************************************/
+
+
+/* list models */
+int drv_SD_list(void)
+{
+ printf("%s", "any");
+ return 0;
+}
+
+
+/* initialize driver & display */
+int drv_SD_init(const char *section, const int quiet)
+{
+ WIDGET_CLASS wc;
+ int ret;
+
+ /* real worker functions */
+ drv_generic_graphic_real_blit = drv_SD_blit;
+
+ /* start display */
+ if ((ret = drv_SD_start(section)) != 0)
+ return ret;
+
+ /* initialize generic graphic driver */
+ if ((ret = drv_generic_graphic_init(section, Name)) != 0)
+ return ret;
+
+ if (!quiet) {
+ char buffer[40];
+ qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
+ if (drv_generic_graphic_greet(buffer, NULL)) {
+ sleep(3);
+ drv_generic_graphic_clear();
+ }
+ }
+
+ /* register text widget */
+ wc = Widget_Text;
+ wc.draw = drv_generic_graphic_draw;
+ widget_register(&wc);
+
+ /* register icon widget */
+ wc = Widget_Icon;
+ wc.draw = drv_generic_graphic_icon_draw;
+ widget_register(&wc);
+
+ /* register bar widget */
+ wc = Widget_Bar;
+ wc.draw = drv_generic_graphic_bar_draw;
+ widget_register(&wc);
+
+ /* register plugins */
+ /* none at the moment... */
+ /* Fixme: SD_FEATURE's */
+
+ return 0;
+}
+
+
+/* close driver & display */
+int drv_SD_quit(const int quiet)
+{
+
+ info("%s: shutting down.", Name);
+
+ drv_generic_graphic_clear();
+
+ if (!quiet) {
+ drv_generic_graphic_greet("goodbye!", NULL);
+ }
+
+ drv_generic_graphic_quit();
+
+ serdisp_quit(dd);
+
+ return (0);
+}
+
+
+DRIVER drv_serdisplib = {
+ name:Name,
+ list:drv_SD_list,
+ init:drv_SD_init,
+ quit:drv_SD_quit,
+};