From 3e02c6bf1074bca0f3686e79b1652ec05fa1e0ae Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sun, 22 Jan 2006 09:16:11 +0000 Subject: [lcd4linux @ 2006-01-22 09:16:05 by reinelt] Image Widget framework added --- Makefile.am | 1 + Makefile.in | 9 +-- configure | 8 ++- drv_X11.c | 12 +++- widget_image.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ widget_image.h | 47 ++++++++++++++++ 6 files changed, 245 insertions(+), 6 deletions(-) create mode 100644 widget_image.c create mode 100644 widget_image.h diff --git a/Makefile.am b/Makefile.am index a407421..7d9b8dc 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_image.c widget_image.h \ widget_gpo.c widget_gpo.h \ \ plugin.c plugin.h \ diff --git a/Makefile.in b/Makefile.in index 1648abb..02632af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -101,7 +101,7 @@ 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 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 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_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_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_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 @@ -126,8 +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 widget.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 +widget_text.o widget_bar.o widget_icon.o widget_image.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) @@ -166,7 +167,7 @@ DEP_FILES = .deps/cfg.P .deps/debug.P .deps/drv.P .deps/drv_BWCT.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 +.deps/widget_icon.P .deps/widget_image.P .deps/widget_text.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/configure b/configure index 1087c51..ecae60f 100755 --- a/configure +++ b/configure @@ -6320,6 +6320,7 @@ I2C="no" if test "$BECKMANNEGLE" = "yes"; then TEXT="yes" + GPIO="yes" SERIAL="yes" DRIVERS="$DRIVERS drv_BeckmannEgle.o" @@ -6347,6 +6348,7 @@ fi if test "$CRYSTALFONTZ" = "yes"; then TEXT="yes" + GPIO="yes" SERIAL="yes" DRIVERS="$DRIVERS drv_Crystalfontz.o" @@ -6375,6 +6377,7 @@ fi if test "$CWLINUX" = "yes"; then TEXT="yes" + GPIO="yes" SERIAL="yes" DRIVERS="$DRIVERS drv_Cwlinux.o" @@ -6441,8 +6444,8 @@ fi if test "$LPH7508" = "yes"; then GRAPHICS="yes" - PARPORT="yes" GPIO="yes" + PARPORT="yes" DRIVERS="$DRIVERS drv_LPH7508.o" cat >>confdefs.h <<\_ACEOF @@ -6469,6 +6472,7 @@ fi if test "$M50530" = "yes"; then TEXT="yes" + GPIO="yes" PARPORT="yes" DRIVERS="$DRIVERS drv_M50530.o" @@ -6480,6 +6484,7 @@ fi if test "$MATRIXORBITAL" = "yes"; then TEXT="yes" + GPIO="yes" SERIAL="yes" DRIVERS="$DRIVERS drv_MatrixOrbital.o" @@ -6553,6 +6558,7 @@ fi if test "$ROUTERBOARD" = "yes"; then TEXT="yes" + GPIO="yes" DRIVERS="$DRIVERS drv_RouterBoard.o" cat >>confdefs.h <<\_ACEOF diff --git a/drv_X11.c b/drv_X11.c index 326df6a..28e2e54 100644 --- a/drv_X11.c +++ b/drv_X11.c @@ -1,4 +1,4 @@ -/* $Id: drv_X11.c,v 1.11 2005/05/08 04:32:44 reinelt Exp $ +/* $Id: drv_X11.c,v 1.12 2006/01/22 09:16:11 reinelt Exp $ * * new style X11 Driver for LCD4Linux * @@ -26,6 +26,9 @@ * * * $Log: drv_X11.c,v $ + * Revision 1.12 2006/01/22 09:16:11 reinelt + * Image Widget framework added + * * Revision 1.11 2005/05/08 04:32:44 reinelt * CodingStyle added and applied * @@ -102,6 +105,7 @@ #include "widget.h" #include "widget_text.h" #include "widget_icon.h" +#include "widget_image.h" #include "widget_bar.h" #include "drv.h" #include "drv_generic_graphic.h" @@ -366,6 +370,7 @@ static int drv_X11_start(const char *section) /* using drv_generic_graphic_draw(W) */ /* using drv_generic_graphic_icon_draw(W) */ +/* using drv_generic_graphic_image_draw(W) */ /* using drv_generic_graphic_bar_draw(W) */ @@ -422,6 +427,11 @@ int drv_X11_init(const char *section, const int quiet) wc.draw = drv_generic_graphic_icon_draw; widget_register(&wc); + /* register image widget */ + wc = Widget_Image; + /* Fixme: wc.draw = drv_generic_graphic_image_draw; */ + widget_register(&wc); + /* register bar widget */ wc = Widget_Bar; wc.draw = drv_generic_graphic_bar_draw; diff --git a/widget_image.c b/widget_image.c new file mode 100644 index 0000000..4b5c898 --- /dev/null +++ b/widget_image.c @@ -0,0 +1,174 @@ +/* $Id: widget_image.c,v 1.1 2006/01/22 09:16:11 reinelt Exp $ + * + * image widget handling + * + * Copyright (C) 2006 Michael Reinelt + * Copyright (C) 2006 The LCD4Linux Team + * + * 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_image.c,v $ + * Revision 1.1 2006/01/22 09:16:11 reinelt + * Image Widget framework added + * + */ + +/* + * exported functions: + * + * WIDGET_CLASS Widget_Image + * the image widget + * + */ + + +#include "config.h" + +#include +#include +#include +#include + +#include "debug.h" +#include "cfg.h" +#include "qprintf.h" +#include "evaluator.h" +#include "timer.h" +#include "widget.h" +#include "widget_image.h" + +#ifdef WITH_DMALLOC +#include +#endif + +void widget_image_update(void *Self) +{ + WIDGET *W = (WIDGET *) Self; + WIDGET_IMAGE *Image = W->data; + RESULT result = { 0, 0, 0, NULL }; + + /* process the parent only */ + if (W->parent == NULL) { + + /* evaluate expressions */ + Image->update = 0; + if (Image->update_tree != NULL) { + Eval(Image->update_tree, &result); + Image->update = R2N(&result); + if (Image->update < 0) + Image->update = 0; + DelResult(&result); + } + + Image->visible = 1; + if (Image->visible_tree != NULL) { + Eval(Image->visible_tree, &result); + Image->visible = R2N(&result); + if (Image->visible < 0) + Image->visible = 0; + DelResult(&result); + } + } + + /* finally, draw it! */ + if (W->class->draw) + W->class->draw(W); + + /* add a new one-shot timer */ + timer_add(widget_image_update, Self, Image->update, 1); + +} + + + +int widget_image_init(WIDGET * Self) +{ + char *section; + WIDGET_IMAGE *Image; + + /* re-use the parent if one exists */ + if (Self->parent == NULL) { + + /* prepare config section */ + /* strlen("Widget:")=7 */ + section = malloc(strlen(Self->name) + 8); + strcpy(section, "Widget:"); + strcat(section, Self->name); + + Image = malloc(sizeof(WIDGET_IMAGE)); + memset(Image, 0, sizeof(WIDGET_IMAGE)); + + /* get raw expressions (we evaluate them ourselves) */ + Image->update_expr = cfg_get_raw(section, "update", NULL); + Image->visible_expr = cfg_get_raw(section, "visible", NULL); + + /* compile'em */ + Compile(Image->update_expr, &Image->update_tree); + Compile(Image->visible_expr, &Image->visible_tree); + + /* sanity check */ + if (Image->update_expr == NULL || *Image->update_expr == '\0') { + error("Image %s has no update, using '100'", Self->name); + Image->update_expr = "100"; + } + + free(section); + Self->data = Image; + + } else { + + /* re-use the parent */ + Self->data = Self->parent->data; + + } + + /* just do it! */ + widget_image_update(Self); + + return 0; +} + + +int widget_image_quit(WIDGET * Self) +{ + if (Self) { + /* do not deallocate child widget! */ + if (Self->parent == NULL) { + if (Self->data) { + WIDGET_IMAGE *Image = Self->data; + DelTree(Image->update_tree); + DelTree(Image->visible_tree); + if (Image->file) + free(Image->file); + free(Self->data); + Self->data = NULL; + } + } + } + + return 0; + +} + + + +WIDGET_CLASS Widget_Image = { + name:"image", + type:WIDGET_TYPE_VIS, + init:widget_image_init, + draw:NULL, + quit:widget_image_quit, +}; diff --git a/widget_image.h b/widget_image.h new file mode 100644 index 0000000..1f89753 --- /dev/null +++ b/widget_image.h @@ -0,0 +1,47 @@ +/* $Id: widget_image.h,v 1.1 2006/01/22 09:16:11 reinelt Exp $ + * + * image widget handling + * + * Copyright (C) 2006 Michael Reinelt + * Copyright (C) 2006 The LCD4Linux Team + * + * 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_image.h,v $ + * Revision 1.1 2006/01/22 09:16:11 reinelt + * Image Widget framework added + * + */ + + +#ifndef _WIDGET_IMAGE_H_ +#define _WIDGET_IMAGE_H_ + +typedef struct WIDGET_IMAGE { + char *update_expr; /* expression for update interval */ + void *update_tree; /* pre-compiled expression for update interval */ + int update; /* update interval (msec) */ + char *visible_expr; /* expression for visibility */ + void *visible_tree; /* pre-compiled expression for visibility */ + int visible; /* icon visible? */ + char *file; /* file containing the image */ +} WIDGET_IMAGE; + +extern WIDGET_CLASS Widget_Image; + +#endif -- cgit v1.2.3