/* $Id$ * $URL$ * * bar widget handling * * Copyright (C) 2003, 2004 Michael Reinelt * Copyright (C) 2004 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. * */ /* * exported functions: * * WIDGET_CLASS Widget_Bar * the bar widget * */ #include "config.h" #include #include #include #include #include "debug.h" #include "cfg.h" #include "property.h" #include "timer.h" #include "widget.h" #include "widget_bar.h" #ifdef WITH_DMALLOC #include #endif void widget_bar_update(void *Self) { WIDGET *W = (WIDGET *) Self; WIDGET_BAR *Bar = W->data; double val1, val2; double min, max; /* evaluate properties */ property_eval(&Bar->expression1); val1 = P2N(&Bar->expression1); if (property_valid(&Bar->expression2)) { property_eval(&Bar->expression2); val2 = P2N(&Bar->expression2); } else { val2 = val1; } /* minimum: if expression is empty, do auto-scaling */ if (property_valid(&Bar->expr_min)) { property_eval(&Bar->expr_min); min = P2N(&Bar->expr_min); } else { min = Bar->min; if (val1 < min) min = val1; if (val2 < min) min = val2; } /* maximum: if expression is empty, do auto-scaling */ if (property_valid(&Bar->expr_max)) { property_eval(&Bar->expr_max); max = P2N(&Bar->expr_max); } else { max = Bar->max; if (val1 > max) max = val1; if (val2 > max) max = val2; } /* calculate bar values */ Bar->min = min; Bar->max = max; if (max > min) { Bar->val1 = (val1 - min) / (max - min); Bar->val2 = (val2 - min) / (max - min); } else { Bar->val1 = 0.0; Bar->val2 = 0.0; } /* finally, draw it! */ if (W->class->draw) W->class->draw(W); } int widget_bar_init(WIDGET * Self) { char *section; char *c; WIDGET_BAR *Bar; /* prepare config section */ /* strlen("Widget:")=7 */ section = malloc(strlen(Self->name) + 8); strcpy(section, "Widget:"); strcat(section, Self->name); Bar = malloc(sizeof(WIDGET_BAR)); memset(Bar, 0, sizeof(WIDGET_BAR)); /* load properties */ property_load(section, "expression", NULL, &Bar->expression1); property_load(section, "expression2", NULL, &Bar->expression2); property_load(section, "min", NULL, &Bar->expr_min); property_load(section, "max", NULL, &Bar->expr_max); /* sanity checks */ if (!property_valid(&Bar->expression1)) { error("Warning: widget %s has no expression", section); } /* bar length, default 1 */ cfg_number(section, "length", 1, 0, -1, &(Bar->length)); /* direction: East (default), West, North, South */ c = cfg_get(section, "direction", "E"); switch (toupper(*c)) { case 'E': Bar->direction = DIR_EAST; break; case 'W': Bar->direction = DIR_WEST; break; case 'N': Bar->direction = DIR_NORTH; break; case 'S': Bar->direction = DIR_SOUTH; break; default: error("widget %s has unknown direction '%s', using 'East'", Self->name, c); Bar->direction = DIR_EAST; } free(c); /* style: none (default), hollow */ c = cfg_get(section, "style", "0"); switch (toupper(*c)) { case 'H': Bar->style = STYLE_HOLLOW; if (!(Bar->direction & (DIR_EAST | DIR_WEST))) { error("widget %s with style \"hollow\" not implemented", Self->name); Bar->style = 0; } break; default: Bar->style = 0; } free(c); /* update interval (msec), default 1 sec */ cfg_number(section, "update", 1000, 10, -1, &(Bar->update)); /* get widget special colors */ Bar->color_valid[0] = widget_color(section, Self->name, "barcolor0", &Bar->color[0]); Bar->color_valid[1] = widget_color(section, Self->name, "barcolor1", &Bar->color[1]); free(section); Self->data = Bar; timer_add(widget_bar_update, Self, Bar->update, 0); return 0; } int widget_bar_quit(WIDGET * Self) { if (Self) { if (Self->data) { WIDGET_BAR *Bar = Self->data; property_free(&Bar->expression1); property_free(&Bar->expression2); property_free(&Bar->expr_min); property_free(&Bar->expr_max); free(Self->data); } Self->data = NULL; } return 0; } WIDGET_CLASS Widget_Bar = { .name = "bar", .type = WIDGET_TYPE_RC, .init = widget_bar_init, .draw = NULL, .quit = widget_bar_quit, }; >2004-06-06[lcd4linux @ 2004-06-06 06:51:59 by reinelt]reinelt16-52/+135 do not display end splash screen if quiet=1 2004-06-05[lcd4linux @ 2004-06-05 14:56:48 by reinelt]reinelt3-24/+37 Cwlinux splash screen fixed USBLCD splash screen fixed plugin_i2c qprintf("%f") replaced with snprintf() 2004-06-05[lcd4linux @ 2004-06-05 06:41:39 by reinelt]reinelt11-42/+87 chancged splash screen again 2004-06-05[lcd4linux @ 2004-06-05 06:13:11 by reinelt]reinelt9-69/+327 splash screen for all text-based display drivers 2004-06-02[lcd4linux @ 2004-06-02 10:09:22 by reinelt]reinelt4-180/+183 splash screen for HD44780 2004-06-02[lcd4linux @ 2004-06-02 09:41:19 by reinelt]reinelt18-114/+211 prepared support for startup splash screen 2004-06-02[lcd4linux @ 2004-06-02 05:56:25 by reinelt]reinelt1-2/+6 extended contrast range for Crystalfontz 2004-06-02[lcd4linux @ 2004-06-02 05:35:55 by reinelt]reinelt1-0/+20 added i2c_sensors example to lcd4linux.conf.sample 2004-06-02[lcd4linux @ 2004-06-02 05:27:59 by reinelt]reinelt26-0/+2405 added documentation tree 2004-06-02[lcd4linux @ 2004-06-02 05:14:16 by reinelt]reinelt2-17/+31 fixed models listing for Beckmann+Egle driver some cosmetic changes 2004-06-01[lcd4linux @ 2004-06-01 06:45:28 by reinelt]reinelt18-71/+241 some Fixme's processed documented some code 2004-06-01[lcd4linux @ 2004-06-01 06:04:25 by reinelt]reinelt2-25/+25 made README.Plugins and plugin_sample up to date. 2004-05-31[lcd4linux @ 2004-05-31 21:23:16 by reinelt]reinelt1-37/+49 some cleanups in the MatrixOrbital driver 2004-05-31[lcd4linux @ 2004-05-31 21:05:13 by reinelt]reinelt5-77/+111 fixed lots of bugs in the Cwlinux driver do not emit EAGAIN error on the first retry made plugin_i2c_sensors a bit less 'chatty' moved init and exit functions to the bottom of plugin_pop3 2004-05-31[lcd4linux @ 2004-05-31 16:39:05 by reinelt]reinelt11-180/+535 added NULL display driver (for debugging/profiling purposes) added backlight/contrast initialisation for matrixOrbital added Backlight initialisation for Cwlinux 2004-05-31[lcd4linux @ 2004-05-31 06:27:34 by reinelt]reinelt1-0/+40 ChangeLog update 2004-05-31[lcd4linux @ 2004-05-31 06:24:42 by reinelt]reinelt2-7/+29 fixed symlink security issue with the image driver 2004-05-31[lcd4linux @ 2004-05-31 05:38:02 by reinelt]reinelt8-42/+94 fixed possible bugs with user-defined chars (clear high bits) thanks to Andy Baxter for debugging the MilfordInstruments driver! 2004-05-31[lcd4linux @ 2004-05-31 01:31:01 by andy-b]andy-b1-10/+12 fixed bug in Milford Instruments driver which drew extra graphics chars in odd places when drawing double bars. (the display doesn't like it if you put the escape character 0xfe inside a define char sequence). 2004-05-30[lcd4linux @ 2004-05-30 08:25:50 by reinelt]reinelt2-30/+92 Crystalfontz 631 driver finished 2004-05-29[lcd4linux @ 2004-05-29 23:30:20 by reinelt]reinelt1-1/+9 fixed a compiler issue with drv_Image.c (thanks to Frank Stratmann) 2004-05-29[lcd4linux @ 2004-05-29 15:53:28 by reinelt]reinelt3-9/+25 M50530: reset parport signals on exit plugin_ppp: ppp() has two parameters, not three lcd4linux.conf.sample: diskstats() corrected 2004-05-29[lcd4linux @ 2004-05-29 01:07:56 by reinelt]reinelt2-21/+25 bug in plugin_diskstats fixed 2004-05-29[lcd4linux @ 2004-05-29 00:27:14 by reinelt]reinelt8-11/+214 added plugin_diskstats.c 2004-05-28[lcd4linux @ 2004-05-28 14:38:10 by reinelt]reinelt2-1/+41 Status and Changelog Update