diff options
-rw-r--r-- | Crystalfontz.c | 477 | ||||
-rw-r--r-- | Cwlinux.c | 533 | ||||
-rw-r--r-- | HD44780.c | 728 | ||||
-rw-r--r-- | Makefile.am | 93 | ||||
-rw-r--r-- | Makefile.in | 56 | ||||
-rw-r--r-- | MatrixOrbital.c | 960 | ||||
-rw-r--r-- | SIN.c | 318 | ||||
-rw-r--r-- | Skeleton.c | 163 | ||||
-rw-r--r-- | bar.c | 460 | ||||
-rw-r--r-- | bar.h | 81 | ||||
-rw-r--r-- | config.h.in | 34 | ||||
-rwxr-xr-x | configure | 83 | ||||
-rw-r--r-- | configure.in | 103 | ||||
-rw-r--r-- | debug.c | 8 | ||||
-rw-r--r-- | display.c | 426 | ||||
-rw-r--r-- | display.h | 161 | ||||
-rw-r--r-- | dvb.c | 134 | ||||
-rw-r--r-- | dvb.h | 38 | ||||
-rw-r--r-- | expr.c | 107 | ||||
-rw-r--r-- | expr.h | 49 | ||||
-rw-r--r-- | filter.c | 215 | ||||
-rw-r--r-- | filter.h | 41 | ||||
-rw-r--r-- | icon.c | 246 | ||||
-rw-r--r-- | icon.h | 49 | ||||
-rw-r--r-- | lcd4linux.c | 101 | ||||
-rw-r--r-- | parport.c | 478 | ||||
-rw-r--r-- | parport.h | 53 | ||||
-rw-r--r-- | parser.c | 399 | ||||
-rw-r--r-- | parser.h | 129 | ||||
-rw-r--r-- | plugin.c | 6 | ||||
-rw-r--r-- | processor.c | 1186 | ||||
-rw-r--r-- | processor.h | 44 | ||||
-rw-r--r-- | system.c | 855 | ||||
-rw-r--r-- | system.h | 81 |
34 files changed, 211 insertions, 8684 deletions
diff --git a/Crystalfontz.c b/Crystalfontz.c deleted file mode 100644 index 9b9dbc7..0000000 --- a/Crystalfontz.c +++ /dev/null @@ -1,477 +0,0 @@ -/* $Id: Crystalfontz.c,v 1.20 2004/01/30 20:57:55 reinelt Exp $ - * - * driver for display modules from Crystalfontz - * - * Copyright 2000 Herbert Rosmanith <herp@wildsau.idv.uni-linz.ac.at> - * - * 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: Crystalfontz.c,v $ - * Revision 1.20 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.19 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.18 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.17 2003/11/16 09:45:49 reinelt - * Crystalfontz changes, small glitch in getopt() fixed - * - * Revision 1.16 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.15 2003/09/13 06:45:43 reinelt - * icons for all remaining drivers - * - * Revision 1.14 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.13 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.12 2003/08/19 04:28:41 reinelt - * more Icon stuff, minor glitches fixed - * - * Revision 1.11 2003/08/17 06:57:04 reinelt - * complete rewrite of the Crystalfontz driver - * - * Revision 1.10 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.9 2003/02/22 07:53:09 reinelt - * cfg_get(key,defval) - * - * Revision 1.8 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.7 2001/04/27 05:04:57 reinelt - * - * replaced OPEN_MAX with sysconf() - * replaced mktemp() with mkstemp() - * unlock serial port if open() fails - * - * Revision 1.6 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.5 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.4 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.3 2000/06/04 21:43:50 herp - * minor bugfix (zero length) - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <termios.h> -#include <fcntl.h> - -#include "debug.h" -#include "cfg.h" -#include "lock.h" -#include "display.h" -#include "bar.h" -#include "icon.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - -#define XRES 6 -#define YRES 8 -#define CHARS 8 - -static LCD Lcd; -static char *Port=NULL; -static speed_t Speed; -static int Device=-1; -static int Icons; -static int GPO; - -static char *FrameBuffer1=NULL; -static char *FrameBuffer2=NULL; - - -static int CF_open (void) -{ - int fd; - pid_t pid; - struct termios portset; - - if ((pid=lock_port(Port))!=0) { - if (pid==-1) - error ("Crystalfontz: port %s could not be locked", Port); - else - error ("Crystalfontz: port %s is locked by process %d", Port, pid); - return -1; - } - fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd==-1) { - error ("Crystalfontz: open(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - if (tcgetattr(fd, &portset)==-1) { - error ("Crystalfontz: tcgetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - cfmakeraw(&portset); - cfsetospeed(&portset, Speed); - if (tcsetattr(fd, TCSANOW, &portset)==-1) { - error ("Crystalfontz: tcsetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - return fd; -} - - -static void CF_write (char *string, int len) -{ - if (Device==-1) return; - if (write (Device, string, len)==-1) { - if (errno==EAGAIN) { - usleep(1000); - if (write (Device, string, len)>=0) return; - } - error ("Crystalfontz: write(%s) failed: %s", Port, strerror(errno)); - } -} - - -static int CF_backlight (void) -{ - char buffer[3]; - int backlight; - - if (cfg_number(NULL, "Backlight", 0, 0, 100, &backlight)<0) return -1; - snprintf (buffer, 3, "\016%c", backlight); - CF_write (buffer, 2); - return 0; -} - - -static int CF_contrast (void) -{ - char buffer[3]; - int contrast; - - if (cfg_number(NULL, "Contrast", 50, 0, 100, &contrast)<0) return -1; - snprintf (buffer, 3, "\017%c", contrast); - CF_write (buffer, 2); - return 0; -} - - -static void CF_define_char (int ascii, char *buffer) -{ - char cmd[2]="\031"; // set custom char bitmap - - cmd[1]=(char)ascii; - CF_write (cmd, 2); - CF_write (buffer, 8); -} - - -static int CF_clear (int full) -{ - memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - - icon_clear(); - bar_clear(); - GPO=0; - - if (full) { - memset (FrameBuffer2, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - CF_write ("\014", 1); // Form Feed (Clear Display) - } - - return 0; -} - - -static int CF_init (LCD *Self) -{ - char *port; - int speed; - - Lcd=*Self; - - // Init the framebuffers - FrameBuffer1 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - FrameBuffer2 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - if (FrameBuffer1==NULL || FrameBuffer2==NULL) { - error ("Crystalfontz: framebuffer could not be allocated: malloc() failed"); - return -1; - } - - if (Port) { - free (Port); - Port=NULL; - } - - port=cfg_get (NULL, "Port", NULL); - if (port==NULL || *port=='\0') { - error ("Crystalfontz: no 'Port' entry in %s", cfg_source()); - return -1; - } - Port=strdup(port); - - - if (cfg_number(NULL, "Speed", 19200, 1200,19200, &speed)<0) return -1; - - switch (speed) { - case 1200: - Speed=B1200; - break; - case 2400: - Speed=B2400; - break; - case 9600: - Speed=B9600; - break; - case 19200: - Speed=B19200; - break; - default: - error ("Crystalfontz: unsupported speed '%d' in %s", speed, cfg_source()); - return -1; - } - - debug ("using port %s at %d baud", Port, speed); - - Device=CF_open(); - if (Device==-1) return -1; - - 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(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, CF_define_char); - Self->icons=Icons; - Lcd.icons=Icons; - } - - bar_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS-Icons); - bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank - // Fixme - // bar_add_segment(255,255,255,255); // ASCII 255 = block - - // MR: why such a large delay? - usleep(350*1000); - - CF_clear(1); - - CF_write ("\004", 1); // hide cursor - CF_write ("\024", 1); // scroll off - CF_write ("\030", 1); // wrap off - - CF_backlight(); - CF_contrast(); - - return 0; -} - - -void CF_goto (int row, int col) -{ - char cmd[3]="\021"; // set cursor position - - if (row==0 && col==0) { - CF_write ("\001", 1); // cursor home - } else { - cmd[1]=(char)col; - cmd[2]=(char)row; - CF_write(cmd,3); - } -} - - -int CF_put (int row, int col, char *text) -{ - char *p=FrameBuffer1+row*Lcd.cols+col; - char *t=text; - - while (*t && col++<=Lcd.cols) { - *p++=*t++; - } - return 0; -} - - -int CF_bar (int type, int row, int col, int max, int len1, int len2) -{ - return bar_draw (type, row, col, max, len1, len2); -} - - -int CF_icon (int num, int seq, int row, int col) -{ - return icon_draw (num, seq, row, col); -} - - -static int CF_flush (void) -{ - int row, col, pos1, pos2; - int c, equal; - - bar_process(CF_define_char); - - for (row=0; row<Lcd.rows; row++) { - for (col=0; col<Lcd.cols; col++) { - c=bar_peek(row, col); - if (c==-1) c=icon_peek(row, col); - if (c!=-1) { - if (c!=32) c+=128; // non-blank - FrameBuffer1[row*Lcd.cols+col]=(char)c; - } - } - for (col=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) continue; - CF_goto (row, col); - for (pos1=col++, pos2=pos1, equal=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) { - // If we find just one equal byte, we don't break, because this - // would require a goto, which takes one byte, too. - if (++equal>4) break; - } else { - pos2=col; - equal=0; - } - } - CF_write (FrameBuffer1+row*Lcd.cols+pos1, pos2-pos1+1); - } - } - - memcpy (FrameBuffer2, FrameBuffer1, Lcd.rows*Lcd.cols*sizeof(char)); - - return 0; -} - - -int CF_quit (void) -{ - info("Crystalfontz: shutting down."); - - debug ("closing port %s", Port); - close (Device); - unlock_port(Port); - - if (FrameBuffer1) { - free(FrameBuffer1); - FrameBuffer1=NULL; - } - - if (FrameBuffer2) { - free(FrameBuffer2); - FrameBuffer2=NULL; - } - - return (0); -} - - -LCD Crystalfontz[] = { - { name: "626", - rows: 2, - cols: 16, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CF_init, - clear: CF_clear, - put: CF_put, - bar: CF_bar, - icon: CF_icon, - gpo: NULL, - flush: CF_flush, - quit: CF_quit - }, - { name: "636", - rows: 2, - cols: 16, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CF_init, - clear: CF_clear, - put: CF_put, - bar: CF_bar, - icon: CF_icon, - gpo: NULL, - flush: CF_flush, - quit: CF_quit - }, - { name: "632", - rows: 2, - cols: 16, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CF_init, - clear: CF_clear, - put: CF_put, - bar: CF_bar, - icon: CF_icon, - gpo: NULL, - flush: CF_flush, - quit: CF_quit - }, - { name: "634", - rows: 4, - cols: 20, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CF_init, - clear: CF_clear, - put: CF_put, - bar: CF_bar, - icon: CF_icon, - gpo: NULL, - flush: CF_flush, - quit: CF_quit - }, - { NULL } -}; diff --git a/Cwlinux.c b/Cwlinux.c deleted file mode 100644 index 30f181b..0000000 --- a/Cwlinux.c +++ /dev/null @@ -1,533 +0,0 @@ -/* $Id: Cwlinux.c,v 1.19 2004/01/30 20:57:55 reinelt Exp $ - * - * driver for Cwlinux serial display modules - * - * Copyright 2002 Andrew Ip <aip@cwlinux.com> - * - * 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: Cwlinux.c,v $ - * Revision 1.19 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.18 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.17 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.16 2003/11/30 16:18:36 reinelt - * Cwlinux: invalidate Framebuffer in case a char got redefined - * - * Revision 1.15 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.14 2003/09/13 06:45:43 reinelt - * icons for all remaining drivers - * - * Revision 1.13 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.12 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.11 2003/08/16 07:31:35 reinelt - * double buffering in all drivers - * - * Revision 1.10 2003/08/01 05:15:42 reinelt - * last cleanups for 0.9.9 - * - * Revision 1.9 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.8 2003/05/19 05:55:17 reinelt - * Cwlinux sleep optimization - * - * Revision 1.7 2003/05/14 06:17:39 reinelt - * added support for CW1602 - * - * Revision 1.6 2003/02/24 04:50:57 reinelt - * cwlinux fixes - * - * Revision 1.5 2003/02/22 07:53:09 reinelt - * cfg_get(key,defval) - * - * Revision 1.4 2003/02/22 07:23:24 reinelt - * Cwlinux fixes - * - * Revision 1.3 2002/09/12 05:24:54 reinelt - * code cleanup, character defining for bars - * - * Revision 1.2 2002/09/11 05:32:35 reinelt - * changed to use new bar functions - * - * Revision 1.1 2002/09/11 05:16:32 reinelt - * added Cwlinux driver - * - */ - -/* - * - * exported fuctions: - * - * struct LCD Cwlinux[] - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <termios.h> -#include <fcntl.h> - -#include "debug.h" -#include "cfg.h" -#include "lock.h" -#include "display.h" -#include "bar.h" -#include "icon.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - -#define CHARS 8 - -static LCD Lcd; -static char *Port = NULL; -static speed_t Speed; -static int Device = -1; -static int Icons; - -static char *FrameBuffer1=NULL; -static char *FrameBuffer2=NULL; - - -static int CW_open(void) -{ - int fd; - pid_t pid; - struct termios portset; - - if ((pid = lock_port(Port)) != 0) { - if (pid == -1) - error("Cwlinux: port %s could not be locked", Port); - else - error("Cwlinux: port %s is locked by process %d", Port, pid); - return -1; - } - - fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd == -1) { - error("Cwlinux: open(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - if (tcgetattr(fd, &portset) == -1) { - error("Cwlinux: tcgetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - cfmakeraw(&portset); - cfsetispeed(&portset, Speed); - cfsetospeed(&portset, Speed); - if (tcsetattr(fd, TCSANOW, &portset) == -1) { - error("Cwlinux: tcsetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - - return fd; -} - - -static void CW_write(char *string, int len) -{ - int ret; - - ret=write (Device, string, len); - if (ret<0 && errno==EAGAIN) { - usleep(1000); - ret=write (Device, string, len); - } - if (ret<0) { - error ("Cwlinux: write(%s) failed: %s", Port, strerror(errno)); - } -} - - -#if 0 -static int CW_read(char *string, int len) -{ - int ret; - - ret=read (Device, string, len); - if (ret<0 && errno==EAGAIN) { - debug ("read(): EAGAIN"); - usleep(10000); - ret=read (Device, string, len); - } - debug ("read(%s)=%d", string, ret); - - if (ret<0) { - error("Cwlinux: read() failed: %s", strerror(errno)); - } - - usleep(20); - - return ret; -} -#endif - -static void CW_Goto(int row, int col) -{ - char cmd[6]="\376Gxy\375"; - cmd[2]=(char)col; - cmd[3]=(char)row; - CW_write(cmd,5); -} - - -static void CW12232_define_char (int ascii, char *buffer) -{ - int i, j; - char cmd[10]="\376Nn123456\375"; - - cmd[2]=(char)(ascii+1); - - // Cwlinux uses a vertical bitmap layout, so - // we have to kind of 'rotate' the bitmap. - - for (i=0; i<6;i++) { - cmd[3+i]=0; - for (j=0; j<8;j++) { - if (buffer[j] & (1<<(5-i))) { - cmd[3+i]|=(1<<j); - } - } - } - CW_write(cmd,10); -} - - -static void CW1602_define_char (int ascii, char *buffer) -{ - int i; - char cmd[12]="\376Nn12345678\375"; - - cmd[2]=(char)(ascii+1); - - for (i=0; i<8; i++) { - cmd[3+i]=buffer[i]; - } - CW_write(cmd,12); - usleep(20); // delay for cw1602 to settle the character defined! -} - - -int CW_clear(int full) -{ - - memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - - icon_clear(); - bar_clear(); - - if (full) { - memset (FrameBuffer2, ' ', Lcd.rows*Lcd.cols*sizeof(char)); -#if 0 - CW_write("\376X\375",3); -#else - // for some mysterious reason, we have to sleep after - // the command _and_ after the CMD_END... - usleep(20); - CW_write("\376X",2); - usleep(20); - CW_write("\375",1); - usleep(20); -#endif - } - - return 0; -} - - -static void CW_Brightness(void) -{ - int level; - char cmd[5]="\376A_\375"; - - if (cfg_number(NULL, "Brightness", 8, 0, 8, &level)<0) return; - - switch (level) { - case 0: - // backlight off - CW_write ("\376F\375", 3); - break; - case 8: - // backlight on - CW_write ("\376B\375", 3); - break; - default: - // backlight level - cmd[2]=level; - CW_write (cmd, 4); - break; - } -} - - -int CW_init(LCD * Self) -{ - char *port; - int speed; - // char buffer[16]; - - Lcd = *Self; - - // Init the framebuffers - FrameBuffer1 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - FrameBuffer2 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - if (FrameBuffer1==NULL || FrameBuffer2==NULL) { - error ("Cwlinux: framebuffer could not be allocated: malloc() failed"); - return -1; - } - - if (Port) { - free(Port); - Port = NULL; - } - - port = cfg_get(NULL, "Port",NULL); - if (port == NULL || *port == '\0') { - error("Cwlinux: no 'Port' entry in %s", cfg_source()); - return -1; - } - Port = strdup(port); - - if (cfg_number(NULL, "Speed", 19200, 9600,19200, &speed)<0) return -1; - switch (speed) { - case 9600: - Speed = B9600; - break; - case 19200: - Speed = B19200; - break; - default: - error("Cwlinux: unsupported speed '%d' in %s", speed, cfg_source()); - return -1; - } - - debug("using port %s at %d baud", Port, speed); - - Device = CW_open(); - if (Device == -1) - return -1; - - // this does not work as I'd expect it... -#if 0 - // read firmware version - CW_read(buffer,sizeof(buffer)); - usleep(100000); - CW_write ("\3761", 2); - usleep(100000); - CW_write ("\375", 1); - usleep(100000); - if (CW_read(buffer,2)!=2) { - info ("unable to read firmware version!"); - } - info ("Cwlinux Firmware %d.%d", (int)buffer[0], (int)buffer[1]); -#endif - - CW_clear(1); - - // auto line wrap off - CW_write ("\376D\375", 3); - - // auto scroll off - // CW_write ("\376R\375", 3); - - // underline cursor off - CW_write ("\376K\375", 3); - - // backlight on - CW_write ("\376B\375", 3); - - // backlight brightness - CW_Brightness(); - - 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(Lcd.rows, Lcd.cols, Lcd.xres, Lcd.yres, CHARS, Icons, CW12232_define_char); - Self->icons=Icons; - Lcd.icons=Icons; - } - - bar_init(Lcd.rows, Lcd.cols, Lcd.xres, Lcd.yres, CHARS-Icons); - bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank - - return 0; -} - - -int CW_put(int row, int col, char *text) -{ - char *p=FrameBuffer1+row*Lcd.cols+col; - char *t = text; - - while (*t && col++ <= Lcd.cols) { - *p++ = *t++; - } - return 0; -} - - -int CW_bar(int type, int row, int col, int max, int len1, int len2) -{ - return bar_draw (type, row, col, max, len1, len2); -} - - -int CW_icon (int num, int seq, int row, int col) -{ - return icon_draw (num, seq, row, col); -} - - -int CW_flush(void) -{ - int row, col, pos1, pos2; - int c, equal; - - for (row = 0; row < Lcd.rows; row++) { - for (col = 0; col < Lcd.cols; col++) { - c=bar_peek(row, col); - if (c==-1) c=icon_peek(row, col); - if (c!=-1) { - if (c!=32) c++; // blank - FrameBuffer1[row*Lcd.cols+col]=(char)c; - // invalidate FrameBuffer: - // Cwlinux does not update the display of a user-defined char - // if it is redefined only. We have to definitely write it - // to the display! We force this by invalidating the DoubleBuffer. - // Fixme: This is bad: we should try to remember which chars - // got redefined, and invalidate only those... - FrameBuffer2[row*Lcd.cols+col]=0; - } - } - for (col = 0; col < Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) continue; - CW_Goto(row, col); - for (pos1=col++, pos2=pos1, equal=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) { - // If we find just one equal byte, we don't break, because this - // would require a goto, which takes five bytes, too. - if (++equal>5) break; - } else { - pos2=col; - equal=0; - } - } - CW_write (FrameBuffer1+row*Lcd.cols+pos1, pos2-pos1+1); - } - } - - memcpy (FrameBuffer2, FrameBuffer1, Lcd.rows*Lcd.cols*sizeof(char)); - - return 0; -} - -int CW12232_flush(void) -{ - bar_process(CW12232_define_char); - return CW_flush(); -} - -int CW1602_flush(void) -{ - bar_process(CW1602_define_char); - return CW_flush(); -} - - -int CW_quit(void) -{ - info("Cwlinux: shutting down."); - - debug("closing port %s", Port); - close(Device); - unlock_port(Port); - - - if (FrameBuffer1) { - free(FrameBuffer1); - FrameBuffer1=NULL; - } - - if (FrameBuffer2) { - free(FrameBuffer2); - FrameBuffer2=NULL; - } - - return (0); -} - - -LCD Cwlinux[] = { - { name: "CW12232", - rows: 4, - cols: 20, - xres: 6, - yres: 8, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CW_init, - clear: CW_clear, - put: CW_put, - bar: CW_bar, - icon: CW_icon, - gpo: NULL, - flush: CW12232_flush, - quit: CW_quit - }, - { name: "CW1602", - rows: 2, - cols: 16, - xres: 5, - yres: 8, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: CW_init, - clear: CW_clear, - put: CW_put, - bar: CW_bar, - icon: CW_icon, - gpo: NULL, - flush: CW1602_flush, - quit: CW_quit - }, - {NULL} -}; diff --git a/HD44780.c b/HD44780.c deleted file mode 100644 index 5995aeb..0000000 --- a/HD44780.c +++ /dev/null @@ -1,728 +0,0 @@ -/* $Id: HD44780.c,v 1.50 2004/01/30 20:57:55 reinelt Exp $ - * - * driver for display modules based on the HD44780 chip - * - * Copyright 1999-2004 Michael Reinelt <reinelt@eunet.at> - * - * Modification for 4-Bit mode - * Copyright 2003 Martin Hejl (martin@hejl.de) - * - * Modification for 2nd controller support - * Copyright 2003 Jesse Brook Kovach <jkovach@wam.umd.edu> - * - * 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: HD44780.c,v $ - * Revision 1.50 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.49 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.48 2004/01/06 22:33:13 reinelt - * Copyright statements cleaned up - * - * Revision 1.47 2003/11/12 05:42:35 reinelt - * small changes to the 16x4 handling - * - * Revision 1.46 2003/10/08 06:48:47 nicowallmeier - * special handling for 16x4 displays - * - * Revision 1.45 2003/10/08 06:45:00 nicowallmeier - * Support of two displays of the same size - * - * Revision 1.44 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.43 2003/09/29 06:12:56 reinelt - * changed default HD44780 wiring: unused signals are GND - * - * Revision 1.42 2003/09/21 06:43:02 reinelt - * - * - * MatrixOrbital: bidirectional communication - * HD44780: special handling for 16x1 displays (thanks to Maciej Witkowiak) - * - * Revision 1.41 2003/09/13 06:20:39 reinelt - * HD44780 timings changed; deactivated libtool - * - * Revision 1.40 2003/09/11 04:09:52 reinelt - * minor cleanups - * - * Revision 1.39 2003/09/10 03:48:22 reinelt - * Icons for M50530, new processing scheme (Ticks.Text...) - * - * Revision 1.38 2003/09/09 11:47:47 reinelt - * basic icon support for HD44780 - * - * Revision 1.37 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.36 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.35 2003/08/22 03:45:08 reinelt - * bug in parallel port code fixed, more icons stuff - * - * Revision 1.34 2003/08/19 05:23:55 reinelt - * HD44780 dual-controller patch from Jesse Brook Kovach - * - * Revision 1.33 2003/08/19 04:28:41 reinelt - * more Icon stuff, minor glitches fixed - * - * Revision 1.32 2003/08/16 07:31:35 reinelt - * double buffering in all drivers - * - * Revision 1.31 2003/08/15 07:54:07 reinelt - * HD44780 4 bit mode implemented - * - * Revision 1.30 2003/08/12 05:10:31 reinelt - * first version of HD44780 4Bit-Mode patch - * - * Revision 1.29 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.28 2003/04/07 06:02:58 reinelt - * further parallel port abstraction - * - * Revision 1.27 2003/04/04 06:01:59 reinelt - * new parallel port abstraction scheme - * - * Revision 1.26 2003/02/22 07:53:09 reinelt - * cfg_get(key,defval) - * - * Revision 1.25 2002/08/19 09:11:34 reinelt - * changed HD44780 to use generic bar functions - * - * Revision 1.24 2002/08/19 07:36:29 reinelt - * - * finished bar.c, USBLCD is the first driver that uses the generic bar functions - * - * Revision 1.23 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.22 2002/08/17 14:14:21 reinelt - * - * USBLCD fixes - * - * Revision 1.21 2002/04/30 07:20:15 reinelt - * - * implemented the new ndelay(nanoseconds) in all parallel port drivers - * - * Revision 1.20 2001/09/09 12:26:03 reinelt - * GPO bug: INIT is _not_ inverted - * - * Revision 1.19 2001/03/15 15:49:22 ltoetsch - * fixed compile HD44780.c, cosmetics - * - * Revision 1.18 2001/03/15 09:47:13 reinelt - * - * some fixes to ppdef - * off-by-one bug in processor.c fixed - * - * Revision 1.17 2001/03/14 16:47:41 reinelt - * minor cleanups - * - * Revision 1.16 2001/03/14 15:30:53 reinelt - * - * make ppdev compatible to earlier kernels - * - * Revision 1.15 2001/03/14 15:14:59 reinelt - * added ppdev parallel port access - * - * Revision 1.14 2001/03/12 13:44:58 reinelt - * - * new udelay() using Time Stamp Counters - * - * Revision 1.13 2001/03/12 12:39:36 reinelt - * - * reworked autoconf a lot: drivers may be excluded, #define's went to config.h - * - * Revision 1.12 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.11 2001/02/13 12:43:24 reinelt - * - * HD_gpo() was missing - * - * Revision 1.10 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.9 2000/10/20 07:17:07 reinelt - * - * - * corrected a bug in HD_goto() - * Thanks to Gregor Szaktilla <gregor@szaktilla.de> - * - * Revision 1.8 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.7 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.6 2000/07/31 10:43:44 reinelt - * - * some changes to support kernel-2.4 (different layout of various files in /proc) - * - * Revision 1.5 2000/07/31 06:46:35 reinelt - * - * eliminated some compiler warnings with glibc - * - * Revision 1.4 2000/04/15 16:56:52 reinelt - * - * moved delay loops to udelay.c - * renamed -d (debugging) switch to -v (verbose) - * new switch -d to calibrate delay loop - * 'Delay' entry for HD44780 back again - * delay loops will not calibrate automatically, because this will fail with hich CPU load - * - * Revision 1.3 2000/04/15 11:13:54 reinelt - * - * added '-d' (debugging) switch - * added several debugging messages - * removed config entry 'Delay' for HD44780 driver - * delay loop for HD44780 will be calibrated automatically - * - * Revision 1.2 2000/04/13 06:09:52 reinelt - * - * added BogoMips() to system.c (not used by now, maybe sometimes we can - * calibrate our delay loop with this value) - * - * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully - * no compiler will optimize away the delay loop! - * - * Revision 1.1 2000/04/12 08:05:45 reinelt - * - * first version of the HD44780 driver - * - */ - -/* - * - * exported fuctions: - * - * struct LCD HD44780[] - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "debug.h" -#include "cfg.h" -#include "display.h" -#include "bar.h" -#include "icon.h" -#include "parport.h" -#include "udelay.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - -#define XRES 5 -#define YRES 8 -#define CHARS 8 - - - -/* low level communication timings [nanoseconds] - * as these values differ from spec to spec, - * we use the worst-case values. - */ - -#define T_CYCLE 1000 // Enable cycle time -#define T_PW 450 // Enable pulse width -#define T_AS 60 // Address setup time -#define T_H 40 // Data hold time - - -/* HD44780 execution timings [microseconds] - * as these values differ from spec to spec, - * we use the worst-case values. - */ - -#define T_INIT1 4100 // first init sequence: 4.1 msec -#define T_INIT2 100 // second init sequence: 100 usec -#define T_EXEC 80 // normal execution time -#define T_WRCG 120 // CG RAM Write -#define T_CLEAR 1640 // Clear Display - - -static LCD Lcd; -static int Icons; -static int Bits=0; -static int GPO=0; -static int Controllers = 0; -static int Controller = 0; - -static char *FrameBuffer1=NULL; -static char *FrameBuffer2=NULL; - -static unsigned char SIGNAL_RW; -static unsigned char SIGNAL_RS; -static unsigned char SIGNAL_ENABLE; -static unsigned char SIGNAL_ENABLE2; -static unsigned char SIGNAL_GPO; - -static void HD_nibble(unsigned char controller, unsigned char nibble) -{ - unsigned char enable; - - // enable signal: 'controller' is a bitmask - // bit 0 .. send to controller #0 - // bit 1 .. send to controller #1 - // so we can send a byte to both controllers at the same time! - enable=0; - if (controller&0x01) enable|=SIGNAL_ENABLE; - if (controller&0x02) enable|=SIGNAL_ENABLE2; - - // clear ENABLE - // put data on DB1..DB4 - // nibble already contains RS bit! - parport_data(nibble); - - // Address set-up time - ndelay(T_AS); - - // rise ENABLE - parport_data(nibble | enable); - - // Enable pulse width - ndelay(T_PW); - - // lower ENABLE - parport_data(nibble); -} - - -static void HD_byte (unsigned char controller, unsigned char data, unsigned char RS) -{ - // send high nibble of the data - HD_nibble (controller, ((data>>4)&0x0f)|RS); - - // Make sure we honour T_CYCLE - ndelay(T_CYCLE-T_AS-T_PW); - - // send low nibble of the data - HD_nibble(controller, (data&0x0f)|RS); -} - - -static void HD_command (unsigned char controller, unsigned char cmd, int delay) -{ - unsigned char enable; - - if (Bits==8) { - - // enable signal: 'controller' is a bitmask - // bit 0 .. send to controller #0 - // bit 1 .. send to controller #1 - // so we can send a byte to both controllers at the same time! - enable=0; - if (controller&0x01) enable|=SIGNAL_ENABLE; - if (controller&0x02) enable|=SIGNAL_ENABLE2; - - // put data on DB1..DB8 - parport_data (cmd); - - // clear RW and RS - parport_control (SIGNAL_RW | SIGNAL_RS, 0); - - // Address set-up time - ndelay(T_AS); - - // send command - parport_toggle (enable, 1, T_PW); - - } else { - - HD_byte (controller, cmd, 0); - - } - - // wait for command completion - udelay(delay); - -} - - -static void HD_write (unsigned char controller, char *string, int len, int delay) -{ - unsigned char enable; - - // sanity check - if (len<=0) return; - - if (Bits==8) { - - // enable signal: 'controller' is a bitmask - // bit 0 .. send to controller #0 - // bit 1 .. send to controller #1 - // so we can send a byte to both controllers at the same time! - enable=0; - if (controller&0x01) enable|=SIGNAL_ENABLE; - if (controller&0x02) enable|=SIGNAL_ENABLE2; - - // clear RW, set RS - parport_control (SIGNAL_RW | SIGNAL_RS, SIGNAL_RS); - - // Address set-up time - ndelay(T_AS); - - while (len--) { - - // put data on DB1..DB8 - parport_data (*(string++)); - - // send command - parport_toggle (enable, 1, T_PW); - - // wait for command completion - udelay(delay); - } - - } else { // 4 bit mode - - while (len--) { - - // send data with RS enabled - HD_byte (controller, *(string++), SIGNAL_RS); - - // wait for command completion - udelay(delay); - } - } -} - - -static void HD_setGPO (int bits) -{ - if (Lcd.gpos>0) { - - // put data on DB1..DB8 - parport_data (bits); - - // 74HCT573 set-up time - ndelay(20); - - // send data - // 74HCT573 enable pulse width = 24ns - parport_toggle (SIGNAL_GPO, 1, 230); - } -} - - -static void HD_define_char (int ascii, char *buffer) -{ - // define chars on *both* controllers! - HD_command (0x03, 0x40|8*ascii, T_EXEC); - HD_write (0x03, buffer, 8, T_WRCG); -} - - -int HD_clear (int full) -{ - - memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - - icon_clear(); - bar_clear(); - - GPO=0; - - if (full) { - memset (FrameBuffer2, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - HD_command (0x03, 0x01, T_CLEAR); // clear *both* displays - HD_command (0x03, 0x03, T_CLEAR); // return home - HD_setGPO (GPO); // all GPO's off - } - - return 0; -} - - -int HD_init (LCD *Self) -{ - int rows=-1, cols=-1, gpos=-1; - char *s; - - s=cfg_get(NULL, "Size", NULL); - if (s==NULL || *s=='\0') { - error ("HD44780: no 'Size' entry in %s", cfg_source()); - return -1; - } - if (sscanf(s,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) { - error ("HD44780: bad size '%s'",s); - return -1; - } - - if (cfg_number(NULL, "GPOs", 0, 0, 8, &gpos)<0) return -1; - info ("HD44780: controlling %d GPO's", gpos); - - if (cfg_number(NULL, "Controllers", 1, 1, 2, &Controllers)<0) return -1; - info ("wiring: using display with %d controllers", Controllers); - - // current controller - Controller=1; - - Self->rows=rows; - Self->cols=cols; - Self->gpos=gpos; - Lcd=*Self; - - // Init the framebuffers - FrameBuffer1 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - FrameBuffer2 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - if (FrameBuffer1==NULL || FrameBuffer2==NULL) { - error ("HD44780: framebuffer could not be allocated: malloc() failed"); - return -1; - } - - if (cfg_number(NULL, "Bits", 8, 4, 8, &Bits)<0) return -1; - if (Bits!=4 && Bits!=8) { - error ("HD44780: bad Bits '%s' in %s, should be '4' or '8'", s, cfg_source()); - return -1; - } - info ("wiring: using %d bit mode", Bits); - - if (Bits==8) { - if ((SIGNAL_RS = parport_wire_ctrl ("RS", "AUTOFD"))==0xff) return -1; - if ((SIGNAL_RW = parport_wire_ctrl ("RW", "GND" ))==0xff) return -1; - if ((SIGNAL_ENABLE = parport_wire_ctrl ("ENABLE", "STROBE"))==0xff) return -1; - if ((SIGNAL_ENABLE2 = parport_wire_ctrl ("ENABLE2", "GND" ))==0xff) return -1; - if ((SIGNAL_GPO = parport_wire_ctrl ("GPO", "GND" ))==0xff) return -1; - } else { - if ((SIGNAL_RS = parport_wire_data ("RS", "DB4"))==0xff) return -1; - if ((SIGNAL_RW = parport_wire_data ("RW", "DB5"))==0xff) return -1; - if ((SIGNAL_ENABLE = parport_wire_data ("ENABLE", "DB6"))==0xff) return -1; - if ((SIGNAL_ENABLE2 = parport_wire_data ("ENABLE2", "GND"))==0xff) return -1; - if ((SIGNAL_GPO = parport_wire_data ("GPO", "GND"))==0xff) return -1; - } - - if (parport_open() != 0) { - error ("HD44780: could not initialize parallel port!"); - return -1; - } - - // clear all signals - if (Bits==8) { - parport_control (SIGNAL_RS|SIGNAL_RW|SIGNAL_ENABLE|SIGNAL_ENABLE2|SIGNAL_GPO, 0); - } else { - parport_data (0); - } - - // set direction: write - parport_direction (0); - - // initialize *both* displays - if (Bits==8) { - HD_command (0x03, 0x30, T_INIT1); // 8 Bit mode, wait 4.1 ms - HD_command (0x03, 0x30, T_INIT2); // 8 Bit mode, wait 100 us - HD_command (0x03, 0x38, T_EXEC); // 8 Bit mode, 1/16 duty cycle, 5x8 font - } else { - HD_nibble(0x03, 0x03); udelay(T_INIT1); // 4 Bit mode, wait 4.1 ms - HD_nibble(0x03, 0x03); udelay(T_INIT2); // 4 Bit mode, wait 100 us - HD_nibble(0x03, 0x03); udelay(T_INIT1); // 4 Bit mode, wait 4.1 ms - HD_nibble(0x03, 0x02); udelay(T_INIT2); // 4 Bit mode, wait 100 us - HD_command (0x03, 0x28, T_EXEC); // 4 Bit mode, 1/16 duty cycle, 5x8 font - } - - HD_command (0x03, 0x08, T_EXEC); // Display off, cursor off, blink off - HD_command (0x03, 0x0c, T_CLEAR); // Display on, cursor off, blink off, wait 1.64 ms - HD_command (0x03, 0x06, T_EXEC); // curser moves to right, no shift - - 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(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, HD_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 - - HD_clear(1); - - return 0; -} - - -void HD_goto (int row, int col) -{ - int pos; - - // handle multiple displays/controllers - if (Controllers>1 && row>=Lcd.rows/2) { - row -= Lcd.rows/2; - Controller = 2; - } else { - Controller = 1; - } - - // 16x1 Displays are organized as 8x2 :-( - if (Lcd.cols==16 && Lcd.rows==1 && col>7) { - row++; - col-=8; - } - - // 16x4 Displays use a slightly different layout - if (Lcd.cols==16 && Lcd.rows==4) { - pos=(row%2)*64+(row/2)*16+col; - } else { - pos=(row%2)*64+(row/2)*20+col; - } - - HD_command (Controller, (0x80|pos), T_EXEC); -} - - -int HD_put (int row, int col, char *text) -{ - char *p=FrameBuffer1+row*Lcd.cols+col; - char *t=text; - - while (*t && col++<=Lcd.cols) { - *p++=*t++; - } - return 0; -} - - -int HD_bar (int type, int row, int col, int max, int len1, int len2) -{ - return bar_draw (type, row, col, max, len1, len2); -} - - -int HD_icon (int num, int seq, int row, int col) -{ - return icon_draw (num, seq, row, col); -} - - -int HD_gpo (int num, int val) -{ - if (num>=Lcd.gpos) - return -1; - - if (val) { - GPO |= 1<<num; // set bit - } else { - GPO &= ~(1<<num); // clear bit - } - return 0; -} - - -int HD_flush (void) -{ - int row, col, pos1, pos2; - int c, equal; - - bar_process(HD_define_char); - - for (row=0; row<Lcd.rows; row++) { - for (col=0; col<Lcd.cols; col++) { - c=bar_peek(row, col); - if (c==-1) c=icon_peek(row, col); - if (c!=-1) { - FrameBuffer1[row*Lcd.cols+col]=(char)c; - } - } - for (col=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) continue; - HD_goto (row, col); - for (pos1=col++, pos2=pos1, equal=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) { - // If we find just one equal byte, we don't break, because this - // would require a goto, which takes one byte, too. - if (++equal>2) break; - } else { - pos2=col; - equal=0; - } - // special handling of 16x1 displays - if (Lcd.rows==1 && Lcd.cols==16 && col==7) { - break; - } - } - HD_write (Controller, FrameBuffer1+row*Lcd.cols+pos1, pos2-pos1+1, T_EXEC); - } - } - - memcpy (FrameBuffer2, FrameBuffer1, Lcd.rows*Lcd.cols*sizeof(char)); - - HD_setGPO(GPO); - - return 0; -} - - -int HD_quit (void) -{ - info("HD44780: shutting down."); - - if (FrameBuffer1) { - free(FrameBuffer1); - FrameBuffer1=NULL; - } - - if (FrameBuffer2) { - free(FrameBuffer2); - FrameBuffer2=NULL; - } - - return parport_close(); -} - - -LCD HD44780[] = { - { name: "HD44780", - rows: 0, - cols: 0, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 0, - init: HD_init, - clear: HD_clear, - put: HD_put, - bar: HD_bar, - icon: HD_icon, - gpo: HD_gpo, - flush: HD_flush, - quit: HD_quit - }, - { NULL } -}; diff --git a/Makefile.am b/Makefile.am index 2826a9f..b181a2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,60 +15,38 @@ lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@ #remove next line for liblcd4linux lcd4linux_DEPENDENCIES = @DRIVERS@ -lcd4linux_SOURCES = \ -lcd4linux.c \ -pid.c pid.h \ -hash.c hash.h \ -parser.c parser.h \ -processor.c processor.h \ -layout.c layout.h \ -timer.c timer.h \ -evaluator.c evaluator.h \ -widget.c widget.h \ +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 \ +lock.c lock.h \ +pid.c pid.h \ +timer.c timer.h \ +udelay.c udelay.h \ + \ +widget.c widget.h \ widget_text.c widget_text.h \ -widget_bar.c widget_bar.h \ +widget_bar.c widget_bar.h \ widget_icon.c widget_icon.h \ -plugin.c plugin.h \ -plugin_math.c \ -plugin_string.c \ -plugin_cfg.c \ -plugin_uname.c \ -plugin_loadavg.c \ -plugin_proc_stat.c \ -plugin_cpuinfo.c \ -plugin_meminfo.c \ -plugin_netdev.c \ -plugin_ppp.c \ -plugin_dvb.c \ -plugin_i2c_sensors.c \ -plugin_xmms.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 \ -exec.c exec.h \ -expr.c expr.h \ -mail2.c \ -socket.c socket.h \ -imon.c imon.h \ -\ -display.c display.h \ -drv.c drv.h \ -drv_generic_serial.c drv_generic_serial.h \ -drv_generic_parport.c drv_generic_parport.h \ -drv_generic_text.c drv_generic_text.h \ -debug.c debug.h \ -cfg.c cfg.h \ -lock.c lock.h \ -pixmap.c pixmap.h \ -bar.c bar.h \ -icon.c icon.h \ -fontmap.c fontmap.h \ -udelay.c udelay.h + \ +plugin.c plugin.h \ +plugin_math.c \ +plugin_string.c \ +plugin_cfg.c \ +plugin_uname.c \ +plugin_loadavg.c \ +plugin_proc_stat.c \ +plugin_cpuinfo.c \ +plugin_meminfo.c \ +plugin_netdev.c \ +plugin_ppp.c \ +plugin_dvb.c \ +plugin_i2c_sensors.c \ +plugin_xmms.c #liblcd4linux_la_DEPENDENCIES = @DRIVERS@ #liblcd4linux_la_LDFLAGS = -version-info 9:12:9 @@ -87,15 +65,17 @@ udelay.c udelay.h #udelay.c udelay.h EXTRA_lcd4linux_SOURCES= \ -parport.c parport.h \ +drv_generic_text.c drv_generic_text.h \ +drv_generic_serial.c drv_generic_serial.h \ +drv_generic_parport.c drv_generic_parport.h \ BeckmannEgle.c \ -drv_Crystalfontz.c Crystalfontz.c \ -drv_Cwlinux.c Cwlinux.c \ +drv_Crystalfontz.c \ +drv_Cwlinux.c \ HD44780.c \ M50530.c \ T6963.c \ USBLCD.c \ -drv_MatrixOrbital.c MatrixOrbital.c \ +drv_MatrixOrbital.c \ MilfordInstruments.c \ PalmPilot.c \ Raster.c \ @@ -121,5 +101,4 @@ README.Tokens \ README.Drivers \ README.Plugins \ README.KDE \ -Skeleton.c \ plugin_sample.c diff --git a/Makefile.in b/Makefile.in index 1dcc66e..dd1a8ff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,7 +106,7 @@ lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@ #remove next line for liblcd4linux lcd4linux_DEPENDENCIES = @DRIVERS@ -lcd4linux_SOURCES = lcd4linux.c pid.c pid.h hash.c hash.h parser.c parser.h processor.c processor.h layout.c layout.h timer.c timer.h evaluator.c evaluator.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_xmms.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 exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h display.c display.h drv.c drv.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_text.c drv_generic_text.h debug.c debug.h cfg.c cfg.h lock.c lock.h pixmap.c pixmap.h bar.c bar.h icon.c icon.h fontmap.c fontmap.h udelay.c udelay.h +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 lock.c lock.h pid.c pid.h timer.c timer.h udelay.c udelay.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_xmms.c #liblcd4linux_la_DEPENDENCIES = @DRIVERS@ @@ -125,10 +125,10 @@ lcd4linux_SOURCES = lcd4linux.c pid.c pid.h hash.c hash.h parser.c parser.h pro #fontmap.c fontmap.h \ #udelay.c udelay.h -EXTRA_lcd4linux_SOURCES = parport.c parport.h BeckmannEgle.c drv_Crystalfontz.c Crystalfontz.c drv_Cwlinux.c Cwlinux.c HD44780.c M50530.c T6963.c USBLCD.c drv_MatrixOrbital.c MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c SIN.c XWindow.c Text.c +EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h BeckmannEgle.c drv_Crystalfontz.c drv_Cwlinux.c HD44780.c M50530.c T6963.c USBLCD.c drv_MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c SIN.c XWindow.c Text.c -EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Rows README.Tokens README.Drivers README.Plugins README.KDE Skeleton.c plugin_sample.c +EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Rows README.Tokens README.Drivers README.Plugins README.KDE plugin_sample.c ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -146,23 +146,16 @@ X_CFLAGS = @X_CFLAGS@ X_LIBS = @X_LIBS@ X_EXTRA_LIBS = @X_EXTRA_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ -lcd4linux_OBJECTS = lcd4linux.$(OBJEXT) pid.$(OBJEXT) hash.$(OBJEXT) \ -parser.$(OBJEXT) processor.$(OBJEXT) layout.$(OBJEXT) timer.$(OBJEXT) \ -evaluator.$(OBJEXT) widget.$(OBJEXT) widget_text.$(OBJEXT) \ -widget_bar.$(OBJEXT) widget_icon.$(OBJEXT) plugin.$(OBJEXT) \ -plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) plugin_cfg.$(OBJEXT) \ -plugin_uname.$(OBJEXT) plugin_loadavg.$(OBJEXT) \ -plugin_proc_stat.$(OBJEXT) plugin_cpuinfo.$(OBJEXT) \ -plugin_meminfo.$(OBJEXT) plugin_netdev.$(OBJEXT) plugin_ppp.$(OBJEXT) \ -plugin_dvb.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) plugin_xmms.$(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) display.$(OBJEXT) drv.$(OBJEXT) \ -drv_generic_serial.$(OBJEXT) drv_generic_parport.$(OBJEXT) \ -drv_generic_text.$(OBJEXT) debug.$(OBJEXT) cfg.$(OBJEXT) lock.$(OBJEXT) \ -pixmap.$(OBJEXT) bar.$(OBJEXT) icon.$(OBJEXT) fontmap.$(OBJEXT) \ -udelay.$(OBJEXT) +lcd4linux_OBJECTS = lcd4linux.$(OBJEXT) cfg.$(OBJEXT) debug.$(OBJEXT) \ +drv.$(OBJEXT) evaluator.$(OBJEXT) hash.$(OBJEXT) layout.$(OBJEXT) \ +lock.$(OBJEXT) pid.$(OBJEXT) timer.$(OBJEXT) udelay.$(OBJEXT) \ +widget.$(OBJEXT) widget_text.$(OBJEXT) widget_bar.$(OBJEXT) \ +widget_icon.$(OBJEXT) plugin.$(OBJEXT) plugin_math.$(OBJEXT) \ +plugin_string.$(OBJEXT) plugin_cfg.$(OBJEXT) plugin_uname.$(OBJEXT) \ +plugin_loadavg.$(OBJEXT) plugin_proc_stat.$(OBJEXT) \ +plugin_cpuinfo.$(OBJEXT) plugin_meminfo.$(OBJEXT) \ +plugin_netdev.$(OBJEXT) plugin_ppp.$(OBJEXT) plugin_dvb.$(OBJEXT) \ +plugin_i2c_sensors.$(OBJEXT) plugin_xmms.$(OBJEXT) CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -178,25 +171,20 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best -DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \ -.deps/HD44780.P .deps/M50530.P .deps/MatrixOrbital.P \ +DEP_FILES = .deps/BeckmannEgle.P .deps/HD44780.P .deps/M50530.P \ .deps/MilfordInstruments.P .deps/PalmPilot.P .deps/Raster.P .deps/SIN.P \ -.deps/T6963.P .deps/Text.P .deps/USBLCD.P .deps/XWindow.P .deps/bar.P \ -.deps/battery.P .deps/cfg.P .deps/debug.P .deps/display.P .deps/drv.P \ -.deps/drv_Crystalfontz.P .deps/drv_Cwlinux.P .deps/drv_MatrixOrbital.P \ -.deps/drv_generic_parport.P .deps/drv_generic_serial.P \ -.deps/drv_generic_text.P .deps/dvb.P .deps/evaluator.P .deps/exec.P \ -.deps/expr.P .deps/filter.P .deps/fontmap.P .deps/hash.P .deps/icon.P \ -.deps/imon.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_cfg.P .deps/plugin_cpuinfo.P \ +.deps/T6963.P .deps/Text.P .deps/USBLCD.P .deps/XWindow.P .deps/cfg.P \ +.deps/debug.P .deps/drv.P .deps/drv_Crystalfontz.P .deps/drv_Cwlinux.P \ +.deps/drv_MatrixOrbital.P .deps/drv_generic_parport.P \ +.deps/drv_generic_serial.P .deps/drv_generic_text.P .deps/evaluator.P \ +.deps/hash.P .deps/layout.P .deps/lcd4linux.P .deps/lock.P .deps/pid.P \ +.deps/plugin.P .deps/plugin_cfg.P .deps/plugin_cpuinfo.P \ .deps/plugin_dvb.P .deps/plugin_i2c_sensors.P .deps/plugin_loadavg.P \ .deps/plugin_math.P .deps/plugin_meminfo.P .deps/plugin_netdev.P \ .deps/plugin_ppp.P .deps/plugin_proc_stat.P .deps/plugin_string.P \ -.deps/plugin_uname.P .deps/plugin_xmms.P .deps/processor.P .deps/seti.P \ -.deps/socket.P .deps/system.P .deps/timer.P .deps/udelay.P \ +.deps/plugin_uname.P .deps/plugin_xmms.P .deps/timer.P .deps/udelay.P \ .deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ -.deps/widget_text.P .deps/wifi.P +.deps/widget_text.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/MatrixOrbital.c b/MatrixOrbital.c deleted file mode 100644 index 2035283..0000000 --- a/MatrixOrbital.c +++ /dev/null @@ -1,960 +0,0 @@ -/* $Id: MatrixOrbital.c,v 1.52 2004/01/30 20:57:55 reinelt Exp $ - * - * driver for Matrix Orbital serial display modules - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: MatrixOrbital.c,v $ - * Revision 1.52 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.51 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.50 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.49 2003/12/19 05:35:14 reinelt - * renamed 'client' to 'plugin' - * - * Revision 1.48 2003/11/16 09:45:49 reinelt - * Crystalfontz changes, small glitch in getopt() fixed - * - * Revision 1.47 2003/10/22 04:19:16 reinelt - * Makefile.in for imon.c/.h, some MatrixOrbital clients - * - * Revision 1.46 2003/10/12 04:46:19 reinelt - * - * - * first try to integrate the Evaluator into a display driver (MatrixOrbital here) - * small warning in processor.c fixed (thanks to Zachary Giles) - * workaround for udelay() on alpha (no msr.h avaliable) (thanks to Zachary Giles) - * - * Revision 1.45 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.44 2003/10/03 03:51:14 reinelt - * start support for new MatrixOrbital MX2 displays - * - * Revision 1.43 2003/09/29 06:12:56 reinelt - * changed default HD44780 wiring: unused signals are GND - * - * Revision 1.42 2003/09/21 06:43:02 reinelt - * - * - * MatrixOrbital: bidirectional communication - * HD44780: special handling for 16x1 displays (thanks to Maciej Witkowiak) - * - * Revision 1.41 2003/09/13 06:45:43 reinelt - * icons for all remaining drivers - * - * Revision 1.40 2003/09/11 04:09:53 reinelt - * minor cleanups - * - * Revision 1.39 2003/09/10 03:48:23 reinelt - * Icons for M50530, new processing scheme (Ticks.Text...) - * - * Revision 1.38 2003/09/09 11:47:47 reinelt - * basic icon support for HD44780 - * - * Revision 1.37 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * 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 - * - * Revision 1.34 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.33 2003/08/24 04:31:56 reinelt - * icon.c icon.h added - * - * Revision 1.32 2003/08/22 03:45:08 reinelt - * bug in parallel port code fixed, more icons stuff - * - * Revision 1.31 2003/08/19 04:28:41 reinelt - * more Icon stuff, minor glitches fixed - * - * Revision 1.30 2003/08/17 16:37:39 reinelt - * more icon framework - * - * Revision 1.29 2003/08/16 07:31:35 reinelt - * double buffering in all drivers - * - * Revision 1.28 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.27 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.26 2003/02/13 10:40:17 reinelt - * - * changed "copyright" to "2003" - * added slightly different protocol for MatrixOrbital "LK202" displays - * - * Revision 1.25 2002/08/19 09:30:18 reinelt - * MatrixOrbital uses generic bar funnctions - * - * Revision 1.24 2002/08/19 07:36:29 reinelt - * - * finished bar.c, USBLCD is the first driver that uses the generic bar functions - * - * Revision 1.23 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.22 2001/04/27 05:04:57 reinelt - * - * replaced OPEN_MAX with sysconf() - * replaced mktemp() with mkstemp() - * unlock serial port if open() fails - * - * Revision 1.21 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.20 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.19 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.18 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.17 2000/04/15 11:13:54 reinelt - * - * added '-d' (debugging) switch - * added several debugging messages - * removed config entry 'Delay' for HD44780 driver - * delay loop for HD44780 will be calibrated automatically - * - * Revision 1.16 2000/04/13 06:09:52 reinelt - * - * added BogoMips() to system.c (not used by now, maybe sometimes we can - * calibrate our delay loop with this value) - * - * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully - * no compiler will optimize away the delay loop! - * - * Revision 1.15 2000/04/12 08:05:45 reinelt - * - * first version of the HD44780 driver - * - * Revision 1.14 2000/04/10 04:40:53 reinelt - * - * minor changes and cleanups - * - * Revision 1.13 2000/04/07 05:42:20 reinelt - * - * UUCP style lockfiles for the serial port - * - * Revision 1.12 2000/03/26 18:46:28 reinelt - * - * bug in pixmap.c that leaded to empty bars fixed - * name conflicts with X11 resolved - * - * Revision 1.11 2000/03/25 05:50:43 reinelt - * - * memory leak in Raster_flush closed - * driver family logic changed - * - * Revision 1.10 2000/03/23 07:24:48 reinelt - * - * PPM driver up and running (but slow!) - * - * Revision 1.9 2000/03/22 07:33:50 reinelt - * - * FAQ added - * new modules 'processor.c' contains all data processing - * - * Revision 1.8 2000/03/19 08:41:28 reinelt - * - * documentation available! README, README.MatrixOrbital, README.Drivers - * added Skeleton.c as a starting point for new drivers - * - * Revision 1.7 2000/03/18 08:07:04 reinelt - * - * vertical bars implemented - * bar compaction improved - * memory information implemented - * - * Revision 1.6 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.5 2000/03/13 15:58:24 reinelt - * - * release 0.9 - * moved row parsing to parser.c - * all basic work finished - * - * Revision 1.4 2000/03/10 17:36:02 reinelt - * - * first unstable but running release - * - */ - -/* - * - * exported fuctions: - * - * struct LCD MatrixOrbital[] - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <termios.h> -#include <fcntl.h> - -#include "debug.h" -#include "cfg.h" -#include "plugin.h" -#include "lock.h" -#include "display.h" -#include "bar.h" -#include "icon.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - -#define XRES 5 -#define YRES 8 -#define CHARS 8 - -static LCD Lcd; -static char *Port=NULL; -static speed_t Speed; -static int Device=-1; -static int Icons; -static int GPO[8]; - -static char *FrameBuffer1=NULL; -static char *FrameBuffer2=NULL; - -typedef struct { - int type; - char *name; -} MODEL; - -static MODEL Model[] = { - { 0x01, "LCD0821" }, - { 0x03, "LCD2021" }, - { 0x04, "LCD1641" }, - { 0x05, "LCD2041" }, - { 0x06, "LCD4021" }, - { 0x07, "LCD4041" }, - { 0x08, "LK202-25" }, - { 0x09, "LK204-25" }, - { 0x0a, "LK404-55" }, - { 0x0b, "VFD2021" }, - { 0x0c, "VFD2041" }, - { 0x0d, "VFD4021" }, - { 0x0e, "VK202-25" }, - { 0x0f, "VK204-25" }, - { 0x10, "GLC12232" }, - { 0x13, "GLC24064" }, - { 0x15, "GLK24064-25" }, - { 0x22, "GLK12232-25" }, - { 0x31, "LK404-AT" }, - { 0x32, "VFD1621" }, - { 0x33, "LK402-12" }, - { 0x34, "LK162-12" }, - { 0x35, "LK204-25PC" }, - { 0x36, "LK202-24-USB" }, - { 0x38, "LK204-24-USB" }, - { 0xff, "Unknown" } -}; - - -static int MO_open (void) -{ - int fd; - pid_t pid; - struct termios portset; - - if ((pid=lock_port(Port))!=0) { - if (pid==-1) - error ("MatrixOrbital: port %s could not be locked", Port); - else - error ("MatrixOrbital: port %s is locked by process %d", Port, pid); - return -1; - } - fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd==-1) { - error ("MatrixOrbital: open(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - if (tcgetattr(fd, &portset)==-1) { - error ("MatrixOrbital: tcgetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - cfmakeraw(&portset); - cfsetospeed(&portset, Speed); - if (tcsetattr(fd, TCSANOW, &portset)==-1) { - error ("MatrixOrbital: tcsetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - return fd; -} - - -static int MO_read (char *string, int len) -{ - int run, ret; - - if (Device==-1) return -1; - for (run=0; run<10; run++) { - ret=read (Device, string, len); - if (ret>=0 || errno!=EAGAIN) break; - debug ("read(): EAGAIN"); - usleep(1000); - } - - if (ret<0) { - error("MatrixOrbital: read(%s, %d) failed: %s", Port, len, strerror(errno)); - } - - return ret; -} - - -static void MO_write (char *string, int len) -{ - int run, ret; - - if (Device==-1) return; - for (run=0; run<10; run++) { - ret=write (Device, string, len); - if (ret>=0 || errno!=EAGAIN) break; - debug ("write(): EAGAIN"); - usleep(1000); - } - - if (ret<0) { - error ("MatrixOrbital: write(%s) failed: %s", Port, strerror(errno)); - } - - // Fixme - if (ret!=len) { - error ("MatrixOrbital: partial write: len=%d ret=%d", len, ret); - } - - return; -} - - -static int MO_contrast (void) -{ - char buffer[4]; - int contrast; - - if (cfg_number(NULL, "Contrast", 160, 0, 255, &contrast)<0) return -1; - snprintf (buffer, 4, "\376P%c", contrast); - MO_write (buffer, 3); - return 0; -} - - -static void MO_define_char (int ascii, char *buffer) -{ - char cmd[3]="\376N"; - - cmd[2]=(char)ascii; - MO_write (cmd, 3); - MO_write (buffer, 8); -} - - -static int MO_clear (int protocol) -{ - int gpo; - - memset (FrameBuffer1, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - - icon_clear(); - bar_clear(); - memset(GPO, 0, sizeof(GPO)); - - if (protocol) { - memset (FrameBuffer2, ' ', Lcd.rows*Lcd.cols*sizeof(char)); - switch (protocol) { - case 1: - MO_write ("\014", 1); // Clear Screen - MO_write ("\376V", 2); // GPO off - break; - case 2: - MO_write ("\376\130", 2); // Clear Screen - for (gpo=1; gpo<=Lcd.gpos; gpo++) { - char cmd1[3]="\376V"; - char cmd2[4]="\376\300x\377"; - cmd1[2]=(char)gpo; - cmd2[2]=(char)gpo; - MO_write (cmd1, 3); // GPO off - MO_write (cmd2, 4); // PWM full power - } - break; - } - } - - return 0; -} - -int MO_clear1 (int full) -{ - return MO_clear(full?1:0); -} - -int MO_clear2 (int full) -{ - return MO_clear(full?2:0); -} - - -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; - snprintf (buffer, 4, "\376P%c", (int)contrast); - MO_write (buffer, 3); - - SetResult(&result, R_NUMBER, &contrast); -} - - -static void plugin_backlight (RESULT *result, RESULT *arg1) -{ - char buffer[4]; - double backlight; - - backlight=R2N(arg1); - if (backlight<-1 ) backlight=-1; - if (backlight>255) backlight=255; - if (backlight<0) { - // backlight off - snprintf (buffer, 3, "\376F"); - MO_write (buffer, 2); - } else { - // backlight on for n minutes - snprintf (buffer, 4, "\376B%c", (int)backlight); - MO_write (buffer, 3); - } - SetResult(&result, R_NUMBER, &backlight); -} - - -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); - - if (num<1) num=1; - if (num>6) num=6; - - if (val>=1.0) { - val=1.0; - } else { - val=0.0; - } - - switch (protocol) { - case 1: - if (num==0) { - if (val>=1.0) { - MO_write ("\376W", 2); // GPO on - } else { - MO_write ("\376V", 2); // GPO off - } - } else { - error("Fixme"); - val=-1.0; - } - break; - - case 2: - if (val>=1.0) { - cmd[1]='W'; // GPO on - } else { - cmd[1]='V'; // GPO off - } - cmd[2]=(char)num; - MO_write (cmd, 3); - break; - } - - SetResult(&result, R_NUMBER, &val); -} - - -static void plugin_pwm (RESULT *result, RESULT *arg1, RESULT *arg2) -{ - int num; - double val; - char cmd[4]="\376\300"; - - num=R2N(arg1); - if (num<1) num=1; - if (num>6) num=6; - cmd[2]=(char)num; - - val=R2N(arg2); - if (val< 0.0) val= 0.0; - if (val>255.0) val=255.0; - cmd[3]=(char)val; - - MO_write (cmd, 4); - - SetResult(&result, R_NUMBER, &val); -} - - -static void plugin_rpm (RESULT *result, RESULT *arg1) -{ - int num; - double val; - char cmd[3]="\376\301"; - char buffer[7]; - - num=R2N(arg1); - if (num<1) num=1; - if (num>6) num=6; - cmd[2]=(char)num; - - MO_write (cmd, 3); - usleep(100000); - MO_read (buffer, 7); - - debug ("rpm: buffer[0]=0x%01x", buffer[0]); - debug ("rpm: buffer[1]=0x%01x", buffer[1]); - debug ("rpm: buffer[2]=0x%01x", buffer[2]); - debug ("rpm: buffer[3]=0x%01x", buffer[3]); - debug ("rpm: buffer[4]=0x%01x", buffer[4]); - debug ("rpm: buffer[5]=0x%01x", buffer[5]); - debug ("rpm: buffer[6]=0x%01x", buffer[6]); - - SetResult(&result, R_NUMBER, &val); -} - - -static int MO_init (LCD *Self, int protocol) -{ - int i; - char *port, buffer[256]; - - - Lcd=*Self; - - // Init the framebuffers - FrameBuffer1 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - FrameBuffer2 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); - if (FrameBuffer1==NULL || FrameBuffer2==NULL) { - error ("MatrixOrbital: framebuffer could not be allocated: malloc() failed"); - return -1; - } - - if (Port) { - free (Port); - Port=NULL; - } - - port=cfg_get (NULL, "Port", NULL); - if (port==NULL || *port=='\0') { - error ("MatrixOrbital: no 'Port' entry in %s", cfg_source()); - return -1; - } - Port=strdup(port); - - if (cfg_number(NULL, "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' in %s", i, cfg_source()); - return -1; - } - - debug ("using port %s at %d baud", Port, i); - - Device=MO_open(); - if (Device==-1) return -1; - - // read module type - MO_write ("\3767", 2); - usleep(1000); - MO_read (buffer, 1); - for (i=0; Model[i].type!=0xff; i++) { - if (Model[i].type == (int)*buffer) break; - } - info ("Display on %s is a MatrixOrbital %s (type 0x%02x)", Port, Model[i].name, Model[i].type); - - // read serial number - MO_write ("\3765", 2); - usleep(100000); - MO_read (buffer, 2); - info ("Display on %s has Serial Number 0x%x", Port, *(short*)buffer); - - // read version number - MO_write ("\3766", 2); - usleep(100000); - MO_read (buffer, 1); - info ("Display on %s has Firmware Version 0x%x", Port, *buffer); - - - 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(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, MO_define_char); - Self->icons=Icons; - Lcd.icons=Icons; - } - - 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 - - MO_clear(protocol); - MO_contrast(); - - MO_write ("\376B", 3); // backlight on - MO_write ("\376K", 2); // cursor off - MO_write ("\376T", 2); // blink off - MO_write ("\376D", 2); // line wrapping off - MO_write ("\376R", 2); // auto scroll off - - // register as a plugin - 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; -} - - -int MO_init1 (LCD *Self) -{ - return MO_init(Self, 1); -} - -int MO_init2 (LCD *Self) -{ - return MO_init(Self, 2); -} - - -void MO_goto (int row, int col) -{ - char cmd[5]="\376Gyx"; - cmd[2]=(char)col+1; - cmd[3]=(char)row+1; - MO_write(cmd,4); -} - - -int MO_put (int row, int col, char *text) -{ - char *p=FrameBuffer1+row*Lcd.cols+col; - char *t=text; - - while (*t && col++<=Lcd.cols) { - *p++=*t++; - } - return 0; -} - - -int MO_bar (int type, int row, int col, int max, int len1, int len2) -{ - return bar_draw (type, row, col, max, len1, len2); -} - - -int MO_icon (int num, int seq, int row, int col) -{ - return icon_draw (num, seq, row, col); -} - - -int MO_gpo (int num, int val) -{ - if (num>=Lcd.gpos) - return -1; - - GPO[num]=val; - - // Fixme - GPO[num]=255; - - return 0; -} - - -static int MO_flush (int protocol) -{ - int row, col, pos1, pos2; - int c, equal; - int gpo; - - bar_process(MO_define_char); - - for (row=0; row<Lcd.rows; row++) { - for (col=0; col<Lcd.cols; col++) { - c=bar_peek(row, col); - if (c==-1) c=icon_peek(row, col); - if (c!=-1) { - FrameBuffer1[row*Lcd.cols+col]=(char)c; - } - } - for (col=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) continue; - MO_goto (row, col); - for (pos1=col++, pos2=pos1, equal=0; col<Lcd.cols; col++) { - if (FrameBuffer1[row*Lcd.cols+col]==FrameBuffer2[row*Lcd.cols+col]) { - // If we find just one equal byte, we don't break, because this - // would require a goto, which takes one byte, too. - if (++equal>5) break; - } else { - pos2=col; - equal=0; - } - } - MO_write (FrameBuffer1+row*Lcd.cols+pos1, pos2-pos1+1); - } - } - - memcpy (FrameBuffer2, FrameBuffer1, Lcd.rows*Lcd.cols*sizeof(char)); - - switch (protocol) { - case 1: - if (GPO[0]) { - MO_write ("\376W", 2); // GPO on - } else { - MO_write ("\376V", 2); // GPO off - } - break; - case 2: - for (gpo=1; gpo<=Lcd.gpos; gpo++) { - char cmd[3]="\376"; - cmd[1]=GPO[gpo]? 'W':'V'; - cmd[2]=(char)gpo; - MO_write (cmd, 3); - } - break; - } - - return 0; -} - -int MO_flush1 (void) -{ - return MO_flush(1); -} - -int MO_flush2 (void) -{ - return MO_flush(2); -} - - -int MO_quit (void) -{ - info("MatrixOrbital: shutting down."); - - debug ("closing port %s", Port); - close (Device); - unlock_port(Port); - - if (FrameBuffer1) { - free(FrameBuffer1); - FrameBuffer1=NULL; - } - - if (FrameBuffer2) { - free(FrameBuffer2); - FrameBuffer2=NULL; - } - - return (0); -} - - -LCD MatrixOrbital[] = { - { name: "LCD0821", - rows: 2, - cols: 8, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 1, - init: MO_init1, - clear: MO_clear1, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush1, - quit: MO_quit - }, - { name: "LCD1621", - rows: 2, - cols: 16, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 1, - init: MO_init1, - clear: MO_clear1, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush1, - quit: MO_quit - }, - { name: "LCD2021", - rows: 2, - cols: 20, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 1, - init: MO_init1, - clear: MO_clear1, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush1, - quit: MO_quit - }, - { name: "LCD2041", - rows: 4, - cols: 20, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 1, - init: MO_init1, - clear: MO_clear1, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush1, - quit: MO_quit - }, - { name: "LCD4021", - rows: 2, - cols: 40, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 1, - init: MO_init1, - clear: MO_clear1, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush1, - quit: MO_quit - }, - { name: "LK202-25", - rows: 2, - cols: 20, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 6, - init: MO_init2, - clear: MO_clear2, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush2, - quit: MO_quit - }, - { name: "LK204-25", - rows: 4, - cols: 20, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2, - icons: 0, - gpos: 6, - init: MO_init2, - clear: MO_clear2, - put: MO_put, - bar: MO_bar, - icon: MO_icon, - gpo: MO_gpo, - flush: MO_flush2, - quit: MO_quit - }, - { NULL } -}; @@ -1,318 +0,0 @@ -/* $Id: SIN.c,v 1.15 2004/01/29 04:40:02 reinelt Exp $ - * - * driver for SIN router displays - * - * Copyright 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: SIN.c,v $ - * Revision 1.15 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.14 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.13 2003/09/13 06:45:43 reinelt - * icons for all remaining drivers - * - * Revision 1.12 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.11 2003/08/17 12:11:58 reinelt - * framework for icons prepared - * - * Revision 1.10 2003/08/17 08:25:30 reinelt - * preparations for liblcd4linux; minor bugs in SIN.c and Skeleton.c - * - * Revision 1.9 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.8 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.7 2001/04/27 05:04:57 reinelt - * - * replaced OPEN_MAX with sysconf() - * replaced mktemp() with mkstemp() - * unlock serial port if open() fails - * - * Revision 1.6 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.5 2000/12/07 20:47:54 reinelt - * - * first try for SIN bars - * - * Revision 1.4 2000/12/01 20:42:37 reinelt - * - * added debugging of SIN driver output, probably found the positioning bug (format %02x instead of %2x) - * - * Revision 1.3 2000/12/01 07:20:26 reinelt - * - * modified text positioning: row starts with 0, column is hexadecimal - * - * Revision 1.2 2000/11/28 17:27:19 reinelt - * - * changed decimal values for screen, row, column to ascii values (shame on you!) - * - * Revision 1.1 2000/11/28 16:46:11 reinelt - * - * first try to support display of SIN router - * - * - */ - -/* - * - * exported fuctions: - * - * struct LCD SIN[] * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <termios.h> -#include <fcntl.h> - -#include "debug.h" -#include "cfg.h" -#include "lock.h" -#include "display.h" -#include "bar.h" - -// FIXME: 6x8 -#define XRES 1 -#define YRES 1 - - -static LCD Lcd; -static char *Port=NULL; -static int Device=-1; - -static char Txt[8][40]; - -static int SIN_open (void) -{ - int fd; - pid_t pid; - struct termios portset; - - if ((pid=lock_port(Port))!=0) { - if (pid==-1) - error ("SIN: port %s could not be locked", Port); - else - error ("SIN: port %s is locked by process %d", Port, pid); - return -1; - } - fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd==-1) { - error ("SIN: open(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - if (tcgetattr(fd, &portset)==-1) { - error ("SIN: tcgetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - cfmakeraw(&portset); - cfsetospeed(&portset, B9600); - if (tcsetattr(fd, TCSANOW, &portset)==-1) { - error ("SIN: tcsetattr(%s) failed: %s", Port, strerror(errno)); - unlock_port(Port); - return -1; - } - return fd; -} - -static void SIN_debug (char *string, int len) -{ - char buffer[256]; - char *p, *c; - - p=buffer; - c=string; - while (len-->0) { - if (isprint(*c)) { - *p++=*c; - } else { - p+=sprintf(p, "\\%02x", *c); - } - c++; - } - *p='\0'; - debug ("sending '%s'", buffer); -} - -static void SIN_write (char *string, int len) -{ - SIN_debug(string, len); - if (Device==-1) return; - if (write (Device, string, len)==-1) { - if (errno==EAGAIN) { - usleep(1000); - if (write (Device, string, len)>=0) return; - } - error ("SIN: write(%s) failed: %s", Port, strerror(errno)); - } -} - -int SIN_clear (int full) -{ - int row, col; - - for (row=0; row<Lcd.rows; row++) { - for (col=0; col<Lcd.cols; col++) { - Txt[row][col]='\t'; - } - } - - if (full) - SIN_write ("\033 ",2); - - return 0; -} - -int SIN_init (LCD *Self) -{ - char *port; - - Lcd=*Self; - - if (Port) { - free (Port); - Port=NULL; - } - - port=cfg_get ("Port",NULL); - if (port==NULL || *port=='\0') { - error ("SIN: no 'Port' entry in %s", cfg_source()); - return -1; - } - Port=strdup(port); - - debug ("using port %s at 9600 baud", Port); - - Device=SIN_open(); - if (Device==-1) return -1; - - SIN_write ("\015", 1); // send 'Enter' - // Fixme: should we read the identifier here.... - SIN_write ("\033S0", 3); // select screen #0 - sleep (1); // FIXME: handshaking - SIN_clear(1); - - return 0; -} - -int SIN_put (int row, int col, char *text) -{ - char *p=&Txt[row][col]; - char *t=text; - - while (*t && col++<=Lcd.cols) { - *p++=*t++; - } - return 0; -} - -int SIN_bar (int type, int row, int col, int max, int len, int dummy) -{ - int rev=0; - - if (len<1) len=1; - else if (len>max) len=max; - - switch (type) { - case BAR_L: - len=max-len; - rev=1; - - case BAR_R: - while (max>0 && col<=Lcd.cols) { - if (len>=XRES) { - Txt[row][col]=rev?0x19:0x18; - len-=XRES; - } else { - Txt[row][col]=rev?0x18:0x19; - len=0; - } - max-=XRES; - col++; - } - break; - } - return 0; -} - -int SIN_flush (void) -{ - char buffer[256]="\015\033T"; // place text - char *p; - int row, col; - - for (row=0; row<Lcd.rows; row++) { - buffer[3]='0'+row; - for (col=0; col<Lcd.cols; col++) { - if (Txt[row][col]=='\t') continue; - sprintf (buffer+4, "%02x", col); - for (p=buffer+6; col<Lcd.cols; col++, p++) { - if (Txt[row][col]=='\t') break; - *p=Txt[row][col]; - } - SIN_write (buffer, p-buffer); - } - } - return 0; -} - -int SIN_quit (void) -{ - debug ("closing port %s", Port); - close (Device); - unlock_port(Port); - return (0); -} - -LCD SIN[] = { - { name: "SIN", - rows: 8, - cols: 40, - xres: XRES, - yres: YRES, - bars: BAR_L | BAR_R, - icons: 0, - gpos: 0, - init: SIN_init, - clear: SIN_clear, - put: SIN_put, - bar: SIN_bar, - icon: NULL, - gpo: NULL, - flush: SIN_flush, - quit: SIN_quit }, - { NULL } -}; diff --git a/Skeleton.c b/Skeleton.c deleted file mode 100644 index 0c7b7f7..0000000 --- a/Skeleton.c +++ /dev/null @@ -1,163 +0,0 @@ -/* $Id: Skeleton.c,v 1.13 2004/01/29 04:40:02 reinelt Exp $ - * - * skeleton driver for new display modules - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: Skeleton.c,v $ - * Revision 1.13 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.12 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.11 2003/09/13 06:45:43 reinelt - * icons for all remaining drivers - * - * Revision 1.10 2003/08/17 12:11:58 reinelt - * framework for icons prepared - * - * Revision 1.9 2003/08/17 08:25:30 reinelt - * preparations for liblcd4linux; minor bugs in SIN.c and Skeleton.c - * - * Revision 1.8 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.7 2001/03/09 13:08:11 ltoetsch - * Added Text driver - * - * Revision 1.6 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.5 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.4 2000/03/26 18:46:28 reinelt - * - * bug in pixmap.c that leaded to empty bars fixed - * name conflicts with X11 resolved - * - * Revision 1.3 2000/03/25 05:50:43 reinelt - * - * memory leak in Raster_flush closed - * driver family logic changed - * - * Revision 1.2 2000/03/22 07:33:50 reinelt - * - * FAQ added - * new modules 'processor.c' contains all data processing - * - * Revision 1.1 2000/03/19 08:41:28 reinelt - * - * documentation available! README, README.MatrixOrbital, README.Drivers - * added Skeleton.c as a starting point for new drivers - * - */ - -/* - * - * exported fuctions: - * - * struct LCD Skeleton[] - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> - -#include "debug.h" -#include "cfg.h" -#include "display.h" -#include "bar.h" - -static LCD Lcd; - -int Skel_clear (int full) -{ - return 0; -} - -int Skel_init (LCD *Self) -{ - Lcd=*Self; - - error ("Skeleton: This driver does not drive anything!"); - return -1; - - Skel_clear(1); - return 0; -} - -int Skel_put (int row, int col, char *text) -{ - return 0; -} - -int Skel_bar (int type, int row, int col, int max, int len1, int len2) -{ - return 0; -} - -int Skel_icon (int num, int seq, int row, int col) -{ - return 0; -} - -int Skel_gpo (int num, int val) -{ - return 0; -} - -int Skel_flush (void) -{ - return 0; -} - -int Skel_quit (void) -{ - info("Skeleton: we shut down now."); - return 0; -} - - -LCD Skeleton[] = { - { name: "Skeleton", - rows: 4, - cols: 20, - xres: 5, - yres: 8, - bars: BAR_L|BAR_R, - icons: 0, - gpos: 0, - init: Skel_init, - clear: Skel_clear, - put: Skel_put, - bar: Skel_bar, - icon: Skel_icon, - gpo: Skel_gpo, - flush: Skel_flush, - quit: Skel_quit }, - { NULL } -}; @@ -1,460 +0,0 @@ -/* $Id: bar.c,v 1.11 2004/01/30 20:57:55 reinelt Exp $ - * - * generic bar handling - * - * Copyright 2002 Michael Reinelt <reinelt@eunet.at> - * - * 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: bar.c,v $ - * Revision 1.11 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.10 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.9 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.8 2003/09/09 05:30:34 reinelt - * even more icons stuff - * - * Revision 1.7 2003/09/01 04:09:34 reinelt - * icons nearly finished, but MatrixOrbital only - * - * Revision 1.6 2003/08/20 05:26:43 reinelt - * small bug in bar compaction fixed - * - * Revision 1.5 2003/08/19 04:28:41 reinelt - * more Icon stuff, minor glitches fixed - * - * Revision 1.4 2003/01/12 06:51:27 reinelt - * fixed bug in bar compaction - * - * Revision 1.3 2002/08/19 07:52:19 reinelt - * corrected type declaration of (*defchar)() - * - * Revision 1.2 2002/08/19 07:36:29 reinelt - * - * finished bar.c, USBLCD is the first driver that uses the generic bar functions - * - * Revision 1.1 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * - */ - -/* - * exported functions: - * - * int bar_init (int rows, int cols, int xres, int yres, int chars) - * - * void bar_clear(void) - * - * void bar_add_segment(int len1, int len2, int type, int ascii) - * - * int bar_draw (int type, int row, int col, int max, int len1, int len2) - * - * int bar_process (void(*defchar)(int ascii, char *matrix)) - * - * int bar_peek (int row, int col) - * - */ - -#include "config.h" - -#include <stdlib.h> - -#include "bar.h" -#include "debug.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - - -static int ROWS=0; -static int COLS=0; -static int XRES=0; -static int YRES=0; -static int CHARS=0; - -static int nSegment=0; -static int fSegment=0; -static SEGMENT Segment[128]; - -static BAR *Bar=NULL; - - -int bar_init (int rows, int cols, int xres, int yres, int chars) -{ - if (rows<1 || cols<1) - return -1; - - ROWS=rows; - COLS=cols; - XRES=xres; - YRES=yres; - CHARS=chars; - - if (Bar) { - free (Bar); - } - - if ((Bar=malloc (ROWS*COLS*sizeof(BAR)))==NULL) { - error ("bar buffer allocation failed: out of memory"); - return -1; - } - - bar_clear(); - - nSegment=0; - fSegment=0; - - return 0; -} - - -void bar_clear(void) -{ - int n; - - for (n=0; n<ROWS*COLS; n++) { - Bar[n].len1=-1; - Bar[n].len2=-1; - Bar[n].type=0; - Bar[n].segment=-1; - } - -} - - -void bar_add_segment(int len1, int len2, int type, int ascii) -{ - Segment[fSegment].len1=len1; - Segment[fSegment].len2=len2; - Segment[fSegment].type=type; - Segment[fSegment].used=0; - Segment[fSegment].ascii=ascii; - - fSegment++; - nSegment=fSegment; -} - - -int bar_draw (int type, int row, int col, int max, int len1, int len2) -{ - int rev=0; - - if (len1<1) len1=1; - else if (len1>max) len1=max; - - if (len2<1) len2=1; - else if (len2>max) len2=max; - - switch (type) { - case BAR_L: - len1=max-len1; - len2=max-len2; - rev=1; - - case BAR_R: - while (max>0 && col<COLS) { - Bar[row*COLS+col].type=type; - Bar[row*COLS+col].segment=-1; - if (len1>=XRES) { - Bar[row*COLS+col].len1=rev?0:XRES; - len1-=XRES; - } else { - Bar[row*COLS+col].len1=rev?XRES-len1:len1; - len1=0; - } - if (len2>=XRES) { - Bar[row*COLS+col].len2=rev?0:XRES; - len2-=XRES; - } else { - Bar[row*COLS+col].len2=rev?XRES-len2:len2; - len2=0; - } - max-=XRES; - col++; - } - break; - - case BAR_U: - len1=max-len1; - len2=max-len2; - rev=1; - - case BAR_D: - while (max>0 && row<ROWS) { - Bar[row*COLS+col].type=type; - Bar[row*COLS+col].segment=-1; - if (len1>=YRES) { - Bar[row*COLS+col].len1=rev?0:YRES; - len1-=YRES; - } else { - Bar[row*COLS+col].len1=rev?YRES-len1:len1; - len1=0; - } - if (len2>=YRES) { - Bar[row*COLS+col].len2=rev?0:YRES; - len2-=YRES; - } else { - Bar[row*COLS+col].len2=rev?YRES-len2:len2; - len2=0; - } - max-=YRES; - row++; - } - break; - - } - return 0; -} - - -static void create_segments (void) -{ - int RES; - int i, j, n; - int l1, l2; - - /* find first unused segment */ - for (i=fSegment; i<nSegment && Segment[i].used; i++); - - /* pack unused segments */ - for (j=i+1; j<nSegment; j++) { - if (Segment[j].used) - Segment[i++]=Segment[j]; - } - nSegment=i; - - /* create needed segments */ - for (n=0; n<ROWS*COLS; n++) { - if (Bar[n].type==0) continue; - RES=Bar[n].type & BAR_H ? XRES:YRES; - for (i=0; i<nSegment; i++) { - if (Segment[i].type & Bar[n].type) { - l1=Segment[i].len1; if (l1>RES) 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++; - Segment[i].len1=Bar[n].len1; - Segment[i].len2=Bar[n].len2; - Segment[i].type=Bar[n].type; - Segment[i].used=0; - Segment[i].ascii=-1; - } - Bar[n].segment=i; - } -} - - -static int segment_deviation (int i, int j) -{ - int RES; - int i1, i2, j1, j2; - - if (i==j) return 65535; - if (!(Segment[i].type & Segment[j].type)) return 65535; - - RES=Segment[i].type & BAR_H ? XRES:YRES; - - i1=Segment[i].len1; if (i1>RES) i1=RES; - i2=Segment[i].len2; if (i2>RES) i2=RES; - j1=Segment[j].len1; if (j1>RES) j1=RES; - j2=Segment[j].len2; if (j2>RES) j2=RES; - - if (i1==0 && j1!=0) return 65535; - if (i2==0 && j2!=0) return 65535; - if (i1==RES && j1<RES) return 65535; - if (i2==RES && j2<RES) return 65535; - if (i1==1 && j1!=1 && i2 > 0) return 65535; - if (i2==1 && j2!=1 && j1 > 0) return 65535; - if (i1==i2 && j1!=j2) return 65535; - - return (i1-j1)*(i1-j1)+(i2-j2)*(i2-j2); -} - - -static void pack_segments (void) -{ - int i, j, n, min; - int pack_i, pack_j; - int pass1=1; - int deviation[nSegment][nSegment]; - - if (nSegment<=fSegment+CHARS) { - return; - } - - for (i=0; i<nSegment; i++) { - for (j=0; j<nSegment; j++) { - deviation[i][j]=segment_deviation(i,j); - } - } - - while (nSegment>fSegment+CHARS) { - min=65535; - pack_i=-1; - pack_j=-1; - for (i=fSegment; i<nSegment; i++) { - if (pass1 && Segment[i].used) continue; - for (j=0; j<nSegment; j++) { - if (deviation[i][j]<min) { - min=deviation[i][j]; - pack_i=i; - pack_j=j; - } - } - } - if (pack_i==-1) { - if (pass1) { - pass1=0; - continue; - } else { - error ("unable to compact bar characters"); - nSegment=CHARS; - break; - } - } - -#if 0 - debug ("pack_segment: n=%d i=%d j=%d min=%d", nSegment, pack_i, pack_j, min); - debug ("Pack_segment: i1=%d i2=%d j1=%d j2=%d\n", - Segment[pack_i].len1, Segment[pack_i].len2, - Segment[pack_j].len1, Segment[pack_j].len2); -#endif - - nSegment--; - Segment[pack_i]=Segment[nSegment]; - - for (i=0; i<nSegment; i++) { - deviation[pack_i][i]=deviation[nSegment][i]; - deviation[i][pack_i]=deviation[i][nSegment]; - } - - for (n=0; n<ROWS*COLS; n++) { - if (Bar[n].segment==pack_i) Bar[n].segment=pack_j; - if (Bar[n].segment==nSegment) Bar[n].segment=pack_i; - } - } -} - - -static void define_chars (void(*defchar)(int ascii, char *matrix)) -{ - int c, i, j; - char buffer[8]; - - for (i=fSegment; i<nSegment; i++) { - if (Segment[i].used) continue; - if (Segment[i].ascii!=-1) continue; - for (c=0; c<CHARS; c++) { - for (j=fSegment; j<nSegment; j++) { - if (Segment[j].ascii==c) break; - } - if (j==nSegment) break; - } - Segment[i].ascii=c; - switch (Segment[i].type) { - case BAR_L: - for (j=0; j<4; j++) { -#if 0 - char Pixel[] = { 0, 1, 3, 7, 15, 31 }; - buffer[j ]=Pixel[Segment[i].len1]; - buffer[j+4]=Pixel[Segment[i].len2]; -#else - buffer[j ]=(1<<Segment[i].len1)-1; - buffer[j+4]=(1<<Segment[i].len2)-1; -#endif - } - break; - case BAR_R: - for (j=0; j<4; j++) { -#if 0 - char Pixel[] = { 0, 16, 24, 28, 30, 31 }; - buffer[j ]=Pixel[Segment[i].len1]; - buffer[j+4]=Pixel[Segment[i].len2]; -#else - buffer[j ]=255<<(XRES-Segment[i].len1); - buffer[j+4]=255<<(XRES-Segment[i].len2); -#endif - } - break; - case BAR_U: - for (j=0; j<Segment[i].len1; j++) { - buffer[7-j]=(1<<XRES)-1; - } - for (; j<YRES; j++) { - buffer[7-j]=0; - } - break; - case BAR_D: - for (j=0; j<Segment[i].len1; j++) { - buffer[j]=(1<<XRES)-1; - } - for (; j<YRES; j++) { - buffer[j]=0; - } - break; - } - defchar(c, buffer); - } -} - - -int bar_process (void(*defchar)(int ascii, char *matrix)) -{ - int n, s; - - create_segments(); - pack_segments(); - define_chars(defchar); - - for (s=0; s<nSegment; s++) { - Segment[s].used=0; - } - - for (n=0; n<ROWS*COLS; n++) { - s=Bar[n].segment; - if (s!=-1) { - Segment[s].used=1; - } - } - - return 0; -} - - -int bar_peek (int row, int col) -{ - int s; - - s=Bar[row*COLS+col].segment; - if (s==-1) { - return -1; - } else { - return Segment[s].ascii; - } -} @@ -1,81 +0,0 @@ -/* $Id: bar.h,v 1.4 2003/10/05 17:58:50 reinelt Exp $ - * - * generic bar handling - * - * Copyright 2002 Michael Reinelt <reinelt@eunet.at> - * - * 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: bar.h,v $ - * Revision 1.4 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.3 2002/08/19 07:52:19 reinelt - * corrected type declaration of (*defchar)() - * - * Revision 1.2 2002/08/19 07:36:29 reinelt - * - * finished bar.c, USBLCD is the first driver that uses the generic bar functions - * - * Revision 1.1 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * - */ - -#ifndef _BAR_H_ -#define _BAR_H_ - -#define BAR_L (1<<0) -#define BAR_R (1<<1) -#define BAR_U (1<<2) -#define BAR_D (1<<3) -#define BAR_H2 (1<<4) -#define BAR_V2 (1<<5) -#define BAR_LOG (1<<6) -#define BAR_T (1<<7) - -#define BAR_H (BAR_L | BAR_R) -#define BAR_V (BAR_U | BAR_D | BAR_T) -#define BAR_HV (BAR_H | BAR_V) - - -typedef struct { - int len1; - int len2; - int type; - int segment; -} BAR; - -typedef struct { - int len1; - int len2; - int type; - int used; - int ascii; -} SEGMENT; - - -int bar_init (int rows, int cols, int xres, int yres, int chars); -void bar_clear(void); -void bar_add_segment(int len1, int len2, int type, int ascii); -int bar_draw (int type, int row, int col, int max, int len1, int len2); -int bar_process (void(*defchar)(int ascii, char *matrix)); -int bar_peek (int row, int col); - -#endif diff --git a/config.h.in b/config.h.in index bb8b87f..9d23e63 100644 --- a/config.h.in +++ b/config.h.in @@ -272,55 +272,49 @@ /* Version number of package */ #undef VERSION -/* junk */ +/* Beckmann&Egle driver */ #undef WITH_BECKMANNEGLE -/* junk */ +/* Crystalfontz driver */ #undef WITH_CRYSTALFONTZ -/* junk */ +/* CwLinux driver */ #undef WITH_CWLINUX /* Define if using the dmalloc debugging malloc package */ #undef WITH_DMALLOC -/* junk */ +/* HD44780 driver */ #undef WITH_HD44780 -/* junk */ +/* M50530 driver */ #undef WITH_M50530 -/* junk */ +/* MatrixOrbital driver */ #undef WITH_MATRIXORBITAL -/* junk */ +/* Milford Instruments driver */ #undef WITH_MILINST -/* junk */ +/* PalmPilot driver */ #undef WITH_PALMPILOT -/* junk */ +/* driver */ #undef WITH_PNG -/* junk */ +/* driver */ #undef WITH_PPM -/* junk */ -#undef WITH_SIN - -/* junk */ -#undef WITH_SKELETON - -/* junk */ +/* T6963 driver */ #undef WITH_T6963 -/* junk */ +/* Curses driver */ #undef WITH_TEXT -/* junk */ +/* USBLCD driver */ #undef WITH_USBLCD -/* junk */ +/* X11 driver */ #undef WITH_X11 /* Define to 1 if the X Window System is missing or not being used. */ @@ -20960,12 +20960,14 @@ done echo "$as_me:$LINENO: result: done" >&5 echo "${ECHO_T}done" >&6 -RASTER="no" PARPORT="no" +SERIAL="no" +TEXT="no" +RASTER="no" if test "$BECKMANNEGLE" = "yes"; then # DRIVERS="$DRIVERS BeckmannEgle.lo" - DRIVERS="$DRIVERS BeckmannEgle.o" +# DRIVERS="$DRIVERS BeckmannEgle.o" cat >>confdefs.h <<\_ACEOF #define WITH_BECKMANNEGLE 1 @@ -20974,8 +20976,10 @@ _ACEOF fi if test "$CRYSTALFONTZ" = "yes"; then -# DRIVERS="$DRIVERS Crystalfontz.lo drv_Crystalfontz.lo" - DRIVERS="$DRIVERS Crystalfontz.o drv_Crystalfontz.o" + TEXT="yes" + SERIAL="yes" +# DRIVERS="$DRIVERS drv_Crystalfontz.lo" + DRIVERS="$DRIVERS drv_Crystalfontz.o" cat >>confdefs.h <<\_ACEOF #define WITH_CRYSTALFONTZ 1 @@ -20984,8 +20988,10 @@ _ACEOF fi if test "$CWLINUX" = "yes"; then -# DRIVERS="$DRIVERS Cwlinux.lo drv_Cwlinux.lo" - DRIVERS="$DRIVERS Cwlinux.o drv_Cwlinux.o" + TEXT="yes" + SERIAL="yes" +# DRIVERS="$DRIVERS drv_Cwlinux.lo" + DRIVERS="$DRIVERS drv_Cwlinux.o" cat >>confdefs.h <<\_ACEOF #define WITH_CWLINUX 1 @@ -20994,9 +21000,10 @@ _ACEOF fi if test "$HD44780" = "yes"; then + TEXT="yes" PARPORT="yes" -# DRIVERS="$DRIVERS HD44780.lo drv_HD44780.lo" - DRIVERS="$DRIVERS HD44780.o drv_HD44780.o" +# DRIVERS="$DRIVERS drv_HD44780.lo" + DRIVERS="$DRIVERS drv_HD44780.o" cat >>confdefs.h <<\_ACEOF #define WITH_HD44780 1 @@ -21007,7 +21014,7 @@ fi if test "$M50530" = "yes"; then PARPORT="yes" # DRIVERS="$DRIVERS M50530.lo" - DRIVERS="$DRIVERS M50530.o" +# DRIVERS="$DRIVERS M50530.o" cat >>confdefs.h <<\_ACEOF #define WITH_M50530 1 @@ -21018,7 +21025,7 @@ fi if test "$T6963" = "yes"; then PARPORT="yes" # DRIVERS="$DRIVERS T6963.lo" - DRIVERS="$DRIVERS T6963.o" +# DRIVERS="$DRIVERS T6963.o" cat >>confdefs.h <<\_ACEOF #define WITH_T6963 1 @@ -21028,7 +21035,7 @@ fi if test "$USBLCD" = "yes"; then # DRIVERS="$DRIVERS USBLCD.lo" - DRIVERS="$DRIVERS USBLCD.o" +# DRIVERS="$DRIVERS USBLCD.o" cat >>confdefs.h <<\_ACEOF #define WITH_USBLCD 1 @@ -21037,8 +21044,9 @@ _ACEOF fi if test "$MATRIXORBITAL" = "yes"; then -# DRIVERS="$DRIVERS MatrixOrbital.lo drv_MatrixOrbital.lo" - DRIVERS="$DRIVERS MatrixOrbital.o drv_MatrixOrbital.o" + SERIAL="yes" +# DRIVERS="$DRIVERS drv_MatrixOrbital.lo" + DRIVERS="$DRIVERS drv_MatrixOrbital.o" cat >>confdefs.h <<\_ACEOF #define WITH_MATRIXORBITAL 1 @@ -21048,7 +21056,7 @@ fi if test "$MILINST" = "yes"; then # DRIVERS="$DRIVERS MilfordInstruments.lo" - DRIVERS="$DRIVERS MilfordInstruments.o" +# DRIVERS="$DRIVERS MilfordInstruments.o" cat >>confdefs.h <<\_ACEOF #define WITH_MILINST 1 @@ -21058,7 +21066,7 @@ fi if test "$PALMPILOT" = "yes"; then # DRIVERS="$DRIVERS PalmPilot.lo" - DRIVERS="$DRIVERS PalmPilot.o" +# DRIVERS="$DRIVERS PalmPilot.o" cat >>confdefs.h <<\_ACEOF #define WITH_PALMPILOT 1 @@ -21095,30 +21103,10 @@ echo "$as_me: WARNING: gd.h not found: PNG driver disabled" >&2;} fi fi -if test "$SIN" = "yes"; then -# DRIVERS="$DRIVERS SIN.lo" - DRIVERS="$DRIVERS SIN.o" - -cat >>confdefs.h <<\_ACEOF -#define WITH_SIN 1 -_ACEOF - -fi - -if test "$SKELETON" = "yes"; then -# DRIVERS="$DRIVERS Skeleton.lo" - DRIVERS="$DRIVERS Skeleton.o" - -cat >>confdefs.h <<\_ACEOF -#define WITH_SKELETON 1 -_ACEOF - -fi - if test "$TEXT" = "yes"; then if test "$has_curses" = true; then # DRIVERS="$DRIVERS Text.lo" - DRIVERS="$DRIVERS Text.o" +# DRIVERS="$DRIVERS Text.o" DRVLIBS="$DRVLIBS $CURSES_LIBS" CPPFLAGS="$CPPFLAGS $CURSES_INCLUDES" @@ -21139,7 +21127,7 @@ echo "$as_me: error: X11 headers or libraries not available: X11 driver disabled { (exit 1); exit 1; }; } else # DRIVERS="$DRIVERS XWindow.lo" - DRIVERS="$DRIVERS XWindow.o" +# DRIVERS="$DRIVERS XWindow.o" DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11" cat >>confdefs.h <<\_ACEOF @@ -21155,16 +21143,29 @@ echo "$as_me: error: You should include at least one driver..." >&2;} { (exit 1); exit 1; }; } fi +# generic text driver +if test "$TEXT" = "yes"; then +# DRIVERS="$DRIVERS drv_generic_text.lo" + DRIVERS="$DRIVERS drv_generic_text.o" +fi + # Raster.lo depends on PPM or PNG if test "$RASTER" = "yes"; then +: # DRIVERS="$DRIVERS Raster.lo" - DRIVERS="$DRIVERS Raster.o" +# DRIVERS="$DRIVERS Raster.o" fi -# parport driver +# generic parport driver if test "$PARPORT" = "yes"; then -# DRIVERS="$DRIVERS parport.lo" - DRIVERS="$DRIVERS parport.o" +# DRIVERS="$DRIVERS drv_generic_parport.lo" + DRIVERS="$DRIVERS drv_generic_parport.o" +fi + +# generic serial driver +if test "$SERIAL" = "yes"; then +# DRIVERS="$DRIVERS drv_generic_serial.lo" + DRIVERS="$DRIVERS drv_generic_serial.o" fi diff --git a/configure.in b/configure.in index 821f245..da2ae23 100644 --- a/configure.in +++ b/configure.in @@ -139,76 +139,84 @@ done AC_MSG_RESULT([done]) -RASTER="no" PARPORT="no" +SERIAL="no" +TEXT="no" +RASTER="no" if test "$BECKMANNEGLE" = "yes"; then # DRIVERS="$DRIVERS BeckmannEgle.lo" - DRIVERS="$DRIVERS BeckmannEgle.o" - AC_DEFINE(WITH_BECKMANNEGLE,1,[junk]) +# DRIVERS="$DRIVERS BeckmannEgle.o" + AC_DEFINE(WITH_BECKMANNEGLE,1,[Beckmann&Egle driver]) fi if test "$CRYSTALFONTZ" = "yes"; then -# DRIVERS="$DRIVERS Crystalfontz.lo drv_Crystalfontz.lo" - DRIVERS="$DRIVERS Crystalfontz.o drv_Crystalfontz.o" - AC_DEFINE(WITH_CRYSTALFONTZ,1,[junk]) + TEXT="yes" + SERIAL="yes" +# DRIVERS="$DRIVERS drv_Crystalfontz.lo" + DRIVERS="$DRIVERS drv_Crystalfontz.o" + AC_DEFINE(WITH_CRYSTALFONTZ,1,[Crystalfontz driver]) fi if test "$CWLINUX" = "yes"; then -# DRIVERS="$DRIVERS Cwlinux.lo drv_Cwlinux.lo" - DRIVERS="$DRIVERS Cwlinux.o drv_Cwlinux.o" - AC_DEFINE(WITH_CWLINUX,1,[junk]) + TEXT="yes" + SERIAL="yes" +# DRIVERS="$DRIVERS drv_Cwlinux.lo" + DRIVERS="$DRIVERS drv_Cwlinux.o" + AC_DEFINE(WITH_CWLINUX,1,[CwLinux driver]) fi if test "$HD44780" = "yes"; then + TEXT="yes" PARPORT="yes" -# DRIVERS="$DRIVERS HD44780.lo drv_HD44780.lo" - DRIVERS="$DRIVERS HD44780.o drv_HD44780.o" - AC_DEFINE(WITH_HD44780,1,[junk]) +# DRIVERS="$DRIVERS drv_HD44780.lo" + DRIVERS="$DRIVERS drv_HD44780.o" + AC_DEFINE(WITH_HD44780,1,[HD44780 driver]) fi if test "$M50530" = "yes"; then PARPORT="yes" # DRIVERS="$DRIVERS M50530.lo" - DRIVERS="$DRIVERS M50530.o" - AC_DEFINE(WITH_M50530,1,[junk]) +# DRIVERS="$DRIVERS M50530.o" + AC_DEFINE(WITH_M50530,1,[M50530 driver]) fi if test "$T6963" = "yes"; then PARPORT="yes" # DRIVERS="$DRIVERS T6963.lo" - DRIVERS="$DRIVERS T6963.o" - AC_DEFINE(WITH_T6963,1,[junk]) +# DRIVERS="$DRIVERS T6963.o" + AC_DEFINE(WITH_T6963,1,[T6963 driver]) fi if test "$USBLCD" = "yes"; then # DRIVERS="$DRIVERS USBLCD.lo" - DRIVERS="$DRIVERS USBLCD.o" - AC_DEFINE(WITH_USBLCD,1,[junk]) +# DRIVERS="$DRIVERS USBLCD.o" + AC_DEFINE(WITH_USBLCD,1,[USBLCD driver]) fi if test "$MATRIXORBITAL" = "yes"; then -# DRIVERS="$DRIVERS MatrixOrbital.lo drv_MatrixOrbital.lo" - DRIVERS="$DRIVERS MatrixOrbital.o drv_MatrixOrbital.o" - AC_DEFINE(WITH_MATRIXORBITAL,1,[junk]) + SERIAL="yes" +# DRIVERS="$DRIVERS drv_MatrixOrbital.lo" + DRIVERS="$DRIVERS drv_MatrixOrbital.o" + AC_DEFINE(WITH_MATRIXORBITAL,1,[MatrixOrbital driver]) fi if test "$MILINST" = "yes"; then # DRIVERS="$DRIVERS MilfordInstruments.lo" - DRIVERS="$DRIVERS MilfordInstruments.o" - AC_DEFINE(WITH_MILINST,1,[junk]) +# DRIVERS="$DRIVERS MilfordInstruments.o" + AC_DEFINE(WITH_MILINST,1,[Milford Instruments driver]) fi if test "$PALMPILOT" = "yes"; then # DRIVERS="$DRIVERS PalmPilot.lo" - DRIVERS="$DRIVERS PalmPilot.o" - AC_DEFINE(WITH_PALMPILOT,1,[junk]) +# DRIVERS="$DRIVERS PalmPilot.o" + AC_DEFINE(WITH_PALMPILOT,1,[PalmPilot driver]) fi if test "$PNG" = "yes"; then if test "$has_gd" = "true"; then RASTER="yes" - AC_DEFINE(WITH_PNG,1,[junk]) + AC_DEFINE(WITH_PNG,1,[ driver]) DRVLIBS="$DRVLIBS -lgd" else AC_MSG_WARN(gd.h not found: PNG driver disabled) @@ -218,31 +226,19 @@ fi if test "$PPM" = "yes"; then if test "$has_gd" = "true"; then RASTER="yes" - AC_DEFINE(WITH_PPM,1,[junk]) + AC_DEFINE(WITH_PPM,1,[ driver]) else AC_MSG_WARN(gd.h not found: PNG driver disabled) fi fi -if test "$SIN" = "yes"; then -# DRIVERS="$DRIVERS SIN.lo" - DRIVERS="$DRIVERS SIN.o" - AC_DEFINE(WITH_SIN,1,[junk]) -fi - -if test "$SKELETON" = "yes"; then -# DRIVERS="$DRIVERS Skeleton.lo" - DRIVERS="$DRIVERS Skeleton.o" - AC_DEFINE(WITH_SKELETON,1,[junk]) -fi - if test "$TEXT" = "yes"; then if test "$has_curses" = true; then # DRIVERS="$DRIVERS Text.lo" - DRIVERS="$DRIVERS Text.o" +# DRIVERS="$DRIVERS Text.o" DRVLIBS="$DRVLIBS $CURSES_LIBS" CPPFLAGS="$CPPFLAGS $CURSES_INCLUDES" - AC_DEFINE(WITH_TEXT,1,[junk]) + AC_DEFINE(WITH_TEXT,1,[Curses driver]) else AC_MSG_WARN(curses not found: Text driver disabled) fi @@ -253,9 +249,9 @@ if test "$X11" = "yes"; then AC_MSG_ERROR(X11 headers or libraries not available: X11 driver disabled) else # DRIVERS="$DRIVERS XWindow.lo" - DRIVERS="$DRIVERS XWindow.o" +# DRIVERS="$DRIVERS XWindow.o" DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11" - AC_DEFINE(WITH_X11,1,[junk]) + AC_DEFINE(WITH_X11,1,[X11 driver]) fi fi @@ -263,16 +259,29 @@ if test "$DRIVERS" = ""; then AC_MSG_ERROR([You should include at least one driver...]) fi +# generic text driver +if test "$TEXT" = "yes"; then +# DRIVERS="$DRIVERS drv_generic_text.lo" + DRIVERS="$DRIVERS drv_generic_text.o" +fi + # Raster.lo depends on PPM or PNG if test "$RASTER" = "yes"; then +: # DRIVERS="$DRIVERS Raster.lo" - DRIVERS="$DRIVERS Raster.o" +# DRIVERS="$DRIVERS Raster.o" fi -# parport driver +# generic parport driver if test "$PARPORT" = "yes"; then -# DRIVERS="$DRIVERS parport.lo" - DRIVERS="$DRIVERS parport.o" +# DRIVERS="$DRIVERS drv_generic_parport.lo" + DRIVERS="$DRIVERS drv_generic_parport.o" +fi + +# generic serial driver +if test "$SERIAL" = "yes"; then +# DRIVERS="$DRIVERS drv_generic_serial.lo" + DRIVERS="$DRIVERS drv_generic_serial.o" fi AC_SUBST(DRIVERS) @@ -1,4 +1,4 @@ -/* $Id: debug.c,v 1.6 2003/10/05 17:58:50 reinelt Exp $ +/* $Id: debug.c,v 1.7 2004/02/10 07:42:35 reinelt Exp $ * * debug() and error() functions * @@ -22,6 +22,9 @@ * * * $Log: debug.c,v $ + * Revision 1.7 2004/02/10 07:42:35 reinelt + * cut off all old-style files which are no longer used with NextGeneration + * * Revision 1.6 2003/10/05 17:58:50 reinelt * libtool junk; copyright messages cleaned up * @@ -84,9 +87,12 @@ void message (int level, const char *format, ...) va_end(ap); if (!running_background) { + // Fixme +#if 0 #ifdef WITH_TEXT extern int curs_err(char *); if (!curs_err(buffer)) +#endif #endif fprintf (level?stdout:stderr, "%s\n", buffer); } diff --git a/display.c b/display.c deleted file mode 100644 index 1ba0941..0000000 --- a/display.c +++ /dev/null @@ -1,426 +0,0 @@ -/* $Id: display.c,v 1.45 2004/01/09 17:03:07 reinelt Exp $ - * - * framework for device drivers - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: display.c,v $ - * Revision 1.45 2004/01/09 17:03:07 reinelt - * initiated transfer to new driver architecture - * new file 'drv.c' will someday replace 'display.c' - * new file 'drv_MatrixOrbital.c' will replace 'MatrixOrbital.c' - * due to this 'soft' transfer lcd4linux should stay usable during the switch - * (at least I hope so) - * - * Revision 1.44 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.43 2003/09/29 06:58:37 reinelt - * new driver for Milford Instruments MI420 by Andy Baxter - * - * Revision 1.42 2003/09/10 03:48:23 reinelt - * Icons for M50530, new processing scheme (Ticks.Text...) - * - * 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 - * - * Revision 1.39 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.38 2003/08/24 04:31:56 reinelt - * icon.c icon.h added - * - * Revision 1.37 2003/08/17 16:37:39 reinelt - * more icon framework - * - * Revision 1.36 2003/08/17 12:11:58 reinelt - * framework for icons prepared - * - * Revision 1.35 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.34 2002/12/05 19:09:57 reinelt - * patches for gcc-3.2 - * - * Revision 1.33 2002/09/11 05:16:33 reinelt - * added Cwlinux driver - * - * Revision 1.32 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.31 2002/08/17 13:10:23 reinelt - * USBLCD driver added - * - * Revision 1.30 2002/04/29 11:00:28 reinelt - * - * added Toshiba T6963 driver - * added ndelay() with nanosecond resolution - * - * Revision 1.29 2001/09/10 13:55:53 reinelt - * M50530 driver - * - * Revision 1.28 2001/03/16 16:40:17 ltoetsch - * implemented time bar - * - * Revision 1.27 2001/03/15 14:25:05 ltoetsch - * added unread/total news - * - * Revision 1.26 2001/03/12 12:39:36 reinelt - * - * reworked autoconf a lot: drivers may be excluded, #define's went to config.h - * - * Revision 1.25 2001/03/09 13:08:11 ltoetsch - * Added Text driver - * - * Revision 1.24 2001/03/01 11:08:16 reinelt - * - * reworked configure to allow selection of drivers - * - * Revision 1.23 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.22 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.21 2000/11/28 16:46:11 reinelt - * - * first try to support display of SIN router - * - * Revision 1.20 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.19 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.18 2000/05/02 23:07:48 herp - * Crystalfontz initial coding - * - * Revision 1.17 2000/05/02 06:05:00 reinelt - * - * driver for 3Com Palm Pilot added - * - * Revision 1.16 2000/04/28 05:19:55 reinelt - * - * first release of the Beckmann+Egle driver - * - * Revision 1.15 2000/04/12 08:05:45 reinelt - * - * first version of the HD44780 driver - * - * Revision 1.14 2000/04/03 17:31:52 reinelt - * - * suppress welcome message if display is smaller than 20x2 - * change lcd4linux.ppm to 32 pixel high so KDE won't stretch the icon - * - * Revision 1.13 2000/03/30 16:46:57 reinelt - * - * configure now handles '--with-x' and '--without-x' correct - * - * Revision 1.12 2000/03/26 18:46:28 reinelt - * - * bug in pixmap.c that leaded to empty bars fixed - * name conflicts with X11 resolved - * - * Revision 1.11 2000/03/25 05:50:43 reinelt - * - * memory leak in Raster_flush closed - * driver family logic changed - * - * Revision 1.10 2000/03/23 07:24:48 reinelt - * - * PPM driver up and running (but slow!) - * - * Revision 1.9 2000/03/22 15:36:21 reinelt - * - * added '-l' switch (list drivers) - * generic pixmap driver added - * X11 Framework done - * - * Revision 1.8 2000/03/19 08:41:28 reinelt - * - * documentation available! README, README.MatrixOrbital, README.Drivers - * added Skeleton.c as a starting point for new drivers - * - * Revision 1.7 2000/03/18 08:07:04 reinelt - * - * vertical bars implemented - * bar compaction improved - * memory information implemented - * - * Revision 1.6 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.5 2000/03/13 15:58:24 reinelt - * - * release 0.9 - * moved row parsing to parser.c - * all basic work finished - * - * Revision 1.4 2000/03/10 17:36:02 reinelt - * - * first unstable but running release - * - * Revision 1.3 2000/03/10 10:49:53 reinelt - * - * MatrixOrbital driver finished - * - * Revision 1.2 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - */ - -/* - * exported functions: - * - * lcd_list (void) - * lists all available drivers to stdout - * - * lcd_init (char *driver) - * initializes the named driver - * - * lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *gpos) - * queries the attributes of the selected driver - * - * lcd_clear () - * clears the display - * - * int lcd_put (int row, int col, char *text) - * writes text at row, col - * - * 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 - * - * int lcd_flush (void) - * flushes the framebuffer to the display - * - * int lcd_quit (void) - * de-initializes the driver - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <math.h> - -#include "debug.h" -#include "cfg.h" -#include "display.h" -#include "bar.h" - -extern LCD BeckmannEgle[]; -extern LCD Crystalfontz[]; -extern LCD Cwlinux[]; -extern LCD HD44780[]; -extern LCD M50530[]; -extern LCD T6963[]; -extern LCD USBLCD[]; -extern LCD MatrixOrbital[]; -extern LCD MilfordInstruments[]; -extern LCD PalmPilot[]; -extern LCD Raster[]; -extern LCD SIN[]; -extern LCD XWindow[]; -extern LCD Text[]; - -// output file for Raster driver -// has to be defined here because it's referenced -// even if the raster driver is not included! -// Fixme: has gone to new drv.c -// char *output=NULL; - -FAMILY oldDriver[] = { -#ifdef WITH_BECKMANNEGLE - { "BeckmannEgle", BeckmannEgle }, -#endif -#ifdef WITH_CRYSTALFONTZ - { "Crystalfontz", Crystalfontz }, -#endif -#ifdef WITH_CWLINUX - { "Cwlinux", Cwlinux }, -#endif -#ifdef WITH_HD44780 - { "HD44780", HD44780 }, -#endif -#ifdef WITH_M50530 - { "M50530", M50530 }, -#endif -#ifdef WITH_T6963 - { "T6963", T6963 }, -#endif -#ifdef WITH_USBLCD - { "USBLCD", USBLCD }, -#endif -#ifdef WITH_MATRIXORBITAL - { "MatrixOrbital", MatrixOrbital }, -#endif -#ifdef WITH_MILINST - { "MilfordInstruments", MilfordInstruments }, -#endif -#ifdef WITH_PALMPILOT - { "PalmPilot", PalmPilot }, -#endif -#if defined (WITH_PNG) || defined(WITH_PPM) - { "Raster", Raster }, -#endif -#ifdef WITH_X11 - { "X11", XWindow }, -#endif -#ifdef WITH_TEXT - { "Text", Text }, -#endif - { NULL } -}; - - -static LCD *Lcd = NULL; - - -int lcd_list (void) -{ - int i, j; - - printf ("available *old* display drivers and models:"); - - for (i=0; oldDriver[i].driver; i++) { - printf ("\n %-20s:", oldDriver[i].driver); - for (j=0; oldDriver[i].Model[j].name; j++) { - printf (" %s", oldDriver[i].Model[j].name); - } - } - printf ("\n"); - return 0; -} - - -int lcd_init (char *driver) -{ - int i, j; - for (i=0; oldDriver[i].driver; i++) { - for (j=0; oldDriver[i].Model[j].name; j++) { - if (strcmp (oldDriver[i].Model[j].name, driver)==0) { - Lcd=&oldDriver[i].Model[j]; - if (Lcd->init==NULL) return 0; - return Lcd->init(Lcd); - } - } - } - error ("lcd_init(%s) failed: no such display", driver); - return -1; -} - - -int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *icons, int *gpos) -{ - if (Lcd==NULL) - return -1; - - if (rows) *rows=Lcd->rows; - if (cols) *cols=Lcd->cols; - if (xres) *xres=Lcd->xres; - if (yres) *yres=Lcd->yres; - if (bars) *bars=Lcd->bars; - if (icons) *icons=Lcd->icons; - if (gpos) *gpos=Lcd->gpos; - - return 0; -} - - -int lcd_clear (int full) -{ - if (Lcd->clear==NULL) return 0; - return Lcd->clear(full); -} - -int lcd_put (int row, int col, char *text) -{ - if (row<1 || row>Lcd->rows) return -1; - if (col<1 || col>Lcd->cols) return -1; - if (Lcd->put==NULL) return 0; - 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; - if (type & BAR_LOG) { - len1=(double)max*log(len1+1)/log(max); - if (!(type & BAR_T)) - len2=(double)max*log(len2+1)/log(max); - } - return Lcd->bar (type & BAR_HV, row-1, col-1, max, len1, len2); -} - - -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 ( row>Lcd->rows) return -1; - if ( col>Lcd->cols) return -1; - return Lcd->icon(num-1, seq-1, row-1, col-1); -} - - -int lcd_gpo (int num, int val) -{ - 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; - return Lcd->quit(); -} diff --git a/display.h b/display.h deleted file mode 100644 index 9a0b8ab..0000000 --- a/display.h +++ /dev/null @@ -1,161 +0,0 @@ -/* $Id: display.h,v 1.23 2004/01/09 17:03:07 reinelt Exp $ - * - * framework for device drivers - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: display.h,v $ - * Revision 1.23 2004/01/09 17:03:07 reinelt - * initiated transfer to new driver architecture - * new file 'drv.c' will someday replace 'display.c' - * new file 'drv_MatrixOrbital.c' will replace 'MatrixOrbital.c' - * due to this 'soft' transfer lcd4linux should stay usable during the switch - * (at least I hope so) - * - * Revision 1.22 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * 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 - * - * Revision 1.19 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.18 2003/08/17 16:37:39 reinelt - * more icon framework - * - * Revision 1.17 2003/08/17 12:11:58 reinelt - * framework for icons prepared - * - * Revision 1.16 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.15 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.14 2001/03/16 16:40:17 ltoetsch - * implemented time bar - * - * Revision 1.13 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.12 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.11 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.10 2000/03/26 18:46:28 reinelt - * - * bug in pixmap.c that leaded to empty bars fixed - * name conflicts with X11 resolved - * - * Revision 1.9 2000/03/25 05:50:43 reinelt - * - * memory leak in Raster_flush closed - * driver family logic changed - * - * Revision 1.8 2000/03/22 15:36:21 reinelt - * - * added '-l' switch (list drivers) - * generic pixmap driver added - * X11 Framework done - * - * Revision 1.7 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.6 2000/03/13 15:58:24 reinelt - * - * release 0.9 - * moved row parsing to parser.c - * all basic work finished - * - * Revision 1.5 2000/03/10 17:36:02 reinelt - * - * first unstable but running release - * - * Revision 1.4 2000/03/10 10:49:53 reinelt - * - * MatrixOrbital driver finished - * - * Revision 1.3 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - * Revision 1.2 2000/01/16 16:58:50 reinelt - * *** empty log message *** - * - */ - -#ifndef _DISPLAY_H_ -#define _DISPLAY_H_ - -typedef struct LCD { - char *name; - int rows; - int cols; - int xres; - int yres; - int bars; - int icons; - int gpos; - int (*init) (struct LCD *Self); - 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 seq, int row, int col); - int (*gpo) (int num, int val); - int (*flush) (void); - int (*quit) (void); -} LCD; - -typedef struct { - char *driver; - LCD *Model; -} FAMILY; - - -// output file for Raster driver -// has to be defined here because it's referenced -// even if the raster driver is not included! -extern char *output; - -int lcd_list (void); -int lcd_init (char *driver); -int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *icons, int *gpos); -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 seq, int row, int col); -int lcd_gpo (int num, int val); -int lcd_flush (void); -int lcd_quit (void); - -#endif @@ -1,134 +0,0 @@ -/* $Id: dvb.c,v 1.7 2003/11/11 04:30:41 reinelt Exp $ - * - * DVB specific functions - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: dvb.c,v $ - * Revision 1.7 2003/11/11 04:30:41 reinelt - * very minor changes - * - * Revision 1.6 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.5 2003/08/08 23:08:38 reinelt - * CVS Id and Log missing from dvb.{c,h} - * - */ - -/* - * exported functions: - * - * DVB (int *strength, int *snr) - * returns 0 if ok, -1 if error - * sets *strength to the signal strength - * sets *snr to the signal/noise ratio - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <time.h> -#include <sys/ioctl.h> -#include <sys/types.h> - -#include "config.h" -#include "debug.h" - -#ifndef HAVE_LINUX_DVB_FRONTEND_H - -#warning linux/dvb/frontend.h not found. -#warning DVB client will be disabled. - -int DVB (double *strength, double *snr) -{ - static int flag=0; - - if (flag==0) { - error("lcd4linux has been compiled without DVB support"); - error("DVB client will be disabled"); - flag=1; - } - - *strength=0.0; - *snr=0.0; - - return 0; -} - -#else - -#include <linux/dvb/frontend.h> -#include "dvb.h" - -int DVB (double *strength, double *snr) -{ - static time_t now=0; - static int fd=-2; - static double strength0=0.0; - static double snr0=0.0; - - unsigned short raw_strength; - unsigned short raw_snr; - - *strength=strength0; - *snr=snr0; - - if (fd==-1) return -1; - - if (time(NULL)==now) return 0; - time(&now); - - if (fd==-2) { - fd = open("/dev/dvb/adapter0/frontend0", O_RDONLY); - if (fd==-1) { - error ("open(/dev/dvb/adapter0/frontend0) failed: %s", strerror(errno)); - return -1; - } - debug ("open (/dev/dvb/adapter0/frontend0)=%d", fd); - } - - if (ioctl(fd, FE_READ_SIGNAL_STRENGTH, &raw_strength)!=0) { - error("ioctl(FE_READ_SIGNAL_STRENGTH) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if (ioctl(fd, FE_READ_SNR, &raw_snr)!=0) { - error("ioctl(FE_READ_SNR) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - // Normalize to 1.0 - strength0=raw_strength/65535.0; - snr0=raw_snr/65535.0; - - *strength=strength0; - *snr=snr0; - - return 0; -} - -#endif @@ -1,38 +0,0 @@ -/* $Id: dvb.h,v 1.3 2003/10/05 17:58:50 reinelt Exp $ - * - * DVB specific functions - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: dvb.h,v $ - * Revision 1.3 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.2 2003/08/08 23:08:38 reinelt - * CVS Id and Log missing from dvb.{c,h} - * - */ - -#ifndef _DVB_H_ -#define _DVB_H_ - -int DVB (double *strength, double *snr); - -#endif @@ -1,107 +0,0 @@ -/* $Id: expr.c,v 1.6 2004/01/29 04:40:02 reinelt Exp $ - * - * expr ('y*') functions - * This is only a workaround to make the Evaluator usable until - * it's fully integrated into lcd4linux. - * - * Copyright 2004 Michael Reinelt <reinelt@eunet.at> - * - * 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: expr.c,v $ - * Revision 1.6 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.5 2004/01/18 06:54:08 reinelt - * bug in expr.c fixed (thanks to Xavier) - * some progress with /proc/stat parsing - * - * Revision 1.4 2004/01/14 11:33:00 reinelt - * new plugin 'uname' which does what it's called - * text widget nearly finished - * first results displayed on MatrixOrbital - * - * Revision 1.3 2004/01/12 03:51:01 reinelt - * evaluating the 'Variables' section in the config file - * - * Revision 1.2 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.1 2004/01/05 11:57:38 reinelt - * added %y tokens to make the Evaluator useable - * - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <ctype.h> -#include <errno.h> -#define IN_EXPR -#include "expr.h" -#include "plugin.h" -#include "debug.h" -#include "cfg.h" - - -int Expr(int index, char string[EXPR_TXT_LEN], double *val) -{ - RESULT result = {0, 0.0, NULL}; - static int errs[EXPRS+1]; - char *expression; - char yn[4]; - - if (index < 0 || index > EXPRS) - return -1; - - if (errs[index]) - return -1; - - sprintf(yn, "y%d", index); - expression = cfg_get_raw(NULL, yn, NULL); - - if (!expression || !*expression) { - error("Empty expression for 'y%d'", index); - errs[index]++; - return -1; - } - - Eval(expression, &result); - strcpy(string, R2S(&result)); - - debug("%s: <%s> = '%s'", yn, expression, string); - - if (isdigit(*string)) { - double max, min; - *val = atof(string); - sprintf(yn, "Max_y%d", index); - max = atof(cfg_get(NULL, yn, "100")); - sprintf(yn, "Min_y%d", index); - min = atof(cfg_get(NULL, yn, "0")); - if (max != min) - *val = (*val - min)/(max - min); - } - - DelResult (&result); - - return 0; -} - @@ -1,49 +0,0 @@ -/* $Id: expr.h,v 1.1 2004/01/05 11:57:38 reinelt Exp $ - * - * expr ('y*') functions - * This is only a workaround to make the Evaluator usable until - * it's fully integrated into lcd4linux. - * - * Copyright 2004 Michael Reinelt <reinelt@eunet.at> - * - * 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: expr.h,v $ - * Revision 1.1 2004/01/05 11:57:38 reinelt - * added %y tokens to make the Evaluator useable - * - */ - -#ifndef _EXPR_H -#define _EXPR_H_ - -#define EXPRS 9 -#define EXPR_TXT_LEN 256 - -#ifdef IN_EXPR - #define EXTERN extern -#else - #define EXTERN -#endif - -EXTERN struct { char s[EXPR_TXT_LEN]; double val; } expr[EXPRS+1]; - -int Expr (int index, char txt[EXPR_TXT_LEN], double *val); - - -#endif diff --git a/filter.c b/filter.c deleted file mode 100644 index 11b198b..0000000 --- a/filter.c +++ /dev/null @@ -1,215 +0,0 @@ -/* $Id: filter.c,v 1.12 2004/01/30 20:57:56 reinelt Exp $ - * - * smooth and damp functions - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: filter.c,v $ - * Revision 1.12 2004/01/30 20:57:56 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.11 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.10 2004/01/16 05:04:53 reinelt - * started plugin proc_stat which should parse /proc/stat - * which again is a paint in the a** - * thinking over implementation methods of delta functions - * (CPU load, ...) - * - * Revision 1.9 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.8 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.7 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.6 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.5 2001/08/05 17:13:29 reinelt - * - * cleaned up inlude of sys/time.h and time.h - * - * Revision 1.4 2000/03/23 07:24:48 reinelt - * - * PPM driver up and running (but slow!) - * - * Revision 1.3 2000/03/22 07:33:50 reinelt - * - * FAQ added - * new modules 'processor.c' contains all data processing - * - * Revision 1.2 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - */ - -/* - * - * exported fuctions: - * - * smooth (name, period, value) - * returns an average value over a given period - * uses global variable "tick" - * - * damp (name, value) - * damps a value with exp(-t/tau) - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <math.h> -#include <time.h> -#include <sys/time.h> - -#include "cfg.h" -#include "filter.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - -extern int tick; - -#define SLOTS 64 -#define SECONDS(x) (x.tv_sec+x.tv_usec/1000000.0) - -typedef struct { - char *name; - int slots; - struct timeval *time; - double *value; -} FILTER; - - -double smooth(char *name, int period, double value) -{ - static FILTER *Filter=NULL; - static int nFilter=0; - struct timeval now; - double t, v; - int i, j; - - gettimeofday (&now, NULL); - - for (i=0; i<nFilter; i++) { - if (strcmp(name, Filter[i].name)==0) - break; - } - - if (i==nFilter) { - int slots=(period+tick-1)/tick; - if (slots<2) - slots=2; - else if (slots>SLOTS) - slots=SLOTS; - - nFilter++; - Filter=realloc(Filter, nFilter*sizeof(FILTER)); - Filter[i].name=strdup(name); - Filter[i].slots=slots; - Filter[i].time=malloc(slots*sizeof(Filter[i].time[0])); - Filter[i].value=malloc(slots*sizeof(Filter[i].value[0])); - for (j=0; j<slots; j++) { - Filter[i].time[j]=now; - Filter[i].value[j]=value; - } - } - - for (j=Filter[i].slots-1; j>0; j--) { - Filter[i].time[j]=Filter[i].time[j-1]; - Filter[i].value[j]=Filter[i].value[j-1]; - } - Filter[i].time[0]=now; - Filter[i].value[0]=value; - - t = SECONDS(Filter[i].time[0]) - SECONDS(Filter[i].time[Filter[i].slots-1]); - v = Filter[i].value[0]-Filter[i].value[Filter[i].slots-1]; - - if (t==0.0 || v<0.0) - return 0; - else - return v/t; -} - - -double damp(char *name, double value) -{ - static int tau=-1; - static FILTER *Filter=NULL; - static int nFilter=0; - struct timeval now; - double max; - int i, j; - - if (tau==-1) - if (cfg_number(NULL, "tau", 500, 0, 1000000, &tau)<0) tau=0.0; - - if (tau==0.0) - return value; - - gettimeofday (&now, NULL); - - for (i=0; i<nFilter; i++) { - if (strcmp(name, Filter[i].name)==0) - break; - } - - if (i==nFilter) { - int slots=log(100)*tau/tick; - if (slots<1) - slots=1; - else if (slots>SLOTS) - slots=SLOTS; - - nFilter++; - Filter=realloc(Filter, nFilter*sizeof(FILTER)); - Filter[i].name=strdup(name); - Filter[i].slots=slots; - Filter[i].time=malloc(slots*sizeof(Filter[i].time)); - Filter[i].value=malloc(slots*sizeof(Filter[i].value)); - for (j=0; j<slots; j++) { - Filter[i].time[j]=now; - Filter[i].value[j]=0; - } - } - - max=value; - for (j=Filter[i].slots-1; j>0; j--) { - double t = SECONDS(Filter[i].time[j]) - SECONDS(Filter[i].time[j-1]); - Filter[i].time[j]=Filter[i].time[j-1]; - Filter[i].value[j]=Filter[i].value[j-1]*exp(-t/tau); - if (Filter[i].value[j]>max) max=Filter[i].value[j]; - } - - Filter[i].time[0]=now; - Filter[i].value[0]=value; - - return max; -} diff --git a/filter.h b/filter.h deleted file mode 100644 index 0cf1440..0000000 --- a/filter.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $Id: filter.h,v 1.3 2003/10/05 17:58:50 reinelt Exp $ - * - * smooth and damp functions - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: filter.h,v $ - * Revision 1.3 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.2 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - * - */ - -#ifndef _FILTER_H_ -#define _FILTER_H_ - -double smooth (char *name, int period, double value); -double damp (char *name, double value); - -#endif @@ -1,246 +0,0 @@ -/* $Id: icon.c,v 1.14 2004/01/30 20:57:56 reinelt Exp $ - * - * generic icon and heartbeat handling - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: icon.c,v $ - * Revision 1.14 2004/01/30 20:57:56 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.13 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.12 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.11 2003/10/22 04:32:25 reinelt - * fixed icon bug found by Rob van Nieuwkerk - * - * Revision 1.10 2003/10/22 04:19:16 reinelt - * Makefile.in for imon.c/.h, some MatrixOrbital clients - * - * Revision 1.9 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.8 2003/09/19 03:51:29 reinelt - * minor fixes, widget.c added - * - * Revision 1.7 2003/09/11 04:09:53 reinelt - * minor cleanups - * - * Revision 1.6 2003/09/10 14:01:53 reinelt - * icons nearly finished\! - * - * Revision 1.5 2003/09/10 03:48:23 reinelt - * Icons for M50530, new processing scheme (Ticks.Text...) - * - * 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 - * - * Revision 1.2 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.1 2003/08/24 04:31:56 reinelt - * icon.c icon.h added - * - * - */ - -/* - * 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 "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "debug.h" -#include "cfg.h" -#include "icon.h" - -#ifdef WITH_DMALLOC -#include <dmalloc.h> -#endif - - -typedef struct BITMAP { - int nData; - int lData; - char *Data; -} BITMAP; - -static int ROWS=0; -static int COLS=0; -static int XRES=0; -static int YRES=0; -static int CHARS; -static int ICONS=0; - -static int *Screen=NULL; -static struct BITMAP *Bitmap=NULL; -static void(*Defchar)(int ascii, char *bitmap); - - -static int icon_read_bitmap (int num) -{ - struct BITMAP *bm = Bitmap+num; - int row, n; - char key[15]; - char *val, *v; - char *map; - - for (row=0; row<YRES; row++) { - snprintf (key, sizeof(key), "Icon%d.Bitmap%d", num+1, row+1); - val=cfg_get(NULL, key, ""); - map=bm->Data+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; - } - } - } - return 0; -} - - -int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, - void(*defchar)(int ascii, char *bitmap)) -{ - int n; - - if (rows<1 || cols<1) - return -1; - - ROWS=rows; - COLS=cols; - XRES=xres; - YRES=yres; - CHARS=chars, - ICONS=icons; - - if ((Screen=malloc(ROWS*COLS*sizeof(*Screen)))==NULL) { - error ("icon buffer allocation failed: out of memory?"); - return -1; - } - - if ((Bitmap=malloc(icons*sizeof(*Bitmap)))==NULL) { - error ("icon allocation failed: out of memory?"); - return -1; - } - - Defchar=defchar; - - icon_clear(); - - for (n=0; n<icons; n++) { - Bitmap[n].nData=1; - Bitmap[n].lData=-1; - Bitmap[n].Data=malloc(YRES*sizeof(char)); - memset (Bitmap[n].Data, 0, YRES*sizeof(char)); - icon_read_bitmap(n); - // icons use last ascii codes from userdef chars - if (Defchar) Defchar (CHARS-n-1, Bitmap[n].Data); - } - - return 0; -} - - -void icon_clear(void) -{ - int n; - - // reset screen buffer - for (n=0; n<ROWS*COLS; n++) { - Screen[n]=-1; - } - - // reset last bitmap pointer - for (n=0; n<ICONS; n++) { - Bitmap[n].lData=-1; - } - -} - - -int icon_draw (int num, int seq, int row, int col) -{ - if (row>=0 && col>=0) { - // icons use last ascii codes from userdef chars - Screen[row*COLS+col]=CHARS-num-1; - } - - if (seq>=0) { - seq%=Bitmap[num].nData; - if (seq!=Bitmap[num].lData) { - Bitmap[num].lData=seq; - if (Defchar) Defchar (CHARS-num-1, Bitmap[num].Data+seq*YRES); - } - } - - return 0; -} - - -int icon_peek (int row, int col) -{ - if (Screen) - return Screen[row*COLS+col]; - else - return -1; -} @@ -1,49 +0,0 @@ -/* $Id: icon.h,v 1.4 2003/10/05 17:58:50 reinelt Exp $ - * - * generic icon and heartbeat handling - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: icon.h,v $ - * Revision 1.4 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * 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 - * - * Revision 1.1 2003/08/24 04:31:56 reinelt - * icon.c icon.h added - * - * - */ - -#ifndef _ICON_H_ -#define _ICON_H_ - -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 seq, int row, int col); -int icon_peek (int row, int col); - -#endif diff --git a/lcd4linux.c b/lcd4linux.c index 409895e..9c192fa 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.62 2004/01/30 20:57:56 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.63 2004/02/10 07:42:35 reinelt Exp $ * * LCD4Linux * @@ -22,6 +22,9 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.63 2004/02/10 07:42:35 reinelt + * cut off all old-style files which are no longer used with NextGeneration + * * Revision 1.62 2004/01/30 20:57:56 reinelt * HD44780 patch from Martin Hejl * dmalloc integrated @@ -310,9 +313,7 @@ #include "debug.h" #include "pid.h" #include "udelay.h" -#include "display.h" // Fixme: remove me... #include "drv.h" -#include "processor.h" // Fixme: remove me... #include "timer.h" #include "layout.h" #include "plugin.h" @@ -340,7 +341,8 @@ static void usage(void) printf (" lcd4linux [-c key=value] [-F] [-f config-file] [-o output-file] [-q] [-v]\n"); } - +#if 0 +// Fixme: how to hello() with new layout? int hello (void) { int i, x, y, flag; @@ -376,7 +378,7 @@ int hello (void) if (flag) lcd_flush(); return flag; } - +#endif void handler (int signal) { @@ -428,8 +430,6 @@ int main (int argc, char *argv[]) case 'l': printf ("%s\n", release); drv_list(); - printf ("\n"); - lcd_list(); exit(0); case 'o': output=optarg; @@ -475,13 +475,8 @@ int main (int argc, char *argv[]) snprintf (section, sizeof(section), "Display:%s", display); driver=cfg_get(section, "Driver", NULL); if (driver==NULL || *driver=='\0') { -#if 0 error ("missing '%s.Driver' entry in %s!", section, cfg_source()); exit (1); -#else - // Fixme: compatibility only... - driver=NULL; -#endif } if (!running_foreground) { @@ -536,40 +531,20 @@ int main (int argc, char *argv[]) running_background=1; } - // Fixme: Compatibility only... - if (driver!=NULL) { - debug ("initializing driver %s", driver); - if (drv_init(section, driver)==-1) { - pid_exit(PIDFILE); - exit (1); - } - } else { - debug ("initializing old-style driver %s", display); - if (lcd_init(display)==-1) { - pid_exit(PIDFILE); - exit (1); - } + debug ("initializing driver %s", driver); + if (drv_init(section, driver)==-1) { + pid_exit(PIDFILE); + exit (1); } // 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); - } + layout_init(layout); // maybe go into interactive mode if (interactive) { @@ -591,13 +566,7 @@ int main (int argc, char *argv[]) printf("eval> "); } printf ("\n"); - // Fixme: compatibility only... - if (layout==NULL) { - lcd_clear(1); - lcd_quit(); - } else { - drv_quit(); - } + drv_quit(); pid_exit(PIDFILE); cfg_exit(); exit (0); @@ -608,15 +577,13 @@ int main (int argc, char *argv[]) cfg_number(NULL, "Quiet", 0, 0, 1, &quiet); } - // Fixme: compatibility only... - if (layout==NULL) { - if (!quiet && hello()) { - sleep (3); - lcd_clear(1); - } - } else { - // Fixme: how to hello() with new layout? +#if 0 + // Fixme: how to hello() with new layout? + if (!quiet && hello()) { + sleep (3); + lcd_clear(1); } +#endif debug ("starting main loop"); @@ -626,30 +593,20 @@ int main (int argc, char *argv[]) signal(SIGQUIT, handler); signal(SIGTERM, handler); - // Fixme: compatibility only... - if (layout==NULL) { - while (got_signal==0) { - process (); - usleep(tack*1000); - } - } else { - while (got_signal==0) { - struct timespec delay; - if (timer_process(&delay)<0) break; - nanosleep(&delay, NULL); - } + while (got_signal==0) { + struct timespec delay; + if (timer_process(&delay)<0) break; + nanosleep(&delay, NULL); } debug ("leaving main loop"); - // Fixme: compatibility only... - if (layout==NULL) { - lcd_clear(1); - if (!quiet) hello(); - lcd_quit(); - } else { - drv_quit(); - } +#if 0 + // Fixme: how to hello() with new layout? + lcd_clear(1); + if (!quiet) hello(); +#endif + drv_quit(); pid_exit(PIDFILE); cfg_exit(); diff --git a/parport.c b/parport.c deleted file mode 100644 index d84dee4..0000000 --- a/parport.c +++ /dev/null @@ -1,478 +0,0 @@ -/* $Id: parport.c,v 1.13 2004/01/13 08:18:20 reinelt Exp $ - * - * generic parallel port handling - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: parport.c,v $ - * Revision 1.13 2004/01/13 08:18:20 reinelt - * timer queues added - * liblcd4linux deactivated turing transformation to new layout - * - * Revision 1.12 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.11 2003/10/08 14:21:10 reinelt - * Changelog; small type in parport.c - * - * Revision 1.10 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.9 2003/10/03 03:53:12 reinelt - * compile error in parport fixed (thanks to Andrew from FilmCan) - * - * Revision 1.8 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.7 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.6 2003/08/22 03:45:09 reinelt - * bug in parallel port code fixed, more icons stuff - * - * Revision 1.5 2003/08/19 05:23:55 reinelt - * HD44780 dual-controller patch from Jesse Brook Kovach - * - * Revision 1.4 2003/08/16 07:31:35 reinelt - * double buffering in all drivers - * - * Revision 1.3 2003/08/15 07:54:07 reinelt - * HD44780 4 bit mode implemented - * - * Revision 1.2 2003/04/07 06:03:05 reinelt - * further parallel port abstraction - * - * Revision 1.1 2003/04/04 06:02:03 reinelt - * new parallel port abstraction scheme - * - */ - -/* - * exported functions: - * - * int parport_open (void) - * reads 'Port' entry from config and opens - * the parallel port - * returns 0 if ok, -1 on failure - * - * int parport_close (void) - * closes parallel port - * returns 0 if ok, -1 on failure - * - * unsigned char parport_wire_ctrl (char *name, char *deflt) - * reads wiring for one control signal from config - * returns PARPORT_CONTROL_* or 255 on error - * - * unsigned char parport_wire_data (char *name, char *deflt) - * reads wiring for one data signal from config - * returns 1<<bitpos or 255 on error - * - * void parport_direction (int direction) - * 0 - write to parport - * 1 - read from parport - * - * void parport_control (unsigned char mask, unsigned char value) - * frobs control line and takes care of inverted signals - * - * void parport_toggle (unsigned char bit, int level, int delay) - * toggles the line <bit> to <level> for <delay> nanoseconds - * - * void parport_data (unsigned char value) - * put data bits on DB1..DB8 - * - * unsigned char parport_read (void) - * reads a byte from the parallel port - * - * void parport_debug(void) - * prints status of control lines - */ - - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <time.h> -#include <errno.h> -#include <sys/ioctl.h> - - -#ifdef HAVE_SYS_IO_H -#include <sys/io.h> -#define WITH_OUTB -#else -#ifdef HAVE_ASM_IO_H -#include <asm/io.h> -#define WITH_OUTB -#endif -#endif - -#if defined (HAVE_LINUX_PARPORT_H) && defined (HAVE_LINUX_PPDEV_H) -#define WITH_PPDEV -#include <linux/parport.h> -#include <linux/ppdev.h> -#else -#define PARPORT_CONTROL_STROBE 0x1 -#define PARPORT_CONTROL_AUTOFD 0x2 -#define PARPORT_CONTROL_INIT 0x4 -#define PARPORT_CONTROL_SELECT 0x8 -#endif - -#if !defined(WITH_OUTB) && !defined(WITH_PPDEV) -#error neither outb() nor ppdev() possible -#error cannot compile parallel port driver -#endif - - -#include "debug.h" -#include "cfg.h" -#include "udelay.h" -#include "parport.h" - - -static unsigned short Port=0; -static char *PPdev=NULL; - -// initial value taken from linux/parport_pc.c -static unsigned char ctr = 0xc; - -#ifdef WITH_PPDEV -static int PPfd=-1; -#endif - - -int parport_open (void) -{ - char *s, *e; - -#ifdef USE_OLD_UDELAY - if (cfg_number(NULL, "Delay", 0, 1, 1000000000, &loops_per_usec)<0) return -1; -#else - udelay_init(); -#endif - - s=cfg_get (NULL, "Port", NULL); - if (s==NULL || *s=='\0') { - error ("parport: no 'Port' entry in %s", cfg_source()); - return -1; - } - PPdev=NULL; - if ((Port=strtol(s, &e, 0))==0 || *e!='\0') { -#ifdef WITH_PPDEV - Port=0; - PPdev=s; -#else - error ("parport: bad Port '%s' in %s", s, cfg_source()); - return -1; -#endif - } - - -#ifdef WITH_PPDEV - - if (PPdev) { - debug ("using ppdev %s", PPdev); - PPfd=open(PPdev, O_RDWR); - if (PPfd==-1) { - error ("parport: open(%s) failed: %s", PPdev, strerror(errno)); - return -1; - } - -#if 0 - // Fixme: this always fails here... - if (ioctl(PPfd, PPEXCL)) { - debug ("ioctl(%s, PPEXCL) failed: %s", PPdev, strerror(errno)); - } else { - debug ("ioctl(%s, PPEXCL) succeded."); - } -#endif - - if (ioctl(PPfd, PPCLAIM)) { - error ("parport: ioctl(%s, PPCLAIM) failed: %d %s", PPdev, errno, strerror(errno)); - return -1; - } - } else - -#endif - - { - debug ("using raw port 0x%x", Port); - if ((Port+3)<=0x3ff) { - if (ioperm(Port, 3, 1)!=0) { - error ("parport: ioperm(0x%x) failed: %s", Port, strerror(errno)); - return -1; - } - } else { - if (iopl(3)!=0) { - error ("parport: iopl(1) failed: %s", strerror(errno)); - return -1; - } - } - } - return 0; -} - - -int parport_close (void) -{ -#ifdef WITH_PPDEV - if (PPdev) { - debug ("closing ppdev %s", PPdev); - if (ioctl(PPfd, PPRELEASE)) { - error ("parport: ioctl(%s, PPRELEASE) failed: %s", PPdev, strerror(errno)); - } - if (close(PPfd)==-1) { - error ("parport: close(%s) failed: %s", PPdev, strerror(errno)); - return -1; - } - } else -#endif - { - debug ("closing raw port 0x%x", Port); - if ((Port+3)<=0x3ff) { - if (ioperm(Port, 3, 0)!=0) { - error ("parport: ioperm(0x%x) failed: %s", Port, strerror(errno)); - return -1; - } - } else { - if (iopl(0)!=0) { - error ("parport: iopl(0) failed: %s", strerror(errno)); - return -1; - } - } - } - return 0; -} - - -unsigned char parport_wire_ctrl (char *name, unsigned char *deflt) -{ - unsigned char w; - char wire[256]; - char *s; - - snprintf (wire, sizeof(wire), "Wire.%s", name); - s=cfg_get (NULL, wire, deflt); - if (strcasecmp(s,"STROBE")==0) { - w=PARPORT_CONTROL_STROBE; - } else if(strcasecmp(s,"AUTOFD")==0) { - w=PARPORT_CONTROL_AUTOFD; - } else if(strcasecmp(s,"INIT")==0) { - w=PARPORT_CONTROL_INIT; - } else if(strcasecmp(s,"SELECT")==0) { - w=PARPORT_CONTROL_SELECT; - } else if(strcasecmp(s,"GND")==0) { - w=0; - } else { - error ("parport: unknown signal <%s> for wire <%s>", s, name); - error (" should be STROBE, AUTOFD, INIT, SELECT or GND"); - return 0xff; - } - - if (w&PARPORT_CONTROL_STROBE) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:STROBE]", name); - } - if (w&PARPORT_CONTROL_AUTOFD) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:AUTOFD]", name); - } - if (w&PARPORT_CONTROL_INIT) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:INIT]", name); - } - if (w&PARPORT_CONTROL_SELECT) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:SELECT]", name); - } - if (w==0) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:GND]", name); - } - - return w; -} - - -unsigned char parport_wire_data (char *name, unsigned char *deflt) -{ - unsigned char w; - char wire[256]; - char *s; - - snprintf (wire, sizeof(wire), "Wire.%s", name); - s=cfg_get (NULL, wire, deflt); - if(strlen(s)==3 && strncasecmp(s,"DB",2)==0 && s[2]>='0' && s[2]<='7') { - w=s[2]-'0'; - } else if(strcasecmp(s,"GND")==0) { - w=0; - } else { - error ("parport: unknown signal <%s> for wire <%s>", s, name); - error (" should be DB0..7 or GND"); - return 0xff; - } - - if (w==0) { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:GND]", name); - } else { - info ("wiring: [DISPLAY:%s]<==>[PARPORT:DB%d]", name, w); - } - - w=1<<w; - - return w; -} - - -void parport_direction (int direction) -{ -#ifdef WITH_PPDEV - if (PPdev) { - ioctl (PPfd, PPDATADIR, &direction); - } else -#endif - { - // code stolen from linux/parport_pc.h - ctr = (ctr & ~0x20) ^ (direction?0x20:0x00); - outb (ctr, Port+2); - } -} - - -void parport_control (unsigned char mask, unsigned char value) -{ - // any signal affected? - // Note: this may happen in case a signal is hardwired to GND - if (mask==0) return; - - // Strobe, Select and AutoFeed are inverted! - value = mask & (value ^ (PARPORT_CONTROL_STROBE|PARPORT_CONTROL_SELECT|PARPORT_CONTROL_AUTOFD)); - -#ifdef WITH_PPDEV - if (PPdev) { - struct ppdev_frob_struct frob; - frob.mask=mask; - frob.val=value; - ioctl (PPfd, PPFCONTROL, &frob); - } else -#endif - { - // code stolen from linux/parport_pc.h - ctr = (ctr & ~mask) ^ value; - outb (ctr, Port+2); - } -} - - -void parport_toggle (unsigned char bits, int level, int delay) -{ - unsigned char value1, value2; - - // any signal affected? - // Note: this may happen in case a signal is hardwired to GND - if (bits==0) return; - - // prepare value - value1=level?bits:0; - value2=level?0:bits; - - // Strobe, Select and AutoFeed are inverted! - value1 = bits & (value1 ^ (PARPORT_CONTROL_STROBE|PARPORT_CONTROL_SELECT|PARPORT_CONTROL_AUTOFD)); - value2 = bits & (value2 ^ (PARPORT_CONTROL_STROBE|PARPORT_CONTROL_SELECT|PARPORT_CONTROL_AUTOFD)); - - -#ifdef WITH_PPDEV - if (PPdev) { - struct ppdev_frob_struct frob; - frob.mask=bits; - - // rise - frob.val=value1; - ioctl (PPfd, PPFCONTROL, &frob); - - // pulse width - ndelay(delay); - - // lower - frob.val=value2; - ioctl (PPfd, PPFCONTROL, &frob); - } else -#endif - { - // rise - ctr = (ctr & ~bits) ^ value1; - outb (ctr, Port+2); - - // pulse width - ndelay(delay); - - // lower - ctr = (ctr & ~bits) ^ value2; - outb (ctr, Port+2); - } -} - - -void parport_data (unsigned char data) -{ -#ifdef WITH_PPDEV - if (PPdev) { - ioctl(PPfd, PPWDATA, &data); - } else -#endif - { - outb (data, Port); - } -} - -unsigned char parport_read (void) -{ - unsigned char data; - -#ifdef WITH_PPDEV - if (PPdev) { - ioctl (PPfd, PPRDATA, &data); - } else -#endif - { - data=inb (Port); - } - return data; -} - - -void parport_debug(void) -{ - unsigned char control; - -#ifdef WITH_PPDEV - if (PPdev) { - ioctl (PPfd, PPRCONTROL, &control); - } else -#endif - { - control=ctr; - } - - debug ("%cSTROBE %cAUTOFD %cINIT %cSELECT", - control & PARPORT_CONTROL_STROBE ? '-':'+', - control & PARPORT_CONTROL_AUTOFD ? '-':'+', - control & PARPORT_CONTROL_INIT ? '+':'-', - control & PARPORT_CONTROL_SELECT ? '-':'+'); - -} diff --git a/parport.h b/parport.h deleted file mode 100644 index 94f5941..0000000 --- a/parport.h +++ /dev/null @@ -1,53 +0,0 @@ -/* $Id: parport.h,v 1.4 2003/10/05 17:58:50 reinelt Exp $ - * - * generic parallel port handling - * - * Copyright 2003 Michael Reinelt <reinelt@eunet.at> - * - * 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: parport.h,v $ - * Revision 1.4 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.3 2003/08/15 07:54:07 reinelt - * HD44780 4 bit mode implemented - * - * Revision 1.2 2003/04/07 06:03:10 reinelt - * further parallel port abstraction - * - * Revision 1.1 2003/04/04 06:02:03 reinelt - * new parallel port abstraction scheme - * - */ - -#ifndef _PARPORT_H_ -#define _PARPORT_H_ - -int parport_open (void); -int parport_close (void); -unsigned char parport_wire_ctrl (char *name, unsigned char *deflt); -unsigned char parport_wire_data (char *name, unsigned char *deflt); -void parport_direction (int direction); -void parport_control (unsigned char mask, unsigned char value); -void parport_toggle (unsigned char bit, int level, int delay); -void parport_data (unsigned char data); -unsigned char parport_read (void); -void parport_debug(void); - -#endif diff --git a/parser.c b/parser.c deleted file mode 100644 index 23ea278..0000000 --- a/parser.c +++ /dev/null @@ -1,399 +0,0 @@ -/* $Id: parser.c,v 1.25 2004/01/29 04:40:02 reinelt Exp $ - * - * row definition parser - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: parser.c,v $ - * Revision 1.25 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.24 2004/01/05 11:57:38 reinelt - * added %y tokens to make the Evaluator useable - * - * Revision 1.23 2003/11/11 04:40:20 reinelt - * WIFI patch from Xavier Vello - * - * Revision 1.22 2003/10/12 06:08:28 nicowallmeier - * imond/telmond support - * - * Revision 1.21 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.20 2003/09/01 04:09:35 reinelt - * icons nearly finished, but MatrixOrbital only - * - * Revision 1.19 2003/06/21 05:46:18 reinelt - * DVB client integrated - * - * Revision 1.18 2002/12/05 19:23:01 reinelt - * fixed undefined operations found by gcc3 - * - * Revision 1.17 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.16 2001/03/16 16:40:17 ltoetsch - * implemented time bar - * - * Revision 1.15 2001/03/14 13:19:29 ltoetsch - * Added pop3/imap4 mail support - * - * Revision 1.14 2001/03/13 08:34:15 reinelt - * - * corrected a off-by-one bug with sensors - * - * Revision 1.13 2001/03/08 15:25:38 ltoetsch - * improved exec - * - * Revision 1.12 2001/03/07 18:10:21 ltoetsch - * added e(x)ec commands - * - * Revision 1.11 2001/03/02 10:18:03 ltoetsch - * added /proc/apm battery stat - * - * Revision 1.10 2001/02/19 00:15:46 reinelt - * - * integrated mail and seti client - * major rewrite of parser and tokenizer to support double-byte tokens - * - * Revision 1.9 2001/02/16 08:23:09 reinelt - * - * new token 'ic' (ISDN connected) by Carsten Nau <info@cnau.de> - * - * Revision 1.8 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.7 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.6 2000/05/21 06:20:35 reinelt - * - * added ppp throughput - * token is '%t[iomt]' at the moment, but this will change in the near future - * - * Revision 1.5 2000/03/24 11:36:56 reinelt - * - * new syntax for raster configuration - * changed XRES and YRES to be configurable - * PPM driver works nice - * - * Revision 1.4 2000/03/19 08:41:28 reinelt - * - * documentation available! README, README.MatrixOrbital, README.Drivers - * added Skeleton.c as a starting point for new drivers - * - * Revision 1.3 2000/03/18 10:31:06 reinelt - * - * added sensor handling (for temperature etc.) - * made data collecting happen only if data is used - * (reading /proc/meminfo takes a lot of CPU!) - * released lcd4linux-0.92 - * - * Revision 1.2 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.1 2000/03/13 15:58:24 reinelt - * - * release 0.9 - * moved row parsing to parser.c - * all basic work finished - * - */ - -/* - * exported functions: - * - * char *parse_row (char *string, int supported_bars, int usage[]) - * converts a row definition from the config file - * into the internal form using tokens - * sets the array usage[token] to usage count - * - * char parse_gpo (char *string, int usage[]) - * converts a GPO definition from the config file - * into the internal form using tokens - * sets the array usage[token] to usage count - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> - -#include "debug.h" -#include "display.h" -#include "bar.h" -#include "parser.h" - -typedef struct { - char *symbol; - TOKEN token; - CLASS class; - int bar; -} SYMTAB; - -static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 }, - { "$", T_DOLLAR, C_GENERIC, 0 }, - { "&", T_AMPERSAND, C_GENERIC, 0 }, - { "o", T_OS, C_GENERIC, 0 }, - { "v", T_RELEASE, C_GENERIC, 0 }, - { "p", T_CPU, C_GENERIC, 0 }, - { "r", T_RAM, C_GENERIC, 0 }, - { "mt", T_MEM_TOTAL, C_MEM, 1 }, - { "mu", T_MEM_USED, C_MEM, 1 }, - { "mf", T_MEM_FREE, C_MEM, 1 }, - { "ms", T_MEM_SHARED, C_MEM, 1 }, - { "mb", T_MEM_BUFFER, C_MEM, 1 }, - { "mc", T_MEM_CACHE, C_MEM, 1 }, - { "ma", T_MEM_AVAIL, C_MEM, 1 }, - { "l1", T_LOAD_1, C_LOAD, 1 }, - { "l2", T_LOAD_2, C_LOAD, 1 }, - { "l3", T_LOAD_3, C_LOAD, 1 }, - { "L", T_OVERLOAD, C_LOAD, 0 }, - { "cu", T_CPU_USER, C_CPU, 1 }, - { "cn", T_CPU_NICE, C_CPU, 1 }, - { "cs", T_CPU_SYSTEM, C_CPU, 1 }, - { "cb", T_CPU_BUSY, C_CPU, 1 }, - { "ci", T_CPU_IDLE, C_CPU, 1 }, - { "dr", T_DISK_READ, C_DISK, 1 }, - { "dw", T_DISK_WRITE, C_DISK, 1 }, - { "dt", T_DISK_TOTAL, C_DISK, 1 }, - { "dm", T_DISK_MAX, C_DISK, 1 }, - { "nr", T_ETH_RX, C_ETH, 1 }, - { "nw", T_ETH_TX, C_ETH, 1 }, - { "nt", T_ETH_TOTAL, C_ETH, 1 }, - { "nm", T_ETH_MAX, C_ETH, 1 }, - { "ic", T_ISDN_USED, C_ISDN, 0 }, - { "ii", T_ISDN_IN, C_ISDN, 1 }, - { "io", T_ISDN_OUT, C_ISDN, 1 }, - { "it", T_ISDN_TOTAL, C_ISDN, 1 }, - { "im", T_ISDN_MAX, C_ISDN, 1 }, - { "ws", T_WIFI_SIGNAL, C_WIFI, 1 }, - { "wl", T_WIFI_LINK, C_WIFI, 1 }, - { "wn", T_WIFI_NOISE, C_WIFI, 1 }, - { "ti", T_PPP_RX, C_PPP, 1 }, - { "to", T_PPP_TX, C_PPP, 1 }, - { "tt", T_PPP_TOTAL, C_PPP, 1 }, - { "tm", T_PPP_MAX, C_PPP, 1 }, - { "hc", T_SETI_PRC, C_SETI, 1 }, - { "ht", T_SETI_CPU, C_SETI, 0 }, - { "bp", T_BATT_PERC, C_BATT, 1 }, - { "bs", T_BATT_STAT, C_BATT, 0 }, - { "bd", T_BATT_DUR, C_BATT, 0 }, - { "ss", T_DVB_STRENGTH, C_DVB, 1 }, - { "sn", T_DVB_SNR, C_DVB, 1 }, - { "e*", T_MAIL, C_MAIL, 0 }, - { "u*", T_MAIL_UNSEEN,C_MAIL, 0 }, - { "s*", T_SENSOR, C_SENSOR, 1 }, - { "x*", T_EXEC, C_EXEC, 1 }, - { "y*", T_EXPR, C_EXPR, 1 }, - { "jc", T_IMON_CPU, C_IMON, 1 }, - { "jv", T_IMON_VER, C_IMON, 0 }, - { "jd", T_IMON_DATE, C_IMON, 0 }, - { "jm", T_IMON_TIME, C_IMON, 0 }, - { "ji*",T_IMON_RIN, C_IMON, 1 }, - { "jo*",T_IMON_ROUT, C_IMON, 1 }, - { "js*",T_IMON_STATUS,C_IMON, 0 }, - { "jn*",T_IMON_PHONE, C_IMON, 0 }, - { "jp*",T_IMON_IP, C_IMON, 0 }, - { "jt*",T_IMON_OTIME, C_IMON, 0 }, - { "jk*",T_IMON_CHARGE,C_IMON, 0 }, - { "kn", T_TELMON_NUMBER, C_TELMON,0 }, - { "km", T_TELMON_MSN, C_TELMON, 0 }, - { "kd", T_TELMON_DATE, C_TELMON, 0 }, - { "kt", T_TELMON_TIME, C_TELMON, 0 }, - { "", -1, 0 }}; - -static int bar_type (char tag) -{ - switch (tag) { - case 'l': - return BAR_L; - case 'r': - return BAR_R; - case 'u': - return BAR_U; - case 'd': - return BAR_D; - case 't': - return BAR_T; - default: - return 0; - } -} - -static int get_token (char *s, char **p, int bar, int usage[]) -{ - char c; - int i, l; - - for (i=0; Symtab[i].token!=-1; i++) { - if (bar && !Symtab[i].bar) continue; - l=strlen(Symtab[i].symbol); - if (Symtab[i].symbol[l-1]=='*') { - if (Symtab[i].token<T_EXTENDED) { - error ("ERROR: internal error in symbol '%s'", Symtab[i].symbol); - return -1; - } - c=*(s+l-1); - if (strncmp(Symtab[i].symbol, s, l-1)==0 && c>='0' && c<='9') { - *p=s+l; - usage[Symtab[i].token]|=(1<<(c-'0')); - usage[Symtab[i].class]=1; - return Symtab[i].token+(c<<8); - } - } else if (strncmp(Symtab[i].symbol, s, l)==0) { - *p=s+l; - usage[Symtab[i].token]=1; - usage[Symtab[i].class]=1; - return Symtab[i].token; - } - } - return -1; -} - -char *parse_row (char *string, int supported_bars, int usage[]) -{ - static char buffer[256]; - char *s=string; - char *p=buffer; - int token, token2; - int type, len; - - do { - switch (*s) { - - case '%': - if ((token=get_token (++s, &s, 0, usage))==-1) { - error ("WARNING: unknown token <%%%c> in <%s>", *s, string); - } else { - *p++='%'; - *p++=token&255; - if (token>256) *p++=token>>8; - } - break; - - case '$': - type=bar_type(tolower(*++s)); - if (type==0) { - error ("WARNING: invalid bar type <$%c> in <%s>", *s, string); - break; - } - if (!(type & supported_bars)) { - error ("WARNING: driver does not support bar type '%c'", *s); - break; - } - if (isupper(*s)) type |= BAR_LOG; - len=strtol(s+1, &s, 10); - if (len<1 || len>127) { - error ("WARNING: invalid bar length in <%s>", string); - break; - } - if ((token=get_token (s, &s, 0, usage))==-1) { - error ("WARNING: unknown token <$%c> in <%s>", *s, string); - break; - } - token2=-1; - if (*s=='+') { - if ((type & BAR_H) && (supported_bars & BAR_H2)) { - type |= BAR_H2; - } else if ((type & BAR_V) && (supported_bars & BAR_V2)) { - type |= BAR_V2; - } else { - error ("WARNING: driver does not support double bars"); - break; - } - if ((token2=get_token (s+1, &s, 0, usage))==-1) { - error ("WARNING: unknown token <$%c> in <%s>", *s, string); - break; - } - } - else if (*s == ',' && (type & BAR_T)) - token2=strtol(s+1, &s, 10); /* get horizontal length */ - *p++='$'; - *p++=type; - *p++=len; - *p++=token&255; - if (token>256) *p++=token>>8; - if (token2!=-1) { - *p++=token2&255; - if (token>256 && !(type & BAR_T)) *p++=token2>>8; - } - break; - - case '&': - if (*(s+1)<'1'||*(s+1)>'9') { - s++; - error ("WARNING: illegal '&%c' in <%s>", *s, string); - } else { - *p++=*s++; - *p++=*s++; - } - break; - - case '\\': - if (*(s+1)=='\\') { - *p++='\\'; - s++; - } else { - unsigned int c=0; int n; - sscanf (s+1, "%3o%n", &c, &n); - if (c==0 || c>255) { - error ("WARNING: illegal '\\' in <%s>", string); - } else { - *p++=c; - s+=n+1; - } - } - break; - - default: - if ((*p++=*s)!='\0') s++; - } - - } while (*s); - - *p='\0'; - return buffer; -} - -int parse_gpo (char *string, int usage[]) -{ - char *s=string; - int token=-1; - - if (*s=='%') { - if ((token=get_token (++s, &s, 0, usage))==-1) { - error ("WARNING: unknown token <%%%c> in <%s>", *s, string); - } - } - - if (*s!='\0') { - error ("WARNING: error while parsing <%s>", string); - } - - return token; -} diff --git a/parser.h b/parser.h deleted file mode 100644 index 05ac93d..0000000 --- a/parser.h +++ /dev/null @@ -1,129 +0,0 @@ -/* $Id: parser.h,v 1.17 2004/01/05 11:57:38 reinelt Exp $ - * - * row definition parser - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: parser.h,v $ - * Revision 1.17 2004/01/05 11:57:38 reinelt - * added %y tokens to make the Evaluator useable - * - * Revision 1.16 2003/11/11 04:40:20 reinelt - * WIFI patch from Xavier Vello - * - * Revision 1.15 2003/10/12 06:08:28 nicowallmeier - * imond/telmond support - * - * Revision 1.14 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.13 2003/09/01 04:09:35 reinelt - * icons nearly finished, but MatrixOrbital only - * - * Revision 1.12 2003/06/21 05:46:18 reinelt - * DVB client integrated - * - * Revision 1.11 2001/03/14 13:19:29 ltoetsch - * Added pop3/imap4 mail support - * - * Revision 1.10 2001/03/07 18:10:21 ltoetsch - * added e(x)ec commands - * - * Revision 1.9 2001/03/02 10:18:03 ltoetsch - * added /proc/apm battery stat - * - * Revision 1.8 2001/02/19 00:15:46 reinelt - * - * integrated mail and seti client - * major rewrite of parser and tokenizer to support double-byte tokens - * - * Revision 1.7 2001/02/16 08:23:09 reinelt - * - * new token 'ic' (ISDN connected) by Carsten Nau <info@cnau.de> - * - * Revision 1.6 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.5 2000/05/21 06:20:35 reinelt - * - * added ppp throughput - * token is '%t[iomt]' at the moment, but this will change in the near future - * - * Revision 1.4 2000/03/19 08:41:28 reinelt - * - * documentation available! README, README.MatrixOrbital, README.Drivers - * added Skeleton.c as a starting point for new drivers - * - * Revision 1.3 2000/03/18 10:31:06 reinelt - * - * added sensor handling (for temperature etc.) - * made data collecting happen only if data is used - * (reading /proc/meminfo takes a lot of CPU!) - * released lcd4linux-0.92 - * - * Revision 1.2 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.1 2000/03/13 15:58:24 reinelt - * - * release 0.9 - * moved row parsing to parser.c - * all basic work finished - * - */ - -#ifndef _PARSER_H_ -#define _PARSER_H_ - -typedef enum { - T_PERCENT=128, T_DOLLAR, T_AMPERSAND, - T_OS, T_RELEASE, T_CPU, T_RAM, - T_MEM_TOTAL, T_MEM_USED, T_MEM_FREE, T_MEM_SHARED, T_MEM_BUFFER, T_MEM_CACHE, T_MEM_AVAIL, - T_LOAD_1, T_LOAD_2, T_LOAD_3, T_OVERLOAD, - T_CPU_USER, T_CPU_NICE, T_CPU_SYSTEM, T_CPU_BUSY, T_CPU_IDLE, - T_DISK_READ, T_DISK_WRITE, T_DISK_TOTAL, T_DISK_MAX, - T_ETH_RX, T_ETH_TX, T_ETH_TOTAL, T_ETH_MAX, - T_PPP_RX, T_PPP_TX, T_PPP_TOTAL, T_PPP_MAX, - T_ISDN_USED, T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, - T_WIFI_SIGNAL, T_WIFI_LINK, T_WIFI_NOISE, - T_SETI_PRC, T_SETI_CPU, - T_BATT_PERC, T_BATT_STAT, T_BATT_DUR, - T_DVB_STRENGTH, T_DVB_SNR, - T_EXTENDED, - T_MAIL, T_MAIL_UNSEEN, - T_SENSOR, - T_EXEC, - T_EXPR, - T_IMON_CPU, T_IMON_VER, T_IMON_DATE, T_IMON_TIME, T_IMON_RIN, T_IMON_ROUT, - T_IMON_STATUS, T_IMON_PHONE, T_IMON_IP, T_IMON_OTIME, T_IMON_CHARGE, - T_TELMON_NUMBER, T_TELMON_MSN, T_TELMON_TIME, T_TELMON_DATE -} TOKEN; - -typedef enum { - C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_WIFI, C_SETI, C_BATT, C_DVB, - C_MAIL, C_SENSOR, C_EXEC, C_EXPR, C_IMON, C_TELMON -} CLASS; - -char *parse_row (char *string, int supported_bars, int usage[]); -int parse_gpo (char *string, int usage[]); - -#endif @@ -1,4 +1,4 @@ -/* $Id: plugin.c,v 1.17 2004/02/10 06:54:39 reinelt Exp $ +/* $Id: plugin.c,v 1.18 2004/02/10 07:42:35 reinelt Exp $ * * plugin handler for the Evaluator * @@ -22,6 +22,9 @@ * * * $Log: plugin.c,v $ + * Revision 1.18 2004/02/10 07:42:35 reinelt + * cut off all old-style files which are no longer used with NextGeneration + * * Revision 1.17 2004/02/10 06:54:39 reinelt * DVB plugin ported * @@ -139,6 +142,7 @@ int plugin_init_cpuinfo (void); int plugin_init_meminfo (void); int plugin_init_netdev (void); int plugin_init_ppp (void); +int plugin_init_dvb (void); int plugin_init_i2c_sensors (void); int plugin_init_xmms (void); diff --git a/processor.c b/processor.c deleted file mode 100644 index afb0757..0000000 --- a/processor.c +++ /dev/null @@ -1,1186 +0,0 @@ -/* $Id: processor.c,v 1.55 2004/01/30 07:12:35 reinelt Exp $ - * - * main data processing - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: processor.c,v $ - * Revision 1.55 2004/01/30 07:12:35 reinelt - * HD44780 busy-flag support from Martin Hejl - * loadavg() uClibc replacement from Martin Heyl - * round() uClibc replacement from Martin Hejl - * warning in i2c_sensors fixed - * [ - * - * Revision 1.54 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.53 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.52 2004/01/05 11:57:38 reinelt - * added %y tokens to make the Evaluator useable - * - * Revision 1.51 2003/11/24 11:34:54 reinelt - * - * 'Fixed' Rows which do not scroll by Lars Kempe - * temporary workaround for debian kernel-header bug - * - * Revision 1.50 2003/11/11 04:40:20 reinelt - * WIFI patch from Xavier Vello - * - * Revision 1.49 2003/10/12 06:08:28 nicowallmeier - * imond/telmond support - * - * Revision 1.48 2003/10/12 04:46:19 reinelt - * - * - * first try to integrate the Evaluator into a display driver (MatrixOrbital here) - * small warning in processor.c fixed (thanks to Zachary Giles) - * workaround for udelay() on alpha (no msr.h avaliable) (thanks to Zachary Giles) - * - * Revision 1.47 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.46 2003/10/03 03:51:14 reinelt - * start support for new MatrixOrbital MX2 displays - * - * Revision 1.45 2003/09/11 04:09:53 reinelt - * minor cleanups - * - * Revision 1.44 2003/09/10 15:59:39 reinelt - * minor cleanups - * - * Revision 1.43 2003/09/10 14:01:53 reinelt - * icons nearly finished\! - * - * Revision 1.42 2003/09/10 08:37:09 reinelt - * icons: reorganized tick_* again... - * - * Revision 1.41 2003/09/10 03:48:23 reinelt - * Icons for M50530, new processing scheme (Ticks.Text...) - * - * Revision 1.40 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * 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 - * - * Revision 1.37 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.36 2003/08/17 16:37:39 reinelt - * more icon framework - * - * Revision 1.35 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.34 2003/07/21 06:34:14 reinelt - * bars on virtual rows fixed - * - * Revision 1.33 2003/07/21 06:10:11 reinelt - * removed maxlen parameter from process_row() - * - * Revision 1.32 2003/06/21 05:46:18 reinelt - * DVB client integrated - * - * Revision 1.31 2003/06/13 06:35:56 reinelt - * added scrolling capability - * - * Revision 1.30 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.29 2003/02/05 04:31:38 reinelt - * - * T_EXEC: remove trailing CR/LF - * T_EXEC: deactivated maxlen calculation (for I don't understand what it is for :-) - * - * Revision 1.28 2002/12/05 19:23:01 reinelt - * fixed undefined operations found by gcc3 - * - * Revision 1.27 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.26 2001/05/06 10:01:27 reinelt - * - * fixed a bug which prevented extendet tokens to be used for GPO's - * many thanks to Carsten Nau! - * - * Revision 1.25 2001/03/17 11:11:31 ltoetsch - * bugfix: max for BAR_T - * - * Revision 1.24 2001/03/16 16:40:17 ltoetsch - * implemented time bar - * - * Revision 1.23 2001/03/16 09:28:08 ltoetsch - * bugfixes - * - * Revision 1.22 2001/03/15 15:49:23 ltoetsch - * fixed compile HD44780.c, cosmetics - * - * Revision 1.21 2001/03/15 09:47:13 reinelt - * - * some fixes to ppdef - * off-by-one bug in processor.c fixed - * - * Revision 1.20 2001/03/14 13:19:29 ltoetsch - * Added pop3/imap4 mail support - * - * Revision 1.19 2001/03/13 08:34:15 reinelt - * - * corrected a off-by-one bug with sensors - * - * Revision 1.18 2001/03/08 15:25:38 ltoetsch - * improved exec - * - * Revision 1.17 2001/03/08 08:39:55 reinelt - * - * fixed two typos - * - * Revision 1.16 2001/03/07 18:10:21 ltoetsch - * added e(x)ec commands - * - * Revision 1.15 2001/03/02 10:18:03 ltoetsch - * added /proc/apm battery stat - * - * Revision 1.14 2001/02/19 00:15:46 reinelt - * - * integrated mail and seti client - * major rewrite of parser and tokenizer to support double-byte tokens - * - * Revision 1.13 2001/02/16 14:15:11 reinelt - * - * fixed type in processor.c - * GPO documentation update from Carsten - * - * Revision 1.12 2001/02/16 08:23:09 reinelt - * - * new token 'ic' (ISDN connected) by Carsten Nau <info@cnau.de> - * - * Revision 1.11 2001/02/14 07:40:16 reinelt - * - * first (incomplete) GPO implementation - * - * Revision 1.10 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.9 2001/02/11 23:34:07 reinelt - * - * fixed a small bug where the throughput of an offline ISDN connection - * is displayed as '----', but the online value is 5 chars long. - * corrected to ' ----'. Thanks to Carsten Nau <info@cnau.de> - * - * Revision 1.8 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.7 2000/07/31 10:43:44 reinelt - * - * some changes to support kernel-2.4 (different layout of various files in /proc) - * - * Revision 1.6 2000/05/21 06:20:35 reinelt - * - * added ppp throughput - * token is '%t[iomt]' at the moment, but this will change in the near future - * - * Revision 1.5 2000/04/15 11:56:35 reinelt - * - * more debug messages - * - * Revision 1.4 2000/04/15 11:13:54 reinelt - * - * added '-d' (debugging) switch - * added several debugging messages - * removed config entry 'Delay' for HD44780 driver - * delay loop for HD44780 will be calibrated automatically - * - * Revision 1.3 2000/04/01 16:22:38 reinelt - * - * bug that caused a segfault in processor.c fixed (thanks to herp) - * - * Revision 1.2 2000/03/23 07:24:48 reinelt - * - * PPM driver up and running (but slow!) - * - * Revision 1.1 2000/03/22 07:33:50 reinelt - * - * FAQ added - * new modules 'processor.c' contains all data processing - * - */ - -/* - * exported functions: - * - * void process_init (void); - * does all necessary initializations - * - * void process (); - * processes a whole screen - * - */ - - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <sys/time.h> -#include <math.h> - -#include "debug.h" -#include "cfg.h" -#include "system.h" -#include "isdn.h" -#include "wifi.h" -#include "parser.h" -#include "display.h" -#include "bar.h" -#include "processor.h" -#include "mail.h" -#include "battery.h" -#include "dvb.h" -#include "seti.h" -#include "exec.h" -#include "expr.h" -#include "imon.h" - -#define ROWS 64 -#define ICONS 8 -#define GPOS 16 - -static char *row[ROWS+1]; -static int gpo[GPOS+1]; -static int rows, cols, xres, yres, supported_bars, icons, gpos; -static int lines, scroll, turn, fixed; -static int token_usage[256]={0,}; - -static struct { int total, used, free, shared, buffer, cache, avail; } ram; -static struct { double load1, load2, load3, overload; } load; -static struct { double user, nice, system, idle; } busy; -static struct { int read, write, total, max, peak; } disk; -static struct { int rx, tx, total, max, peak, bytes; } net; -static struct { int usage, in, out, total, max, peak; } isdn; -static struct { int signal, link, noise; } wifi; -static struct { int rx, tx, total, max, peak; } ppp; -static struct { int perc, stat; double dur; } batt; -static struct { double perc, cput; } seti; -static struct { int num, unseen;} mail[MAILBOXES+1]; -static struct { double val, min, max; } sensor[SENSORS+1]; -static struct { double strength, snr; } dvb; -static struct imonchannel imonch[CHANNELS+1]; -static struct imon imon; -static struct telmon telmon; - -extern int tick, tack; -static int tick_text, tick_bar, tick_icon, tick_gpo; - -#ifdef DONT_HAVE_ROUND -double round(double x) { - static int y=0; - if (x<0) { - y = (x-0.5); - } else { - y = (x-0.5); - } - return((double)y); -} -#endif - -static double query (int token) -{ - switch (token&255) { - - case T_MEM_TOTAL: - return ram.total; - case T_MEM_USED: - return ram.used; - case T_MEM_FREE: - return ram.free; - case T_MEM_SHARED: - return ram.shared; - case T_MEM_BUFFER: - return ram.buffer; - case T_MEM_CACHE: - return ram.cache; - case T_MEM_AVAIL: - return ram.avail; - - case T_LOAD_1: - return load.load1; - case T_LOAD_2: - return load.load2; - case T_LOAD_3: - return load.load3; - - case T_CPU_USER: - return busy.user; - case T_CPU_NICE: - return busy.nice; - case T_CPU_SYSTEM: - return busy.system; - case T_CPU_BUSY: - return 1.0-busy.idle; - case T_CPU_IDLE: - return busy.idle; - - case T_DISK_READ: - return disk.read; - case T_DISK_WRITE: - return disk.write; - case T_DISK_TOTAL: - return disk.total; - case T_DISK_MAX: - return disk.max; - - case T_ETH_RX: - return net.rx; - case T_ETH_TX: - return net.tx; - case T_ETH_TOTAL: - return net.total; - case T_ETH_MAX: - return net.max; - - case T_ISDN_IN: - return isdn.in; - case T_ISDN_OUT: - return isdn.out; - case T_ISDN_TOTAL: - return isdn.total; - case T_ISDN_MAX: - return isdn.max; - case T_ISDN_USED: - return isdn.usage; - - case T_WIFI_SIGNAL: - return wifi.signal; - case T_WIFI_LINK: - return wifi.link; - case T_WIFI_NOISE: - return wifi.noise; - - case T_PPP_RX: - return ppp.rx; - case T_PPP_TX: - return ppp.tx; - case T_PPP_TOTAL: - return ppp.total; - case T_PPP_MAX: - return ppp.max; - - case T_SETI_PRC: - return seti.perc; - case T_SETI_CPU: - return seti.cput; - - case T_BATT_PERC: - return batt.perc; - case T_BATT_STAT: - return batt.stat; - case T_BATT_DUR: - return batt.dur; - - case T_DVB_STRENGTH: - return dvb.strength; - case T_DVB_SNR: - return dvb.snr; - - case T_MAIL: - return mail[(token>>8)-'0'].num; - - case T_MAIL_UNSEEN: - return mail[(token>>8)-'0'].unseen; - - case T_SENSOR: - return sensor[(token>>8)-'0'].val; - - case T_EXEC: - return exec[(token>>8)-'0'].val; - - case T_EXPR: - return expr[(token>>8)-'0'].val; - - case T_IMON_CPU: - return imon.cpu; - - case T_IMON_RIN: - return ((double)imonch[(token>>8)-'0'].rate_in)/1024; - - case T_IMON_ROUT: - return ((double)imonch[(token>>8)-'0'].rate_out)/1024; - } - return 0.0; -} - - -/* return a value 0..1 */ -static double query_bar (int token) -{ - int i; - double value=query(token); - - switch (token & 255) { - - case T_MEM_TOTAL: - case T_MEM_USED: - case T_MEM_FREE: - case T_MEM_SHARED: - case T_MEM_BUFFER: - case T_MEM_CACHE: - case T_MEM_AVAIL: - return value/ram.total; - - case T_LOAD_1: - case T_LOAD_2: - case T_LOAD_3: - return value/load.overload; - - case T_DISK_READ: - case T_DISK_WRITE: - case T_DISK_MAX: - return value/disk.peak; - case T_DISK_TOTAL: - return value/disk.peak/2.0; - - case T_ETH_RX: - case T_ETH_TX: - case T_ETH_MAX: - return value/net.peak; - case T_ETH_TOTAL: - return value/net.peak/2.0; - - case T_ISDN_IN: - case T_ISDN_OUT: - case T_ISDN_MAX: - return value/isdn.peak; - case T_ISDN_TOTAL: - return value/isdn.peak/2.0; - - case T_WIFI_SIGNAL: - case T_WIFI_LINK: - case T_WIFI_NOISE: - return value/100; - - case T_PPP_RX: - case T_PPP_TX: - case T_PPP_MAX: - return value/ppp.peak; - case T_PPP_TOTAL: - return value/ppp.peak/2.0; - - case T_SETI_PRC: - return value; - - case T_BATT_PERC: - { - static int alarm; - alarm=((alarm+1) % 3); - if(value < atoi(cfg_get(NULL, "battwarning", "10")) && !alarm) /* flash bar */ - value = 0; - return value/100; - } - - case T_SENSOR: - i=(token>>8)-'0'; - return (value-sensor[i].min)/(sensor[i].max-sensor[i].min); - - case T_IMON_CPU: - return value/100; - - case T_IMON_RIN: - i=(token>>8)-'0'; - return value/(imonch[i].max_in/8); - - case T_IMON_ROUT: - i=(token>>8)-'0'; - return value/(imonch[i].max_out/8); - } - - return value; -} - - -static void print_token (int token, char **p, char *start) -{ - double val; - int i; - - switch (token & 255) { - - case T_PERCENT: - *(*p)++='%'; - break; - - case T_DOLLAR: - *(*p)++='$'; - break; - - case T_OS: - *p+=sprintf (*p, "%s", System()); - break; - - case T_RELEASE: - *p+=sprintf (*p, "%s", Release()); - break; - - case T_CPU: - *p+=sprintf (*p, "%s", Processor()); - break; - - case T_RAM: - *p+=sprintf (*p, "%d", Memory()); - break; - - case T_OVERLOAD: - *(*p)++=load.load1>load.overload?'!':' '; - break; - - case T_MEM_TOTAL: - case T_MEM_USED: - case T_MEM_FREE: - case T_MEM_SHARED: - case T_MEM_BUFFER: - case T_MEM_CACHE: - case T_MEM_AVAIL: - *p+=sprintf (*p, "%6.0f", query(token)); - break; - - case T_LOAD_1: - case T_LOAD_2: - case T_LOAD_3: - case T_SENSOR: - val=query(token); - if (val<10.0) - *p+=sprintf (*p, "%5.2f", val); - else if (val<100.0) - *p+=sprintf (*p, "%5.1f", val); - else - *p+=sprintf (*p, "%5.0f", val); - break; - - case T_CPU_USER: - case T_CPU_NICE: - case T_CPU_SYSTEM: - case T_CPU_BUSY: - case T_CPU_IDLE: - *p+=sprintf (*p, "%3.0f", 100.0*query(token)); - break; - - case T_ETH_RX: - case T_ETH_TX: - case T_ETH_MAX: - case T_ETH_TOTAL: - val=query(token); - if (net.bytes) - val/=1024.0; - *p+=sprintf (*p, "%5.0f", val); - break; - - case T_ISDN_IN: - case T_ISDN_OUT: - case T_ISDN_MAX: - case T_ISDN_TOTAL: - if (isdn.usage) - *p+=sprintf (*p, "%5.0f", query(token)); - else - *p+=sprintf (*p, " ----"); - break; - - case T_ISDN_USED: - if (isdn.usage) - *p+=sprintf (*p, "*"); - else - *p+=sprintf (*p, " "); - break; - - case T_WIFI_SIGNAL: - case T_WIFI_LINK: - case T_WIFI_NOISE: - *p+=sprintf (*p, "%3.0f", query(token)); - break; - - - case T_SETI_PRC: - val=100.0*query(token); - if (val<100.0) - *p+=sprintf (*p, "%4.1f", val); - else - *p+=sprintf (*p, " 100"); - break; - case T_SETI_CPU: - val=query(token); - *p+=sprintf (*p, "%2d.%2.2d:%2.2d", (int)val/86400, - (int)((int)val%86400)/3600, - (int)(((int)val%86400)%3600)/60 ); - break; - - case T_BATT_PERC: - *p+=sprintf(*p, "%3.0f", query(token)); - 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; - } - } - (*p)++; - break; - case T_BATT_DUR: - { - char eh = 's'; - val = query(token); - if (val > 99) { - val /= 60; - eh = 'm'; - } - if (val > 99) { - val /= 60; - eh = 'h'; - } - if (val > 99) { - val /= 24; - eh = 'd'; - } - *p+=sprintf(*p, "%2.0f%c", val, eh); - } - break; - - case T_DVB_STRENGTH: - case T_DVB_SNR: - *p+=sprintf (*p, "%5.1f", 100.0*query(token)); - break; - - case T_EXEC: - i = (token>>8)-'0'; - *p+=sprintf (*p, "%.*s",cols-(int)(*p-start), exec[i].s); - break; - - case T_EXPR: - i = (token>>8)-'0'; - *p+=sprintf (*p, "%.*s",cols-(int)(*p-start), expr[i].s); - break; - - case T_IMON_VER: - *p+=sprintf (*p, "%s", ImonVer()); - break; - - case T_IMON_DATE: - *p+=sprintf (*p, "%s ", imon.date); - break; - - case T_IMON_TIME: - *p+=sprintf (*p, "%s ", imon.time); - break; - - case T_IMON_CPU: - *p+=sprintf (*p, "%3.0f", query(token)); - break; - - case T_IMON_RIN: - case T_IMON_ROUT: - *p+=sprintf(*p, "%4.1f", query(token)); - break; - - case T_IMON_STATUS: - *p+=sprintf(*p, "%s", imonch[(token>>8)-'0'].status); - break; - - case T_IMON_PHONE: - *p+=sprintf(*p, "%s", imonch[(token>>8)-'0'].phone); - break; - - case T_IMON_IP: - *p+=sprintf(*p, "%s", imonch[(token>>8)-'0'].ip); - break; - - case T_IMON_OTIME: - *p+=sprintf(*p, "%s", imonch[(token>>8)-'0'].otime); - break; - - case T_IMON_CHARGE: - *p+=sprintf(*p, "%s", imonch[(token>>8)-'0'].charge); - break; - - case T_TELMON_NUMBER: - *p+=sprintf(*p, "%s", telmon.number); - break; - - case T_TELMON_MSN: - *p+=sprintf(*p, "%s", telmon.msn); - break; - - case T_TELMON_DATE: - *p+=sprintf(*p, "%s", telmon.date); - break; - - case T_TELMON_TIME: - *p+=sprintf(*p, "%s", telmon.time); - break; - - default: - *p+=sprintf (*p, "%5.0f", query(token)); - } -} - - -static void collect_data (void) -{ - int i; - - if (token_usage[C_MEM]) { - Ram (&ram.total, &ram.free, &ram.shared, &ram.buffer, &ram.cache); - ram.used=ram.total-ram.free; - ram.avail=ram.free+ram.buffer+ram.cache; - } - - if (token_usage[C_LOAD]) { - Load (&load.load1, &load.load2, &load.load3); - } - - if (token_usage[C_CPU]) { - Busy (&busy.user, &busy.nice, &busy.system, &busy.idle); - } - - if (token_usage[C_DISK]) { - Disk (&disk.read, &disk.write); - disk.total=disk.read+disk.write; - disk.max=disk.read>disk.write?disk.read:disk.write; - if (disk.max>disk.peak) disk.peak=disk.max; - } - - if (token_usage[C_ETH]) { - Net (&net.rx, &net.tx, &net.bytes); - net.total=net.rx+net.tx; - net.max=net.rx>net.tx?net.rx:net.tx; - if (net.max>net.peak) net.peak=net.max; - } - - if (token_usage[C_ISDN]) { - Isdn (&isdn.in, &isdn.out, &isdn.usage); - isdn.total=isdn.in+isdn.out; - isdn.max=isdn.in>isdn.out?isdn.in:isdn.out; - if (isdn.max>isdn.peak) isdn.peak=isdn.max; - } - - if (token_usage[C_WIFI]) { - Wifi (&wifi.signal, &wifi.link, &wifi.noise); - } - - if (token_usage[C_PPP]) { - PPP (0, &ppp.rx, &ppp.tx); - ppp.total=ppp.rx+ppp.tx; - ppp.max=ppp.rx>ppp.tx?ppp.rx:ppp.tx; - if (ppp.max>ppp.peak) ppp.peak=ppp.max; - } - - if (token_usage[C_SETI]) { - Seti (&seti.perc, &seti.cput); - } - - if (token_usage[C_BATT]) { - Battery (&batt.perc, &batt.stat, &batt.dur); - } - - if (token_usage[C_DVB]) { - DVB (&dvb.strength, &dvb.snr); - } - - if (token_usage[C_IMON]) { - if (token_usage[T_IMON_CPU] || - token_usage[T_IMON_DATE] || - token_usage[T_IMON_TIME]) { - Imon (&imon, T_IMON_CPU, T_IMON_DATE+T_IMON_TIME); - } - for (i=0; i<=CHANNELS; i++) { - if (((1<<i) & token_usage[T_IMON_RIN]) || - ((1<<i) & token_usage[T_IMON_ROUT]) || - ((1<<i) & token_usage[T_IMON_STATUS]) || - ((1<<i) & token_usage[T_IMON_PHONE]) || - ((1<<i) & token_usage[T_IMON_IP]) || - ((1<<i) & token_usage[T_IMON_OTIME]) || - ((1<<i) & token_usage[T_IMON_CHARGE])){ - ImonCh(i, &imonch[i], token_usage); - } - } - } - - if (token_usage[C_TELMON]) { - Telmon (&telmon); - } - - for (i=0; i<=MAILBOXES; i++) { - if (token_usage[T_MAIL]&(1<<i) || token_usage[T_MAIL_UNSEEN]&(1<<i) ) { - Mail (i, &mail[i].num, &mail[i].unseen); - } - } - - for (i=0; i<=SENSORS; i++) { - if (token_usage[T_SENSOR]&(1<<i)) { - Sensor (i, &sensor[i].val, &sensor[i].min, &sensor[i].max); - } - } - - for (i=0; i<=EXECS; i++) { - if (token_usage[T_EXEC]&(1<<i)) { - Exec (i, exec[i].s, &exec[i].val); - } - } - - for (i=0; i<=EXPRS; i++) { - if (token_usage[T_EXPR]&(1<<i)) { - Expr (i, expr[i].s, &exec[i].val); - } - } - -} - - -static char *process_row (char *data, int row, int len) -{ - static char buffer[256]; - char *p=buffer; - char *s=data; - int token; - int n; - - do { - if (*s=='%') { - token = *(unsigned char*)++s; - if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8; - print_token (token, &p, buffer); - - } else if (*s=='$') { - double val1, val2; - int i, type, len; - type=*++s; - len=*++s; - token = *(unsigned char*)++s; - if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8; - val1=query_bar(token); - val2=val1; - if (type & (BAR_H2 | BAR_V2)) { - token = *(unsigned char*)++s; - if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8; - val2=query_bar(token); - } - else if (type & BAR_T) - val2 = *(unsigned char*)++s; /* width */ - if (type & BAR_H) - lcd_bar (type, row, p-buffer+1, len*xres, val1*len*xres, val2*len*xres); - else if (type & BAR_T) - lcd_bar (type, row, p-buffer+1, len*yres, val1*len*yres, val2*xres); - else - lcd_bar (type, row, p-buffer+1, len*yres, val1*len*yres, val2*len*yres); - - if (type & BAR_H) { - for (i=0; i<len && p-buffer<cols; i++) - *p++='\t'; - } else { - *p++='\t'; - } - - } else if (*s=='&') { - if (lcd_icon(*(++s)-'0', 0, row, p-buffer+1)<0) - *p++='*'; // error - else - *p++='\t'; // all ok - - } else { - *p++=*s; - } - - } while (*s++); - - // pad with blanks - for (n=strlen(buffer); n<cols; n++) { - buffer[n]=' '; - } - buffer[n]='\0'; - - return buffer; -} - - -static int process_gpo (int n) -{ - int token; - int val; - - token=gpo[n]; - val=round(query(token)); - - return val; -} - - -static int Turn (void) -{ - static struct timeval old = {tv_sec:0, tv_usec:0}; - static struct timeval new = {tv_sec:0, tv_usec:0}; - struct timeval now; - int initialized; - - if (turn<=0) return 0; - - gettimeofday (&now, NULL); - - // first time invocation? - initialized=(new.tv_sec>0); - - if (now.tv_sec==new.tv_sec ? now.tv_usec>new.tv_usec : now.tv_sec>new.tv_sec) { - old=now; - new.tv_sec =old.tv_sec; - new.tv_usec=old.tv_usec+turn*1000; - while (new.tv_usec>=1000000) { - new.tv_usec-=1000000; - new.tv_sec++; - } - return initialized; - } - return 0; -} - - -void process_init (void) -{ - int i; - - load.overload=atof(cfg_get(NULL, "overload", "2.0")); - - - lcd_query (&rows, &cols, &xres, &yres, &supported_bars, &icons, &gpos); - if (rows>ROWS) { - error ("%d rows exceeds limit, reducing to %d rows", rows, ROWS); - rows=ROWS; - } - if (icons>ICONS) { - error ("%d icons exceeds limit, reducing to %d icons", icons, ICONS); - icons=ICONS; - } - if (gpos>GPOS) { - error ("%d gpos exceeds limit, reducing to %d gpos", gpos, GPOS); - gpos=GPOS; - } - debug ("Display: %d rows, %d columns, %dx%d pixels, %d icons, %d GPOs", rows, cols, xres, yres, icons, gpos); - - - if (cfg_number(NULL, "Rows", 1, 1, 1000, &lines)<0) { - lines=1; - error ("ignoring bad 'Rows' value and using '%d'", lines); - } - if (lines>ROWS) { - error ("%d virtual rows exceeds limit, reducing to %d rows", lines, ROWS); - lines=ROWS; - } - if (lines>rows) { - if (cfg_number(NULL, "Scroll", 1, 1, 1000, &scroll)<0) { - scroll=1; - error ("ignoring bad 'Scroll' value and using '%d'", scroll); - } - if (scroll>rows) { - error ("'Scroll' entry in %s is %d, > %d display rows.", cfg_source(), scroll, rows); - error ("This may lead to unexpected results!"); - } - if (cfg_number(NULL, "Fixed", 0, -1000000, 1000000, &fixed)<0) { - fixed=0; - error ("ignoring bad 'Fixed' value and using '%d'", fixed); - } - if (abs(fixed)>=rows) { - error ("'Fixed' entry in %s is abs(%d), >= %d display rows.", cfg_source(), fixed, rows); - fixed=(fixed<0)? -rows+1 : rows-1; - error ("ignoring bad 'Fixed' value and using '%d'", fixed); - } - if (cfg_number(NULL, "Turn", 1000, 1, 1000000, &turn)<0) { - turn=1000; - error ("ignoring bad 'Scroll' value and using '%d'", turn); - } - debug ("Virtual: %d rows, scroll %d lines every %d msec", lines, scroll, turn); - } else { - lines=rows; - scroll=0; - turn=0; - fixed=0; - } - - if (cfg_number(NULL, "Tick.Text", 500, 1, 1000000, &tick_text)<0) { - tick_text=500; - error ("ignoring bad 'Tick.Text' value and using '%d'", tick_text); - } - if (cfg_number(NULL, "Tick.Bar", 100, 1, 1000000, &tick_bar)<0) { - tick_bar=100; - error ("ignoring bad 'Tick.Bar' value and using '%d'", tick_bar); - } - if (cfg_number(NULL, "Tick.Icon", 100, 1, 1000000, &tick_icon)<0) { - tick_icon=100; - error ("ignoring bad 'Tick.Icon' value and using '%d'", tick_icon); - } - if (cfg_number(NULL, "Tick.GPO", 100, 1, 1000000, &tick_gpo)<0) { - tick_gpo=100; - error ("ignoring bad 'Tick.GPO' value and using '%d'", tick_gpo); - } - - // global Tick is minimum of tick_text, _bar, _gpo - tick=tick_text; - if (tick>tick_bar) tick=tick_bar; - if (tick>tick_gpo) tick=tick_gpo; - - // global Tack is minimum of tick, tick_gpo - tack=tick; - if (tack>tick_icon) tack=tick_icon; - - debug ("========================"); - debug ("Timings:"); - debug ("%3d msec Text updates", tick_text); - debug ("%3d msec Bar updates", tick_bar ); - debug ("%3d msec Icon updates", tick_icon); - debug ("%3d msec GPO updates", tick_gpo ); - debug ("------------------------"); - debug ("%3d msec data collection", tick); - debug ("%3d msec data processing", tack); - debug ("========================"); - - for (i=1; i<=lines; i++) { - char buffer[8], *p; - snprintf (buffer, sizeof(buffer), "Row%d", i); - p=cfg_get(NULL, buffer, ""); - debug ("%s: %s", buffer, p); - row[i]=strdup(parse_row(p, supported_bars, token_usage)); - } - - - for (i=1; i<=gpos; i++) { - char buffer[8], *p; - snprintf (buffer, sizeof(buffer), "GPO%d", i); - p=cfg_get(NULL, buffer, ""); - debug ("%s: %s", buffer, p); - gpo[i]=parse_gpo(p, token_usage); - } - -} - - -void process (void) -{ - static int loop_tick=0; - static int loop_text=0; - static int loop_bar=0; - static int loop_icon=0; - static int loop_gpo=0; - static int offset=0; - - int i, j, val; - char *txt; - - // collect data every tick msec - if (loop_tick==0) { - collect_data(); - } - // maybe scroll - if (Turn() && loop_text==0) { - offset+=scroll; - while (offset>=lines) offset-=lines; - lcd_clear(0); // soft clear - } - - if (loop_text==0 || loop_bar==0) { - if (fixed > 0){ // first n lines fixed, rest scrolled - // fixed part - for (i=1; i<=fixed; i++) { - txt=process_row (row[i], i, cols); - if (loop_text==0) - lcd_put(i, 1, txt); - } - // scrolled part - for (i=fixed+1; i<=rows; i++) { - j=i+offset; - while (j>lines) j-=lines-fixed; - txt=process_row (row[j], i, cols); - if (loop_text==0) - lcd_put (i, 1, txt); - } - } else if (fixed < 0) { // first lines scrolled, last n fixed - // scrolled part - for (i=1; i <= rows+fixed; i++){ - j=i+offset; - while (j>lines+fixed) j-=lines+fixed; - txt=process_row (row[j], i, cols); - if (loop_text==0) - lcd_put (i, 1, txt); - } - //fixed part - for (i=rows+fixed+1; i<=rows;i++){ - j = i+lines-rows; - txt=process_row (row[j], j, cols); - if (loop_text==0) - lcd_put(i,1,txt); - } - } else { // only scroll - for (i=1; i<=rows; i++) { - j=i+offset; - while (j>lines) j-=lines; - txt=process_row (row[j], i, cols); - if (loop_text==0) - lcd_put (i, 1, txt); - } - } - } - - // update GPO's - if (loop_gpo==0) { - for (i=1; i<=gpos; i++) { - val=process_gpo (i); - lcd_gpo (i, val); - } - } - - // rotate icon animations - if (loop_icon==0) { - static int sequence=0; - for (i=1; i<=icons; i++) { - lcd_icon (i, sequence, 0, 0); - } - sequence++; - } - - // flush in every case - // note that we flush too often, but usually - // nothing has changed - lcd_flush(); - - - // increase loop counters - if ((loop_tick+=tack) >= tick ) loop_tick=0; - if ((loop_text+=tack) >= tick_text) loop_text=0; - if ((loop_bar +=tack) >= tick_bar ) loop_bar =0; - if ((loop_icon+=tack) >= tick_icon) loop_icon=0; - if ((loop_gpo +=tack) >= tick_gpo ) loop_gpo =0; - -} diff --git a/processor.h b/processor.h deleted file mode 100644 index 52e7aed..0000000 --- a/processor.h +++ /dev/null @@ -1,44 +0,0 @@ -/* $Id: processor.h,v 1.3 2003/10/05 17:58:50 reinelt Exp $ - * - * main data processing - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: processor.h,v $ - * Revision 1.3 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * 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 - * new modules 'processor.c' contains all data processing - * - */ - -#ifndef _PROCESSOR_H_ -#define _PROCESSOR_H_ - -void process_init (void); -void process (void); - -#endif diff --git a/system.c b/system.c deleted file mode 100644 index fe49ca7..0000000 --- a/system.c +++ /dev/null @@ -1,855 +0,0 @@ -/* $Id: system.c,v 1.33 2004/01/16 05:04:53 reinelt Exp $ - * - * system status retreivement - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: system.c,v $ - * Revision 1.33 2004/01/16 05:04:53 reinelt - * started plugin proc_stat which should parse /proc/stat - * which again is a paint in the a** - * thinking over implementation methods of delta functions - * (CPU load, ...) - * - * Revision 1.32 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.31 2003/12/01 07:08:51 reinelt - * - * Patches from Xavier: - * - WiFi: make interface configurable - * - "quiet" as an option from the config file - * - ignore missing "MemShared" on Linux 2.6 - * - * Revision 1.30 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.29 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.28 2003/06/26 05:31:16 reinelt - * bug in /proc/net/dev parsing fixed - * - * Revision 1.27 2003/06/13 05:11:10 reinelt - * error message cosmetics - * - * Revision 1.26 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.25 2002/12/05 19:12:47 reinelt - * sensors factor and offset patch from Petri Damsten <petri.damsten@raketti.net> - * - * Revision 1.24 2001/08/05 17:13:29 reinelt - * - * cleaned up inlude of sys/time.h and time.h - * - * Revision 1.23 2001/03/13 08:34:15 reinelt - * - * corrected a off-by-one bug with sensors - * - * Revision 1.22 2001/03/12 12:39:36 reinelt - * - * reworked autoconf a lot: drivers may be excluded, #define's went to config.h - * - * Revision 1.21 2001/03/09 12:14:24 reinelt - * - * minor cleanups - * - * Revision 1.20 2001/03/02 20:18:12 reinelt - * - * allow compile on systems without net/if_ppp.h - * - * Revision 1.19 2001/02/16 08:23:09 reinelt - * - * new token 'ic' (ISDN connected) by Carsten Nau <info@cnau.de> - * - * Revision 1.18 2000/11/17 10:36:23 reinelt - * - * fixed parsing of /proc/net/dev for 2.0 kernels - * - * Revision 1.17 2000/10/08 09:16:40 reinelt - * - * - * Linux-2.4.0-test9 changed the layout of /proc/stat (especially the disk_io line) - * rearranged parsing of some /proc files and (hopefully) made it more robust in concerns of format changes - * - * Revision 1.16 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.15 2000/08/09 11:03:07 reinelt - * - * fixed a bug in system.c where the format of /proc/net/dev was not correctly - * detected and parsed with different kernels - * - * Revision 1.14 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.13 2000/07/31 10:43:44 reinelt - * - * some changes to support kernel-2.4 (different layout of various files in /proc) - * - * Revision 1.12 2000/05/21 06:20:35 reinelt - * - * added ppp throughput - * token is '%t[iomt]' at the moment, but this will change in the near future - * - * Revision 1.11 2000/04/15 11:56:35 reinelt - * - * more debug messages - * - * Revision 1.10 2000/04/13 06:09:52 reinelt - * - * added BogoMips() to system.c (not used by now, maybe sometimes we can - * calibrate our delay loop with this value) - * - * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully - * no compiler will optimize away the delay loop! - * - * Revision 1.9 2000/03/28 07:22:15 reinelt - * - * version 0.95 released - * X11 driver up and running - * minor bugs fixed - * - * Revision 1.8 2000/03/23 07:24:48 reinelt - * - * PPM driver up and running (but slow!) - * - * Revision 1.7 2000/03/18 08:07:04 reinelt - * - * vertical bars implemented - * bar compaction improved - * memory information implemented - * - * Revision 1.6 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.5 2000/03/10 17:36:02 reinelt - * - * first unstable but running release - * - * Revision 1.4 2000/03/10 10:49:53 reinelt - * - * MatrixOrbital driver finished - * - * Revision 1.3 2000/03/07 11:01:34 reinelt - * - * system.c cleanup - * - * Revision 1.2 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - * - */ - -/* - * exported functions: - * - * char *System (void); - * returns OS name ('Linux') - * - * char *Release (void); - * returns OS release ('2.0.38') - * - * char *Processor (void); - * returns processor type ('i686') - * - * double BogoMips (void); - * returns BogoMips from /proc/cpuinfo - * - * int Memory (void); - * returns main memory (Megabytes) - * - * int Ram (int *total, int *free, int *shared, int *buffer, int *cached) - * sets various usage of ram - * retuns 0 if ok, -1 on error - * - * int Load (double *load1, double *load2, double *load3) - * sets load average during thwe last 1, 5 and 15 minutes - * retuns 0 if ok, -1 on error - * - * int Busy (double *user, double *nice, double *system, double *idle) - * sets percentage of CPU time spent in user processes, nice'd processes - * system calls and idle state - * returns 0 if ok, -1 on error - * - * int Disk (int *r, int *w); - * sets number of blocks read and written from/to all disks - * returns 0 if ok, -1 on error - * - * int Net (int *rx, int *tx, int *bytes); - * sets number of packets or bytes received and transmitted - * *bytes ist set to 0 if rx/tx are packets - * *bytes ist set to 1 if rx/tx are bytes - * returns 0 if ok, -1 on error - * - * int PPP (int unit, int *rx, int *tx); - * sets number of packets received and transmitted - * returns 0 if ok, -1 on error - * - * int Sensor (int index, double *val, double *min, double *max) - * sets the current value of the index'th sensor and - * the minimum and maximum values from the config file - * returns 0 if ok, -1 on error - * - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> -#include <ctype.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <time.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/utsname.h> -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#ifdef HAVE_NET_IF_PPP_H -#include <net/if_ppp.h> -#else -#warning if_ppp.h not found. PPP support deactivated. -#endif - -#include "debug.h" -#include "cfg.h" -#include "system.h" -#include "filter.h" - - -static int parse_meminfo (char *tag, char *buffer) -{ - char *p; - unsigned long val; - - p=strstr(buffer, tag); - if (p==NULL) { - error ("parse(/proc/meminfo) failed: no '%s' line", tag); - return -1; - } - if (sscanf(p+strlen(tag), "%lu", &val)!=1) { - error ("parse(/proc/meminfo) failed: unknown '%s' format", tag); - return -1; - } - return val; -} - - -char *System(void) -{ - static char buffer[32]=""; - struct utsname ubuf; - - if (*buffer=='\0') { - if (uname(&ubuf)==-1) { - error ("uname() failed: %s", strerror(errno)); - strcpy (buffer, "unknown"); - } else { - debug ("uname(sysname)=%s", ubuf.sysname); - strncpy (buffer, ubuf.sysname, sizeof(buffer)); - } - } - return buffer; -} - - -char *Release(void) -{ - static char buffer[32]=""; - struct utsname ubuf; - - if (*buffer=='\0') { - if (uname(&ubuf)==-1) { - error ("uname() failed: %s", strerror(errno)); - strcpy (buffer, "unknown"); - } else { - debug ("uname(release)=%s", ubuf.release); - strncpy (buffer, ubuf.release, sizeof(buffer)); - } - } - return buffer; -} - - -char *Processor(void) -{ - static char buffer[16]=""; - struct utsname ubuf; - - if (*buffer=='\0') { - if (uname(&ubuf)==-1) { - error ("uname() failed: %s", strerror(errno)); - strcpy (buffer, "unknown"); - } else { - debug ("uname(machine)=%s", ubuf.machine); - strncpy (buffer, ubuf.machine, sizeof(buffer)); - } - } - return buffer; -} - - -double BogoMips (void) -{ - static double val=-2; - char buffer[4096]; - - if (val==-1) return -1; - - if (val==-2) { - char *p; - int fd=open("/proc/cpuinfo", O_RDONLY); - if (fd==-1) { - error ("open(/proc/cpuinfo) failed: %s", strerror(errno)); - val=-1; - return -1; - } - debug ("open(proc/cpuinfo)=%d", fd); - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(/proc/cpuinfo) failed: %s", strerror(errno)); - close (fd); - val=-1; - return -1; - } - close (fd); - p=strstr(buffer, "bogomips"); - if (p==NULL) { - error ("parse(/proc/cpuinfo) failed: no 'bogomips' line"); - val=-1; - return -1; - } - if (sscanf(p+8, " : %lf", &val)!=1) { - error ("parse(/proc/cpuinfo) failed: unknown 'bogomips' format"); - val=-1; - return -1; - } - debug ("BogoMips=%f", val); - } - return val; -} - - -int Memory(void) -{ - static int value=-1; - struct stat buf; - - if (value==-1) { - if (stat("/proc/kcore", &buf)==-1) { - error ("stat(/proc/kcore) failed: %s", strerror(errno)); - value=0; - } else { - debug ("sizeof(/proc/kcore)=%ld bytes", buf.st_size); - value=buf.st_size>>20; - } - } - return value; -} - -int Ram (int *total, int *free, int *shared, int *buffered, int *cached) -{ - static time_t now=0; - static int fd=-2; - static int v1=0; - static int v2=0; - static int v3=0; - static int v4=0; - static int v5=0; - char buffer[4096]; - - *total=v1; - *free=v2; - *shared=v3; - *buffered=v4; - *cached=v5; - - if (fd==-1) return -1; - - if (time(NULL)==now) return 0; - time(&now); - - if (fd==-2) { - fd = open("/proc/meminfo", O_RDONLY | O_NDELAY); - if (fd==-1) { - error ("open(/proc/meminfo) failed: %s", strerror(errno)); - return -1; - } - debug ("open(/proc/meminfo)=%d", fd); - } - - if (lseek(fd, 0L, SEEK_SET)!=0) { - error ("lseek(/proc/meminfo) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(/proc/meminfo) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if ((v1=parse_meminfo ("MemTotal:", buffer))<0) { - fd=-1; - return -1; - } - if ((v2=parse_meminfo ("MemFree:", buffer))<0) { - fd=-1; - return -1; - } - if ((v3=parse_meminfo ("MemShared:", buffer))<0) { - // The "MemShared" entriy disappeared in Kernel 2.6... -#if 0 - fd=-1; - return -1; -#else - v3=0; -#endif - } - if ((v4=parse_meminfo ("Buffers:", buffer))<0) { - fd=-1; - return -1; - } - if ((v5=parse_meminfo ("Cached:", buffer))<0) { - fd=-1; - return -1; - } - - *total=v1; - *free=v2; - *shared=v3; - *buffered=v4; - *cached=v5; - - return 0; - -} - - -int Load (double *load1, double *load2, double *load3) -{ - static int fd=-2; - char buffer[16]; - static double val1=0; - static double val2=0; - static double val3=0; - static time_t now=0; - - *load1=val1; - *load2=val2; - *load3=val3; - - if (fd==-1) return -1; - - if (time(NULL)==now) return 0; - time(&now); - - if (fd==-2) { - fd=open("/proc/loadavg", O_RDONLY); - if (fd==-1) { - error ("open(/proc/loadavg) failed: %s", strerror(errno)); - return -1; - } - debug ("open(/proc/loadavg)=%d", fd); - } - - if (lseek(fd, 0L, SEEK_SET)!=0) { - error("lseek(/proc/loadavg) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error("read(/proc/loadavg) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if (sscanf(buffer, "%lf %lf %lf", &val1, &val2, &val3)!=3) { - error ("parse(/proc/loadavg) failed: unknown format"); - fd=-1; - return -1; - } - - *load1=val1; - *load2=val2; - *load3=val3; - - return 0; -} - - -int Busy (double *user, double *nice, double *system, double *idle) -{ - static int fd=-2; - char buffer[64], *p; - unsigned long v1, v2, v3, v4; - double d1, d2, d3, d4, d5; - - *user=0.0; - *nice=0.0; - *system=0.0; - *idle=0.0; - - if (fd==-1) return -1; - - if (fd==-2) { - fd=open("/proc/stat", O_RDONLY); - if (fd==-1) { - error ("open(proc/stat) failed: %s", strerror(errno)); - return -1; - } - debug ("open (/proc/stat)=%d", fd); - } - - if (lseek(fd, 0L, SEEK_SET)!=0) { - error ("lseek(/proc/stat) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(/proc/stat) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - p=strstr(buffer, "cpu "); - if (p==NULL) { - error ("parse(/proc/stat) failed: no 'cpu' line"); - fd=-1; - return -1; - } - - if (sscanf(p+4, " %lu %lu %lu %lu", &v1, &v2, &v3, &v4)!=4) { - error ("parse(/proc/stat) failed: unknown 'cpu' format"); - fd=-1; - return -1; - } - - d1=smooth("cpu_user", 500, v1); - d2=smooth("cpu_nice", 500, v2); - d3=smooth("cpu_sys", 500, v3); - d4=smooth("cpu_idle", 500, v4); - d5=d1+d2+d3+d4; - - if (d5!=0.0) { - *user=(d1+d2)/d5; - *nice=d2/d5; - *system=d3/d5; - *idle=d4/d5; - } - return 0; -} - - -int Disk (int *r, int *w) -{ - char buffer[4096], *p; - static int fd=-2; - - *r=0; - *w=0; - - if (fd==-1) return -1; - - if (fd==-2) { - fd = open("/proc/stat", O_RDONLY | O_NDELAY); - if (fd==-1) { - error ("open(/proc/stat) failed: %s", strerror(errno)); - return -1; - } - debug ("open (/proc/stat)=%d", fd); - } - - if (lseek(fd, 0L, SEEK_SET)!=0) { - error ("lseek(/proc/stat) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(/proc/stat) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - p=strstr(buffer, "disk_io:"); - if (p!=NULL) { - unsigned long rsum=0, wsum=0; - p+=8; while (*p==' ') p++; - while (*p && *p!='\n') { - int i, n; - unsigned long dummy; - unsigned long rblk, wblk; - i=sscanf(p, "(%lu,%lu):(%lu,%lu,%lu,%lu,%lu)%n", - &dummy, &dummy, &dummy, &dummy, &rblk, &dummy, &wblk, &n); - if (n==0 || i!= 7) { - i=sscanf(p, "(%lu,%lu):(%lu,%lu,%lu,%lu)%n", - &dummy, &dummy, &dummy, &rblk, &dummy, &wblk, &n)+1; - } - if (n>0 && i==7) { - rsum+=rblk; - wsum+=wblk; - p+=n; while (*p==' ') p++; - } else { - error ("parse(/proc/stat) failed: unknown 'disk_io' format"); - fd=-1; - return -1; - } - } - // assume that we got the number of sectors, and a sector size of 512 bytes. - // to get te number in kilobytes/sec, we calculate as follows: - // kb=blocks*512/1024, which is blocks/2 - *r=smooth ("disk_r", 500, rsum/2); - *w=smooth ("disk_w", 500, wsum/2); - - } else { - - unsigned long r1, r2, r3, r4; - unsigned long w1, w2, w3, w4; - p=strstr(buffer, "disk_rblk"); - if (p==NULL) { - error ("parse(/proc/stat) failed: neither 'disk_io' nor 'disk_rblk' found"); - fd=-1; - return -1; - } - if (sscanf(p+9, "%lu %lu %lu %lu", &r1, &r2, &r3, &r4)!=4) { - error ("parse(/proc/stat) failed: unknown 'disk_rblk' format"); - fd=-1; - return -1; - } - p=strstr(buffer, "disk_wblk"); - if (p==NULL) { - error ("parse(/proc/stat) failed: no 'disk_wblk' line"); - fd=-1; - return -1; - } - if (sscanf(p+9, "%lu %lu %lu %lu", &w1, &w2, &w3, &w4)!=4) { - error ("parse(/proc/stat) failed: unknown 'disk_wblk' format"); - fd=-1; - return -1; - } - *r=smooth ("disk_r", 500, r1+r2+r3+r4); - *w=smooth ("disk_w", 500, w1+w2+w3+w4); - } - - return 0; -} - - -int Net (int *rx, int *tx, int *bytes) -{ - char buffer[4096], *p, *s; - static int fd=-2; - unsigned long pkg_rx, pkg_tx; - - *rx=0; - *tx=0; - *bytes=0; - - if (fd==-1) return -1; - - if (fd==-2) { - fd = open("/proc/net/dev", O_RDONLY | O_NDELAY); - if (fd==-1) { - error ("open(/proc/net/dev) failed: %s", strerror(errno)); - return -1; - } - debug ("open (/proc/net/dev)=%d", fd); - } - - if (lseek(fd, 0L, SEEK_SET)!=0) { - error ("lseek(/proc/net/dev) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(/proc/net/dev) failed: %s", strerror(errno)); - fd=-1; - return -1; - } - - pkg_rx=0; - pkg_tx=0; - p=buffer; - while ((s=strsep(&p, "\n"))) { - int n, u; - unsigned long v[16]={0}; - n=sscanf (s, " eth%d:%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", - &u, &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], - &v[8], &v[9], &v[10], &v[11], &v[12], &v[13], &v[14], &v[15]); - - if (n==17) { - pkg_rx+=v[0]; - pkg_tx+=v[8]; - *bytes=1; - } else if (n==12) { - pkg_rx+=v[0]; - pkg_tx+=v[5]; - *bytes=0; - } else if (n>0) { - error ("parse(/proc/net/dev) failed: unknown format"); - fd=-1; - return -1; - } - } - - *rx=smooth("net_rx", 500, pkg_rx); - *tx=smooth("net_tx", 500, pkg_tx); - - return 0; -} - - -int PPP (int unit, int *rx, int *tx) -{ - static int fd=-2; - char buffer[16]; - -#ifdef HAVE_NET_IF_PPP_H - struct ifpppstatsreq req; -#endif - - *rx=0; - *tx=0; - -#ifdef HAVE_NET_IF_PPP_H - - if (fd==-1) return -1; - - if (fd==-2) { - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd==-1) { - error ("socket() failed: %s", strerror(errno)); - return -1; - } - debug ("socket()=%d", fd); - } - - memset (&req, 0, sizeof (req)); - req.stats_ptr = (caddr_t) &req.stats; - snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); - - if (ioctl(fd, SIOCGPPPSTATS, &req) < 0) - return 0; - - snprintf (buffer, sizeof(buffer), "ppp%d_rx", unit); - *rx=smooth(buffer, 500, req.stats.p.ppp_ibytes); - snprintf (buffer, sizeof(buffer), "ppp%d_tx", unit); - *tx=smooth(buffer, 500, req.stats.p.ppp_obytes); - -#endif - - return 0; -} - - -int Sensor (int index, double *val, double *min, double *max) -{ - char buffer[32]; - double dummy, value; - static int fd[SENSORS+1]={[0 ... SENSORS]=-2,}; - static char *sensor[SENSORS+1]={NULL,}; - static double val_buf[SENSORS+1]={0.0,}; - static double min_buf[SENSORS+1]={0.0,}; - static double max_buf[SENSORS+1]={0.0,}; - static double factor_buf[SENSORS+1]={0.0,}; - static double offset_buf[SENSORS+1]={0.0,}; - static time_t now[SENSORS+1]={0,}; - - if (index<0 || index>SENSORS) return -1; - - *val=val_buf[index]; - *min=min_buf[index]; - *max=max_buf[index]; - - if (fd[index]==-1) return -1; - - if (time(NULL)==now[index]) return 0; - time(&now[index]); - - if (fd[index]==-2) { - snprintf(buffer, 32, "Sensor%d", index); - sensor[index]=cfg_get(NULL, buffer, NULL); - if (sensor[index]==NULL || *sensor[index]=='\0') { - error ("no entry for '%s' in %s", buffer, cfg_source()); - fd[index]=-1; - return -1; - } - - snprintf(buffer, 32, "Sensor%d_min", index); - min_buf[index]=atof(cfg_get(NULL, buffer, "0")); - *min=min_buf[index]; - - snprintf(buffer, 32, "Sensor%d_max", index); - max_buf[index]=atof(cfg_get(NULL, buffer, "100")); - *max=max_buf[index]; - - snprintf(buffer, 32, "Sensor%d_factor", index); - factor_buf[index]=atof(cfg_get(NULL, buffer, "1")); - - snprintf(buffer, 32, "Sensor%d_offset", index); - offset_buf[index]=atof(cfg_get(NULL, buffer, "0")); - - fd[index]=open(sensor[index], O_RDONLY); - if (fd[index]==-1) { - error ("open(%s) failed: %s", sensor[index], strerror(errno)); - return -1; - } - debug ("open (%s)=%d", sensor[index], fd[index]); - } - - if (lseek(fd[index], 0L, SEEK_SET)!=0) { - error ("lseek(%s) failed: %s", sensor[index], strerror(errno)); - fd[index]=-1; - return -1; - } - - if (read (fd[index], &buffer, sizeof(buffer)-1)==-1) { - error ("read(%s) failed: %s", sensor[index], strerror(errno)); - fd[index]=-1; - return -1; - } - - if (sscanf(buffer, "%lf %lf %lf", &dummy, &dummy, &value)!=3) { - error ("parse(%s) failed: unknown format", sensor[index]); - fd[index]=-1; - return -1; - } - value *= factor_buf[index]; - value += offset_buf[index]; - val_buf[index]=value; - *val=value; - return 0; -} diff --git a/system.h b/system.h deleted file mode 100644 index ad6acc6..0000000 --- a/system.h +++ /dev/null @@ -1,81 +0,0 @@ -/* $Id: system.h,v 1.9 2003/10/05 17:58:50 reinelt Exp $ - * - * system status retreivement - * - * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at> - * - * 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: system.h,v $ - * Revision 1.9 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.8 2000/07/31 10:43:44 reinelt - * - * some changes to support kernel-2.4 (different layout of various files in /proc) - * - * Revision 1.7 2000/05/21 06:20:35 reinelt - * - * added ppp throughput - * token is '%t[iomt]' at the moment, but this will change in the near future - * - * Revision 1.6 2000/04/13 06:09:52 reinelt - * - * added BogoMips() to system.c (not used by now, maybe sometimes we can - * calibrate our delay loop with this value) - * - * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully - * no compiler will optimize away the delay loop! - * - * Revision 1.5 2000/03/17 09:21:42 reinelt - * - * various memory statistics added - * - * Revision 1.4 2000/03/10 17:36:02 reinelt - * - * first unstable but running release - * - * Revision 1.3 2000/03/07 11:01:34 reinelt - * - * system.c cleanup - * - * Revision 1.2 2000/03/06 06:04:06 reinelt - * - * minor cleanups - * - */ - -#ifndef _SYSTEM_H_ -#define _SYSTEM_H_ - -#define SENSORS 9 - -char *System (void); -char *Release (void); -char *Processor (void); -double BogoMips (void); -int Memory (void); -int Ram (int *total, int *free, int *shared, int *buffered, int *cached); -int Load (double *load1, double *load2, double *load3); -int Busy (double *user, double *nice, double *system, double *idle); -int Disk (int *r, int *w); -int Net (int *rx, int *tx, int *bytes); -int PPP (int unit, int *rx, int *tx); -int Sensor (int index, double *val, double *min, double *max); - -#endif |