]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2006-02-21 05:50:34 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 21 Feb 2006 05:50:34 +0000 (05:50 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 21 Feb 2006 05:50:34 +0000 (05:50 +0000)
keypad support from Cris Maj

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@641 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

12 files changed:
Makefile.am
Makefile.in
configure
drivers.m4
drv_Crystalfontz.c
drv_generic_keypad.c [new file with mode: 0644]
drv_generic_keypad.h [new file with mode: 0644]
layout.c
widget.c
widget.h
widget_keypad.c [new file with mode: 0644]
widget_keypad.h [new file with mode: 0644]

index 32ec0632c6ea609556e283b51d3af5a9f11b0042..53488fd4567675daf0af6933ef89ccc461848edf 100644 (file)
@@ -33,6 +33,7 @@ widget_text.c widget_text.h   \
 widget_bar.c  widget_bar.h    \
 widget_icon.c widget_icon.h   \
 widget_image.c widget_image.h \
+widget_keypad.c widget_keypad.h    \
 widget_timer.c widget_timer.h \
 widget_gpo.c  widget_gpo.h    \
                               \
@@ -56,6 +57,8 @@ drv_generic_parport.c         \
 drv_generic_parport.h         \
 drv_generic_i2c.c             \
 drv_generic_i2c.h             \
+drv_generic_keypad.c          \
+drv_generic_keypad.h          \
 drv_BeckmannEgle.c            \
 drv_BWCT.c                    \
 drv_Crystalfontz.c            \
index 0922e78684a7140299408c5e57f0156c3485759f..e4c2effe8012d2dcab30fd2f8ce5f41a90852d43 100644 (file)
@@ -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       rgb.c         rgb.h                                         widget.c      widget.h        widget_text.c widget_text.h   widget_bar.c  widget_bar.h    widget_icon.c widget_icon.h   widget_image.c widget_image.h widget_timer.c widget_timer.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
+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       rgb.c         rgb.h                                         widget.c      widget.h        widget_text.c widget_text.h   widget_bar.c  widget_bar.h    widget_icon.c widget_icon.h   widget_image.c widget_image.h widget_keypad.c widget_keypad.h    widget_timer.c widget_timer.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_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_G15.c                     drv_HD44780.c                 drv_Image.c                   drv_LCD2USB.c                 drv_LCDLinux.c                drv_LCDTerm.c                 drv_LPH7508.c                 drv_LUIse.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_file.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_generic_keypad.c          drv_generic_keypad.h          drv_BeckmannEgle.c            drv_BWCT.c                    drv_Crystalfontz.c            drv_Curses.c                  drv_Cwlinux.c                 drv_G15.c                     drv_HD44780.c                 drv_Image.c                   drv_LCD2USB.c                 drv_LCDLinux.c                drv_LCDTerm.c                 drv_LPH7508.c                 drv_LUIse.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_file.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,9 +126,9 @@ 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 rgb.o widget.o \
-widget_text.o widget_bar.o widget_icon.o widget_image.o widget_timer.o \
-widget_gpo.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_image.o widget_keypad.o \
+widget_timer.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)
@@ -153,23 +153,23 @@ DEP_FILES =  .deps/cfg.P .deps/debug.P .deps/drv.P .deps/drv_BWCT.P \
 .deps/drv_T6963.P .deps/drv_Trefon.P .deps/drv_USBLCD.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_file.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/rgb.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_image.P .deps/widget_text.P \
-.deps/widget_timer.P
+.deps/drv_generic_keypad.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_file.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/rgb.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_image.P \
+.deps/widget_keypad.P .deps/widget_text.P .deps/widget_timer.P
 SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
 OBJECTS = $(lcd4linux_OBJECTS)
 
index e91a58a194fd59595330d0ccf68c5b0469d93440..fd44593deee8cc308e24dc3a89a3687e2c1741b4 100755 (executable)
--- a/configure
+++ b/configure
@@ -6321,6 +6321,7 @@ IMAGE="no"
 PARPORT="no"
 SERIAL="no"
 I2C="no"
+KEYPAD="no"
 
 
 if test "$BECKMANNEGLE" = "yes"; then
@@ -6355,6 +6356,7 @@ if test "$CRYSTALFONTZ" = "yes"; then
    TEXT="yes"
    GPIO="yes"
    SERIAL="yes"
+   KEYPAD="yes"
    DRIVERS="$DRIVERS drv_Crystalfontz.o"
 
 cat >>confdefs.h <<\_ACEOF
