=lcdm001.c now uses the report.h and configfile.h changes

This commit is contained in:
reenoo
2001-11-30 18:23:57 +00:00
parent 4991788dc2
commit 786c9e4d80
+47 -106
View File
@@ -24,13 +24,23 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <syslog.h> #include <syslog.h>
# if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h> # include <time.h>
# else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
#include "lcd.h" #include "lcd.h"
#include "lcdm001.h" #include "lcdm001.h"
#include "drv_base.h" /*#include "shared/debug.h"*/
#include "shared/debug.h"
#include "shared/str.h" #include "shared/str.h"
#include "shared/report.h"
#include "configfile.h"
#include "render.h" #include "render.h"
// Moved here from lcdm001.h to reduce the number of warning. // Moved here from lcdm001.h to reduce the number of warning.
@@ -111,8 +121,6 @@ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
static void lcdm001_cursorblink (int on); static void lcdm001_cursorblink (int on);
static void lcdm001_string (int x, int y, char *string); static void lcdm001_string (int x, int y, char *string);
static void lcdm001_usage (void);
#define ValidX(x) if ((x) > lcdm001->wid) { (x) = lcdm001->wid; } else (x) = (x) < 1 ? 1 : (x); #define ValidX(x) if ((x) > lcdm001->wid) { (x) = lcdm001->wid; } else (x) = (x) < 1 ? 1 : (x);
#define ValidY(y) if ((y) > lcdm001->hgt) { (y) = lcdm001->hgt; } else (y) = (y) < 1 ? 1 : (y); #define ValidY(y) if ((y) > lcdm001->hgt) { (y) = lcdm001->hgt; } else (y) = (y) < 1 ? 1 : (y);
@@ -124,23 +132,13 @@ lcdm001_cursorblink (int on)
{ {
if (on) { if (on) {
write (fd, "~K1", 3); write (fd, "~K1", 3);
debug(RPT_INFO, "LCDM001: cursorblink turned on");
if (debug_level > 3)
syslog(LOG_DEBUG, "LCDM001: cursorblink turned on");
} else { } else {
write (fd, "~K0", 3); write (fd, "~K0", 3);
debug(RPT_INFO, "LCDM001: cursorblink turned off");
if (debug_level > 3)
syslog(LOG_DEBUG, "LCDM001: cursorblink turned off");
} }
} }
static void
lcdm001_usage (void) {
printf ("LCDproc LCDM001 LCD driver\n"
"\t-d\t\tSelect the output device to use [/dev/lcd]\n"
"\t-h\t\tShow this help information\n");
}
// TODO: Get lcd.framebuf to properly work as whatever driver is running... // TODO: Get lcd.framebuf to properly work as whatever driver is running...
@@ -150,29 +148,27 @@ lcdm001_usage (void) {
int int
lcdm001_init (struct lcd_logical_driver *driver, char *args) lcdm001_init (struct lcd_logical_driver *driver, char *args)
{ {
char device[256]="/dev/lcd"; char * device;
int speed=B38400; int speed=B38400;
char *argv[64];
int argc;
int i;
struct termios portset; struct termios portset;
//char c;
char out[5]=""; char out[5]="";
//fprintf(stderr,"lcdm001_init()\n");
lcdm001 = driver; lcdm001 = driver;
debug( RPT_INFO, "LCDM001: init(%p,%s)", driver, args );
driver->wid = 20; driver->wid = 20;
driver->hgt = 4; driver->hgt = 4;
// You must use driver->framebuf here, but may use lcd.framebuf later. // You must use driver->framebuf here, but may use lcd.framebuf later.
if (!driver->framebuf) if (!driver->framebuf) {
driver->framebuf = malloc (driver->wid * driver->hgt); driver->framebuf = malloc (driver->wid * driver->hgt);
}
if (!driver->framebuf) { if (!driver->framebuf) {
lcdm001_close (); lcdm001_close ();
fprintf(stderr, "\nError: unable to create LCDM001 framebuffer.\n"); report(RPT_ERR, "\nError: unable to create LCDM001 framebuffer.\n");
return -1; return -1;
} }
// Debugging... // Debugging...
@@ -184,75 +180,33 @@ lcdm001_init (struct lcd_logical_driver *driver, char *args)
driver->cellwid = 5; driver->cellwid = 5;
driver->cellhgt = 8; driver->cellhgt = 8;
argc = get_args(argv, args, 64); // TODO: replace DriverName with driver->name when that field exists.
#define DriverName "lcdm001"
/* //READ CONFIG FILE:
for(i=0; i<argc; i++)
{
printf("Arg(%i): %s\n", i, argv[i]);
}
*/
#ifdef USE_GETOPT //which serial device should be used
while ((c = getopt(argc, argv, "d:h")) > 0) { device = config_get_string ( DriverName , "Device" , 0 , "/dev/lcd");
switch(c) { report (RPT_INFO,"LCDM001: Using device: %s", device);
case 'd':
strncpy(device, optarg, sizeof(device));
break;
case 'h':
lcdm001_usage();
return -1;
default:
lcdm001_usage();
return -1;
}
}
#else
for (i = 0; i < argc; i++) {
char *p;
p = argv[i];
//printf("Arg(%i): %s\n", i, argv[i]);
if (*p == '-') {
p++;
switch (*p) {
case 'd':
if (i + 1 > argc) {
fprintf (stderr, "lcdm001_init: %s requires an argument\n", argv[i]);
return -1;
}
strcpy (device, argv[++i]);
break;
case 'h':
lcdm001_usage();
return -1;
break;
default:
printf ("Invalid parameter: %s\n", argv[i]);
break;
}
}
}
#endif
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
debug( RPT_DEBUG, "LCDM001: Opening serial device: %s", device);
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) if (fd == -1)
{ {
switch (errno) { switch (errno) {
case ENOENT: fprintf(stderr, "lcdm001_init: %s device file missing!\n", device); case ENOENT: report( RPT_ERR, "LCDM001: lcdm001_init() failed: Device file missing: %s\n", device);
break; break;
case EACCES: fprintf(stderr, "lcdm001_init: %s device could not be opened...\n", device); case EACCES: report( RPT_ERR, "LCDM001: lcdm001_init() failed: Could not open device: %s\n", device);
fprintf(stderr, "lcdm001_init: make sure you have rw access to %s!\n", device); report( RPT_ERR, "LCDM001: lcdm001_init() failed: Make sure you have rw access to %s!\n", device);
break; break;
default: fprintf (stderr, "lcdm001_init: failed (%s)\n", strerror (errno)); default: report( RPT_ERR, "LCDM001: lcdm001_init() failed (%s)\n", strerror (errno));
break; break;
} }
return -1; return -1;
} else } else {
syslog(LOG_INFO, "opened LCDM001 display on %s\n", device); report (RPT_INFO, "opened LCDM001 display on %s\n", device);
}
tcgetattr(fd, &portset); tcgetattr(fd, &portset);
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
// The easy way // The easy way
@@ -317,6 +271,8 @@ static void lcdm001_num (int x, int num)
{ {
int y, dx; int y, dx;
debug (RPT_DEBUG, "LCDM001: Writing big number \"%d\" at x = %d", num, x);
for (y = 1; y < 5; y++) for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++) for (dx = 0; dx < 3; dx++)
lcdm001_chr (x + dx, y, num_icon[num][y-1][dx]); lcdm001_chr (x + dx, y, num_icon[num][y-1][dx]);
@@ -364,12 +320,12 @@ lcdm001_close ()
free (lcdm001->framebuf); free (lcdm001->framebuf);
lcdm001->framebuf = NULL; lcdm001->framebuf = NULL;
//switch off all LEDs
snprintf (out, sizeof(out), "\%cL%c%c", 126, 0, 0); snprintf (out, sizeof(out), "\%cL%c%c", 126, 0, 0);
write (fd, out, 4); write (fd, out, 4);
close (fd); close (fd);
if (debug_level > 3) report (RPT_INFO, "LCDM001: closed");
syslog(LOG_DEBUG, "LCDM001: closed");
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -384,8 +340,7 @@ lcdm001_clear ()
write (fd, "~C", 2); // instant clear... write (fd, "~C", 2); // instant clear...
clear = 1; clear = 1;
if (debug_level > 3) debug (RPT_DEBUG, "LCDM001: cleared screen");
syslog(LOG_DEBUG, "lcdm001: cleared screen");
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@@ -396,9 +351,7 @@ lcdm001_flush ()
{ {
lcdm001_draw_frame(lcdm001->framebuf); lcdm001_draw_frame(lcdm001->framebuf);
if (debug_level > 4) debug (RPT_DEBUG, "LCDM001: frame buffer flushed");
syslog(LOG_DEBUG, "LCDM001: frame buffer flushed");
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -415,10 +368,8 @@ lcdm001_flush_box (int lft, int top, int rgt, int bot)
snprintf (out, sizeof(out), "%cP%c%c", 126, lft, y); snprintf (out, sizeof(out), "%cP%c%c", 126, lft, y);
write (fd, out, 4); write (fd, out, 4);
write (fd, lcdm001->framebuf + (y * lcdm001->wid) + lft, rgt - lft + 1); write (fd, lcdm001->framebuf + (y * lcdm001->wid) + lft, rgt - lft + 1);
if (debug_level > 4)
syslog(LOG_DEBUG, "LCDM001: frame buffer box flushed");
} }
debug (RPT_DEBUG, "LCDM001: frame buffer box flushed");
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -444,14 +395,8 @@ lcdm001_chr (int x, int y, char c)
offset = (y * lcdm001->wid) + x; offset = (y * lcdm001->wid) + x;
lcdm001->framebuf[offset] = c; lcdm001->framebuf[offset] = c;
if (debug_level > 2) { snprintf(buf, sizeof(buf), "LCDM001: writing character %02X to position (%d,%d)", c, x, y);
snprintf(buf, sizeof(buf), "writing character %02X to position (%d,%d)", debug (RPT_DEBUG, buf);
c, x, y);
syslog(LOG_DEBUG, buf);
if (debug_level > 4)
syslog(LOG_DEBUG, "LCDM001: printed a char at (%d,%d)", x, y);
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -473,8 +418,7 @@ lcdm001_string (int x, int y, char string[])
memcpy(lcdm001->framebuf + offset, string, siz); memcpy(lcdm001->framebuf + offset, string, siz);
if (debug_level > 4) debug (RPT_DEBUG, "LCDM001: printed string at (%d,%d)", x, y);
syslog(LOG_DEBUG, "LCDM001: printed string at (%d,%d)", x, y);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -498,8 +442,7 @@ lcdm001_output (int on)
snprintf (out, sizeof(out), "~L%c%c",one,two); snprintf (out, sizeof(out), "~L%c%c",one,two);
write(fd,out,4); write(fd,out,4);
if (debug_level > 3) debug (RPT_DEBUG, "LCDM001: current LED state: %d", on);
syslog(LOG_DEBUG, "LCDM001: current LED state: %d", on);
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -531,8 +474,7 @@ lcdm001_vbar(int x, int len)
{ {
int y = 4; int y = 4;
if (debug_level > 4) debug (RPT_DEBUG , "LCDM001: vertical bar at %d set to %d", x, len);
syslog(LOG_DEBUG, "LCDM001: vertical bar at %d set to %d", x, len);
while (len >= 8) while (len >= 8)
{ {
@@ -558,8 +500,7 @@ lcdm001_hbar(int x, int y, int len)
ValidX(x); ValidX(x);
ValidY(y); ValidY(y);
if (debug_level > 4) debug (RPT_DEBUG, "LCDM001: horizontal bar at %d set to %d", x, len);
syslog(LOG_DEBUG, "LCDM001: horizontal bar at %d set to %d", x, len);
//TODO: Improve this function //TODO: Improve this function