aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-10 20:22:33 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-10 20:22:33 +0000
commita390d8386961109a8e182897753080538dce8625 (patch)
treecc950b0ce0cb241f374de0671aa2bc2cacae8140
parent76ffcfa4c6fb4cf45126bfd97c3ab0affe1e8e0d (diff)
downloadlcd4linux-a390d8386961109a8e182897753080538dce8625.tar.gz
[lcd4linux @ 2004-01-10 20:22:33 by reinelt]
added new function 'cfg_list()' (not finished yet) added layout.c (will replace processor.c someday) added widget_text.c (will be the first and most important widget) modified lcd4linux.c so that old-style configs should work, too git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@304 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--Makefile.am4
-rw-r--r--Makefile.in21
-rw-r--r--cfg.c35
-rw-r--r--cfg.h10
-rw-r--r--drv.h10
-rw-r--r--drv_MatrixOrbital.c311
-rw-r--r--layout.c75
-rw-r--r--layout.h39
-rw-r--r--lcd4linux.c115
-rw-r--r--plugin.c11
-rw-r--r--widget.c43
-rw-r--r--widget.h31
-rw-r--r--widget_text.c59
13 files changed, 554 insertions, 210 deletions
diff --git a/Makefile.am b/Makefile.am
index c7877b5..25f1164 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,12 +17,15 @@ lcd4linux.c \
pid.c pid.h \
parser.c parser.h \
processor.c processor.h \
+layout.c layout.h \
evaluator.c evaluator.h \
plugin.c plugin.h \
plugin_math.c \
plugin_string.c \
plugin_xmms.c \
plugin_i2c_sensors.c \
+widget.c widget.h \
+widget_text.c widget_text.h \
system.c system.h \
isdn.c isdn.h \
wifi.c wifi.h \
@@ -31,7 +34,6 @@ seti.c seti.h \
battery.c battery.h \
dvb.c dvb.h \
filter.c filter.h \
-widget.c widget.h \
exec.c exec.h \
expr.c expr.h \
mail2.c \
diff --git a/Makefile.in b/Makefile.in
index 1c9ce36..77ce17d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -101,7 +101,7 @@ AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall
lcd4linux_LDFLAGS = $(X_LIBS)
lcd4linux_LDADD = liblcd4linux.la @DRVLIBS@
-lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c plugin_i2c_sensors.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h widget.c widget.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h
+lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h layout.c layout.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c plugin_i2c_sensors.c widget.c widget.h widget_text.c widget_text.h system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h
liblcd4linux_la_DEPENDENCIES = @DRIVERS@
@@ -137,12 +137,13 @@ bin_PROGRAMS = lcd4linux$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
lcd4linux_OBJECTS = lcd4linux.$(OBJEXT) pid.$(OBJEXT) parser.$(OBJEXT) \
-processor.$(OBJEXT) evaluator.$(OBJEXT) plugin.$(OBJEXT) \
-plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) plugin_xmms.$(OBJEXT) \
-plugin_i2c_sensors.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) \
-wifi.$(OBJEXT) mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) \
-dvb.$(OBJEXT) filter.$(OBJEXT) widget.$(OBJEXT) exec.$(OBJEXT) \
-expr.$(OBJEXT) mail2.$(OBJEXT) socket.$(OBJEXT) imon.$(OBJEXT)
+processor.$(OBJEXT) layout.$(OBJEXT) evaluator.$(OBJEXT) \
+plugin.$(OBJEXT) plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) \
+plugin_xmms.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) widget.$(OBJEXT) \
+widget_text.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) wifi.$(OBJEXT) \
+mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) dvb.$(OBJEXT) \
+filter.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) mail2.$(OBJEXT) \
+socket.$(OBJEXT) imon.$(OBJEXT)
lcd4linux_DEPENDENCIES = liblcd4linux.la
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -166,12 +167,12 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \
.deps/battery.P .deps/cfg.P .deps/debug.P .deps/display.P .deps/drv.P \
.deps/drv_MatrixOrbital.P .deps/dvb.P .deps/evaluator.P .deps/exec.P \
.deps/expr.P .deps/filter.P .deps/fontmap.P .deps/icon.P .deps/imon.P \
-.deps/isdn.P .deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/mail2.P \
-.deps/parport.P .deps/parser.P .deps/pid.P .deps/pixmap.P \
+.deps/isdn.P .deps/layout.P .deps/lcd4linux.P .deps/lock.P .deps/mail.P \
+.deps/mail2.P .deps/parport.P .deps/parser.P .deps/pid.P .deps/pixmap.P \
.deps/plugin.P .deps/plugin_i2c_sensors.P .deps/plugin_math.P \
.deps/plugin_string.P .deps/plugin_xmms.P .deps/processor.P \
.deps/seti.P .deps/socket.P .deps/system.P .deps/udelay.P \
-.deps/widget.P .deps/wifi.P
+.deps/widget.P .deps/widget_text.P .deps/wifi.P
SOURCES = $(liblcd4linux_la_SOURCES) $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
OBJECTS = $(liblcd4linux_la_OBJECTS) $(lcd4linux_OBJECTS)
diff --git a/cfg.c b/cfg.c
index bfcfde0..ddf9f4b 100644
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.23 2004/01/09 04:16:06 reinelt Exp $^
+/* $Id: cfg.c,v 1.24 2004/01/10 20:22:33 reinelt Exp $^
*
* config file stuff
*
@@ -23,6 +23,12 @@
*
*
* $Log: cfg.c,v $
+ * Revision 1.24 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.23 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
@@ -314,6 +320,30 @@ int l4l_cfg_cmd (char *arg)
}
+char *l4l_cfg_list (char *section)
+{
+ int i, len;
+ char *key;
+
+ // calculate key length
+ len=strlen(section)+1;
+
+ // prepare search key
+ key=malloc(len+1);
+ strcpy (key, section);
+ strcat (key, ".");
+
+ // search matching entries
+ for (i=0; i<nConfig; i++) {
+ if (strncasecmp(Config[i].key, key, len)==0) {
+ debug ("found list: %s", Config[i].key);
+ }
+ }
+
+ return NULL;
+}
+
+
char *l4l_cfg_get (char *section, char *key, char *defval)
{
int len;
@@ -579,7 +609,7 @@ static void cfg_plugin (RESULT *result, int argc, RESULT *argv[])
for (i=0; i<argc; i++) {
len+=strlen(R2S(argv[i]))+1;
}
-
+
// allocate key buffer
buffer=malloc(len+1);
@@ -632,6 +662,7 @@ char *l4l_cfg_source (void)
int (*cfg_init) (char *source) = l4l_cfg_init;
char *(*cfg_source) (void) = l4l_cfg_source;
int (*cfg_cmd) (char *arg) = l4l_cfg_cmd;
+char *(*cfg_list) (char *section) = l4l_cfg_list;
char *(*cfg_get) (char *section, char *key, char *defval) = l4l_cfg_get;
int (*cfg_number) (char *section, char *key, int defval,
int min, int max, int *value) = l4l_cfg_number;
diff --git a/cfg.h b/cfg.h
index b1fa8d6..49895be 100644
--- a/cfg.h
+++ b/cfg.h
@@ -1,4 +1,4 @@
-/* $Id: cfg.h,v 1.7 2004/01/09 04:16:06 reinelt Exp $
+/* $Id: cfg.h,v 1.8 2004/01/10 20:22:33 reinelt Exp $
*
* config file stuff
*
@@ -22,6 +22,12 @@
*
*
* $Log: cfg.h,v $
+ * Revision 1.8 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.7 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
@@ -57,6 +63,7 @@
extern int (*cfg_init) (char *source);
extern char *(*cfg_source) (void);
extern int (*cfg_cmd) (char *arg);
+extern char *(*cfg_list) (char *section);
extern char *(*cfg_get) (char *section, char *key, char *defval);
extern int (*cfg_number) (char *section, char *key, int defval,
int min, int max, int *value);
@@ -64,6 +71,7 @@ extern int (*cfg_number) (char *section, char *key, int defval,
int l4l_cfg_init (char *file);
char *l4l_cfg_source (void);
int l4l_cfg_cmd (char *arg);
+char *l4l_cfg_list (char *section);
char *l4l_cfg_get (char *section, char *key, char *defval);
int l4l_cfg_number (char *section, char *key, int defval,
int min, int max, int *value);
diff --git a/drv.h b/drv.h
index 59cf376..7f5ef85 100644
--- a/drv.h
+++ b/drv.h
@@ -1,4 +1,4 @@
-/* $Id: drv.h,v 1.1 2004/01/09 17:03:07 reinelt Exp $
+/* $Id: drv.h,v 1.2 2004/01/10 20:22:33 reinelt Exp $
*
* new framework for display drivers
*
@@ -23,6 +23,12 @@
*
*
* $Log: drv.h,v $
+ * Revision 1.2 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.1 2004/01/09 17:03:07 reinelt
* initiated transfer to new driver architecture
* new file 'drv.c' will someday replace 'display.c'
@@ -38,7 +44,7 @@
typedef struct DRIVER {
char *name;
int (*list) (void);
- int (*init) (struct DRIVER *Self);
+ int (*init) (char *section);
int (*quit) (void);
} DRIVER;
diff --git a/drv_MatrixOrbital.c b/drv_MatrixOrbital.c
index bb12094..c0e8da1 100644
--- a/drv_MatrixOrbital.c
+++ b/drv_MatrixOrbital.c
@@ -1,4 +1,4 @@
-/* $Id: drv_MatrixOrbital.c,v 1.3 2004/01/10 17:34:40 reinelt Exp $
+/* $Id: drv_MatrixOrbital.c,v 1.4 2004/01/10 20:22:33 reinelt Exp $
*
* new style driver for Matrix Orbital serial display modules
*
@@ -23,6 +23,12 @@
*
*
* $Log: drv_MatrixOrbital.c,v $
+ * Revision 1.4 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.3 2004/01/10 17:34:40 reinelt
* further matrixOrbital changes
* widgets initialized
@@ -62,17 +68,21 @@
#include "drv.h"
#include "bar.h"
#include "icon.h"
+#include "widget.h"
+
+// these values are hardcoded
+#define XRES 5
+#define YRES 8
+#define CHARS 8
static char *Port=NULL;
static speed_t Speed;
static int Device=-1;
static int Model;
-static int ROWS, COLS;
-static int XRES, YRES;
-static int CHARS, ICONS, GPOS;
-static int PROTOCOL;
+static int ROWS, COLS, GPOS;
+static int ICONS, PROTOCOL;
static char *FrameBuffer1=NULL;
static char *FrameBuffer2=NULL;
@@ -201,15 +211,15 @@ static void drv_MO_write (char *string, int len)
}
-static int drv_MO_contrast (void)
+static int drv_MO_contrast (int contrast)
{
char buffer[4];
- int contrast;
-
- if (cfg_number(NULL, "Contrast", 160, 0, 255, &contrast)<0) return -1;
+
+ if (contrast<0 ) contrast=0;
+ if (contrast>255) contrast=255;
snprintf (buffer, 4, "\376P%c", contrast);
drv_MO_write (buffer, 3);
- return 0;
+ return contrast;
}
@@ -223,19 +233,19 @@ static void drv_MO_define_char (int ascii, char *buffer)
}
-static int drv_MO_clear (int protocol)
+static int drv_MO_clear (int full)
{
int gpo;
memset (FrameBuffer1, ' ', ROWS*COLS*sizeof(char));
-
+
icon_clear();
bar_clear();
memset(GPO, 0, sizeof(GPO));
- if (protocol) {
+ if (full) {
memset (FrameBuffer2, ' ', ROWS*COLS*sizeof(char));
- switch (protocol) {
+ switch (PROTOCOL) {
case 1:
drv_MO_write ("\014", 1); // Clear Screen
drv_MO_write ("\376V", 2); // GPO off
@@ -304,7 +314,142 @@ static int drv_MO_gpo (int num, int val)
}
-static int drv_MO_flush (int protocol)
+// start display
+static int drv_MO_start (char *section)
+{
+ int i;
+ char *port, buffer[256];
+ char *model;
+
+ if (Port) {
+ free (Port);
+ Port=NULL;
+ }
+
+ model=cfg_get(section, "Model", NULL);
+ if (model!=NULL && *model!='\0') {
+ for (i=0; Models[i].type!=0xff; i++) {
+ if (strcasecmp(Models[i].name, model)==0) break;
+ }
+ if (Models[i].type==0xff) {
+ error ("MatrixOrbital: %s.Model '%s' is unknown from %s", section, model, cfg_source());
+ return -1;
+ }
+ Model=i;
+ info ("MatrixOrbital: using model '%s'", Models[Model].name);
+ } else {
+ info ("MatrixOrbital: no '%s.Model' entry from %s, auto-dedecting", section, cfg_source());
+ Model=-1;
+ }
+
+
+ port=cfg_get(section, "Port", NULL);
+ if (port==NULL || *port=='\0') {
+ error ("MatrixOrbital: no '%s.Port' entry from %s", section, cfg_source());
+ return -1;
+ }
+ Port=strdup(port);
+
+ if (cfg_number(section, "Speed", 19200, 1200, 19200, &i)<0) return -1;
+ switch (i) {
+ case 1200:
+ Speed=B1200;
+ break;
+ case 2400:
+ Speed=B2400;
+ break;
+ case 9600:
+ Speed=B9600;
+ break;
+ case 19200:
+ Speed=B19200;
+ break;
+ default:
+ error ("MatrixOrbital: unsupported speed '%d' from %s", i, cfg_source());
+ return -1;
+ }
+
+ info ("MatrixOrbital: using port '%s' at %d baud", Port, i);
+
+ Device=drv_MO_open();
+ if (Device==-1) return -1;
+
+ // read module type
+ drv_MO_write ("\3767", 2);
+ usleep(1000);
+ drv_MO_read (buffer, 1);
+ for (i=0; Models[i].type!=0xff; i++) {
+ if (Models[i].type == (int)*buffer) break;
+ }
+ info ("MatrixOrbital: Display identifies itself as a '%s' (type 0x%02x)",
+ Models[i].name, Models[i].type);
+
+ // auto-dedection
+ if (Model==-1) Model=i;
+
+ // auto-dedection matches specified model?
+ if (Model!=i) {
+ error ("MatrixOrbital: %s.Model '%s' from %s does not match dedected Model '%s'",
+ section, model, cfg_source(), Models[i].name);
+ return -1;
+ }
+
+ // read serial number
+ drv_MO_write ("\3765", 2);
+ usleep(100000);
+ drv_MO_read (buffer, 2);
+ info ("MatrixOrbital: Display reports Serial Number 0x%x", *(short*)buffer);
+
+ // read version number
+ drv_MO_write ("\3766", 2);
+ usleep(100000);
+ drv_MO_read (buffer, 1);
+ info ("MatrixOrbital: Display reports Firmware Version 0x%x", *buffer);
+
+
+ // initialize global variables
+ ROWS = Models[Model].rows;
+ COLS = Models[Model].cols;
+ GPOS = Models[Model].gpos;
+ PROTOCOL = Models[Model].protocol;
+
+
+ // init the framebuffers
+ FrameBuffer1 = (char*)malloc(COLS*ROWS*sizeof(char));
+ FrameBuffer2 = (char*)malloc(COLS*ROWS*sizeof(char));
+ if (FrameBuffer1==NULL || FrameBuffer2==NULL) {
+ error ("MatrixOrbital: framebuffer could not be allocated: malloc() failed");
+ return -1;
+ }
+
+ // init Icons
+ if (cfg_number(NULL, "Icons", 0, 0, CHARS, &ICONS)<0) return -1;
+ if (ICONS>0) {
+ debug ("reserving %d of %d user-defined characters for icons", ICONS, CHARS);
+ icon_init(ROWS, COLS, XRES, YRES, CHARS, ICONS, drv_MO_define_char);
+ }
+
+ // init Bars
+ bar_init(ROWS, COLS, XRES, YRES, CHARS-ICONS);
+ bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank
+ bar_add_segment(255,255,255,255); // ASCII 255 = block
+
+
+ drv_MO_clear(1);
+ // Fixme: where to init contrast?
+ drv_MO_contrast(160);
+
+ drv_MO_write ("\376B", 3); // backlight on
+ drv_MO_write ("\376K", 2); // cursor off
+ drv_MO_write ("\376T", 2); // blink off
+ drv_MO_write ("\376D", 2); // line wrapping off
+ drv_MO_write ("\376R", 2); // auto scroll off
+
+ return 0;
+}
+
+
+static int drv_MO_flush (void)
{
int row, col, pos1, pos2;
int c, equal;
@@ -339,7 +484,7 @@ static int drv_MO_flush (int protocol)
memcpy (FrameBuffer2, FrameBuffer1, ROWS*COLS*sizeof(char));
- switch (protocol) {
+ switch (PROTOCOL) {
case 1:
if (GPO[0]) {
drv_MO_write ("\376W", 2); // GPO on
@@ -371,7 +516,7 @@ static void plugin_contrast (RESULT *result, RESULT *arg1)
{
char buffer[4];
double contrast;
-
+
contrast=R2N(arg1);
if (contrast<0 ) contrast=0;
if (contrast>255) contrast=255;
@@ -408,8 +553,6 @@ static void plugin_gpo (RESULT *result, RESULT *arg1, RESULT *arg2)
int num;
double val;
char cmd[3]="\376";
- // Fixme
- int protocol=2;
num=R2N(arg1);
val=R2N(arg2);
@@ -423,7 +566,7 @@ static void plugin_gpo (RESULT *result, RESULT *arg1, RESULT *arg2)
val=0.0;
}
- switch (protocol) {
+ switch (PROTOCOL) {
case 1:
if (num==0) {
if (val>=1.0) {
@@ -523,133 +666,25 @@ int drv_MO_list (void)
// initialize driver & display
int drv_MO_init (char *section)
{
- int i;
- char *port, buffer[256];
- char *model;
-
- if (Port) {
- free (Port);
- Port=NULL;
- }
-
- model=cfg_get(section, "Model", NULL);
- if (model!=NULL && *model!='\0') {
- for (i=0; Models[i].type!=0xff; i++) {
- if (strcasecmp(Models[i].name, model)==0) break;
- }
- if (Models[i].type==0xff) {
- error ("MatrixOrbital: %s.Model '%s' is unknown from %s", section, model, cfg_source());
- return -1;
- }
- Model=i;
- info ("MatrixOrbital: using model '%s'", Models[Model].name);
- } else {
- info ("MatrixOrbital: no '%s.Model' entry from %s, auto-dedecting", section, cfg_source());
- Model=-1;
- }
-
-
- port=cfg_get(section, "Port", NULL);
- if (port==NULL || *port=='\0') {
- error ("MatrixOrbital: no '%s.Port' entry from %s", section, cfg_source());
- return -1;
- }
- Port=strdup(port);
-
- if (cfg_number(section, "Speed", 19200, 1200, 19200, &i)<0) return -1;
- switch (i) {
- case 1200:
- Speed=B1200;
- break;
- case 2400:
- Speed=B2400;
- break;
- case 9600:
- Speed=B9600;
- break;
- case 19200:
- Speed=B19200;
- break;
- default:
- error ("MatrixOrbital: unsupported speed '%d' from %s", i, cfg_source());
- return -1;
- }
-
- info ("MatrixOrbital: using port '%s' at %d baud", Port, i);
+ WIDGET_CLASS wc;
+ int ret;
- Device=drv_MO_open();
- if (Device==-1) return -1;
-
- // read module type
- drv_MO_write ("\3767", 2);
- usleep(1000);
- drv_MO_read (buffer, 1);
- for (i=0; Models[i].type!=0xff; i++) {
- if (Models[i].type == (int)*buffer) break;
- }
- info ("MatrixOrbital: Display identifies itself as a '%s' (type 0x%02x)",
- Models[i].name, Models[i].type);
+ // start display
+ if ((ret=drv_MO_start (section))!=0)
+ return ret;
- // auto-dedection
- if (Model==-1) Model=i;
-
- // auto-dedection matches specified model?
- if (Model!=i) {
- error ("MatrixOrbital: %s.Model '%s' from %s does not match dedected Model '%s'",
- section, model, cfg_source(), Models[i].name);
- return -1;
- }
-
- // read serial number
- drv_MO_write ("\3765", 2);
- usleep(100000);
- drv_MO_read (buffer, 2);
- info ("MatrixOrbital: Display reports Serial Number 0x%x", *(short*)buffer);
+ // register text widget
+ wc=Widget_Text;
+ wc.render=NULL;
+ widget_register(&wc);
- // read version number
- drv_MO_write ("\3766", 2);
- usleep(100000);
- drv_MO_read (buffer, 1);
- info ("MatrixOrbital: Display reports Firmware Version 0x%x", *buffer);
-
-
- // Init the framebuffers
- FrameBuffer1 = (char*)malloc(COLS*ROWS*sizeof(char));
- FrameBuffer2 = (char*)malloc(COLS*ROWS*sizeof(char));
- if (FrameBuffer1==NULL || FrameBuffer2==NULL) {
- error ("MatrixOrbital: framebuffer could not be allocated: malloc() failed");
- return -1;
- }
-
- // init Icons
- if (cfg_number(NULL, "Icons", 0, 0, CHARS, &ICONS)<0) return -1;
- if (ICONS>0) {
- debug ("reserving %d of %d user-defined characters for icons", ICONS, CHARS);
- icon_init(ROWS, COLS, XRES, YRES, CHARS, ICONS, drv_MO_define_char);
- }
-
- // init Bars
- bar_init(ROWS, COLS, XRES, YRES, CHARS-ICONS);
- bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank
- bar_add_segment(255,255,255,255); // ASCII 255 = block
-
-
- drv_MO_clear(PROTOCOL);
- drv_MO_contrast();
-
- drv_MO_write ("\376B", 3); // backlight on
- drv_MO_write ("\376K", 2); // cursor off
- drv_MO_write ("\376T", 2); // blink off
- drv_MO_write ("\376D", 2); // line wrapping off
- drv_MO_write ("\376R", 2); // auto scroll off
-
// register plugins
AddFunction ("contrast", 1, plugin_contrast);
AddFunction ("backlight", 1, plugin_backlight);
AddFunction ("gpo", 2, plugin_gpo);
AddFunction ("pwm", 2, plugin_pwm);
AddFunction ("rpm", 1, plugin_rpm);
-
+
return 0;
}
diff --git a/layout.c b/layout.c
new file mode 100644
index 0000000..774a4bf
--- /dev/null
+++ b/layout.c
@@ -0,0 +1,75 @@
+/* $Id: layout.c,v 1.1 2004/01/10 20:22:33 reinelt Exp $
+ *
+ * new layouter framework
+ *
+ * Copyright 1999-2003 Michael Reinelt <reinelt@eunet.at>
+ * Copyright 2004 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: layout.c,v $
+ * Revision 1.1 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
+ */
+
+/*
+ * exported functions:
+ *
+ * layout_init (char *section)
+ * initializes the layouter
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "debug.h"
+#include "cfg.h"
+#include "layout.h"
+
+
+#define MAX_ROWS 32
+#define MAX_COLS 80
+
+int layout_init (char *layout)
+{
+ char *section, *widget;
+ char buffer[15];
+ int row, col;
+
+ info ("initializing layout '%s'", layout);
+
+ // prepare config section
+ // strlen("Layout:")=7, +1=8
+ section=malloc(strlen(layout)+8);
+ strcpy(section, "Layout:");
+ strcat(section, layout);
+
+ cfg_list(section);
+
+
+ return 0;
+}
+
diff --git a/layout.h b/layout.h
new file mode 100644
index 0000000..2870260
--- /dev/null
+++ b/layout.h
@@ -0,0 +1,39 @@
+/* $Id: layout.h,v 1.1 2004/01/10 20:22:33 reinelt Exp $
+ *
+ * new layouter framework
+ *
+ * Copyright 1999-2003 Michael Reinelt <reinelt@eunet.at>
+ * Copyright 2004 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: layout.h,v $
+ * Revision 1.1 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
+ */
+
+#ifndef _LAYOUT_H_
+#define _LAYOUT_H_
+
+int layout_init(char *section);
+
+#endif
diff --git a/lcd4linux.c b/lcd4linux.c
index 745c8e3..255d94a 100644
--- a/lcd4linux.c
+++ b/lcd4linux.c
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.57 2004/01/10 17:45:26 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.58 2004/01/10 20:22:33 reinelt Exp $
*
* LCD4Linux
*
@@ -22,6 +22,12 @@
*
*
* $Log: lcd4linux.c,v $
+ * Revision 1.58 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.57 2004/01/10 17:45:26 reinelt
* changed initialization order so cfg() gets initialized before plugins.
* This way a plugin's init() can use cfg_get().
@@ -290,6 +296,7 @@
#include "display.h" // Fixme: remove me...
#include "drv.h"
#include "processor.h"
+#include "layout.h"
#include "plugin.h"
#define PIDFILE "/var/run/lcd4linux.pid"
@@ -307,9 +314,6 @@ static void usage(void)
printf ("%s\n", release);
printf ("usage: lcd4linux [-h]\n");
printf (" lcd4linux [-l]\n");
-#ifdef USE_OLD_UDELAY
- printf (" lcd4linux [-d]\n");
-#endif
printf (" lcd4linux [-c key=value] [-i] [-f config-file] [-v]\n");
printf (" lcd4linux [-c key=value] [-F] [-f config-file] [-o output-file] [-q] [-v]\n");
}
@@ -352,25 +356,6 @@ int hello (void)
}
-#ifdef USE_OLD_UDELAY
-void calibrate (void)
-{
- int i;
- unsigned long max=0;
-
- printf ("%s\n", release);
- printf ("calibrating delay loop:");
- fflush(stdout);
- for (i=0; i<10; i++) {
- udelay_calibrate();
- if (loops_per_usec>max)
- max=loops_per_usec;
- }
- printf (" Delay=%ld\n", max);
-}
-#endif
-
-
void handler (int signal)
{
debug ("got signal %d", signal);
@@ -381,7 +366,7 @@ void handler (int signal)
int main (int argc, char *argv[])
{
char *cfg="/etc/lcd4linux.conf";
- char *display, *driver;
+ char *display, *driver, *layout;
char section[32];
int c;
int quiet=0;
@@ -397,11 +382,8 @@ int main (int argc, char *argv[])
running_foreground=0;
running_background=0;
-#ifdef USE_OLD_UDELAY
- while ((c=getopt (argc, argv, "c:dFf:hilo:qv"))!=EOF) {
-#else
while ((c=getopt (argc, argv, "c:Ff:hilo:qv"))!=EOF) {
-#endif
+
switch (c) {
case 'c':
if (cfg_cmd (optarg)<0) {
@@ -409,11 +391,6 @@ int main (int argc, char *argv[])
exit(2);
}
break;
-#ifdef USE_OLD_UDELAY
- case 'd':
- calibrate();
- exit(0);
-#endif
case 'F':
running_foreground++;
break;
@@ -460,7 +437,7 @@ int main (int argc, char *argv[])
if (!running_foreground && (my_argv[0]==NULL || my_argv[0][0]!='/')) {
info ("invoked without full path; restart may not work!");
}
-
+
if (cfg_init(cfg)==-1)
exit (1);
@@ -479,6 +456,9 @@ int main (int argc, char *argv[])
#if 0
error ("missing '%s.Driver' entry in %s!", section, cfg_source());
exit (1);
+#else
+ // Fixme: compatibility only...
+ driver=NULL;
#endif
}
@@ -548,9 +528,26 @@ int main (int argc, char *argv[])
exit (1);
}
}
-
- // process_init sets global vars tick, tack
- process_init();
+
+ // check for new-style layout
+ layout=cfg_get(NULL, "Layout", NULL);
+ if (layout==NULL || *layout=='\0') {
+#if 0
+ error ("missing 'Layout' entry in %s!", cfg_source());
+ exit (1);
+#else
+ layout=NULL;
+ info ("using old-style layout!");
+#endif
+ }
+
+ // Fixme: compatibility only...
+ if (layout==NULL) {
+ // process_init sets global vars tick, tack
+ process_init();
+ } else {
+ layout_init(layout);
+ }
// maybe go into interactive mode
if (interactive) {
@@ -571,8 +568,13 @@ int main (int argc, char *argv[])
printf("eval> ");
}
printf ("\n");
- lcd_clear(1);
- lcd_quit();
+ // Fixme: compatibility only...
+ if (layout==NULL) {
+ lcd_clear(1);
+ lcd_quit();
+ } else {
+ drv_quit();
+ }
pid_exit(PIDFILE);
exit (0);
}
@@ -582,11 +584,16 @@ int main (int argc, char *argv[])
quiet = atoi(cfg_get(NULL, "Quiet", "0"));
}
- if (!quiet && hello()) {
- sleep (3);
- lcd_clear(1);
+ // Fixme: compatibility only...
+ if (layout==NULL) {
+ if (!quiet && hello()) {
+ sleep (3);
+ lcd_clear(1);
+ }
+ } else {
+ // Fixme: how to hello() with new layout?
}
-
+
debug ("starting main loop");
// now install our own signal handler
@@ -595,17 +602,24 @@ int main (int argc, char *argv[])
signal(SIGQUIT, handler);
signal(SIGTERM, handler);
- while (got_signal==0) {
- process ();
- usleep(tack*1000);
+ // Fixme: compatibility only...
+ if (layout==NULL) {
+ while (got_signal==0) {
+ process ();
+ usleep(tack*1000);
+ }
}
debug ("leaving main loop");
- lcd_clear(1);
- if (!quiet) hello();
- lcd_quit();
-
+ // Fixme: compatibility only...
+ if (layout==NULL) {
+ lcd_clear(1);
+ if (!quiet) hello();
+ lcd_quit();
+ } else {
+ drv_quit();
+ }
pid_exit(PIDFILE);
if (got_signal==SIGHUP) {
@@ -623,3 +637,4 @@ int main (int argc, char *argv[])
}
exit (0);
}
+
diff --git a/plugin.c b/plugin.c
index 44363d3..405f15d 100644
--- a/plugin.c
+++ b/plugin.c
@@ -1,4 +1,4 @@
-/* $Id: plugin.c,v 1.7 2004/01/10 17:45:26 reinelt Exp $
+/* $Id: plugin.c,v 1.8 2004/01/10 20:22:33 reinelt Exp $
*
* plugin handler for the Evaluator
*
@@ -22,6 +22,12 @@
*
*
* $Log: plugin.c,v $
+ * Revision 1.8 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.7 2004/01/10 17:45:26 reinelt
* changed initialization order so cfg() gets initialized before plugins.
* This way a plugin's init() can use cfg_get().
@@ -96,7 +102,8 @@ int plugin_init (void)
plugin_init_math();
plugin_init_string();
plugin_init_xmms();
- plugin_init_i2c_sensors();
+ // MR: segfaults here
+ // plugin_init_i2c_sensors();
return 0;
}
diff --git a/widget.c b/widget.c
index d2bb73d..e152571 100644
--- a/widget.c
+++ b/widget.c
@@ -1,4 +1,4 @@
-/* $Id: widget.c,v 1.3 2004/01/10 17:34:40 reinelt Exp $
+/* $Id: widget.c,v 1.4 2004/01/10 20:22:33 reinelt Exp $
*
* generic widget handling
*
@@ -21,6 +21,12 @@
*
*
* $Log: widget.c,v $
+ * Revision 1.4 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.3 2004/01/10 17:34:40 reinelt
* further matrixOrbital changes
* widgets initialized
@@ -50,6 +56,39 @@
#include "cfg.h"
#include "widget.h"
-int widget_register (void)
+
+static WIDGET_CLASS *Classes=NULL;
+static int nClasses=0;
+
+static WIDGET *Widgets=NULL;
+static int nWidgets=0;
+
+
+int widget_register (WIDGET_CLASS *widget)
+{
+ int i;
+
+ for (i=0; i<nClasses; i++) {
+ if (strcasecmp(widget->name, Classes[i].name)==0) {
+ error ("internal error: widget '%s' already exists!");
+ return -1;
+ }
+ }
+
+ nClasses++;
+ Classes=realloc(Classes, nClasses*sizeof(WIDGET_CLASS));
+ Classes[nClasses-1] = *widget;
+
+ return 0;
+}
+
+
+int widget_add (char *section, char *name)
{
+ nWidgets++;
+ Widgets=realloc(Widgets, nWidgets*sizeof(WIDGET));
+
+ Widgets[nWidgets-1].name = name;
+
+ return 0;
}
diff --git a/widget.h b/widget.h
index 05999e6..2ff0c8d 100644
--- a/widget.h
+++ b/widget.h
@@ -1,4 +1,4 @@
-/* $Id: widget.h,v 1.3 2004/01/10 17:34:40 reinelt Exp $
+/* $Id: widget.h,v 1.4 2004/01/10 20:22:33 reinelt Exp $
*
* generic widget handling
*
@@ -23,6 +23,12 @@
*
*
* $Log: widget.h,v $
+ * Revision 1.4 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
* Revision 1.3 2004/01/10 17:34:40 reinelt
* further matrixOrbital changes
* widgets initialized
@@ -39,6 +45,27 @@
#ifndef _WIDGET_H_
#define _WIDGET_H_
-int widget_register (void);
+
+struct WIDGET; // forward declaration
+
+typedef struct WIDGET_CLASS {
+ char *name;
+ int (*init) (struct WIDGET *Self);
+ int (*update) (struct WIDGET *Self);
+ int (*render) (struct WIDGET *Self);
+ int (*quit) (struct WIDGET *Self);
+} WIDGET_CLASS;
+
+typedef struct WIDGET{
+ char *name;
+ WIDGET_CLASS *class;
+} WIDGET;
+
+
+int widget_register (WIDGET_CLASS *widget);
+
+
+// some basic widgets
+WIDGET_CLASS Widget_Text;
#endif
diff --git a/widget_text.c b/widget_text.c
new file mode 100644
index 0000000..59a122d
--- /dev/null
+++ b/widget_text.c
@@ -0,0 +1,59 @@
+/* $Id: widget_text.c,v 1.1 2004/01/10 20:22:33 reinelt Exp $
+ *
+ * simple text widget handling
+ *
+ * Copyright 2003,2004 Michael Reinelt <reinelt@eunet.at>
+ * Copyright 2004 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_text.c,v $
+ * Revision 1.1 2004/01/10 20:22:33 reinelt
+ * added new function 'cfg_list()' (not finished yet)
+ * added layout.c (will replace processor.c someday)
+ * added widget_text.c (will be the first and most important widget)
+ * modified lcd4linux.c so that old-style configs should work, too
+ *
+ */
+
+/*
+ * exported functions:
+ *
+ * WIDGET_CLASS Widget_Text
+ * a simple text widget which
+ * must be supported by all displays
+ *
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "debug.h"
+#include "cfg.h"
+#include "widget.h"
+
+
+WIDGET_CLASS Widget_Text = {
+ name: "text",
+ init: NULL,
+ update: NULL,
+ render: NULL,
+ quit: NULL,
+};
+
+