@@ -6746,6 +6748,10 @@ _ACEOF
 
 fi
 
+# generic keypad driver
+if test "$KEYPAD" = "yes"; then
+   DRIVERS="$DRIVERS drv_generic_keypad.o"
+fi
 
 
 
index 4b5789e22403493740b6069a23c8c72978656b73..5888051d6e0a686304bc233412f3a90a8b9c9ce7 100644 (file)
@@ -186,6 +186,7 @@ IMAGE="no"
 PARPORT="no"
 SERIAL="no"
 I2C="no"
+KEYPAD="no"
 
 
 if test "$BECKMANNEGLE" = "yes"; then
@@ -211,6 +212,7 @@ if test "$CRYSTALFONTZ" = "yes"; then
    TEXT="yes"
    GPIO="yes"
    SERIAL="yes"
+   KEYPAD="yes"
    DRIVERS="$DRIVERS drv_Crystalfontz.o"
    AC_DEFINE(WITH_CRYSTALFONTZ,1,[Crystalfontz driver])
 fi
@@ -483,6 +485,10 @@ if test "$I2C" = "yes"; then
    AC_DEFINE(WITH_I2C, 1, [I2C bus driver])
 fi
 
+# generic keypad driver
+if test "$KEYPAD" = "yes"; then
+   DRIVERS="$DRIVERS drv_generic_keypad.o"
+fi
 
 AC_SUBST(DRIVERS)
 AC_SUBST(DRVLIBS)
index e179a15ec3aee6fd08c066ab616315368e9a1880..e63d803217422f7e25928ad8bc3257f373445f3b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_Crystalfontz.c,v 1.39 2006/02/19 15:37:38 reinelt Exp $
+/* $Id: drv_Crystalfontz.c,v 1.40 2006/02/21 05:50:34 reinelt Exp $
  *
  * new style driver for Crystalfontz display modules
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: drv_Crystalfontz.c,v $
+ * Revision 1.40  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
  * Revision 1.39  2006/02/19 15:37:38  reinelt
  * CF635 GPO patch from cmaj
  *
 #include "widget_text.h"
 #include "widget_icon.h"
 #include "widget_bar.h"
+#include "widget_keypad.h"
 #include "drv.h"
 #include "drv_generic_text.h"
 #include "drv_generic_gpio.h"
 #include "drv_generic_serial.h"
+#include "drv_generic_keypad.h"
 
 
 static char Name[] = "Crystalfontz";
@@ -244,20 +249,22 @@ typedef struct {
     int gpos;
     int protocol;
     int payload;
+    int keypadsize;
 } MODEL;
 
 /* Fixme #1: number of GPI's & GPO's should be verified */
 /* Fixme #2: protocol should be verified */
+/* Fixme #3: number of keys on the keypad should be verified */
 
 static MODEL Models[] = {
-    {626, "626", 2, 16, 0, 0, 1, 0},
-    {631, "631", 2, 20, 0, 0, 3, 22},
-    {632, "632", 2, 16, 0, 0, 1, 0},
-    {633, "633", 2, 16, 4, 4, 2, 18},
-    {634, "634", 4, 20, 0, 0, 1, 0},
-    {635, "635", 4, 20, 4, 12, 3, 22},
-    {636, "636", 2, 16, 0, 0, 1, 0},
-    {-1, "Unknown", -1, -1, 0, 0, 0, 0}
+    {626, "626", 2, 16, 0, 0, 1, 0, 0},
+    {631, "631", 2, 20, 0, 0, 3, 22, 4},
+    {632, "632", 2, 16, 0, 0, 1, 0, 0},
+    {633, "633", 2, 16, 4, 4, 2, 18, 6},
+    {634, "634", 4, 20, 0, 0, 1, 0, 0},
+    {635, "635", 4, 20, 0, 0, 3, 22, 6},
+    {636, "636", 2, 16, 0, 0, 1, 0, 0},
+    {-1, "Unknown", -1, -1, 0, 0, 0, 0, 0}
 };
 
 
@@ -312,6 +319,7 @@ static void drv_CF_process_packet(void)
        case 0x00:
            /* Key Activity */
            debug("Key Activity: %d", Packet.data[0]);
+           drv_generic_keypad_press(Packet.data[0]);
            break;
 
        case 0x01:
