From 875ee72589b13c76b34ffce63f5b3b2b518e5460 Mon Sep 17 00:00:00 2001 From: ddouthitt Date: Mon, 24 Sep 2001 22:33:59 +0000 Subject: [PATCH] Major change was to convert from multiple drivers to a single driver. Other minor things: comments, more robust MtxOrb driver, and more use of syslog. --- server/drivers/MtxOrb.c | 178 ++++++---- server/drivers/MtxOrb.h | 44 +-- server/drivers/lcd.c | 725 ++++++++++++---------------------------- server/drivers/lcd.h | 30 +- server/main.c | 1 + server/screenlist.c | 5 +- 6 files changed, 361 insertions(+), 622 deletions(-) diff --git a/server/drivers/MtxOrb.c b/server/drivers/MtxOrb.c index d5a2b4e..79d94be 100644 --- a/server/drivers/MtxOrb.c +++ b/server/drivers/MtxOrb.c @@ -52,6 +52,7 @@ static int custom = 0; static enum {MTXORB_LCD, MTXORB_LKD, MTXORB_VFD, MTXORB_VKD} MtxOrb_type; +extern int debug_level; // TODO: Remove this custom_type if not in use anymore. typedef enum { @@ -98,8 +99,9 @@ static int use[9] = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; static void MtxOrb_linewrap (int on); static void MtxOrb_autoscroll (int on); static void MtxOrb_cursorblink (int on); +static void MtxOrb_string (int x, int y, char *string); -int +static int MtxOrb_set_type (char * str) { char c; c = str[0]; @@ -126,7 +128,7 @@ MtxOrb_set_type (char * str) { return (-1); } -int +static int MtxOrb_get_speed (char *arg) { int speed; @@ -150,7 +152,7 @@ MtxOrb_get_speed (char *arg) { return speed; } -void +static void MtxOrb_usage (void) { printf ("LCDproc Matrix-Orbital LCD driver\n" "\t-d\t--device\tSelect the output device to use [/dev/lcd]\n" @@ -162,7 +164,7 @@ MtxOrb_usage (void) { "\t-t\t--type\t\tdisplay type: lcd, lkd, vfd, vkd\n"); } -int +static int MtxOrb_set_contrast (char * str) { int contrast; @@ -174,7 +176,7 @@ MtxOrb_set_contrast (char * str) { return contrast; } -// TODO: Get rid of this variable? +// TODO: Get rid of this variable? Probably not... lcd_logical_driver *MtxOrb; // set by MtxOrb_init(); doesn't seem to be used anywhere // TODO: Get the frame buffers working right @@ -323,7 +325,7 @@ MtxOrb_init (lcd_logical_driver * driver, char *args) MtxOrb_contrast (contrast); if (!driver->framebuf) { - fprintf (stderr, "MtxOrb_init: No frame buffer.\n"); + syslog(LOG_ERR, "no frame buffer! exiting driver init..."); driver->close (); return -1; } @@ -332,13 +334,13 @@ MtxOrb_init (lcd_logical_driver * driver, char *args) * Configure the display functions */ - driver->clear = MtxOrb_clear; // was GENERIC - driver->string = GENERIC; - driver->chr = MtxOrb_chr; // was GENERIC + driver->clear = MtxOrb_clear; + driver->string = MtxOrb_string; + driver->chr = MtxOrb_chr; driver->vbar = MtxOrb_vbar; - driver->init_vbar = MtxOrb_init_vbar; // was GENERIC + driver->init_vbar = MtxOrb_init_vbar; driver->hbar = MtxOrb_hbar; - driver->init_hbar = MtxOrb_init_hbar; // was GENERIC + driver->init_hbar = MtxOrb_init_hbar; driver->num = MtxOrb_num; driver->init_num = MtxOrb_init_num; @@ -369,18 +371,20 @@ MtxOrb_init (lcd_logical_driver * driver, char *args) // This reliance on drv_base_clear seems suspicious... especially as // using a (void *) -1 in the driver structure does the same thing... // -void +static void MtxOrb_clear () { - drv_base_clear (); // do we need this? - write(fd, "\x0FEX", 2); // instant clear... + if (MtxOrb->framebuf != NULL) + memset (MtxOrb->framebuf, ' ', (MtxOrb->wid * MtxOrb->hgt)); + + write(fd, "\x0FE" "X", 2); // instant clear... clear = 1; } ///////////////////////////////////////////////////////////////// // Clean-up // -void +static void MtxOrb_close () { close (fd); @@ -391,24 +395,48 @@ MtxOrb_close () MtxOrb->framebuf = NULL; } -void -MtxOrb_flush () +static void +MtxOrb_string (int x, int y, char *string) { - MtxOrb_draw_frame (lcd.framebuf); + int offset, siz; + + x--; y--; // Convert 1-based coords to 0-based... + + // Check range of Y + if (y > MtxOrb->hgt) { + syslog(LOG_WARNING, "lcd height overflow!"); + return; + } + + // Check range of X + if (x > MtxOrb->wid) { + syslog(LOG_WARNING, "lcd width overflow!"); + return; + } + + offset = (y * MtxOrb->wid) + x; + siz = (MtxOrb->wid * MtxOrb->hgt) - offset - 1; + siz = siz > strlen(string) ? strlen(string) : siz; + + memcpy(MtxOrb->framebuf + offset, string, siz); } -void +static void +MtxOrb_flush () +{ + MtxOrb_draw_frame (MtxOrb->framebuf); +} + +static void MtxOrb_flush_box (int lft, int top, int rgt, int bot) { int y; char out[LCD_MAX_WIDTH]; -// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); - for (y = top; y <= bot; y++) { sprintf (out, "\x0FEG%c%c", lft, y); write (fd, out, 4); - write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1); + write (fd, MtxOrb->framebuf + (y * MtxOrb->wid) + lft, rgt - lft + 1); } @@ -418,29 +446,41 @@ MtxOrb_flush_box (int lft, int top, int rgt, int bot) // Prints a character on the lcd display, at position (x,y). The // upper-left is (1,1), and the lower right should be (20,4). // -void +static void MtxOrb_chr (int x, int y, char c) { - char out[10]; + char out[10], buf[64]; + int offset; + + // Characters may or may NOT be alphabetic; it appears + // that characters 0..4 (or similar) are graphic fonts // validate x and y - if (y > lcd.hgt) - y = lcd.hgt; - if (x > lcd.wid) - x = lcd.wid; - if (y < 1) - y = 1; + if (x > MtxOrb->wid) + x = MtxOrb->wid; if (x < 1) x = 1; + if (y > MtxOrb->hgt) + y = MtxOrb->hgt; + if (y < 1) + y = 1; + // write immediately to screen... this code was taken // from the LK202-25; should work for others, yes? - sprintf(out, "\x0FEG%c%c%c", x, y, c); - write (fd, out, 4); + // sprintf(out, "\x0FEG%c%c%c", x, y, c); + // write (fd, out, 4); // write to frame buffer - y--; x--; - lcd.framebuf[(y * lcd.wid) + x] = c; + y--; x--; // translate to 0-index + offset = (y * MtxOrb->wid) + x; + MtxOrb->framebuf[offset] = c; + + if (debug_level > 2) { + snprintf(buf, sizeof(buf), "writing character %02X to position (%d,%d)", + c, x, y); + syslog(LOG_DEBUG, buf); + } } ///////////////////////////////////////////////////////////////// @@ -448,7 +488,7 @@ MtxOrb_chr (int x, int y, char c) // note: works only for LCD displays // Is it better to use the brightness for VFD/VKD displays ? // -int +static int MtxOrb_contrast (int contrast) { char out[4]; @@ -479,7 +519,7 @@ MtxOrb_contrast (int contrast) #define BACKLIGHT_OFF 0 #define BACKLIGHT_ON 1 -void +static void MtxOrb_backlight (int on) { switch (on) { @@ -502,7 +542,7 @@ MtxOrb_backlight (int on) // displays with keypad have 6 outputs but the one without kepad // have only one output // NOTE: length of command are different -void +static void MtxOrb_output (int on) { char out[5]; @@ -561,7 +601,7 @@ MtxOrb_cursorblink (int on) ///////////////////////////////////////////////////////////////// // Sets up for vertical bars. Call before lcd.vbar() // -void +static void MtxOrb_init_vbar () { // Isn't this function supposed to go away? @@ -572,7 +612,7 @@ MtxOrb_init_vbar () ///////////////////////////////////////////////////////////////// // Inits horizontal bars... // -void +static void MtxOrb_init_hbar () { // Isn't this function supposed to go away? @@ -582,7 +622,7 @@ MtxOrb_init_hbar () ///////////////////////////////////////////////////////////////// // Returns string with general information about the display // -char * +static char * MtxOrb_getinfo (void) { char in = 0; @@ -707,7 +747,7 @@ MtxOrb_getinfo (void) // Draws a vertical bar... // This is the new version ussing dynamic icon alocation // -void +static void MtxOrb_vbar (int x, int len) { unsigned char mapu[9] = { barw, baru1, baru2, baru3, baru4, baru5, baru6, baru7, barb }; @@ -720,23 +760,23 @@ MtxOrb_vbar (int x, int len) // REMOVE THE PREVIOUS LINE FOR TESTING ONLY... if (len > 0) { - for (y = lcd.hgt; y > 0 && len > 0; y--) { - if (len >= lcd.cellhgt) + for (y = MtxOrb->hgt; y > 0 && len > 0; y--) { + if (len >= MtxOrb->cellhgt) MtxOrb_chr (x, y, 255); else MtxOrb_chr (x, y, MtxOrb_ask_bar (mapu[len])); - len -= lcd.cellhgt; + len -= MtxOrb->cellhgt; } } else { len = -len; - for (y = 2; y <= lcd.hgt && len > 0; y++) { - if (len >= lcd.cellhgt) + for (y = 2; y <= MtxOrb->hgt && len > 0; y++) { + if (len >= MtxOrb->cellhgt) MtxOrb_chr (x, y, 255); else MtxOrb_chr (x, y, MtxOrb_ask_bar (mapd[len])); - len -= lcd.cellhgt; + len -= MtxOrb->cellhgt; } } @@ -747,31 +787,31 @@ MtxOrb_vbar (int x, int len) // Draws a horizontal bar to the right. // This is the new version ussing dynamic icon alocation // -void +static void MtxOrb_hbar (int x, int y, int len) { unsigned char mapr[6] = { barw, barr1, barr2, barr3, barr4, barb }; unsigned char mapl[6] = { barw, barl1, barl2, barl3, barl4, barb }; if (len > 0) { - for (; x <= lcd.wid && len > 0; x++) { - if (len >= lcd.cellwid) + for (; x <= MtxOrb->wid && len > 0; x++) { + if (len >= MtxOrb->cellwid) MtxOrb_chr (x, y, 255); else MtxOrb_chr (x, y, MtxOrb_ask_bar (mapr[len])); - len -= lcd.cellwid; + len -= MtxOrb->cellwid; } } else { len = -len; for (; x > 0 && len > 0; x--) { - if (len >= lcd.cellwid) + if (len >= MtxOrb->cellwid) MtxOrb_chr (x, y, 255); else MtxOrb_chr (x, y, MtxOrb_ask_bar (mapl[len])); - len -= lcd.cellwid; + len -= MtxOrb->cellwid; } } @@ -783,7 +823,7 @@ MtxOrb_hbar (int x, int y, int len) ///////////////////////////////////////////////////////////////// // Sets up for big numbers. // -void +static void MtxOrb_init_num () { if (custom != bign) { @@ -797,7 +837,7 @@ MtxOrb_init_num () ///////////////////////////////////////////////////////////////// // Writes a big number. // -void +static void MtxOrb_num (int x, int num) { char out[5]; @@ -814,7 +854,7 @@ MtxOrb_num (int x, int num) // // The input is just an array of characters... // -void +static void MtxOrb_set_char (int n, char *dat) { char out[4]; @@ -829,17 +869,17 @@ MtxOrb_set_char (int n, char *dat) sprintf (out, "\x0FEN%c", n); write (fd, out, 3); - for (row = 0; row < lcd.cellhgt; row++) { + for (row = 0; row < MtxOrb->cellhgt; row++) { letter = 0; - for (col = 0; col < lcd.cellwid; col++) { + for (col = 0; col < MtxOrb->cellwid; col++) { letter <<= 1; - letter |= (dat[(row * lcd.cellwid) + col] > 0); + letter |= (dat[(row * MtxOrb->cellwid) + col] > 0); } write (fd, &letter, 1); } } -void +static void MtxOrb_icon (int which, char dest) { char icons[3][5 * 8] = { @@ -888,7 +928,7 @@ MtxOrb_icon (int which, char dest) // // Input is a character array, sized lcd.wid*lcd.hgt // -void +static void MtxOrb_draw_frame (char *dat) { char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT]; @@ -901,10 +941,10 @@ MtxOrb_draw_frame (char *dat) write(fd, out, 4); write(fd, dat, lcd.wid*lcd.hgt); */ - for (i = 0; i < lcd.hgt; i++) { + for (i = 0; i < MtxOrb->hgt; i++) { sprintf (out, "\x0FEG\x001%c", i + 1); write (fd, out, 4); - write (fd, dat + (lcd.wid * i), lcd.wid); + write (fd, dat + (MtxOrb->wid * i), MtxOrb->wid); } } @@ -912,7 +952,7 @@ MtxOrb_draw_frame (char *dat) // returns one character from the keypad... // (A-Z) on success, 0 on failure... // -char +static char MtxOrb_getkey () { char in = 0; @@ -930,7 +970,7 @@ MtxOrb_getkey () // I really hope it is working and bug-less because it is not // completely tested, just a quick hack. // -int +static int MtxOrb_ask_bar (int type) { int i; @@ -1072,18 +1112,18 @@ MtxOrb_ask_bar (int type) ///////////////////////////////////////////////////////////// // Does the heartbeat... // -char +static char MtxOrb_heartbeat (int timer) { MtxOrb_icon (!((timer + 4) & 5), 0); - MtxOrb_chr (lcd.wid, 1, 0); + MtxOrb_chr (MtxOrb->wid, 1, 0); return (char) 0; } ///////////////////////////////////////////////////////////////// // Sets up a well known character for use. // -void +static void MtxOrb_set_known_char (int car, int type) { char all_bar[25][5 * 8] = { @@ -1324,7 +1364,7 @@ MtxOrb_set_known_char (int car, int type) // PS: There might be reference to this code left, so keep it for some time. // // MtxOrb_init_hbar and MtxOrb_init_vbar use it; it's prototyped in MtxOrb.h ... -void +static void MtxOrb_init_all (int type) { } diff --git a/server/drivers/MtxOrb.h b/server/drivers/MtxOrb.h index 6419112..6f9034e 100644 --- a/server/drivers/MtxOrb.h +++ b/server/drivers/MtxOrb.h @@ -4,29 +4,29 @@ extern lcd_logical_driver *MtxOrb; int MtxOrb_init (lcd_logical_driver * driver, char *device); -void MtxOrb_clear (); -void MtxOrb_close (); -void MtxOrb_flush (); -void MtxOrb_flush_box (int lft, int top, int rgt, int bot); -void MtxOrb_chr (int x, int y, char c); -int MtxOrb_contrast (int contrast); -void MtxOrb_backlight (int on); -void MtxOrb_output (int on); -void MtxOrb_init_vbar (); -void MtxOrb_init_hbar (); -void MtxOrb_vbar (int x, int len); -void MtxOrb_hbar (int x, int y, int len); -void MtxOrb_init_num (); -void MtxOrb_num (int x, int num); -void MtxOrb_set_char (int n, char *dat); -void MtxOrb_icon (int which, char dest); -void MtxOrb_draw_frame (char *dat); -char MtxOrb_getkey (); -char * MtxOrb_getinfo (); +static void MtxOrb_clear (); +static void MtxOrb_close (); +static void MtxOrb_flush (); +static void MtxOrb_flush_box (int lft, int top, int rgt, int bot); +static void MtxOrb_chr (int x, int y, char c); +static int MtxOrb_contrast (int contrast); +static void MtxOrb_backlight (int on); +static void MtxOrb_output (int on); +static void MtxOrb_init_vbar (); +static void MtxOrb_init_hbar (); +static void MtxOrb_vbar (int x, int len); +static void MtxOrb_hbar (int x, int y, int len); +static void MtxOrb_init_num (); +static void MtxOrb_num (int x, int num); +static void MtxOrb_set_char (int n, char *dat); +static void MtxOrb_icon (int which, char dest); +static void MtxOrb_draw_frame (char *dat); +static char MtxOrb_getkey (); +static char * MtxOrb_getinfo (); -int MtxOrb_ask_bar (int type); -void MtxOrb_set_known_char (int car, int type); +static int MtxOrb_ask_bar (int type); +static void MtxOrb_set_known_char (int car, int type); // Isn't this function supposed to go away? -void MtxOrb_init_all (int type); +static void MtxOrb_init_all (int type); #endif diff --git a/server/drivers/lcd.c b/server/drivers/lcd.c index 6c19da0..73ede19 100644 --- a/server/drivers/lcd.c +++ b/server/drivers/lcd.c @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include "config.h" @@ -23,7 +24,27 @@ #include "lcd.h" -#include "drv_base.h" +static int lcd_drv_init (lcd_logical_driver * driver, char *args); +static void lcd_drv_close (); +static void lcd_drv_clear (); +static void lcd_drv_flush (); +static void lcd_drv_string (int x, int y, char *string); +static void lcd_drv_chr (int x, int y, char c); +static int lcd_drv_contrast (int contrast); +static void lcd_drv_backlight (int on); +static void lcd_drv_output (int on); +static void lcd_drv_init_vbar (); +static void lcd_drv_init_hbar (); +static void lcd_drv_init_num (); +static void lcd_drv_num (int x, int num); +static void lcd_drv_set_char (int n, char *dat); +static void lcd_drv_vbar (int x, int len); +static void lcd_drv_hbar (int x, int y, int len); +static void lcd_drv_icon (int which, char dest); +static void lcd_drv_flush_box (int lft, int top, int rgt, int bot); +static void lcd_drv_draw_frame (); +static char lcd_drv_getkey (); +static char *lcd_drv_getinfo (); #ifdef MTXORB_DRV #include "MtxOrb.h" @@ -105,7 +126,7 @@ lcd_logical_driver lcd; // names, as well as older ones... // lcd_physical_driver drivers[] = { - {"base", drv_base_init,}, + #ifdef MTXORB_DRV {"MtxOrb", MtxOrb_init,}, #endif @@ -162,46 +183,73 @@ LL *list; // "base" array. To initialize a specific driver, use the // lcd_add_driver() function. // +// This was eliminated; everything +// done here is to be replaced by the use of lcd_add_driver()... int lcd_init (char *args) { -// int i; - int err; + return 0; +} - list = LL_new (); - if (!list) { - printf ("Error allocating driver list.\n"); - return -1; +// This sets up all of the "wrapper" driver functions +// which call all of the drivers in turn. +// +static int +lcd_drv_init (struct lcd_logical_driver *driver, char *args) +{ + driver->wid = LCD_STD_WIDTH; + driver->hgt = LCD_STD_HEIGHT; + + driver->cellwid = LCD_STD_CELL_WIDTH; + driver->cellhgt = LCD_STD_CELL_HEIGHT; + + driver->framebuf = NULL; + + // Set up these wrapper functions... + driver->clear = lcd_drv_clear; + driver->string = lcd_drv_string; + driver->chr = lcd_drv_chr; + driver->vbar = lcd_drv_vbar; + driver->hbar = lcd_drv_hbar; + driver->init_num = lcd_drv_init_num; + driver->num = lcd_drv_num; + + driver->init = lcd_drv_init; + driver->close = lcd_drv_close; + driver->flush = lcd_drv_flush; + driver->flush_box = lcd_drv_flush_box; + driver->contrast = lcd_drv_contrast; + driver->backlight = lcd_drv_backlight; + driver->output = lcd_drv_output; + driver->set_char = lcd_drv_set_char; + driver->icon = lcd_drv_icon; + driver->init_vbar = lcd_drv_init_vbar; + driver->init_hbar = lcd_drv_init_hbar; + driver->draw_frame = lcd_drv_draw_frame; + + driver->getkey = lcd_drv_getkey; + driver->getinfo = lcd_drv_getinfo; + + return 1; // 1 is arbitrary. (must be 1 or more) +} + +/* + * This function can be replaced later with something + * that utilizes the results of dynamic library loading + * + */ + +static +void * +lcd_find_init (char *driver) { + int i; + + for (i = 0; drivers[i].name; i++) { + if (strcmp(driver, drivers[i].name) == 0) { + return (*drivers[i].init); + } } - - // This sets up functions which call all drivers in - // round-robin fashion - lcd_drv_init (NULL, NULL); - - // "base" driver is a special driver which is always - // loaded... - err = lcd_add_driver ("base", args); - - lcd.wid = 20; - lcd.hgt = 4; - - return err; - - /* - drv_base_init(args); - - for(i=0; drivers[i].name; i++) - { - if(!strcmp(driver, drivers[i].name)) - { - return drivers[i].init(args); - } - } - - printf("Invalid driver: %s\n", driver); - return -1; - */ - + return NULL; } // TODO: lcd_remove_driver() @@ -209,56 +257,47 @@ lcd_init (char *args) // This initializes the specified driver and sends parameters to // it. This is the function which calls, for example, // MtxOrb_init. The specifics come from the drivers[] array. -// + int lcd_add_driver (char *driver, char *args) { int i; + char buf[64]; + int (*init_driver) (); lcd_logical_driver *add; - for (i = 0; drivers[i].name; i++) { + if ((init_driver = (void *) lcd_find_init(driver)) != NULL) { - //printf("Checking driver: %s\n", drivers[i].name); + // This creates an instance of the lcd structure specific to the + // driver... it is passed to the driver's init routine... - if (0 == strcmp (driver, drivers[i].name)) { + //if ((add = malloc (sizeof (*add))) == NULL) { + // snprintf (buf, sizeof(buf), "couldn't allocate space for driver \"%s\"", driver); + // syslog (LOG_ERR, buf); + // return -1; + //} - //printf("Found driver: %s (%s)\n", drivers[i].name, driver); + add = &lcd; + memset (add, 0, sizeof (add)); - // This creates an instance of the lcd structure specific to the - // driver... it is passed to the driver's init routine... - add = malloc (sizeof (lcd_logical_driver)); - if (!add) { - printf ("Couldn't allocate driver \"%s\".\n", driver); - return -1; - } - //printf("Allocated driver\n"); - memset (add, 0, sizeof (lcd_logical_driver)); + // Default settings for the driver... + lcd_drv_init(add, NULL); - add->wid = lcd.wid; - add->hgt = lcd.hgt; - add->cellwid = lcd.cellwid; - add->cellhgt = lcd.cellhgt; - -// printf("LCD driver info:\n\twid: %i\thgt: %i\n", -// add->wid, add->hgt); - - add->framebuf = malloc (add->wid * add->hgt); - - if (!add->framebuf) { - printf ("Couldn't allocate framebuffer for driver \"%s\".\n", driver); - free (add); - return -1; - } - //printf("Allocated frame buffer\n"); - - LL_Push (list, (void *) add); - - // This is where the driver itself is actually called; - return drivers[i].init (add, args); + // Allocate space for a framebuffer... + if ((add->framebuf = malloc (add->wid * add->hgt)) == NULL) { + snprintf (buf, sizeof(buf), "couldn't allocate framebuffer for driver \"%s\"", driver); + syslog (LOG_ERR, buf); + // free (add); + return -1; } - } + memset (add->framebuf, ' ', (add->wid * add->hgt)); + return init_driver (add, args); + } else { + snprintf(buf, sizeof(buf), "invalid driver: %s", driver); + syslog(LOG_ERR, buf); + } return -1; } @@ -268,87 +307,11 @@ lcd_shutdown () { lcd_logical_driver *driver; - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - //printf("driver...\n"); - lcd.framebuf = driver->framebuf; - - if ((int) driver->close > 0) { - driver->close (); - } else if ((int) driver->close == -1) { - drv_base->close (); - } - - LL_Shift (list); - // FIXME: This crashes! - //if(driver) free(driver); - //printf("...freed\n"); - } - - } while (LL_Length (list) > 0); + lcd.close (); return 0; } -// This sets up all of the "wrapper" driver functions -// which call all of the drivers in turn. -// -int -lcd_drv_init (struct lcd_logical_driver *driver, char *args) -{ -// printf("lcd_drv_init()\n"); - - lcd.wid = LCD_MAX_WID; - lcd.hgt = LCD_MAX_HGT; - - lcd.framebuf = NULL; -/* - if(!lcd.framebuf) - lcd.framebuf = malloc(lcd.wid * lcd.hgt); - - if(!lcd.framebuf) - { - lcd_drv_close(); - return -1; - } - memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt); -*/ -// Debugging... -// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf); - - lcd.cellwid = 5; - lcd.cellhgt = 8; - - // Set up these wrapper functions... - lcd.clear = lcd_drv_clear; - lcd.string = lcd_drv_string; - lcd.chr = lcd_drv_chr; - lcd.vbar = lcd_drv_vbar; - lcd.hbar = lcd_drv_hbar; - lcd.init_num = lcd_drv_init_num; - lcd.num = lcd_drv_num; - - lcd.init = lcd_drv_init; - lcd.close = lcd_drv_close; - lcd.flush = lcd_drv_flush; - lcd.flush_box = lcd_drv_flush_box; - lcd.contrast = lcd_drv_contrast; - lcd.backlight = lcd_drv_backlight; - lcd.output = lcd_drv_output; - lcd.set_char = lcd_drv_set_char; - lcd.icon = lcd_drv_icon; - lcd.init_vbar = lcd_drv_init_vbar; - lcd.init_hbar = lcd_drv_init_hbar; - lcd.draw_frame = lcd_drv_draw_frame; - - lcd.getkey = lcd_drv_getkey; - lcd.getinfo = lcd_drv_getinfo; - - return 1; // 1 is arbitrary. (must be 1 or more) -} - ////////////////////////////////////////////////////////////////////// // All functions below here call their respective driver functions... // @@ -364,438 +327,188 @@ lcd_drv_init (struct lcd_logical_driver *driver, char *args) // driver->func() == -1 means it should call the generic driver. ////////////////////////////////////////////////////////////////////// -void +/* + * The functions below are wrapper functions for the actual driver + * functions. + * + */ + +/* + * TODO: Convert these functions to either null functions (output) + * or to use a new interface for a linked list (input). + * + */ + +// lcd_drv_close () +// lcd_drv_clear () +// lcd_drv_flush () +// lcd_drv_string (int x, int y, char string[]) +// lcd_drv_chr (int x, int y, char c) +// lcd_drv_contrast (int contrast) +// lcd_drv_backlight (int on) +// lcd_drv_output (int on) +// lcd_drv_init_vbar () +// lcd_drv_init_hbar () +// lcd_drv_init_num () +// lcd_drv_num (int x, int num) +// lcd_drv_set_char (int n, char *dat) +// lcd_drv_vbar (int x, int len) +// lcd_drv_hbar (int x, int y, int len) +// lcd_drv_icon (int which, char dest) +// lcd_drv_flush_box (int lft, int top, int rgt, int bot) +// lcd_drv_draw_frame (char *dat) +// lcd_drv_getkey () +// lcd_drv_getinfo () + +static void lcd_drv_close () { - lcd_logical_driver *driver; - -// printf("lcd_drv_close()\n"); - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->close > 0) { - printf ("Calling close()\n"); - driver->close (); - } else if ((int) driver->close == -1) { - drv_base->close (); - } - } - } while (LL_Next (list) == 0); - + ; } -void +static void lcd_drv_clear () { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->clear > 0) - driver->clear (); - else if ((int) driver->clear == -1) { - drv_base->clear (); - } - } - } while (LL_Next (list) == 0); - + ; } -void +static void lcd_drv_flush () { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->flush > 0) - driver->flush (); - else if ((int) driver->flush == -1) { - drv_base->flush (); - } - } - } while (LL_Next (list) == 0); + ; } -void -lcd_drv_string (int x, int y, char string[]) +static void +lcd_drv_string (int x, int y, char *string) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->string > 0) - driver->string (x, y, string); - else if ((int) driver->string == -1) { - drv_base->string (x, y, string); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_chr (int x, int y, char c) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->chr > 0) - driver->chr (x, y, c); - else if ((int) driver->chr == -1) { - drv_base->chr (x, y, c); - } - } - } while (LL_Next (list) == 0); + ; } -int +static int lcd_drv_contrast (int contrast) { - int res = 0; - - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->contrast > 0) { - res = driver->contrast (contrast); - if (res >= 0) - return res; - } - /* - else if((int)driver->contrast == -1) - { - res=drv_base->contrast(contrast); - } - */ - } - } while (LL_Next (list) == 0); - - return res; + return -1; } -void +static void lcd_drv_backlight (int on) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->backlight > 0) - driver->backlight (on); - else if ((int) driver->backlight == -1) { - drv_base->backlight (on); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_output (int on) { - lcd_logical_driver *driver; - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - if ((int) driver->output > 0) - driver->output (on); - else if ((int) driver->output == -1) { - drv_base->output (on); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_init_vbar () { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->init_vbar > 0) - driver->init_vbar (); - else if ((int) driver->init_vbar == -1) { - drv_base->init_vbar (); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_init_hbar () { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->init_hbar > 0) - driver->init_hbar (); - else if ((int) driver->init_hbar == -1) { - drv_base->init_hbar (); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_init_num () { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->init_num > 0) - driver->init_num (); - else if ((int) driver->init_num == -1) { - drv_base->init_num (); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_num (int x, int num) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->num > 0) - driver->num (x, num); - else if ((int) driver->num == -1) { - drv_base->num (x, num); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_set_char (int n, char *dat) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->set_char > 0) - driver->set_char (n, dat); - else if ((int) driver->set_char == -1) { - drv_base->set_char (n, dat); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_vbar (int x, int len) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->vbar > 0) - driver->vbar (x, len); - else if ((int) driver->vbar == -1) { - drv_base->vbar (x, len); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_hbar (int x, int y, int len) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->hbar > 0) - driver->hbar (x, y, len); - else if ((int) driver->hbar == -1) { - drv_base->hbar (x, y, len); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_icon (int which, char dest) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->icon > 0) - driver->icon (which, dest); - else if ((int) driver->icon == -1) { - drv_base->icon (which, dest); - } - } - } while (LL_Next (list) == 0); + ; } -void +static void lcd_drv_flush_box (int lft, int top, int rgt, int bot) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->flush_box > 0) - driver->flush_box (lft, top, rgt, bot); - else if ((int) driver->flush_box == -1) { - drv_base->flush_box (lft, top, rgt, bot); - } - } - } while (LL_Next (list) == 0); - + ; } // TODO: Check whether lcd.draw_frame() should really take a framebuffer // TODO: as an argument, or if it should always use lcd.framebuf -void +static void lcd_drv_draw_frame (char *dat) { - lcd_logical_driver *driver; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->draw_frame > 0) - driver->draw_frame (dat); - else if ((int) driver->draw_frame == -1) { - drv_base->draw_frame (dat); - } - } - } while (LL_Next (list) == 0); - + ; } -char +static char * +lcd_drv_getinfo () +{ + return NULL; +} + +// Input functions: may come from multiple sources... + +static char lcd_drv_getkey () { - lcd_logical_driver *driver; - - char key; - - LL_Rewind (list); - do { - driver = (lcd_logical_driver *) LL_Get (list); - if (driver) { - lcd.framebuf = driver->framebuf; - - if ((int) driver->getkey > 0) { - key = driver->getkey (); - if (key) - return key; - } else if ((int) driver->getkey == -1) { - key = drv_base->getkey (); - if (key) - return key; - } - } - } while (LL_Next (list) == 0); - return 0; } -#define MAX_INFO_BUF 1024 +// char +// lcd_drv_getkey () +// { +// lcd_logical_driver *driver; +// +// char key; +// +// LL_Rewind (list); +// do { +// driver = (lcd_logical_driver *) LL_Get (list); +// if (driver) { +// lcd.framebuf = driver->framebuf; +// +// if ((int) driver->getkey > 0) { +// key = driver->getkey (); +// if (key) +// return key; +// } else if ((int) driver->getkey == -1) { +// key = drv_base->getkey (); +// if (key) +// return key; +// } +// } +// } while (LL_Next (list) == 0); +// +// return 0; +// } -char * -lcd_drv_getinfo () -{ - static char info[MAX_INFO_BUF]; - char *p; - lcd_logical_driver *driver; - - memset(info, '\0', sizeof(info)); - - ResetList(list); - do { - driver = GetDriverData(list); - - if (DriverPresent(driver)) { - if (FunctionPresent(driver->getinfo)) { - p = (char *) driver->getinfo (); - if (strlen(p) + strlen(info) < (MAX_INFO_BUF - 2)) { - strcat(info, p); - } - strcat(info, "\n"); - } - - } - - } while (MoreDrivers(list)); - - return info; -} diff --git a/server/drivers/lcd.h b/server/drivers/lcd.h index 8bf2e59..9a1b8cf 100644 --- a/server/drivers/lcd.h +++ b/server/drivers/lcd.h @@ -2,11 +2,15 @@ #define LCD_H // Maximum supported sizes -#define LCD_MAX_WID 256 #define LCD_MAX_WIDTH 256 -#define LCD_MAX_HGT 256 #define LCD_MAX_HEIGHT 256 +// Standard supported sizes +#define LCD_STD_WIDTH 20 +#define LCD_STD_HEIGHT 4 +#define LCD_STD_CELL_WIDTH 5 +#define LCD_STD_CELL_HEIGHT 8 + int lcd_init (char *args); int lcd_add_driver (char *driver, char *args); int lcd_shutdown (); @@ -66,26 +70,4 @@ typedef struct lcd_physical_driver { extern lcd_logical_driver lcd; -int lcd_drv_init (lcd_logical_driver * driver, char *args); -void lcd_drv_close (); -void lcd_drv_clear (); -void lcd_drv_flush (); -void lcd_drv_string (int x, int y, char string[]); -void lcd_drv_chr (int x, int y, char c); -int lcd_drv_contrast (int contrast); -void lcd_drv_backlight (int on); -void lcd_drv_output (int on); -void lcd_drv_init_vbar (); -void lcd_drv_init_hbar (); -void lcd_drv_init_num (); -void lcd_drv_num (int x, int num); -void lcd_drv_set_char (int n, char *dat); -void lcd_drv_vbar (int x, int len); -void lcd_drv_hbar (int x, int y, int len); -void lcd_drv_icon (int which, char dest); -void lcd_drv_flush_box (int lft, int top, int rgt, int bot); -void lcd_drv_draw_frame (); -char lcd_drv_getkey (); -char *lcd_drv_getinfo (); - #endif diff --git a/server/main.c b/server/main.c index 799d551..3faf328 100644 --- a/server/main.c +++ b/server/main.c @@ -39,6 +39,7 @@ #define MAX_TIMER 0x10000 #define DEFAULT_USER "nobody" +int debug_level = 3; char *version = VERSION; char *protocol_version = PROTOCOL_VERSION; char *build_date = __DATE__; diff --git a/server/screenlist.c b/server/screenlist.c index e8da137..35692d1 100644 --- a/server/screenlist.c +++ b/server/screenlist.c @@ -1,5 +1,6 @@ #include #include +#include #include "shared/LL.h" #include "shared/sockets.h" @@ -29,7 +30,7 @@ screenlist_init () screenlist = LL_new (); if (!screenlist) { - fprintf (stderr, "screenlist_init: Error allocating list\n"); + syslog(LOG_ERR, "screenlist_init: error allocating list"); return -1; } @@ -116,6 +117,7 @@ screenlist_current () sock_send_string (c->sock, str); } else // The server has the display, so do nothing { + ; } //debug("screenlist_current: ... sent ignore\n"); } @@ -129,6 +131,7 @@ screenlist_current () sock_send_string (c->sock, str); } else // The server has the display, so do nothing { + ; } } }