From b39a42b909dfb1c174044cf977d272f94445b18e Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Tue, 9 Sep 2003 05:30:34 +0000 Subject: [lcd4linux @ 2003-09-09 05:30:33 by reinelt] even more icons stuff --- MatrixOrbital.c | 14 ++++---- TODO | 23 +++++++----- USBLCD.c | 43 +++++++++++++++++++--- bar.c | 18 +++++++--- display.c | 28 +++++++++++---- display.h | 9 +++-- icon.c | 109 +++++++++++++++++++++++++++++++++++++++++++------------- icon.h | 7 ++-- lcd4linux.c | 32 ++++++++++------- processor.c | 43 +++++++++++++--------- processor.h | 7 ++-- 11 files changed, 243 insertions(+), 90 deletions(-) diff --git a/MatrixOrbital.c b/MatrixOrbital.c index bf45282..f27b04a 100644 --- a/MatrixOrbital.c +++ b/MatrixOrbital.c @@ -1,4 +1,4 @@ -/* $Id: MatrixOrbital.c,v 1.35 2003/09/01 04:09:34 reinelt Exp $ +/* $Id: MatrixOrbital.c,v 1.36 2003/09/09 05:30:33 reinelt Exp $ * * driver for Matrix Orbital serial display modules * @@ -20,6 +20,9 @@ * * * $Log: MatrixOrbital.c,v $ + * Revision 1.36 2003/09/09 05:30:33 reinelt + * even more icons stuff + * * Revision 1.35 2003/09/01 04:09:34 reinelt * icons nearly finished, but MatrixOrbital only * @@ -274,6 +277,7 @@ static int MO_clear (int protocol) int gpo; memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); + icon_clear(); bar_clear(); GPO=0; @@ -365,18 +369,16 @@ static int MO_init (LCD *Self, int protocol) s=cfg_get("Icons", "0"); Icons=strtol(s, &e, 0); if (*e!='\0' || Icons<0 || Icons>8) { - debug ("Icons=%d e=<%s>", Icons, e); error ("MatrixOrbital: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source()); return -1; } if (Icons>0) { info ("reserving %d of %d user-defined characters for icons", Icons, CHARS); + icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, MO_define_char); Self->icons=Icons; Lcd.icons=Icons; } - icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, MO_define_char); - bar_init(Lcd.rows, Lcd.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 @@ -446,9 +448,9 @@ int MO_icon_old (int num, int row, int col, unsigned char *bitmap) } -int MO_icon (int num, int row, int col) +int MO_icon (int num, int seq, int row, int col) { - return icon_draw (num, row, col); + return icon_draw (num, seq, row, col); } diff --git a/TODO b/TODO index 2ff0042..aead6e4 100644 --- a/TODO +++ b/TODO @@ -58,10 +58,11 @@ will be done with the big config-rework // at least try to.... // done 2001-03-14 -mr -2001-03-09 Leo Tötsch -read configuration file earlier (before forking) so that specific drivers -(especially 'Text') would not fork. -There's a reason for forking that early, but I forgot... +// 2001-03-09 Leo Tötsch +// read configuration file earlier (before forking) so that specific drivers +// (especially 'Text') would not fork. +// There's a reason for forking that early, but I forgot... +// done somewhere in mid 2003 MR 2001-03-12 Michael Reinelt remove USE_OLD_UDELAY after wide testing of new udelay code @@ -89,10 +90,11 @@ change network clients to support different devices at the moment the sum of all eth* devices is calculated %n* should be extended tokens -2001-03-24 Brian Cleven -support 40x4 displays with two HD44780 chips on it -we need another 'Enable' line for this -this way one could connect two displays to one parallel port, too +// 2001-03-24 Brian Cleven +// support 40x4 displays with two HD44780 chips on it +// we need another 'Enable' line for this +// this way one could connect two displays to one parallel port, too +// done with 0.9.11 MR // 2001-05-25 Jens Garthe // detect wether curses.h and libncurses is installed, and @@ -126,3 +128,8 @@ should resume 2002-02-15 Udo Altmann (udo.altmann@web.de) support for inversed/blinking text don't know if displays support this feature... + +2003-09-08 Michael Reinelt (reinelt@eunet.at> +at least one of my HD44780 displays use an inverted "P" instead of +a full block. Therefore a bar my look strange. Make the ASCII code +of the full block configurable... diff --git a/USBLCD.c b/USBLCD.c index a3871aa..54a0c02 100644 --- a/USBLCD.c +++ b/USBLCD.c @@ -1,4 +1,4 @@ -/* $Id: USBLCD.c,v 1.12 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: USBLCD.c,v 1.13 2003/09/09 05:30:34 reinelt Exp $ * * Driver for USBLCD ( see http://www.usblcd.de ) * This Driver is based on HD44780.c @@ -22,6 +22,9 @@ * * * $Log: USBLCD.c,v $ + * Revision 1.13 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.12 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -90,6 +93,7 @@ #include "debug.h" #include "cfg.h" #include "display.h" +#include "icon.h" #include "bar.h" #define GET_HARD_VERSION 1 @@ -102,6 +106,7 @@ static LCD Lcd; static char *Port=NULL; static int usblcd_file; +static int Icons; static char *FrameBuffer1=NULL; static char *FrameBuffer2=NULL; @@ -203,6 +208,8 @@ int USBLCD_clear (int full) { memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); + + icon_clear(); bar_clear(); if (full) { @@ -217,7 +224,7 @@ int USBLCD_clear (int full) int USBLCD_init (LCD *Self) { int rows=-1, cols=-1 ; - char *port,*s ; + char *port, *s, *e; if (Port) { free(Port); @@ -268,7 +275,21 @@ int USBLCD_init (LCD *Self) if (USBLCD_open()!=0) return -1; - bar_init(rows, cols, XRES, YRES, CHARS); + s=cfg_get("Icons", "0"); + Icons=strtol(s, &e, 0); + if (*e!='\0' || Icons<0 || Icons>8) { + debug ("Icons=%d e=<%s>", Icons, e); + error ("USBLCD: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source()); + return -1; + } + if (Icons>0) { + info ("reserving %d of %d user-defined characters for icons", Icons, CHARS); + icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, USBLCD_define_char); + Self->icons=Icons; + Lcd.icons=Icons; + } + + 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 @@ -304,11 +325,18 @@ int USBLCD_bar (int type, int row, int col, int max, int len1, int len2) } +int USBLCD_icon (int num, int seq, int row, int col) +{ + return icon_draw (num, seq, row, col); +} + + int USBLCD_flush (void) { int row, col, pos1, pos2; int c, equal; - + static int junk=0; //Fixme + bar_process(USBLCD_define_char); for (row=0; rowRES) l1=RES; + l2=Segment[i].len2; if (l2>RES) l2=RES; + if (l1 == Bar[n].len1 && l2 == Bar[n].len2) break; + } } if (i==nSegment) { nSegment++; diff --git a/display.c b/display.c index 5028b02..ecc58a5 100644 --- a/display.c +++ b/display.c @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.40 2003/09/01 04:09:34 reinelt Exp $ +/* $Id: display.c,v 1.41 2003/09/09 05:30:34 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,9 @@ * * * $Log: display.c,v $ + * Revision 1.41 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.40 2003/09/01 04:09:34 reinelt * icons nearly finished, but MatrixOrbital only * @@ -199,6 +202,9 @@ * int lcd_bar (int type, int row, int col, int max, int len1, int len2) * draws a specified bar at row, col with len * + * int lcd_icon (int num, int seq, int row, int col) + * draws icon #num sequence #seq at row, col + * * int lcd_gpo (int num, int val) * sets GPO #num to val * @@ -290,6 +296,7 @@ FAMILY Driver[] = { static LCD *Lcd = NULL; + int lcd_list (void) { int i, j; @@ -306,6 +313,7 @@ int lcd_list (void) return 0; } + int lcd_init (char *driver) { int i, j; @@ -322,6 +330,7 @@ int lcd_init (char *driver) return -1; } + int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *icons, int *gpos) { if (Lcd==NULL) @@ -338,6 +347,7 @@ int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *icons return 0; } + int lcd_clear (int full) { if (Lcd->clear==NULL) return 0; @@ -352,8 +362,10 @@ int lcd_put (int row, int col, char *text) return Lcd->put(row-1, col-1, text); } + int lcd_bar (int type, int row, int col, int max, int len1, int len2) { + if (Lcd->bar==NULL) return 0; if (row<1 || row>Lcd->rows) return -1; if (col<1 || col>Lcd->cols) return -1; if (!(type & (BAR_H2 | BAR_V2 | BAR_T))) len2=len1; @@ -362,32 +374,36 @@ int lcd_bar (int type, int row, int col, int max, int len1, int len2) if (!(type & BAR_T)) len2=(double)max*log(len2+1)/log(max); } - if (Lcd->bar==NULL) return 0; return Lcd->bar (type & BAR_HV, row-1, col-1, max, len1, len2); } -int lcd_icon (int num, int row, int col) + +int lcd_icon (int num, int seq, int row, int col) { + if (Lcd->icon==NULL) return 0; if (num<1 || num>Lcd->icons) return -1; + if (seq<1) return -1; if (row<1 || row>Lcd->rows) return -1; if (col<1 || col>Lcd->cols) return -1; - if (Lcd->icon==NULL) return 0; - return Lcd->icon(num-1, row-1, col-1); + return Lcd->icon(num-1, seq-1, row-1, col-1); } + int lcd_gpo (int num, int val) { - if (num<1 || num>Lcd->gpos) return -1; if (Lcd->gpo==NULL) return 0; + if (num<1 || num>Lcd->gpos) return -1; return Lcd->gpo(num-1, val); } + int lcd_flush (void) { if (Lcd->flush==NULL) return 0; return Lcd->flush(); } + int lcd_quit (void) { if (Lcd->quit==NULL) return 0; diff --git a/display.h b/display.h index 11510aa..748f8e6 100644 --- a/display.h +++ b/display.h @@ -1,4 +1,4 @@ -/* $Id: display.h,v 1.20 2003/09/01 04:09:34 reinelt Exp $ +/* $Id: display.h,v 1.21 2003/09/09 05:30:34 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,9 @@ * * * $Log: display.h,v $ + * Revision 1.21 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.20 2003/09/01 04:09:34 reinelt * icons nearly finished, but MatrixOrbital only * @@ -115,7 +118,7 @@ typedef struct LCD { int (*clear) (int full); int (*put) (int x, int y, char *text); int (*bar) (int type, int x, int y, int max, int len1, int len2); - int (*icon) (int num, int row, int col); + int (*icon) (int num, int seq, int row, int col); int (*gpo) (int num, int val); int (*flush) (void); int (*quit) (void); @@ -138,7 +141,7 @@ int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *icons int lcd_clear (int full); int lcd_put (int row, int col, char *text); int lcd_bar (int type, int row, int col, int max, int len1, int le2); -int lcd_icon (int num, int row, int col); +int lcd_icon (int num, int seq, int row, int col); int lcd_gpo (int num, int val); int lcd_flush (void); int lcd_quit (void); diff --git a/icon.c b/icon.c index ae5e332..12e5a22 100644 --- a/icon.c +++ b/icon.c @@ -1,4 +1,4 @@ -/* $Id: icon.c,v 1.3 2003/09/01 04:09:34 reinelt Exp $ +/* $Id: icon.c,v 1.4 2003/09/09 05:30:34 reinelt Exp $ * * generic icon and heartbeat handling * @@ -20,6 +20,9 @@ * * * $Log: icon.c,v $ + * Revision 1.4 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.3 2003/09/01 04:09:34 reinelt * icons nearly finished, but MatrixOrbital only * @@ -32,6 +35,24 @@ * */ +/* + * exported functions: + * + * int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, + * void(*defchar)(int ascii, char *bitmap)) + * initializes all icons stuff and reads the bitmaps from config file. + * + * void icon_clear(void) + * clears the icon framebuffer + * + * int icon_draw (int num, int seq, int row, int col) + * puts icon #num sequence #seq at position row, col in the icon framebuffer + * + * int icon_peek (int row, int col) + * returns icon# or -1 if none from position row, col + * + */ + #include #include @@ -42,6 +63,12 @@ #include "icon.h" +typedef struct BITMAP { + int nData; + int lData; + char *Data; +} BITMAP; + static int ROWS=0; static int COLS=0; static int XRES=0; @@ -49,35 +76,49 @@ static int YRES=0; static int CHARS; static int ICONS=0; -static int *Screen=NULL; -static char *Bitmap=NULL; +static int *Screen=NULL; +static struct BITMAP *Bitmap=NULL; +static void(*Defchar)(int ascii, char *bitmap); + -static int icon_read_bitmap (int num, char *bitmap) +static int icon_read_bitmap (int num) { - int row, col, len; + struct BITMAP *bm = Bitmap+num; + int row, n; char key[15]; - char *val; - char map; + char *val, *v; + char *map; for (row=0; row len=%d", num, row, val, len); - for (col=0; colData+row; + n=0; + for (v=val; *v!='\0'; v++) { + if (n>=bm->nData) { + bm->nData++; + bm->Data=realloc(bm->Data, bm->nData*YRES*sizeof(char)); + memset (bm->Data+n*YRES, 0, YRES*sizeof(char)); + map=bm->Data+n*YRES+row; + } + switch (*v) { + case '|': + n++; + map+=YRES; + break; + case '*': + (*map)<<=1; + (*map)|=1; + break; + default: + (*map)<<=1; } } - *(bitmap+row-1)=map; } return 0; } - int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, void(*defchar)(int ascii, char *bitmap)) { @@ -108,19 +149,23 @@ int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, free (Bitmap); } - if ((Bitmap=malloc(YRES*icons*sizeof(*Bitmap)))==NULL) { - error ("icon bitmap allocation failed: out of memory"); + if ((Bitmap=malloc(icons*sizeof(*Bitmap)))==NULL) { + error ("icon allocation failed: out of memory"); return -1; } - - memset (Bitmap, 0, YRES*icons*sizeof(*Bitmap)); + + Defchar=defchar; for (n=0; n=ICONS) return -1; + if (row>=ROWS) return -1; + if (col>=COLS) return -1; + + seq%=Bitmap[num].nData; + if (seq!=Bitmap[num].lData) { + Bitmap[num].lData=seq; + Defchar (CHARS-num-1, Bitmap[num].Data+seq*YRES); + } + + // just redefine icon? + if (row<0 || col<0) return 0; + // icons use last ascii codes from userdef chars Screen[row*COLS+col]=CHARS-num-1; + return 0; } diff --git a/icon.h b/icon.h index caa3edb..348d63d 100644 --- a/icon.h +++ b/icon.h @@ -1,4 +1,4 @@ -/* $Id: icon.h,v 1.2 2003/09/01 04:09:35 reinelt Exp $ +/* $Id: icon.h,v 1.3 2003/09/09 05:30:34 reinelt Exp $ * * generic icon and heartbeat handling * @@ -20,6 +20,9 @@ * * * $Log: icon.h,v $ + * Revision 1.3 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.2 2003/09/01 04:09:35 reinelt * icons nearly finished, but MatrixOrbital only * @@ -35,7 +38,7 @@ int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, void(*defchar)(int ascii, char *bitmap)); void icon_clear(void); -int icon_draw (int num, int row, int col); +int icon_draw (int num, int seq, int row, int col); int icon_peek (int row, int col); #endif diff --git a/lcd4linux.c b/lcd4linux.c index f4e5b28..400fdd0 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.44 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.45 2003/09/09 05:30:34 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,9 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.45 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.44 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -239,7 +242,6 @@ char *release="LCD4Linux " VERSION " (c) 2003 Michael Reinelt "; char **my_argv; int got_signal=0; -int tick, tack; extern char* output; @@ -319,7 +321,9 @@ int main (int argc, char *argv[]) { char *cfg="/etc/lcd4linux.conf"; char *driver; - int c, smooth; + char *s, *e; + int c; + int tick; int quiet=0; // save arguments for restart @@ -462,27 +466,29 @@ int main (int argc, char *argv[]) signal(SIGQUIT, handler); signal(SIGTERM, handler); - tick=atoi(cfg_get("tick","100")); - tack=atoi(cfg_get("tack","500")); - + s=cfg_get("tick", "100"); + tick=strtol(s, &e, 0); + if (*e!='\0' || tick<0) { + error ("bad tick entry '%s' in %s", s, cfg_source()); + pid_exit(PIDFILE); + exit (1); + } + process_init(); lcd_clear(1); - + if (!quiet && hello()) { sleep (3); lcd_clear(1); } debug ("starting main loop"); - - smooth=0; + while (got_signal==0) { - process (smooth); - smooth+=tick; - if (smooth>tack) smooth=0; + process (); usleep(tick*1000); } - + debug ("leaving main loop"); lcd_clear(1); diff --git a/processor.c b/processor.c index 1ca308a..67e1129 100644 --- a/processor.c +++ b/processor.c @@ -1,4 +1,4 @@ -/* $Id: processor.c,v 1.38 2003/09/01 04:09:35 reinelt Exp $ +/* $Id: processor.c,v 1.39 2003/09/09 05:30:34 reinelt Exp $ * * main data processing * @@ -20,6 +20,9 @@ * * * $Log: processor.c,v $ + * Revision 1.39 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.38 2003/09/01 04:09:35 reinelt * icons nearly finished, but MatrixOrbital only * @@ -174,13 +177,12 @@ * void process_init (void); * does all necessary initializations * - * void process (int smooth); + * void process (); * processes a whole screen - * bars will always be processed - * texts only if smooth=0 * */ + #include #include #include @@ -224,6 +226,7 @@ static struct { int num, unseen;} mail[MAILBOXES+1]; static struct { double val, min, max; } sensor[SENSORS+1]; static struct { double strength, snr; } dvb; + static double query (int token) { switch (token&255) { @@ -332,6 +335,7 @@ static double query (int token) return 0.0; } + /* return a value 0..1 */ static double query_bar (int token) { @@ -401,6 +405,7 @@ static double query_bar (int token) return value; } + static void print_token (int token, char **p, char *start) { double val; @@ -513,12 +518,12 @@ static void print_token (int token, char **p, char *start) break; case T_BATT_STAT: { int ival = (int) query(token); - switch (ival) { - case 0: **p = '='; break; - case 1: **p = '+'; break; - case 2: **p = '-'; break; - default: **p = '?'; break; - } + switch (ival) { + case 0: **p = '='; break; + case 1: **p = '+'; break; + case 2: **p = '-'; break; + default: **p = '?'; break; + } } (*p)++; break; @@ -553,10 +558,11 @@ static void print_token (int token, char **p, char *start) break; default: - *p+=sprintf (*p, "%5.0f", query(token)); + *p+=sprintf (*p, "%5.0f", query(token)); } } + static void collect_data (void) { int i; @@ -635,6 +641,7 @@ static void collect_data (void) } + static char *process_row (char *data, int row, int len) { static char buffer[256]; @@ -674,14 +681,14 @@ static char *process_row (char *data, int row, int len) if (type & BAR_H) { for (i=0; i 0.0); } + static int Turn (void) { static struct timeval old = {tv_sec:0, tv_usec:0}; @@ -736,6 +745,7 @@ static int Turn (void) return 0; } + void process_init (void) { int i; @@ -809,7 +819,8 @@ void process_init (void) } } -void process (int smooth) + +void process (void) { int i, j, val; char *txt; diff --git a/processor.h b/processor.h index eb489a4..6554590 100644 --- a/processor.h +++ b/processor.h @@ -1,4 +1,4 @@ -/* $Id: processor.h,v 1.1 2000/03/22 07:33:50 reinelt Exp $ +/* $Id: processor.h,v 1.2 2003/09/09 05:30:34 reinelt Exp $ * * main data processing * @@ -20,6 +20,9 @@ * * * $Log: processor.h,v $ + * Revision 1.2 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.1 2000/03/22 07:33:50 reinelt * * FAQ added @@ -31,6 +34,6 @@ #define _PROCESSOR_H_ void process_init (void); -void process (int smooth); +void process (void); #endif -- cgit v1.2.3