@@ -666,6 +674,52 @@ static int drv_CF_backlight(int backlight)
 }
 
 
+static int drv_CF_keypad(const int num)
+{
+    int val = 0;
+
+    switch (Protocol) {
+    case 1:
+    case 2:
+       break;
+    case 3:
+       if (num < 8)
+           val = KEY_PRESSED;
+       else
+           val = KEY_RELEASED;
+       switch (num) {
+       case 1:
+       case 8:
+           val += KEY_UP;
+           break;
+       case 2:
+       case 9:
+           val += KEY_DOWN;
+           break;
+       case 3:
+       case 10:
+           val += KEY_LEFT;
+           break;
+       case 4:
+       case 11:
+           val += KEY_RIGHT;
+           break;
+       case 5:
+       case 12:
+           val += KEY_CONFIRM;
+           break;
+       case 7:
+       case 13:
+           val += KEY_CANCEL;
+           break;
+       }
+       break;
+    }
+
+    return val;
+}
+
+
 static int drv_CF_GPI(const int num)
 {
     if (num < 0 || num > 3) {
@@ -677,7 +731,7 @@ static int drv_CF_GPI(const int num)
 
 static int drv_CF_GPO(const int num, const int val)
 {
-    static unsigned char PWM2[4] = { 0, 0, 0, 0};
+    static unsigned char PWM2[4] = { 0, 0, 0, 0 };
     static unsigned char PWM3[2];
 
     int v = val;
@@ -931,6 +985,7 @@ static int drv_CF_start(const char *section)
     GPOS = Models[Model].gpos;
     Protocol = Models[Model].protocol;
     Payload = Models[Model].payload;
+    KEYPADSIZE = Models[Model].keypadsize;
 
 
     switch (Protocol) {
@@ -1027,6 +1082,7 @@ static void plugin_backlight(RESULT * result, const int argc, RESULT * argv[])
 /* using drv_generic_text_icon_draw(W) */
 /* using drv_generic_text_bar_draw(W) */
 /* using drv_generic_gpio_draw(W) */
+/* using drv_generic_keypad_draw(W) */
 
 
 /****************************************/
@@ -1052,7 +1108,7 @@ int drv_CF_init(const char *section, const int quiet)
     WIDGET_CLASS wc;
     int ret;
 
-    info("%s: %s", Name, "$Revision: 1.39 $");
+    info("%s: %s", Name, "$Revision: 1.40 $");
 
     /* start display */
     if ((ret = drv_CF_start(section)) != 0) {
@@ -1087,6 +1143,7 @@ int drv_CF_init(const char *section, const int quiet)
        drv_generic_text_real_defchar = drv_CF_defchar23;
        drv_generic_gpio_real_get = drv_CF_GPI;
        drv_generic_gpio_real_set = drv_CF_GPO;
+       drv_generic_keypad_real_press = drv_CF_keypad;
        break;
     }
 
@@ -1120,6 +1177,10 @@ int drv_CF_init(const char *section, const int quiet)
     if ((ret = drv_generic_gpio_init(section, Name)) != 0)
        return ret;
 
+    /* initialize generic key pad driver */
+    if ((ret = drv_generic_keypad_init(section, Name)) != 0)
+       return ret;
+
     /* register text widget */
     wc = Widget_Text;
     wc.draw = drv_generic_text_draw;
@@ -1151,6 +1212,7 @@ int drv_CF_quit(const int quiet)
 
     drv_generic_text_quit();
     drv_generic_gpio_quit();
+    drv_generic_keypad_quit();
 
     /* clear display */
     drv_CF_clear();
diff --git a/drv_generic_keypad.c b/drv_generic_keypad.c
new file mode 100644 (file)
index 0000000..cdf2d08
--- /dev/null
@@ -0,0 +1,84 @@
+/* $Id: drv_generic_keypad.c,v 1.1 2006/02/21 05:50:34 reinelt Exp $
+ *
+ * generic driver helper for keypads
+ *
+ * Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
+ * Copyright (C) 2006 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_keypad.c,v $
+ * Revision 1.1  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
+ *
+ */
+
+#include <stdio.h>
+
+#include "debug.h"
+#include "widget.h"
+#include "widget_keypad.h"
+
+#include "drv_generic_keypad.h"
+
+#define MAX_KEYPADSIZE 32
+
+static char *Section = NULL;
+static char *Driver = NULL;
+
+int KEYPADSIZE = 0;
+
+int (*drv_generic_keypad_real_press) () = NULL;
+
+int drv_generic_keypad_init(const char *section, const char *driver)
+{
+    WIDGET_CLASS wc;
+
+    Section = (char *) section;
+    Driver = (char *) driver;
+
+    info("%s: using KEYPADSIZE %d", Driver, KEYPADSIZE);
+
+    /* register keypad widget */
+    wc = Widget_Keypad;
+    widget_register(&wc);
+
+    return 0;
+}
+
+int drv_generic_keypad_press(const int num)
+{
+    WIDGET *w;
+    int val = 0;
+
+    if (drv_generic_keypad_real_press)
+       val = drv_generic_keypad_real_press(num);
+
+    w = widget_find(WIDGET_TYPE_KEYPAD, &val);
+
+    if (w && w->class->update)
+       w->class->update(w);
+
+    return val;
+}
+
+int drv_generic_keypad_quit(void)
+{
+    return 0;
+}
diff --git a/drv_generic_keypad.h b/drv_generic_keypad.h
new file mode 100644 (file)
index 0000000..1bc0c03
--- /dev/null
@@ -0,0 +1,45 @@
+/* $Id: drv_generic_keypad.h,v 1.1 2006/02/21 05:50:34 reinelt Exp $
+ *
+ * generic driver helper for keypads
+ *
+ * Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
+ * Copyright (C) 2006 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: drv_generic_keypad.h,v $
+ * Revision 1.1  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
+ *
+ */
+
+#ifndef _DRV_GENERIC_KEYPAD_H_
+#define _DRV_GENERIC_KEYPAD_H_
+
+#include "widget.h"
+
+extern int KEYPADSIZE;         /* number of keys on the pad */
+
+/* these functinos must be implemented by the real driver */
+extern int (*drv_generic_keypad_real_press) (const int num);
+
+/* generic functions and widget callbacks */
+int drv_generic_keypad_init(const char *section, const char *driver);
+int drv_generic_keypad_press(const int num);
+int drv_generic_keypad_draw(WIDGET * W);
+int drv_generic_keypad_quit(void);
+
+#endif
index 2108468a6e36540a981f66f8007c0af612705753..e6a397f69f2cd9d1345d9f33d67e8a019dcc19ba 100644 (file)
--- a/layout.c
+++ b/layout.c
@@ -1,4 +1,4 @@
-/* $Id: layout.c,v 1.21 2006/02/08 04:55:05 reinelt Exp $
+/* $Id: layout.c,v 1.22 2006/02/21 05:50:34 reinelt Exp $
  *
  * new layouter framework
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: layout.c,v $
+ * Revision 1.22  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
  * Revision 1.21  2006/02/08 04:55:05  reinelt
  * moved widget registration to drv_generic_graphic
  *
@@ -169,7 +172,7 @@ int layout_init(const char *layout)
        i = sscanf(l, "layer:%d.x%d.y%d%n", &lay, &row, &col, &n);
        if (i == 3 && l[n] == '\0') {
            if (lay < 0 || lay >= LAYERS) {
-               error ("%s: layer %d out of bounds (0..%d)", section, lay, LAYERS-1);
+               error("%s: layer %d out of bounds (0..%d)", section, lay, LAYERS - 1);
            } else {
                widget = cfg_get(section, l, NULL);
                if (widget != NULL && *widget != '\0') {
@@ -183,7 +186,7 @@ int layout_init(const char *layout)
        i = sscanf(l, "layer:%d.row%d.col%d%n", &lay, &row, &col, &n);
        if (i == 3 && l[n] == '\0') {
            if (lay < 0 || lay >= LAYERS) {
-               error ("%s: layer %d out of bounds (0..%d)", section, lay, LAYERS-1);
+               error("%s: layer %d out of bounds (0..%d)", section, lay, LAYERS - 1);
            } else {
                widget = cfg_get(section, l, NULL);
                if (widget != NULL && *widget != '\0') {
@@ -193,7 +196,7 @@ int layout_init(const char *layout)
            }
        }
 
-       /* row/col widgets w/o layer*/
+       /* row/col widgets w/o layer */
        i = sscanf(l, "row%d.col%d%n", &row, &col, &n);
        if (i == 2 && l[n] == '\0') {
            widget = cfg_get(section, l, NULL);
@@ -224,6 +227,16 @@ int layout_init(const char *layout)
            free(widget);
        }
 
+       /* keypad widget */
+       i = sscanf(l, "keypad%d%n", &num, &n);
+       if (i == 1 && l[n] == '\0') {
+           widget = cfg_get(section, l, NULL);
+           if (widget != NULL && *widget != '\0') {
+               widget_add(widget, WIDGET_TYPE_KEYPAD, 0, num - 1, 0);
+           }
+           free(widget);
+       }
+
        /* next field */
        l = p ? p + 1 : NULL;
     }
index 5476cd1e07233a574b8472009123f06cb37e7fb0..5ade00ca073af69970d30331f3db4ede35d787bf 100644 (file)
--- a/widget.c
+++ b/widget.c
@@ -1,4 +1,4 @@
-/* $Id: widget.c,v 1.22 2006/01/30 05:47:38 reinelt Exp $
+/* $Id: widget.c,v 1.23 2006/02/21 05:50:34 reinelt Exp $
  *
  * generic widget handling
  *
@@ -21,6 +21,9 @@
  *
  *
  * $Log: widget.c,v $
+ * Revision 1.23  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
  * Revision 1.22  2006/01/30 05:47:38  reinelt
  * graphic subsystem changed to full-color RGBA
  *
@@ -318,3 +321,21 @@ int widget_add(const char *name, const int type, const int layer, const int row,
 
     return 0;
 }
+
+/* return the found widget, or else NULL */
+WIDGET *widget_find(int type, void *needle)
+{
+    WIDGET *widget = NULL;
+    int i;
+
+    for (i = 0; i < nWidgets; i++) {
+       widget = &(Widgets[i]);
+       if (widget->class->type == type) {
+           if (widget->class->find != NULL && widget->class->find(widget, needle) == 0)
+               break;
+       }
+       widget = NULL;
+    }
+
+    return widget;
+}
index 4300164d1553717cac6e440dfb3b01aec7811c6b..d5f7abd7bcf1bd03740d876a0c308780fe48ecbf 100644 (file)
--- a/widget.h
+++ b/widget.h
@@ -1,4 +1,4 @@
-/* $Id: widget.h,v 1.17 2006/01/30 05:47:38 reinelt Exp $
+/* $Id: widget.h,v 1.18 2006/02/21 05:50:34 reinelt Exp $
  *
  * generic widget handling
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: widget.h,v $
+ * Revision 1.18  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
  * Revision 1.17  2006/01/30 05:47:38  reinelt
  * graphic subsystem changed to full-color RGBA
  *
@@ -107,6 +110,8 @@ typedef struct WIDGET_CLASS {
     int type;
     int (*init) (struct WIDGET * Self);
     int (*draw) (struct WIDGET * Self);
+    int (*find) (struct WIDGET * Self, void *needle);
+    void (*update) (void *Self);
     int (*quit) (struct WIDGET * Self);
 } WIDGET_CLASS;
 
@@ -130,10 +135,12 @@ typedef struct WIDGET {
 #define WIDGET_TYPE_XY 2
 #define WIDGET_TYPE_GPO 3
 #define WIDGET_TYPE_TIMER 4
+#define WIDGET_TYPE_KEYPAD 5
 
 
 int widget_register(WIDGET_CLASS * widget);
 void widget_unregister(void);
 int widget_add(const char *name, const int type, const int layer, const int row, const int col);
+WIDGET *widget_find(int type, void *needle);
 
 #endif
diff --git a/widget_keypad.c b/widget_keypad.c
new file mode 100644 (file)
index 0000000..8c278b1
--- /dev/null
@@ -0,0 +1,176 @@
+/* $Id: widget_keypad.c,v 1.1 2006/02/21 05:50:34 reinelt Exp $
+ *
+ * keypad widget handling
+ *
+ * Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
+ * Copyright (C) 2006 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_keypad.c,v $
+ * Revision 1.1  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * WIDGET_CLASS Widget_Keypad
+ *   the keypad 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_keypad.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+
+void widget_keypad_update(void *Self)
+{
+    WIDGET *W = (WIDGET *) Self;
+    WIDGET_KEYPAD *keypad = W->data;
+    RESULT result = { 0, 0, 0, NULL };
+
+    int val;
+
+    /* evaluate expression */
+    val = 0;
+    if (keypad->tree != NULL) {
+       Eval(keypad->tree, &result);
+       val = R2N(&result);
+       DelResult(&result);
+    }
+    keypad->val = val;
+
+    /* finally, draw it! */
+    if (W->class->draw)
+       W->class->draw(W);
+
+}
+
+
+int widget_keypad_init(WIDGET * Self)
+{
+    char *section;
+    char *c;
+    WIDGET_KEYPAD *keypad;
+
+    /* prepare config section */
+    /* strlen("Widget:")=7 */
+    section = malloc(strlen(Self->name) + 8);
+    strcpy(section, "Widget:");
+    strcat(section, Self->name);
+
+    keypad = malloc(sizeof(WIDGET_KEYPAD));
+    memset(keypad, 0, sizeof(WIDGET_KEYPAD));
+
+    /* get raw expression (we evaluate them ourselves) */
+    keypad->expression = cfg_get_raw(section, "expression", NULL);
+
+    /* sanity check */
+    if (keypad->expression == NULL || *keypad->expression == '\0') {
+       error("widget %s has no expression, using '0.0'", Self->name);
+       keypad->expression = "0";
+    }
+
+    /* compile expression */
+    Compile(keypad->expression, &keypad->tree);
+
+    /* state: pressed (default), released */
+    c = cfg_get(section, "state", "pressed");
+    if (!strcasecmp(c, "released"))
+       keypad->key = KEY_RELEASED;
+    else
+       keypad->key = KEY_PRESSED;
+
+    /* position: confirm (default), up, down, left, right, cancel */
+    c = cfg_get(section, "position", "confirm");
+    if (!strcasecmp(c, "up"))
+       keypad->key += KEY_UP;
+    else if (!strcasecmp(c, "down"))
+       keypad->key += KEY_DOWN;
+    else if (!strcasecmp(c, "left"))
+       keypad->key += KEY_LEFT;
+    else if (!strcasecmp(c, "right"))
+       keypad->key += KEY_RIGHT;
+    else if (!strcasecmp(c, "cancel"))
+       keypad->key += KEY_CANCEL;
+    else
+       keypad->key += KEY_CONFIRM;
+
+    free(section);
+    Self->data = keypad;
+
+    return 0;
+}
+
+int widget_keypad_find(WIDGET * Self, void *needle)
+{
+    WIDGET_KEYPAD *keypad;
+    unsigned int *n = needle;
+
+    if (Self) {
+       if (Self->data) {
+           keypad = Self->data;
+           if (keypad->key == *n)
+               return 0;
+       }
+    }
+
+    return -1;
+}
+
+int widget_keypad_quit(WIDGET * Self)
+{
+    if (Self) {
+       if (Self->data) {
+           WIDGET_KEYPAD *KEYPAD = Self->data;
+           DelTree(KEYPAD->tree);
+           free(Self->data);
+       }
+       Self->data = NULL;
+    }
+    return 0;
+}
+
+
+
+WIDGET_CLASS Widget_Keypad = {
+  name:"keypad",
+  type:WIDGET_TYPE_KEYPAD,
+  init:widget_keypad_init,
+  draw:NULL,
+  find:widget_keypad_find,
+  update:widget_keypad_update,
+  quit:widget_keypad_quit,
+};
diff --git a/widget_keypad.h b/widget_keypad.h
new file mode 100644 (file)
index 0000000..e877aea
--- /dev/null
@@ -0,0 +1,49 @@
+/* $Id: widget_keypad.h,v 1.1 2006/02/21 05:50:34 reinelt Exp $
+ *
+ * keypad widget handling
+ *
+ * Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
+ * Copyright (C) 2006 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_keypad.h,v $
+ * Revision 1.1  2006/02/21 05:50:34  reinelt
+ * keypad support from Cris Maj
+ *
+ *
+ */
+
+
+#ifndef _WIDGET_KEYPAD_H_
+#define _WIDGET_KEYPAD_H_
+
+typedef enum { KEY_UP = 1, KEY_DOWN = 2, KEY_LEFT = 4, KEY_RIGHT = 8, KEY_CONFIRM = 16, KEY_CANCEL = 32, KEY_PRESSED =
+       64, KEY_RELEASED = 128 } KEYPADKEY;
+
+typedef struct WIDGET_KEYPAD {
+    char *expression;          /* expression that delivers the value */
+    void *tree;                        /* pre-compiled expression that delivers the value */
+    int val;                   /* current value of the expression */
+    KEYPADKEY key;             /* which key */
+} WIDGET_KEYPAD;
+
+
+extern WIDGET_CLASS Widget_Keypad;
+
+#endif