cleanup connection type recognition, prepare for aliases, ...
This commit is contained in:
@@ -29,36 +29,61 @@
|
||||
// add new connection type header files here
|
||||
|
||||
|
||||
// symbolic names for connection types
|
||||
#define HD44780_CT_UNKNOWN 0
|
||||
#define HD44780_CT_4BIT 1
|
||||
#define HD44780_CT_8BIT 2
|
||||
#define HD44780_CT_SERIALLPT 3
|
||||
#define HD44780_CT_WINAMP 4
|
||||
#define HD44780_CT_PICANLCD 5
|
||||
#define HD44780_CT_LCDSERIALIZER 6
|
||||
#define HD44780_CT_LOS_PANEL 7
|
||||
#define HD44780_CT_VDR_LCD 8
|
||||
#define HD44780_CT_VDR_WAKEUP 9
|
||||
#define HD44780_CT_PERTELIAN 10
|
||||
#define HD44780_CT_LIS2 11
|
||||
#define HD44780_CT_BWCTUSB 12
|
||||
#define HD44780_CT_LCDUSB 13
|
||||
#define HD44780_CT_I2C 14
|
||||
|
||||
// symbolic names for interface types
|
||||
#define IF_TYPE_UNKNOWN 0
|
||||
#define IF_TYPE_PARPORT 1
|
||||
#define IF_TYPE_SERIAL 2
|
||||
#define IF_TYPE_USB 3
|
||||
#define IF_TYPE_I2C 4
|
||||
|
||||
// connectionType enumerator:
|
||||
// - string to identify connection in config file
|
||||
// - connection type identifier
|
||||
// - interface type
|
||||
// - initialisation function
|
||||
static const ConnectionMapping connectionMapping[] = {
|
||||
// connectionType enumerator
|
||||
// string to identify connection on command line
|
||||
// your initialisation function
|
||||
// help string for your particular connection
|
||||
#ifdef HAVE_PCSTYLE_LPT_CONTROL
|
||||
{ "4bit", hd_init_4bit, "\tnone\n" },
|
||||
{ "8bit", hd_init_ext8bit, "\tnone\n" },
|
||||
{ "serialLpt", hd_init_serialLpt, "\tnone\n" },
|
||||
{ "winamp", hd_init_winamp, "\tnone\n" },
|
||||
{ "4bit", HD44780_CT_4BIT, IF_TYPE_PARPORT, hd_init_4bit },
|
||||
{ "8bit", HD44780_CT_8BIT, IF_TYPE_PARPORT, hd_init_ext8bit },
|
||||
{ "serialLpt", HD44780_CT_SERIALLPT, IF_TYPE_PARPORT, hd_init_serialLpt },
|
||||
{ "winamp", HD44780_CT_WINAMP, IF_TYPE_PARPORT, hd_init_winamp },
|
||||
#endif
|
||||
/* Serial connectiontypes */
|
||||
{ "picanlcd", hd_init_serial, "\tnone\n" },
|
||||
{ "lcdserializer", hd_init_serial, "\tnone\n" },
|
||||
{ "los-panel", hd_init_serial, "\tnone\n" },
|
||||
{ "vdr-lcd", hd_init_serial, "\tnone\n" },
|
||||
{ "vdr-wakeup", hd_init_serial, "\tnone\n" },
|
||||
{ "pertelian", hd_init_serial, "\tnone\n" },
|
||||
{ "picanlcd", HD44780_CT_PICANLCD, IF_TYPE_SERIAL, hd_init_serial },
|
||||
{ "lcdserializer", HD44780_CT_LCDSERIALIZER, IF_TYPE_SERIAL, hd_init_serial },
|
||||
{ "los-panel", HD44780_CT_LOS_PANEL, IF_TYPE_SERIAL, hd_init_serial },
|
||||
{ "vdr-lcd", HD44780_CT_VDR_LCD, IF_TYPE_SERIAL, hd_init_serial },
|
||||
{ "vdr-wakeup", HD44780_CT_VDR_WAKEUP, IF_TYPE_SERIAL, hd_init_serial },
|
||||
{ "pertelian", HD44780_CT_PERTELIAN, IF_TYPE_SERIAL, hd_init_serial },
|
||||
/* End serial connectiontypes */
|
||||
{ "lis2", hd_init_lis2, "\tnone\n" },
|
||||
{ "lis2", HD44780_CT_LIS2, IF_TYPE_SERIAL, hd_init_lis2 },
|
||||
#ifdef HAVE_LIBUSB
|
||||
{ "bwctusb", hd_init_bwct_usb, "\tnone\n" },
|
||||
{ "lcd2usb", hd_init_lcd2usb, "\tnone\n" },
|
||||
{ "bwctusb", HD44780_CT_BWCTUSB, IF_TYPE_USB, hd_init_bwct_usb },
|
||||
{ "lcd2usb", HD44780_CT_I2C, IF_TYPE_USB, hd_init_lcd2usb },
|
||||
#endif
|
||||
#ifdef HAVE_I2C
|
||||
{ "i2c", hd_init_i2c, "\tnone\n" },
|
||||
{ "i2c", HD44780_CT_I2C, IF_TYPE_I2C, hd_init_i2c },
|
||||
#endif
|
||||
// add new connection types and their string specifier here
|
||||
// default, end of structure element (do not delete)
|
||||
{ NULL, NULL, NULL }
|
||||
{ NULL, HD44780_CT_UNKNOWN, IF_TYPE_UNKNOWN, NULL }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -47,8 +47,9 @@ typedef struct cgram_cache {
|
||||
|
||||
typedef struct ConnectionMapping {
|
||||
char *name;
|
||||
int connectiontype;
|
||||
int if_type;
|
||||
int (*init_fn)(Driver *drvthis);
|
||||
const char *helpMsg;
|
||||
} ConnectionMapping;
|
||||
|
||||
typedef struct driver_private_data {
|
||||
@@ -75,7 +76,7 @@ typedef struct driver_private_data {
|
||||
CGmode ccmode;
|
||||
|
||||
// Connection type data
|
||||
int connectiontype_index;
|
||||
int connectiontype;
|
||||
struct hwDependentFns *hd44780_functions;
|
||||
|
||||
// spanList[line number] = display line number is in
|
||||
|
||||
+25
-24
@@ -120,9 +120,6 @@ MODULE_EXPORT int stay_in_foreground = 0;
|
||||
MODULE_EXPORT int supports_multiple = 1; // yes, we have no global variables (except for constants)
|
||||
MODULE_EXPORT char *symbol_prefix = "HD44780_";
|
||||
|
||||
#define IF_TYPE_PARPORT 0
|
||||
#define IF_TYPE_USB 1
|
||||
#define IF_TYPE_SERIAL 2
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Opens com port and sets baud correctly...
|
||||
@@ -134,8 +131,9 @@ HD44780_init(Driver *drvthis)
|
||||
// TODO: single point of return
|
||||
char buf[40];
|
||||
const char *s;
|
||||
int i;
|
||||
int if_type = IF_TYPE_PARPORT;
|
||||
int i = 0;
|
||||
int (*init_fn)(Driver *drvthis) = NULL;
|
||||
int if_type = IF_TYPE_UNKNOWN;
|
||||
PrivateData *p;
|
||||
|
||||
// Alocate and store private data
|
||||
@@ -169,22 +167,17 @@ HD44780_init(Driver *drvthis)
|
||||
|
||||
// Get and search for the connection type
|
||||
s = drvthis->config_get_string(drvthis->name, "ConnectionType", 0, "4bit");
|
||||
for (i = 0; connectionMapping[i].name != NULL && strcmp(s, connectionMapping[i].name) != 0; i++);
|
||||
if (connectionMapping[i].name == NULL) {
|
||||
report(RPT_ERR, "%s: unknown ConnectionType: %s", drvthis->name, s);
|
||||
return -1; // fatal error
|
||||
for (i = 0; (connectionMapping[i].name != NULL) &&
|
||||
(strcmp(s, connectionMapping[i].name) != 0); i++);
|
||||
if (connectionMapping[i].name == NULL) {
|
||||
report(RPT_ERR, "%s: unknown ConnectionType: %s", drvthis->name, s);
|
||||
return -1; // fatal error
|
||||
} else {
|
||||
p->connectiontype_index = i;
|
||||
/* check if ConnectionType contains the string "usb" or "USB" */
|
||||
if ((strstr(connectionMapping[p->connectiontype_index].name, "usb") != NULL) ||
|
||||
(strstr(connectionMapping[p->connectiontype_index].name, "USB") != NULL))
|
||||
if_type = IF_TYPE_USB;
|
||||
/* check if it is the serial driver */
|
||||
for (i = 0; i < (sizeof(serial_interfaces)/sizeof(SerialInterface)); i++) {
|
||||
if (strcasecmp(connectionMapping[p->connectiontype_index].name,
|
||||
serial_interfaces[i].name)==0)
|
||||
if_type = IF_TYPE_SERIAL;
|
||||
}
|
||||
/* set connection type */
|
||||
p->connectiontype = connectionMapping[i].connectiontype;
|
||||
|
||||
if_type = connectionMapping[i].if_type;
|
||||
init_fn = connectionMapping[i].init_fn;
|
||||
}
|
||||
|
||||
// Get and parse vspan only when specified
|
||||
@@ -341,7 +334,7 @@ HD44780_init(Driver *drvthis)
|
||||
p->hd44780_functions->close = NULL;
|
||||
|
||||
// Do connection type specific display init
|
||||
if (connectionMapping[p->connectiontype_index].init_fn(drvthis) != 0)
|
||||
if (init_fn(drvthis) != 0)
|
||||
return -1;
|
||||
|
||||
// Display startup parameters on the LCD
|
||||
@@ -349,21 +342,29 @@ HD44780_init(Driver *drvthis)
|
||||
sprintf(buf, "HD44780 %dx%d", p->width, p->height);
|
||||
HD44780_string(drvthis, 1, 1, buf);
|
||||
switch(if_type) {
|
||||
case IF_TYPE_USB:
|
||||
case IF_TYPE_USB:
|
||||
sprintf(buf, "USB %s%s%s",
|
||||
(p->have_backlight?" bl":""),
|
||||
(p->have_keypad?" key":""),
|
||||
(p->have_output?" out":"")
|
||||
);
|
||||
break;
|
||||
case IF_TYPE_SERIAL:
|
||||
case IF_TYPE_SERIAL:
|
||||
sprintf(buf, "SERIAL %s%s%s",
|
||||
(p->have_backlight?" bl":""),
|
||||
(p->have_keypad?" key":""),
|
||||
(p->have_output?" out":"")
|
||||
);
|
||||
break;
|
||||
default:
|
||||
case IF_TYPE_I2C:
|
||||
sprintf(buf, "I2C %s%s%s",
|
||||
(p->have_backlight?" bl":""),
|
||||
(p->have_keypad?" key":""),
|
||||
(p->have_output?" out":"")
|
||||
);
|
||||
break;
|
||||
case IF_TYPE_PARPORT:
|
||||
default:
|
||||
sprintf(buf, "LPT 0x%x%s%s%s", p->port,
|
||||
(p->have_backlight?" bl":""),
|
||||
(p->have_keypad?" key":""),
|
||||
|
||||
Reference in New Issue
Block a user