]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2000-04-15 11:13:54 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 15 Apr 2000 11:13:54 +0000 (11:13 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 15 Apr 2000 11:13:54 +0000 (11:13 +0000)
added '-d' (debugging) switch
added several debugging messages
removed config entry 'Delay' for HD44780 driver
delay loop for HD44780 will be calibrated automatically

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@45 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

HD44780.c
Makefile.am
Makefile.in
MatrixOrbital.c
README
cfg.c
debug.h [new file with mode: 0644]
lcd4kde.conf
lcd4linux.c
processor.c

index 5d3d6dd326cf2e0427b9666d46dbaee41c03929c..5ce60d663190ca6dd274db3560c2db5481b2a5cc 100644 (file)
--- a/HD44780.c
+++ b/HD44780.c
@@ -1,4 +1,4 @@
-/* $Id: HD44780.c,v 1.2 2000/04/13 06:09:52 reinelt Exp $
+/* $Id: HD44780.c,v 1.3 2000/04/15 11:13:54 reinelt Exp $
  *
  * driver for display modules based on the HD44780 chip
  *
  *
  *
  * $Log: HD44780.c,v $
+ * 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
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <time.h>
 #include <signal.h>
 #include <errno.h>
 #include <asm/io.h>
 
+#include "debug.h"
 #include "cfg.h"
 #include "display.h"
 
@@ -74,7 +83,7 @@ typedef struct {
 
 static LCD Lcd;
 static unsigned short Port=0;
-static unsigned long  Delay;
+static unsigned long  loops_per_usec;
 
 static char Txt[4][40];
 static BAR  Bar[4][40];
@@ -85,10 +94,40 @@ static SEGMENT Segment[128] = {{ len1:0,   len2:0,   type:255, used:0, ascii:32
 
 static void HD_delay (unsigned long usec)
 {
-  unsigned long i=usec*Delay/2;
+  unsigned long i=usec*loops_per_usec;
   while (i--);
 }
 
+static void HD_calibrate_delay (void)
+{
+  clock_t tick;
+  unsigned long bit;
+
+  loops_per_usec=1;
+  while (loops_per_usec<<=1) {
+    tick=clock();
+    while (clock()==tick);
+    tick=clock();
+    HD_delay(1000000/CLOCKS_PER_SEC);
+    if (clock()>tick)
+      break;
+  }
+  
+  loops_per_usec>>=1;
+  bit=loops_per_usec;
+  while (bit>>=1) {
+    loops_per_usec|=bit;
+    tick=clock();
+    while (clock()==tick);
+    tick=clock();
+    HD_delay(1000000/CLOCKS_PER_SEC);
+    if (clock()>tick)
+      loops_per_usec&=~bit;
+  }
+  debug ("calibrating delay: %ld loops/usec\n", loops_per_usec);
+}
+
 static void HD_command (unsigned char cmd, int delay)
 {
   outb (cmd, Port);    // put data on DB1..DB8
@@ -111,8 +150,9 @@ static void HD_write (char *string, int len, int delay)
 
 static int HD_open (void)
 {
+  debug ("using port 0x%x\n", Port);
   if (ioperm(Port, 3, 1)!=0) {
-    fprintf (stderr, "HD44780: ioperm() failed: %s\n", strerror(errno));
+    fprintf (stderr, "HD44780: ioperm(0x%x) failed: %s\n", Port, strerror(errno));
     return -1;
   }
 
@@ -338,20 +378,12 @@ int HD_init (LCD *Self)
     return -1;
   }
 
-  s=cfg_get ("Delay");
-  if (s==NULL || *s=='\0') {
-    fprintf (stderr, "HD44780: no 'Delay' entry in %s\n", cfg_file());
-    return -1;
-  }
-  if ((Delay=strtol(s, &e, 0))==0 || *e!='\0' || Delay<1) {
-    fprintf (stderr, "HD44780: bad delay '%s' in %s\n", s, cfg_file());
-    return -1;
-  }    
-
   Self->rows=rows;
   Self->cols=cols;
   Lcd=*Self;
 
+  HD_calibrate_delay();
+
   if (HD_open()!=0)
     return -1;
   
@@ -493,9 +525,9 @@ int lcd_hello (void); // prototype from lcd4linux.c
 
 static void HD_quit (int signal)
 {
+  debug ("got signal %d\n", signal);
   HD_clear();
   lcd_hello();
-  // Fixme: ioperm rückgängig machen?
   exit (0);
 }
 
index d753ee0d95b647e1fd0d6fab17a895997e557b19..e9d30ea3e3ec6bbafad66712e645997962ec8f54 100644 (file)
@@ -13,6 +13,7 @@ endif
 
 lcd4linux_SOURCES = \
 lcd4linux.c \
+debug.h \
 cfg.c cfg.h \
 lock.c lock.h \
 parser.c parser.h \
index de72cb1397457c3358a6e88a77e73fada369fd80..bc87e065b1a4bc2aa9879c1ff19e4131ee37cb40 100644 (file)
@@ -73,7 +73,7 @@ AM_CFLAGS = $(X_CFLAGS) -Wall
 lcd4linux_LDFLAGS = $(X_LIBS)
 @WITH_X_TRUE@lcd4linux_LDADD = -lX11
 
-lcd4linux_SOURCES =  lcd4linux.c cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h filter.c filter.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h Skeleton.c MatrixOrbital.c HD44780.c Raster.c XWindow.c
+lcd4linux_SOURCES =  lcd4linux.c debug.h cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h filter.c filter.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h Skeleton.c MatrixOrbital.c HD44780.c Raster.c XWindow.c
 
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
index b9575b2e954c28900b98c311981973a282da41ff..5096ee07d89d122f0219415a52b7f7248d35ed78 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: MatrixOrbital.c,v 1.16 2000/04/13 06:09:52 reinelt Exp $
+/* $Id: MatrixOrbital.c,v 1.17 2000/04/15 11:13:54 reinelt Exp $
  *
  * driver for Matrix Orbital serial display modules
  *
  *
  *
  * $Log: MatrixOrbital.c,v $
+ * 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
 #include <termios.h>
 #include <fcntl.h>
 
+#include "debug.h"
 #include "cfg.h"
 #include "lock.h"
 #include "display.h"
@@ -419,6 +427,8 @@ int MO_init (LCD *Self)
     return -1;
   }    
 
+  debug ("using port %s at %d baud\n", Port, atoi(speed));
+
   Device=MO_open();
   if (Device==-1) return -1;
 
@@ -561,6 +571,7 @@ int lcd_hello (void); // prototype from lcd4linux.c
 
 static void MO_quit (int signal)
 {
+  debug ("got signal %d\n", signal);
   MO_clear();
   lcd_hello();
   close (Device);
diff --git a/README b/README
index 56e9c89e48862cbdbe2cf9e703eebcf8376c3892..2c507592199e7a5ccb281ea89e0c3bbfaed885b7 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 #
-# $Id: README,v 1.4 2000/04/10 04:40:53 reinelt Exp $
+# $Id: README,v 1.5 2000/04/15 11:13:54 reinelt Exp $
 #
 
 This is the README file for lcd4linux
@@ -22,12 +22,13 @@ print version number and a small help text, then exit
 lcd4linux -l 
 list available drivers
 
-lcd4linux [-c key=val] [-f config-file] [-o output] [-q]
+lcd4linux [-c key=val] [-d] [-f config-file] [-o output] [-q]
 run lcd4linux 
+generate debugging messages with '-d'  
 use configuration from 'config-file' instead of /etc/lcd4linux.conf
 write picture to 'output' (raster driver only)
 overwrite entries from the config-file with '-c'
-supress startup splash screen with '-q_
+suppress startup splash screen with '-q'
 
 SUPPORTED DISPLAYS
 
diff --git a/cfg.c b/cfg.c
index f44add395816131c641189b8b97f04f2e5627715..b4f261fedc76f96aedf7d0886707260704d4142a 100644 (file)
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.6 2000/04/03 04:46:38 reinelt Exp $
+/* $Id: cfg.c,v 1.7 2000/04/15 11:13:54 reinelt Exp $
  *
  * config file stuff
  *
  *
  *
  * $Log: cfg.c,v $
+ * Revision 1.7  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.6  2000/04/03 04:46:38  reinelt
  *
  * added '-c key=val' option
@@ -140,7 +147,7 @@ static char *dequote (char *string)
 static void cfg_add (char *key, char *val, int lock)
 {
   int i;
-  
+
   for (i=0; i<nConfig; i++) {
     if (strcasecmp(Config[i].key, key)==0) {
       if (Config[i].lock>lock) return;
diff --git a/debug.h b/debug.h
new file mode 100644 (file)
index 0000000..bd2b9fa
--- /dev/null
+++ b/debug.h
@@ -0,0 +1,38 @@
+/* $Id: debug.h,v 1.1 2000/04/15 11:13:54 reinelt Exp $
+ *
+ * debug messages
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: debug.h,v $
+ * Revision 1.1  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
+ *
+ */
+
+#ifndef _DEBUG_H_
+#define _DEBUG_H_
+
+extern int debugging;
+#define debug(args...) do { if (debugging) printf(__FILE__ ": " args); } while(0)
+
+#endif
index d0f24c09a1cab60e3808bcfeb02eb6662f61a8e5..19ead74525fe0497dfbc4fc777e6b554c6b23396 100644 (file)
@@ -3,7 +3,7 @@ size 6x5
 font 6x8
 pixel 1+0
 gap 1x0
-border 2
+border 3
 foreground \#102000
 halfground \#90c000
 background \#a0d000
index f41af96dd0ddb31cfcb7c0e35b6f16903db3e697..25210fcad076a781fe91239b31cdd8ec5608709d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.19 2000/04/10 04:40:53 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.20 2000/04/15 11:13:54 reinelt Exp $
  *
  * LCD4Linux
  *
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.20  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.19  2000/04/10 04:40:53  reinelt
  *
  * minor changes and cleanups
 #include <stdio.h>
 #include <unistd.h>
 
+#include "debug.h"
 #include "cfg.h"
 #include "display.h"
 #include "processor.h"
 
 char *release="LCD4Linux V" VERSION " (c) 2000 Michael Reinelt <reinelt@eunet.at>";
 char *output=NULL;
+int debugging=0;
 int tick, tack;
 
 static void usage(void)
 {
   printf ("%s\n", release);
-  printf ("usage: lcd4linux [-h] [-l] [-c key=value] [-f config-file] [-o output-file] [-q]\n");
+  printf ("usage: lcd4linux [-h]\n");
+  printf ("       lcd4linux [-l]\n");
+  printf ("       lcd4linux [-c key=value] [-d] [-f config-file] [-o output-file] [-q]\n");
 }
 
 int lcd_hello (void)
@@ -171,7 +182,7 @@ int main (int argc, char *argv[])
   int c, smooth;
   int quiet=0;
 
-  while ((c=getopt (argc, argv, "c:f:hlo:q"))!=EOF) {
+  while ((c=getopt (argc, argv, "c:df:hlo:q"))!=EOF) {
     switch (c) {
     case 'c':
       if (cfg_cmd (optarg)<0) {
@@ -179,6 +190,9 @@ int main (int argc, char *argv[])
        exit(2);
       }
       break;
+    case 'd':
+      debugging++;
+      break;
     case 'h':
       usage();
       exit(0);
@@ -205,6 +219,8 @@ int main (int argc, char *argv[])
     exit(2);
   }
 
+  debug ("LCD4Linux " VERSION "\n");
+
   // set default values
  
   cfg_set ("row1", "*** %o %v ***");
@@ -220,6 +236,8 @@ int main (int argc, char *argv[])
     fprintf (stderr, "%s: missing 'display' entry!\n", cfg_file());
     exit (1);
   }
+  
+  debug ("initializing driver %s\n", driver);
   if (lcd_init(driver)==-1) {
     exit (1);
   }
index f388813ae538a6053393a20dbc685cc4d7136ac0..02b2775e8cfe0f9a8dee4d9c77bc8ba1ee9da938 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: processor.c,v 1.3 2000/04/01 16:22:38 reinelt Exp $
+/* $Id: processor.c,v 1.4 2000/04/15 11:13:54 reinelt Exp $
  *
  * main data processing
  *
  *
  *
  * $Log: processor.c,v $
+ * 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)
@@ -52,6 +59,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "debug.h"
 #include "cfg.h"
 #include "system.h"
 #include "isdn.h"
@@ -379,7 +387,7 @@ void process_init (void)
 
   load.overload=atof(cfg_get("overload")?:"2.0");
   lcd_query (&rows, &cols, &xres, &yres, &supported_bars);
-
+  debug ("%d rows, %d columns, %dx%d pixels\n", rows, cols, xres, yres);
   for (i=1; i<=rows; i++) {
     snprintf (buffer, sizeof(buffer), "row%d", i);
     row[i]=strdup(parse(cfg_get(buffer)?:"", supported_bars, token_usage));