aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--Makefile.in41
-rwxr-xr-xconfigure6
-rw-r--r--drivers.m46
-rw-r--r--drv_LPH7508.c147
-rw-r--r--drv_generic_gpio.c159
-rw-r--r--drv_generic_gpio.h50
-rw-r--r--layout.c27
-rw-r--r--lcd4linux.conf.sample21
-rw-r--r--widget.c19
-rw-r--r--widget.h11
-rw-r--r--widget_bar.c6
-rw-r--r--widget_gpo.c141
-rw-r--r--widget_gpo.h46
-rw-r--r--widget_icon.c10
-rw-r--r--widget_text.c6
16 files changed, 637 insertions, 62 deletions
diff --git a/Makefile.am b/Makefile.am
index ac2917d..75ffe02 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,6 +31,7 @@ widget.c widget.h \
widget_text.c widget_text.h \
widget_bar.c widget_bar.h \
widget_icon.c widget_icon.h \
+widget_gpo.c widget_gpo.h \
\
plugin.c plugin.h \
plugin_cfg.c \
@@ -44,6 +45,8 @@ drv_generic_text.c \
drv_generic_text.h \
drv_generic_graphic.c \
drv_generic_graphic.h \
+drv_generic_gpio.c \
+drv_generic_gpio.h \
drv_generic_serial.c \
drv_generic_serial.h \
drv_generic_parport.c \
diff --git a/Makefile.in b/Makefile.in
index 96b5e63..80aa295 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -101,10 +101,10 @@ lcd4linux_LDFLAGS =
lcd4linux_LDADD = @DRIVERS@ @PLUGINS@ @DRVLIBS@ @PLUGINLIBS@
lcd4linux_DEPENDENCIES = @DRIVERS@ @PLUGINS@
-lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h pid.c pid.h timer.c timer.h thread.c thread.h udelay.c udelay.h qprintf.c qprintf.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_cfg.c plugin_math.c plugin_string.c plugin_test.c plugin_time.c
+lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h pid.c pid.h timer.c timer.h thread.c thread.h udelay.c udelay.h qprintf.c qprintf.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h widget_gpo.c widget_gpo.h plugin.c plugin.h plugin_cfg.c plugin_math.c plugin_string.c plugin_test.c plugin_time.c
-EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_i2c.c drv_generic_i2c.h drv_BeckmannEgle.c drv_BWCT.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_HD44780.c drv_Image.c drv_LCDLinux.c drv_LCDLinux.h drv_LCDTerm.c drv_LPH7508.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_Noritake.c drv_NULL.c drv_RouterBoard.c drv_Sample.c drv_serdisplib.c drv_SimpleLCD.c drv_T6963.c drv_Trefon.c drv_USBLCD.c drv_WincorNixdorf.c drv_X11.c font_6x8.h lcd4linux_i2c.h plugin_apm.c plugin_cpuinfo.c plugin_diskstats.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_python.c plugin_sample.c plugin_seti.c plugin_statfs.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c
+EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_gpio.c drv_generic_gpio.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_i2c.c drv_generic_i2c.h drv_BeckmannEgle.c drv_BWCT.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_HD44780.c drv_Image.c drv_LCDLinux.c drv_LCDLinux.h drv_LCDTerm.c drv_LPH7508.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_Noritake.c drv_NULL.c drv_RouterBoard.c drv_Sample.c drv_serdisplib.c drv_SimpleLCD.c drv_T6963.c drv_Trefon.c drv_USBLCD.c drv_WincorNixdorf.c drv_X11.c font_6x8.h lcd4linux_i2c.h plugin_apm.c plugin_cpuinfo.c plugin_diskstats.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_python.c plugin_sample.c plugin_seti.c plugin_statfs.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c
EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Drivers README.Plugins README.KDE plugin_sample.c
@@ -126,8 +126,8 @@ X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
lcd4linux_OBJECTS = lcd4linux.o cfg.o debug.o drv.o evaluator.o hash.o \
layout.o pid.o timer.o thread.o udelay.o qprintf.o widget.o \
-widget_text.o widget_bar.o widget_icon.o plugin.o plugin_cfg.o \
-plugin_math.o plugin_string.o plugin_test.o plugin_time.o
+widget_text.o widget_bar.o widget_icon.o widget_gpo.o plugin.o \
+plugin_cfg.o plugin_math.o plugin_string.o plugin_test.o plugin_time.o
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
@@ -149,22 +149,23 @@ DEP_FILES = .deps/cfg.P .deps/debug.P .deps/drv.P .deps/drv_BWCT.P \
.deps/drv_MilfordInstruments.P .deps/drv_NULL.P .deps/drv_Noritake.P \
.deps/drv_RouterBoard.P .deps/drv_Sample.P .deps/drv_SimpleLCD.P \
.deps/drv_T6963.P .deps/drv_Trefon.P .deps/drv_USBLCD.P \
-.deps/drv_WincorNixdorf.P .deps/drv_X11.P .deps/drv_generic_graphic.P \
-.deps/drv_generic_i2c.P .deps/drv_generic_parport.P \
-.deps/drv_generic_serial.P .deps/drv_generic_text.P \
-.deps/drv_serdisplib.P .deps/evaluator.P .deps/hash.P .deps/layout.P \
-.deps/lcd4linux.P .deps/pid.P .deps/plugin.P .deps/plugin_apm.P \
-.deps/plugin_cfg.P .deps/plugin_cpuinfo.P .deps/plugin_diskstats.P \
-.deps/plugin_dvb.P .deps/plugin_exec.P .deps/plugin_i2c_sensors.P \
-.deps/plugin_imon.P .deps/plugin_isdn.P .deps/plugin_loadavg.P \
-.deps/plugin_math.P .deps/plugin_meminfo.P .deps/plugin_mysql.P \
-.deps/plugin_netdev.P .deps/plugin_pop3.P .deps/plugin_ppp.P \
-.deps/plugin_proc_stat.P .deps/plugin_python.P .deps/plugin_sample.P \
-.deps/plugin_seti.P .deps/plugin_statfs.P .deps/plugin_string.P \
-.deps/plugin_test.P .deps/plugin_time.P .deps/plugin_uname.P \
-.deps/plugin_uptime.P .deps/plugin_wireless.P .deps/plugin_xmms.P \
-.deps/qprintf.P .deps/thread.P .deps/timer.P .deps/udelay.P \
-.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \
+.deps/drv_WincorNixdorf.P .deps/drv_X11.P .deps/drv_generic_gpio.P \
+.deps/drv_generic_graphic.P .deps/drv_generic_i2c.P \
+.deps/drv_generic_parport.P .deps/drv_generic_serial.P \
+.deps/drv_generic_text.P .deps/drv_serdisplib.P .deps/evaluator.P \
+.deps/hash.P .deps/layout.P .deps/lcd4linux.P .deps/pid.P \
+.deps/plugin.P .deps/plugin_apm.P .deps/plugin_cfg.P \
+.deps/plugin_cpuinfo.P .deps/plugin_diskstats.P .deps/plugin_dvb.P \
+.deps/plugin_exec.P .deps/plugin_i2c_sensors.P .deps/plugin_imon.P \
+.deps/plugin_isdn.P .deps/plugin_loadavg.P .deps/plugin_math.P \
+.deps/plugin_meminfo.P .deps/plugin_mysql.P .deps/plugin_netdev.P \
+.deps/plugin_pop3.P .deps/plugin_ppp.P .deps/plugin_proc_stat.P \
+.deps/plugin_python.P .deps/plugin_sample.P .deps/plugin_seti.P \
+.deps/plugin_statfs.P .deps/plugin_string.P .deps/plugin_test.P \
+.deps/plugin_time.P .deps/plugin_uname.P .deps/plugin_uptime.P \
+.deps/plugin_wireless.P .deps/plugin_xmms.P .deps/qprintf.P \
+.deps/thread.P .deps/timer.P .deps/udelay.P .deps/widget.P \
+.deps/widget_bar.P .deps/widget_gpo.P .deps/widget_icon.P \
.deps/widget_text.P
SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
OBJECTS = $(lcd4linux_OBJECTS)
diff --git a/configure b/configure
index af5c1ff..a55452a 100755
--- a/configure
+++ b/configure
@@ -6147,6 +6147,7 @@ echo "${ECHO_T}done" >&6
# generic display drivers
TEXT="no"
GRAPHIC="no"
+GPIO="no"
IMAGE="no"
# generiv I/O drivers
@@ -6262,6 +6263,7 @@ fi
if test "$LPH7508" = "yes"; then
GRAPHICS="yes"
PARPORT="yes"
+ GPIO="yes"
DRIVERS="$DRIVERS drv_LPH7508.o"
cat >>confdefs.h <<\_ACEOF
@@ -6494,6 +6496,10 @@ if test "$GRAPHIC" = "yes"; then
DRIVERS="$DRIVERS drv_generic_graphic.o"
fi
+# generic GPIO driver
+if test "$GPIO" = "yes"; then
+ DRIVERS="$DRIVERS drv_generic_gpio.o"
+fi
# generic parport driver
if test "$PARPORT" = "yes"; then
diff --git a/drivers.m4 b/drivers.m4
index 4b7ed5b..cd85974 100644
--- a/drivers.m4
+++ b/drivers.m4
@@ -166,6 +166,7 @@ AC_MSG_RESULT([done])
# generic display drivers
TEXT="no"
GRAPHIC="no"
+GPIO="no"
IMAGE="no"
# generiv I/O drivers
@@ -246,6 +247,7 @@ fi
if test "$LPH7508" = "yes"; then
GRAPHICS="yes"
PARPORT="yes"
+ GPIO="yes"
DRIVERS="$DRIVERS drv_LPH7508.o"
AC_DEFINE(WITH_LPH7508,1,[LPH7508 driver])
fi
@@ -404,6 +406,10 @@ if test "$GRAPHIC" = "yes"; then
DRIVERS="$DRIVERS drv_generic_graphic.o"
fi
+# generic GPIO driver
+if test "$GPIO" = "yes"; then
+ DRIVERS="$DRIVERS drv_generic_gpio.o"
+fi
# generic parport driver
if test "$PARPORT" = "yes"; then
diff --git a/drv_LPH7508.c b/drv_LPH7508.c
index 24f7ebc..cf731d0 100644
--- a/drv_LPH7508.c
+++ b/drv_LPH7508.c
@@ -1,4 +1,4 @@
-/* $Id: drv_LPH7508.c,v 1.2 2005/12/13 14:07:28 reinelt Exp $
+/* $Id: drv_LPH7508.c,v 1.3 2005/12/18 16:18:36 reinelt Exp $
*
* driver for Pollin LPH7508
*
@@ -23,6 +23,9 @@
*
*
* $Log: drv_LPH7508.c,v $
+ * Revision 1.3 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.2 2005/12/13 14:07:28 reinelt
* LPH7508 driver finished
*
@@ -61,6 +64,7 @@
#include "widget_bar.h"
#include "drv.h"
#include "drv_generic_graphic.h"
+#include "drv_generic_gpio.h"
#include "drv_generic_parport.h"
#ifdef WITH_DMALLOC
@@ -77,7 +81,8 @@ static unsigned char SIGNAL_A0;
static int PAGES, SROWS, SCOLS;
-unsigned char *Buffer1, *Buffer2;
+static unsigned char *Buffer1, *Buffer2;
+
/****************************************/
@@ -124,13 +129,42 @@ static void drv_L7_write_data(const unsigned char data)
}
-static void drv_L7_clear (void)
+static void drv_L7_page(int page)
+{
+ static int cp = -1;
+
+ if (page != cp) {
+ cp = page;
+ drv_L7_write_ctrl(0xb0 | cp);
+ }
+
+}
+
+
+static void drv_L7_put(int col, int val)
+{
+ static int cc = -1;
+
+ /* select page 8 */
+ drv_L7_page(8);
+
+ if (col != cc) {
+ cc = col;
+ drv_L7_write_ctrl(0x00 | (cc & 0x0f));
+ drv_L7_write_ctrl(0x10 | (cc >> 4));
+ }
+ drv_L7_write_data(val);
+ cc++;
+}
+
+
+static void drv_L7_clear(void)
{
int p, c;
- for (p= 0; p < PAGES; p++) {
+ for (p = 0; p < PAGES; p++) {
/* select page */
- drv_L7_write_ctrl(0xb0 | p);
+ drv_L7_page(p);
/* select column address */
drv_L7_write_ctrl(0x00);
drv_L7_write_ctrl(0x10);
@@ -143,11 +177,12 @@ static void drv_L7_clear (void)
static void drv_L7_blit(const int row, const int col, const int height, const int width)
{
- int r, p, p0;
+ int r, p;
/* transfer layout to display framebuffer */
for (r = row; r < row + height; r++) {
- if (r >= SROWS)
+ /* do not process extra row for symbols */
+ if (r >= SROWS - 1)
break;
/* page */
int p = r / 8;
@@ -170,16 +205,17 @@ static void drv_L7_blit(const int row, const int col, const int height, const in
}
/* process display framebuffer */
- p0 = -1;
for (p = row / 8; p <= (row + height) / 8; p++) {
int i, j, a, e;
if (p >= PAGES)
break;
- for (i = col; i < col+width; i++) {
+ for (i = col; i < col + width; i++) {
+ if (i >= SCOLS)
+ break;
a = p * SCOLS + i;
if (Buffer1[a] == Buffer2[a])
continue;
- for (j = i, e = 0; i < col+width; i++) {
+ for (j = i, e = 0; i < col + width; i++) {
a = p * SCOLS + i;
if (Buffer1[a] == Buffer2[a]) {
if (++e > 2)
@@ -188,11 +224,8 @@ static void drv_L7_blit(const int row, const int col, const int height, const in
e = 0;
}
}
- /* change page if necessary */
- if (p != p0) {
- p0 = p;
- drv_L7_write_ctrl(0xb0 | p);
- }
+ /* select page */
+ drv_L7_page(p);
/* column address */
/* first column address = 32 */
drv_L7_write_ctrl(0x00 | ((j + 32) & 0x0f));
@@ -208,6 +241,71 @@ static void drv_L7_blit(const int row, const int col, const int height, const in
}
+static int drv_L7_GPO(const int num, const int val)
+{
+ switch (num) {
+ case 0:
+ /* battery symbol */
+ drv_L7_put(32, (val > 0) ? 1 : 0);
+ break;
+ case 1:
+ /* battery level */
+ if (val < 0) {
+ drv_L7_put(46, 0);
+ drv_L7_put(47, 0);
+ drv_L7_put(48, 0);
+ drv_L7_put(49, 0);
+ } else {
+ drv_L7_put(46, (val & 1) ? 1 : 0);
+ drv_L7_put(47, (val & 2) ? 1 : 0);
+ drv_L7_put(48, (val & 4) ? 1 : 0);
+ drv_L7_put(49, (val & 8) ? 1 : 0);
+ }
+ break;
+ case 2:
+ /* earpiece */
+ drv_L7_put(59, (val > 0) ? 1 : 0);
+ break;
+ case 3:
+ /* triangle */
+ drv_L7_put(69, (val > 0) ? 1 : 0);
+ Buffer1[8 * SCOLS + 69 - 32] = (val > 0);
+ break;
+ case 4:
+ /* head */
+ drv_L7_put(83, (val > 0) ? 1 : 0);
+ Buffer1[8 * SCOLS + 83 - 32] = (val > 0);
+ break;
+ case 5:
+ /* message */
+ drv_L7_put(98, (val > 0) ? 1 : 0);
+ Buffer1[8 * SCOLS + 98 - 32] = (val > 0);
+ break;
+ case 6:
+ /* antenna */
+ drv_L7_put(117, (val > 0) ? 1 : 0);
+ Buffer1[8 * SCOLS + 117 - 32] = (val > 0);
+ break;
+ case 7:
+ /* signal level */
+ if (val < 0) {
+ drv_L7_put(112, 0);
+ drv_L7_put(113, 0);
+ drv_L7_put(114, 0);
+ drv_L7_put(115, 0);
+ } else {
+ drv_L7_put(112, (val & 1) ? 1 : 0);
+ drv_L7_put(113, (val & 2) ? 1 : 0);
+ drv_L7_put(114, (val & 4) ? 1 : 0);
+ drv_L7_put(115, (val & 8) ? 1 : 0);
+ }
+ break;
+ }
+
+ return 0;
+}
+
+
static int drv_L7_contrast(int contrast)
{
if (contrast < 0)
@@ -229,10 +327,11 @@ static int drv_L7_start(const char *section)
/* fixed size */
DROWS = 64;
DCOLS = 100;
+ GPOS = 8;
/* SED1560 display RAM layout */
PAGES = 8;
- SROWS = PAGES * 8;
+ SROWS = 64;
SCOLS = 166;
s = cfg_get(section, "Font", "6x8");
@@ -255,20 +354,20 @@ static int drv_L7_start(const char *section)
}
/* provide room for page 8 (symbols) */
- Buffer1 = malloc((PAGES + 1) * SCOLS);
+ Buffer1 = malloc(PAGES * SCOLS);
if (Buffer1 == NULL) {
error("%s: framebuffer #1 could not be allocated: malloc() failed", Name);
return -1;
}
- Buffer2 = malloc((PAGES + 1) * SCOLS);
+ Buffer2 = malloc(PAGES * SCOLS);
if (Buffer2 == NULL) {
error("%s: framebuffer #2 could not be allocated: malloc() failed", Name);
return -1;
}
- memset(Buffer1, 0, (PAGES + 1) * SCOLS * sizeof(*Buffer1));
- memset(Buffer2, 0, (PAGES + 1) * SCOLS * sizeof(*Buffer2));
+ memset(Buffer1, 0, PAGES * SCOLS * sizeof(*Buffer1));
+ memset(Buffer2, 0, PAGES * SCOLS * sizeof(*Buffer2));
if (drv_generic_parport_open(section, Name) != 0) {
error("%s: could not initialize parallel port!", Name);
@@ -348,6 +447,7 @@ static void plugin_contrast(RESULT * result, RESULT * arg1)
/* using drv_generic_graphic_draw(W) */
/* using drv_generic_graphic_icon_draw(W) */
/* using drv_generic_graphic_bar_draw(W) */
+/* using drv_generic_gpio_draw(W) */
/****************************************/
@@ -371,6 +471,7 @@ int drv_L7_init(const char *section, const int quiet)
/* real worker functions */
drv_generic_graphic_real_blit = drv_L7_blit;
+ drv_generic_gpio_real_set = drv_L7_GPO;
/* start display */
if ((ret = drv_L7_start(section)) != 0)
@@ -380,6 +481,10 @@ int drv_L7_init(const char *section, const int quiet)
if ((ret = drv_generic_graphic_init(section, Name)) != 0)
return ret;
+ /* initialize generic GPIO driver */
+ if ((ret = drv_generic_gpio_init(section, Name)) != 0)
+ return ret;
+
if (!quiet) {
char buffer[40];
qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
@@ -419,12 +524,14 @@ int drv_L7_quit(const int quiet)
info("%s: shutting down.", Name);
drv_generic_graphic_clear();
+ drv_generic_gpio_clear();
if (!quiet) {
drv_generic_graphic_greet("goodbye!", NULL);
}
drv_generic_graphic_quit();
+ drv_generic_gpio_quit();
drv_generic_parport_close();
if (Buffer1) {
diff --git a/drv_generic_gpio.c b/drv_generic_gpio.c
new file mode 100644
index 0000000..4e3a811
--- /dev/null
+++ b/drv_generic_gpio.c
@@ -0,0 +1,159 @@
+/* $Id: drv_generic_gpio.c,v 1.1 2005/12/18 16:18:36 reinelt Exp $
+ *
+ * generic driver helper for GPO's
+ *
+ * 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_generic_gpio.c,v $
+ * Revision 1.1 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
+ */
+
+/*
+ *
+ * exported variables:
+ *
+ * extern int GPIS, GPOS; number of Inputs and Outputs
+ *
+ *
+ * these functions must be implemented by the real driver:
+ *
+ * void (*drv_generic_gpio_real_set) (const int num, const int val);
+ * sets GPO num to val
+ *
+ * int (*drv_generic_gpio_real_get) (const int num);
+ * reads GPI num
+ *
+ *
+ * exported fuctions:
+ *
+ * int drv_generic_gpio_init(const char *section, const char *driver);
+ * initializes the generic GPIO driver
+ *
+ * int drv_generic_gpio_clear(void);
+ * resets all GPO's
+ *
+ * int drv_generic_gpio_draw(WIDGET * W);
+ * 'draws' GPO widget
+ * calls drv_generic_gpio_real_set()
+ *
+ * int drv_generic_gpio_quit(void);
+ * closes the generic GPIO driver
+ *
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include "debug.h"
+#include "plugin.h"
+#include "widget.h"
+#include "widget_gpo.h"
+
+#include "drv_generic_gpio.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+#define MAX_GPOS 32
+
+
+static char *Section = NULL;
+static char *Driver = NULL;
+
+static int GPO[MAX_GPOS];
+
+int GPOS = 0;
+int GPIS = 0;
+
+
+int drv_generic_gpio_init(const char *section, const char *driver)
+{
+ WIDGET_CLASS wc;
+
+ Section = (char *) section;
+ Driver = (char *) driver;
+
+ if (GPIS <= 0 && GPOS <= 0) {
+ error("%s: Huh? gpio_init(GPIS=%d, GPOS=%d)", Driver, GPIS, GPOS);
+ }
+
+ /* reset all GPO's */
+ drv_generic_gpio_clear();
+
+ /* register gpo widget */
+ wc = Widget_GPO;
+ wc.draw = drv_generic_gpio_draw;
+ widget_register(&wc);
+
+
+ /* register plugins */
+ /* Fixme */
+
+ return 0;
+}
+
+
+int drv_generic_gpio_clear(void)
+{
+ int i;
+
+ /* init GPO bufferr */
+ for (i = 0; i < MAX_GPOS; i++) {
+ GPO[i] = 0;
+ }
+
+ /* really clear GPO's */
+ for (i = 0; i < GPOS; i++) {
+ drv_generic_gpio_real_set(i, 0);
+ }
+
+ return 0;
+}
+
+
+int drv_generic_gpio_draw(WIDGET * W)
+{
+ WIDGET_GPO *gpo = W->data;
+ int num = gpo->num;
+ int val = gpo->val;
+
+ if (num < 0 || num >= GPOS) {
+ error("%s: gpio_draw(%d): GPO out of range (0..%d)", Driver, num + 1, GPOS);
+ return -1;
+ }
+
+ if (GPO[num] != val) {
+ drv_generic_gpio_real_set(num, val);
+ GPO[num] = val;
+ }
+
+ return 0;
+}
+
+
+int drv_generic_gpio_quit(void)
+{
+ return 0;
+}
diff --git a/drv_generic_gpio.h b/drv_generic_gpio.h
new file mode 100644
index 0000000..114e049
--- /dev/null
+++ b/drv_generic_gpio.h
@@ -0,0 +1,50 @@
+/* $Id: drv_generic_gpio.h,v 1.1 2005/12/18 16:18:36 reinelt Exp $
+ *
+ * generic driver helper for GPIO's
+ *
+ * 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_generic_gpio.h,v $
+ * Revision 1.1 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
+ */
+
+
+#ifndef _DRV_GENERIC_GPO_H_
+#define _DRV_GENERIC_GPO_H_
+
+#include "widget.h"
+
+extern int GPIS; /* number of GPO's */
+extern int GPOS; /* number of GPO's */
+
+/* these function must be implemented by the real driver */
+int (*drv_generic_gpio_real_set) (const int num, const int val);
+int (*drv_generic_gpio_real_get) (const int num);
+
+/* generic functions and widget callbacks */
+int drv_generic_gpio_init(const char *section, const char *driver);
+int drv_generic_gpio_clear(void);
+int drv_generic_gpio_draw(WIDGET * W);
+int drv_generic_gpio_quit(void);
+
+#endif
diff --git a/layout.c b/layout.c
index 9bc1b3f..7b4fd57 100644
--- a/layout.c
+++ b/layout.c
@@ -1,4 +1,4 @@
-/* $Id: layout.c,v 1.16 2005/05/08 04:32:44 reinelt Exp $
+/* $Id: layout.c,v 1.17 2005/12/18 16:18:36 reinelt Exp $
*
* new layouter framework
*
@@ -23,6 +23,9 @@
*
*
* $Log: layout.c,v $
+ * Revision 1.17 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.16 2005/05/08 04:32:44 reinelt
* CodingStyle added and applied
*
@@ -116,20 +119,12 @@
#endif
-int layout_addItem(const char *name, const int row, const int col)
-{
- /* allocate widget */
- widget_add(name, row - 1, col - 1);
- return 0;
-}
-
-
int layout_init(const char *layout)
{
char *section;
char *list, *l;
char *widget;
- int row, col;
+ int row, col, gpo;
info("initializing layout '%s'", layout);
@@ -155,11 +150,21 @@ int layout_init(const char *layout)
l++;
if ((p = strchr(l, '|')) != NULL)
*p = '\0';
+ /* visible widgets */
i = sscanf(l, "row%d.col%d%n", &row, &col, &n);
if (i == 2 && l[n] == '\0') {
widget = cfg_get(section, l, NULL);
if (widget != NULL && *widget != '\0') {
- layout_addItem(widget, row, col);
+ widget_add(widget, WIDGET_TYPE_VIS, row - 1, col - 1);
+ }
+ free(widget);
+ }
+ /* GPO widgets */
+ i = sscanf(l, "gpo%d%n", &gpo, &n);
+ if (i == 1 && l[n] == '\0') {
+ widget = cfg_get(section, l, NULL);
+ if (widget != NULL && *widget != '\0') {
+ widget_add(widget, WIDGET_TYPE_GPO, gpo - 1, 0);
}
free(widget);
}
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 408c4ad..ca04793 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -729,6 +729,18 @@ Widget Test2 {
speed 150
}
+Widget GPO_Test {
+ class 'GPO'
+ expression test::onoff(1)
+ update 300
+}
+
+Widget GPO_Test2 {
+ class 'GPO'
+ expression test::bar(0,15, 0, 1)
+ update 300
+}
+
Layout Default {
Row1 {
Col1 'OS'
@@ -828,6 +840,12 @@ Layout Test2 {
Row08.Col1 'Test2'
}
+Layout TestGPO {
+ Row1.Col1 'Test1'
+# GPO7 'GPO_Test'
+ GPO2 'GPO_Test2'
+}
+
Layout testMySQL {
Row1 {
Col1 'MySQLtest1'
@@ -866,11 +884,12 @@ Layout testMySQL {
#Display 'LPH7508-serdisplib'
Display 'LPH7508'
-Layout 'Default'
+#Layout 'Default'
#Layout 'L8x2'
#Layout 'L16x2'
#Layout 'L20x2'
#Layout 'Test'
#Layout 'Test2'
+Layout 'TestGPO'
diff --git a/widget.c b/widget.c
index a830316..57c2c4a 100644
--- a/widget.c
+++ b/widget.c
@@ -1,4 +1,4 @@
-/* $Id: widget.c,v 1.20 2005/11/06 09:17:20 reinelt Exp $
+/* $Id: widget.c,v 1.21 2005/12/18 16:18:36 reinelt Exp $
*
* generic widget handling
*
@@ -21,6 +21,9 @@
*
*
* $Log: widget.c,v $
+ * Revision 1.21 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.20 2005/11/06 09:17:20 reinelt
* re-use icons (thanks to Jesus de Santos Garcia)
*
@@ -169,7 +172,7 @@ void widget_unregister(void)
for (i = 0; i < nWidgets; i++) {
Widgets[i].class->quit(&(Widgets[i]));
if (Widgets[i].name)
- free (Widgets[i].name);
+ free(Widgets[i].name);
}
free(Widgets);
@@ -179,7 +182,7 @@ void widget_unregister(void)
nClasses = 0;
}
-int widget_add(const char *name, const int row, const int col)
+int widget_add(const char *name, const int type, const int row, const int col)
{
int i;
char *section;
@@ -204,6 +207,7 @@ int widget_add(const char *name, const int row, const int col)
return -1;
}
free(section);
+
/* lookup widget class */
Class = NULL;
for (i = 0; i < nClasses; i++) {
@@ -218,9 +222,18 @@ int widget_add(const char *name, const int row, const int col)
free(class);
return -1;
}
+
+ /* check if widget type matches */
+ if ((Class->type & type) == 0) {
+ error("widget '%s': class '%s' not applicable", name, class);
+ free(class);
+ return -1;
+ }
+
if (class)
free(class);
+
/* do NOT use realloc here because there may be pointers to the old */
/* memory area, which would point to nowhere if realloc moves the area */
if (Widgets == NULL) {
diff --git a/widget.h b/widget.h
index 5805041..04de327 100644
--- a/widget.h
+++ b/widget.h
@@ -1,4 +1,4 @@
-/* $Id: widget.h,v 1.14 2005/11/06 09:17:20 reinelt Exp $
+/* $Id: widget.h,v 1.15 2005/12/18 16:18:36 reinelt Exp $
*
* generic widget handling
*
@@ -23,6 +23,9 @@
*
*
* $Log: widget.h,v $
+ * Revision 1.15 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.14 2005/11/06 09:17:20 reinelt
* re-use icons (thanks to Jesus de Santos Garcia)
*
@@ -93,6 +96,7 @@ struct WIDGET; /* forward declaration */
typedef struct WIDGET_CLASS {
char *name;
+ int type;
int (*init) (struct WIDGET * Self);
int (*draw) (struct WIDGET * Self);
int (*quit) (struct WIDGET * Self);
@@ -109,9 +113,12 @@ typedef struct WIDGET {
} WIDGET;
+#define WIDGET_TYPE_VIS 1
+#define WIDGET_TYPE_GPO 2
+
int widget_register(WIDGET_CLASS * widget);
void widget_unregister(void);
-int widget_add(const char *name, const int row, const int col);
+int widget_add(const char *name, const int type, const int row, const int col);
#endif
diff --git a/widget_bar.c b/widget_bar.c
index 810c69a..62db084 100644
--- a/widget_bar.c
+++ b/widget_bar.c
@@ -1,4 +1,4 @@
-/* $Id: widget_bar.c,v 1.16 2005/05/08 04:32:45 reinelt Exp $
+/* $Id: widget_bar.c,v 1.17 2005/12/18 16:18:36 reinelt Exp $
*
* bar widget handling
*
@@ -21,6 +21,9 @@
*
*
* $Log: widget_bar.c,v $
+ * Revision 1.17 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.16 2005/05/08 04:32:45 reinelt
* CodingStyle added and applied
*
@@ -296,6 +299,7 @@ int widget_bar_quit(WIDGET * Self)
WIDGET_CLASS Widget_Bar = {
name:"bar",
+ type:WIDGET_TYPE_VIS,
init:widget_bar_init,
draw:NULL,
quit:widget_bar_quit,
diff --git a/widget_gpo.c b/widget_gpo.c
new file mode 100644
index 0000000..a53b012
--- /dev/null
+++ b/widget_gpo.c
@@ -0,0 +1,141 @@
+/* $Id: widget_gpo.c,v 1.1 2005/12/18 16:18:36 reinelt Exp $
+ *
+ * GPO widget handling
+ *
+ * Copyright (C) 2005 Michael Reinelt <reinelt@eunet.at>
+ * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ *
+ * This program 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.
+ *
+ * This program 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: widget_gpo.c,v $
+ * Revision 1.1 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
+ */
+
+/*
+ * exported functions:
+ *
+ * WIDGET_CLASS Widget_GPO
+ * the GPO widget
+ *
+ */
+
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "debug.h"
+#include "cfg.h"
+#include "evaluator.h"
+#include "timer.h"
+#include "widget.h"
+#include "widget_gpo.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+
+void widget_gpo_update(void *Self)
+{
+ WIDGET *W = (WIDGET *) Self;
+ WIDGET_GPO *GPO = W->data;
+ RESULT result = { 0, 0, 0, NULL };
+
+ int val;
+
+ /* evaluate expression */
+ val = 0;
+ if (GPO->tree != NULL) {
+ Eval(GPO->tree, &result);
+ val = R2N(&result);
+ DelResult(&result);
+ }
+ GPO->num = W->row;
+ GPO->val = val;
+
+ /* finally, draw it! */
+ if (W->class->draw)
+ W->class->draw(W);
+
+}
+
+
+int widget_gpo_init(WIDGET * Self)
+{
+ char *section;
+ WIDGET_GPO *GPO;
+
+ /* prepare config section */
+ /* strlen("Widget:")=7 */
+ section = malloc(strlen(Self->name) + 8);
+ strcpy(section, "Widget:");
+ strcat(section, Self->name);
+
+ GPO = malloc(sizeof(WIDGET_GPO));
+ memset(GPO, 0, sizeof(WIDGET_GPO));
+
+ /* get raw expression (we evaluate them ourselves) */
+ GPO->expression = cfg_get_raw(section, "expression", NULL);
+
+ /* sanity check */
+ if (GPO->expression == NULL || *GPO->expression == '\0') {
+ error("widget %s has no expression, using '0.0'", Self->name);
+ GPO->expression = "0";
+ }
+
+ /* compile expression */
+ Compile(GPO->expression, &GPO->tree);
+
+ /* update interval (msec), default 1 sec */
+ cfg_number(section, "update", 1000, 10, -1, &(GPO->update));
+
+ free(section);
+ Self->data = GPO;
+
+ timer_add(widget_gpo_update, Self, GPO->update, 0);
+
+ return 0;
+}
+
+
+int widget_gpo_quit(WIDGET * Self)
+{
+ if (Self) {
+ if (Self->data) {
+ WIDGET_GPO *GPO = Self->data;
+ DelTree(GPO->tree);
+ free(Self->data);
+ }
+ Self->data = NULL;
+ }
+ return 0;
+}
+
+
+
+WIDGET_CLASS Widget_GPO = {
+ name:"gpo",
+ type:WIDGET_TYPE_GPO,
+ init:widget_gpo_init,
+ draw:NULL,
+ quit:widget_gpo_quit,
+};
diff --git a/widget_gpo.h b/widget_gpo.h
new file mode 100644
index 0000000..cc93f84
--- /dev/null
+++ b/widget_gpo.h
@@ -0,0 +1,46 @@
+/* $Id: widget_gpo.h,v 1.1 2005/12/18 16:18:36 reinelt Exp $
+ *
+ * GPO widget handling
+ *
+ * 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: widget_gpo.h,v $
+ * Revision 1.1 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
+ */
+
+
+#ifndef _WIDGET_GPO_H_
+#define _WIDGET_GPO_H_
+
+typedef struct WIDGET_GPO {
+ char *expression; /* expression that delivers the value */
+ void *tree; /* pre-compiled expression that delivers the value */
+ int update; /* update interval (msec) */
+ int num; /* GPO number */
+ int val; /* GPO value */
+} WIDGET_GPO;
+
+
+extern WIDGET_CLASS Widget_GPO;
+
+#endif
diff --git a/widget_icon.c b/widget_icon.c
index 81a6867..bb21918 100644
--- a/widget_icon.c
+++ b/widget_icon.c
@@ -1,4 +1,4 @@
-/* $Id: widget_icon.c,v 1.19 2005/11/06 09:54:43 reinelt Exp $
+/* $Id: widget_icon.c,v 1.20 2005/12/18 16:18:36 reinelt Exp $
*
* icon widget handling
*
@@ -21,6 +21,9 @@
*
*
* $Log: widget_icon.c,v $
+ * Revision 1.20 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.19 2005/11/06 09:54:43 reinelt
* fixed icon size removed, uses XRES & YRES (I hope this doesn't lead to problemes...)
*
@@ -261,10 +264,10 @@ int widget_icon_init(WIDGET * Self)
Icon->ascii = -1;
} else {
-
+
/* re-use the parent */
Self->data = Self->parent->data;
-
+
}
/* just do it! */
@@ -299,6 +302,7 @@ int widget_icon_quit(WIDGET * Self)
WIDGET_CLASS Widget_Icon = {
name:"icon",
+ type:WIDGET_TYPE_VIS,
init:widget_icon_init,
draw:NULL,
quit:widget_icon_quit,
diff --git a/widget_text.c b/widget_text.c
index f205a59..d34a7c0 100644
--- a/widget_text.c
+++ b/widget_text.c
@@ -1,4 +1,4 @@
-/* $Id: widget_text.c,v 1.22 2005/05/08 04:32:45 reinelt Exp $
+/* $Id: widget_text.c,v 1.23 2005/12/18 16:18:36 reinelt Exp $
*
* simple text widget handling
*
@@ -21,6 +21,9 @@
*
*
* $Log: widget_text.c,v $
+ * Revision 1.23 2005/12/18 16:18:36 reinelt
+ * GPO's added again
+ *
* Revision 1.22 2005/05/08 04:32:45 reinelt
* CodingStyle added and applied
*
@@ -478,6 +481,7 @@ int widget_text_quit(WIDGET * Self)
WIDGET_CLASS Widget_Text = {
name:"text",
+ type:WIDGET_TYPE_VIS,
init:widget_text_init,
draw:NULL,
quit:widget_text_quit,