Patched lcd.c to work with older drivers that use 0 or (void *) -1
as valid function pointer values (now logs to syslog); fixed text driver, curses driver, and CFontz driver to work correctly in new environment.
This commit is contained in:
+35
-2
@@ -187,8 +187,10 @@ CFontz_init (lcd_logical_driver * driver, char *args)
|
|||||||
}
|
}
|
||||||
// Set the functions the driver supports...
|
// Set the functions the driver supports...
|
||||||
|
|
||||||
driver->clear = (void *) -1;
|
//driver->clear = (void *) -1;
|
||||||
driver->string = (void *) -1;
|
driver->clear = CFontz_clear;
|
||||||
|
//driver->string = (void *) -1;
|
||||||
|
driver->string = CFontz_string;
|
||||||
// driver->chr = CFontz_chr;
|
// driver->chr = CFontz_chr;
|
||||||
driver->chr = CFontz_chr;
|
driver->chr = CFontz_chr;
|
||||||
driver->vbar = CFontz_vbar;
|
driver->vbar = CFontz_vbar;
|
||||||
@@ -694,3 +696,34 @@ CFontz_draw_frame (char *dat)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
// Clears the LCD screen
|
||||||
|
//
|
||||||
|
void
|
||||||
|
CFontz_clear ()
|
||||||
|
{
|
||||||
|
memset (lcd.framebuf, ' ', lcd.wid * lcd.hgt);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
// Prints a string on the lcd display, at position (x,y). The
|
||||||
|
// upper-left is (1,1), and the lower right should be (20,4).
|
||||||
|
//
|
||||||
|
void
|
||||||
|
CFontz_string (int x, int y, char string[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
x -= 1; // Convert 1-based coords to 0-based...
|
||||||
|
y -= 1;
|
||||||
|
|
||||||
|
for (i = 0; string[i]; i++) {
|
||||||
|
// Check for buffer overflows...
|
||||||
|
if ((y * lcd.wid) + x + i > (lcd.wid * lcd.hgt))
|
||||||
|
break;
|
||||||
|
lcd.framebuf[(y * lcd.wid) + x + i] = string[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,5 +19,7 @@ void CFontz_num (int x, int num);
|
|||||||
void CFontz_set_char (int n, char *dat);
|
void CFontz_set_char (int n, char *dat);
|
||||||
void CFontz_icon (int which, char dest);
|
void CFontz_icon (int which, char dest);
|
||||||
void CFontz_draw_frame (char *dat);
|
void CFontz_draw_frame (char *dat);
|
||||||
|
void CFontz_clear (void);
|
||||||
|
void CFontz_string (int x, int y, char string[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -37,8 +37,6 @@
|
|||||||
#define DEFAULT_AUTOSCROLL 1
|
#define DEFAULT_AUTOSCROLL 1
|
||||||
#define DEFAULT_CURSORBLINK 0
|
#define DEFAULT_CURSORBLINK 0
|
||||||
|
|
||||||
#define GENERIC (void *) -1
|
|
||||||
|
|
||||||
#define IS_LCD_DISPLAY (MtxOrb_type == MTXORB_LCD)
|
#define IS_LCD_DISPLAY (MtxOrb_type == MTXORB_LCD)
|
||||||
#define IS_LKD_DISPLAY (MtxOrb_type == MTXORB_LKD)
|
#define IS_LKD_DISPLAY (MtxOrb_type == MTXORB_LKD)
|
||||||
#define IS_VFD_DISPLAY (MtxOrb_type == MTXORB_VFD)
|
#define IS_VFD_DISPLAY (MtxOrb_type == MTXORB_VFD)
|
||||||
@@ -367,10 +365,6 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
|
|||||||
// forget bar caracter not in use anymore and reuse the
|
// forget bar caracter not in use anymore and reuse the
|
||||||
// slot for another bar caracter.
|
// slot for another bar caracter.
|
||||||
//
|
//
|
||||||
// Why not just use Matrix Orbital's "clear screen" function or output a "^L"?
|
|
||||||
// This reliance on drv_base_clear seems suspicious... especially as
|
|
||||||
// using a (void *) -1 in the driver structure does the same thing...
|
|
||||||
//
|
|
||||||
static void
|
static void
|
||||||
MtxOrb_clear ()
|
MtxOrb_clear ()
|
||||||
{
|
{
|
||||||
|
|||||||
+63
-1
@@ -233,6 +233,63 @@ lcd_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
return 1; // 1 is arbitrary. (must be 1 or more)
|
return 1; // 1 is arbitrary. (must be 1 or more)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ChkNull(a,b,c) if ((driver->a) == 0) { syslog(LOG_INFO, "warning: %s: null entries deprecated!", (c)); driver->a = (b); }
|
||||||
|
#define ChkBaseDrv(a,b,c) if ((driver->a) == (void *) -1) { syslog(LOG_ERR, "warning: %s: base driver has been REMOVED!", (c)); driver->a = (b); }
|
||||||
|
|
||||||
|
static int
|
||||||
|
lcd_drv_patch_init (struct lcd_logical_driver *driver)
|
||||||
|
{
|
||||||
|
// These are to patch drivers that use "NULL" as a valid value...
|
||||||
|
ChkNull(clear, lcd_drv_clear, "clear");
|
||||||
|
ChkNull(string, lcd_drv_string, "string");
|
||||||
|
ChkNull(chr, lcd_drv_chr, "chr");
|
||||||
|
ChkNull(vbar, lcd_drv_vbar, "vbar");
|
||||||
|
ChkNull(hbar, lcd_drv_hbar, "hbar");
|
||||||
|
ChkNull(init_num, lcd_drv_init_num, "init_num");
|
||||||
|
ChkNull(num, lcd_drv_num, "num");
|
||||||
|
|
||||||
|
ChkNull(init, lcd_drv_init, "init");
|
||||||
|
ChkNull(close, lcd_drv_close, "close");
|
||||||
|
ChkNull(flush, lcd_drv_flush, "flush");
|
||||||
|
ChkNull(flush_box, lcd_drv_flush_box, "flush_box");
|
||||||
|
ChkNull(contrast, lcd_drv_contrast, "contrast");
|
||||||
|
ChkNull(backlight, lcd_drv_backlight, "backlight");
|
||||||
|
ChkNull(output, lcd_drv_output, "output");
|
||||||
|
ChkNull(set_char, lcd_drv_set_char, "set_char");
|
||||||
|
ChkNull(icon, lcd_drv_icon, "icon");
|
||||||
|
ChkNull(init_vbar, lcd_drv_init_vbar, "init_vbar");
|
||||||
|
ChkNull(init_hbar, lcd_drv_init_hbar, "init_hbar");
|
||||||
|
ChkNull(draw_frame, lcd_drv_draw_frame, "draw_frame");
|
||||||
|
|
||||||
|
// Now check for base driver entries...;
|
||||||
|
ChkBaseDrv(getkey, lcd_drv_getkey, "getkey");
|
||||||
|
ChkBaseDrv(getinfo, lcd_drv_getinfo, "getinfo");
|
||||||
|
|
||||||
|
ChkBaseDrv(clear, lcd_drv_clear, "clear");
|
||||||
|
ChkBaseDrv(string, lcd_drv_string, "string");
|
||||||
|
ChkBaseDrv(chr, lcd_drv_chr, "chr");
|
||||||
|
ChkBaseDrv(vbar, lcd_drv_vbar, "vbar");
|
||||||
|
ChkBaseDrv(hbar, lcd_drv_hbar, "hbar");
|
||||||
|
ChkBaseDrv(init_num, lcd_drv_init_num, "init_num");
|
||||||
|
ChkBaseDrv(num, lcd_drv_num, "num");
|
||||||
|
|
||||||
|
ChkBaseDrv(init, lcd_drv_init, "init");
|
||||||
|
ChkBaseDrv(close, lcd_drv_close, "close");
|
||||||
|
ChkBaseDrv(flush, lcd_drv_flush, "flush");
|
||||||
|
ChkBaseDrv(flush_box, lcd_drv_flush_box, "flush_box");
|
||||||
|
ChkBaseDrv(contrast, lcd_drv_contrast, "contrast");
|
||||||
|
ChkBaseDrv(backlight, lcd_drv_backlight, "backlight");
|
||||||
|
ChkBaseDrv(output, lcd_drv_output, "output");
|
||||||
|
ChkBaseDrv(set_char, lcd_drv_set_char, "set_char");
|
||||||
|
ChkBaseDrv(icon, lcd_drv_icon, "icon");
|
||||||
|
ChkBaseDrv(init_vbar, lcd_drv_init_vbar, "init_vbar");
|
||||||
|
ChkBaseDrv(init_hbar, lcd_drv_init_hbar, "init_hbar");
|
||||||
|
ChkBaseDrv(draw_frame, lcd_drv_draw_frame, "draw_frame");
|
||||||
|
|
||||||
|
ChkBaseDrv(getkey, lcd_drv_getkey, "getkey");
|
||||||
|
ChkBaseDrv(getinfo, lcd_drv_getinfo, "getinfo");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function can be replaced later with something
|
* This function can be replaced later with something
|
||||||
* that utilizes the results of dynamic library loading
|
* that utilizes the results of dynamic library loading
|
||||||
@@ -278,6 +335,9 @@ lcd_add_driver (char *driver, char *args)
|
|||||||
// return -1;
|
// return -1;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "adding %s driver", driver);
|
||||||
|
syslog(LOG_INFO, buf);
|
||||||
|
|
||||||
add = &lcd;
|
add = &lcd;
|
||||||
memset (add, 0, sizeof (add));
|
memset (add, 0, sizeof (add));
|
||||||
|
|
||||||
@@ -293,7 +353,9 @@ lcd_add_driver (char *driver, char *args)
|
|||||||
}
|
}
|
||||||
memset (add->framebuf, ' ', (add->wid * add->hgt));
|
memset (add->framebuf, ' ', (add->wid * add->hgt));
|
||||||
|
|
||||||
return init_driver (add, args);
|
i = init_driver (add, args);
|
||||||
|
lcd_drv_patch_init (add); // patches drivers that think NULL is okay...
|
||||||
|
return i;
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf, sizeof(buf), "invalid driver: %s", driver);
|
snprintf(buf, sizeof(buf), "invalid driver: %s", driver);
|
||||||
syslog(LOG_ERR, buf);
|
syslog(LOG_ERR, buf);
|
||||||
|
|||||||
+24
-17
@@ -13,6 +13,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
@@ -24,42 +25,48 @@ lcd_logical_driver *text;
|
|||||||
////////////////////// For Text-Mode Output //////////////////////////////
|
////////////////////// For Text-Mode Output //////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define LCD_DEFAULT_WIDTH 20
|
||||||
|
#define LCD_DEFAULT_HEIGHT 4
|
||||||
|
#define LCD_DEFAULT_CELL_WIDTH 5
|
||||||
|
#define LCD_DEFAULT_CELL_HEIGHT 8
|
||||||
|
|
||||||
int
|
int
|
||||||
text_init (lcd_logical_driver * driver, char *args)
|
text_init (lcd_logical_driver * driver, char *args)
|
||||||
{
|
{
|
||||||
text = driver;
|
text = driver;
|
||||||
|
|
||||||
if (!driver->framebuf) {
|
if (!driver->framebuf) {
|
||||||
|
syslog(LOG_ERR, "text: no frame buffer!");
|
||||||
driver->close ();
|
driver->close ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
driver->wid = 20;
|
driver->wid = LCD_DEFAULT_WIDTH;
|
||||||
driver->hgt = 4;
|
driver->hgt = LCD_DEFAULT_HEIGHT;
|
||||||
driver->cellwid = 5;
|
driver->cellwid = LCD_DEFAULT_CELL_WIDTH;
|
||||||
driver->cellhgt = 8;
|
driver->cellhgt = LCD_DEFAULT_CELL_HEIGHT;
|
||||||
|
|
||||||
driver->clear = (void *) -1;
|
driver->clear = text_clear;
|
||||||
driver->string = (void *) -1;
|
driver->string = text_string;
|
||||||
driver->chr = (void *) -1;
|
driver->chr = text_chr;
|
||||||
driver->vbar = text_vbar;
|
driver->vbar = text_vbar;
|
||||||
driver->init_vbar = NULL;
|
//driver->init_vbar = NULL;
|
||||||
driver->hbar = text_hbar;
|
driver->hbar = text_hbar;
|
||||||
driver->init_hbar = NULL;
|
//driver->init_hbar = NULL;
|
||||||
driver->num = (void *) -1;
|
driver->num = text_num;
|
||||||
driver->init_num = NULL;
|
//driver->init_num = NULL;
|
||||||
|
|
||||||
driver->init = text_init;
|
driver->init = text_init;
|
||||||
driver->close = text_close;
|
driver->close = text_close;
|
||||||
driver->flush = text_flush;
|
driver->flush = text_flush;
|
||||||
driver->flush_box = NULL;
|
//driver->flush_box = NULL;
|
||||||
driver->contrast = NULL;
|
//driver->contrast = NULL;
|
||||||
driver->backlight = NULL;
|
//driver->backlight = NULL;
|
||||||
driver->set_char = NULL;
|
//driver->set_char = NULL;
|
||||||
driver->icon = NULL;
|
//driver->icon = NULL;
|
||||||
driver->draw_frame = text_draw_frame;
|
driver->draw_frame = text_draw_frame;
|
||||||
|
|
||||||
driver->getkey = NULL;
|
//driver->getkey = NULL;
|
||||||
|
|
||||||
return 200; // 200 is arbitrary. (must be 1 or more)
|
return 200; // 200 is arbitrary. (must be 1 or more)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user