Starting to use PrivateData, just for def[] and use[]
This commit is contained in:
+64
-9
@@ -158,8 +158,9 @@ static int fd;
|
|||||||
/* Control when the LCD is cleared to custom char are not in use anymore */
|
/* Control when the LCD is cleared to custom char are not in use anymore */
|
||||||
static int clear = 1;
|
static int clear = 1;
|
||||||
|
|
||||||
static int def[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
/* Those information are moving to PrivateData */
|
||||||
static int use[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
/* static int def[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 }; */
|
||||||
|
/* static int use[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; */
|
||||||
|
|
||||||
static char *framebuf = NULL;
|
static char *framebuf = NULL;
|
||||||
static int width = LCD_DEFAULT_WIDTH;
|
static int width = LCD_DEFAULT_WIDTH;
|
||||||
@@ -179,6 +180,27 @@ static char forward_key = MTXORB_DEFAULT_FORWARD_KEY;
|
|||||||
static char main_menu_key = MTXORB_DEFAULT_MAIN_MENU_KEY;
|
static char main_menu_key = MTXORB_DEFAULT_MAIN_MENU_KEY;
|
||||||
static int keypad_test_mode = 0;
|
static int keypad_test_mode = 0;
|
||||||
|
|
||||||
|
/* This is an embrionic Private Date, it need to grow ! */
|
||||||
|
typedef struct p {
|
||||||
|
int def[9];
|
||||||
|
int use[9];
|
||||||
|
/*
|
||||||
|
int type;
|
||||||
|
int port;
|
||||||
|
char * keymap[MAXKEYS];
|
||||||
|
char * framebuf_text;
|
||||||
|
char * lcd_contents_text;
|
||||||
|
char * framebuf_graph;
|
||||||
|
char * lcd_contents_graph;
|
||||||
|
int width, height;
|
||||||
|
//int cellwidth, cellheight;
|
||||||
|
int graph_width, graph_height;
|
||||||
|
int cursor_x, cursor_y;
|
||||||
|
char cursor_state;
|
||||||
|
int bytesperline;
|
||||||
|
*/
|
||||||
|
} PrivateData;
|
||||||
|
|
||||||
/* Vars for the server core */
|
/* Vars for the server core */
|
||||||
MODULE_EXPORT char *api_version = API_VERSION;
|
MODULE_EXPORT char *api_version = API_VERSION;
|
||||||
MODULE_EXPORT int stay_in_foreground = 0;
|
MODULE_EXPORT int stay_in_foreground = 0;
|
||||||
@@ -244,6 +266,18 @@ MtxOrb_parse_speed (Driver *drvthis, char *arg) {
|
|||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
MtxOrb_usage (void) {
|
||||||
|
printf ("LCDproc Matrix-Orbital LCD driver\n"
|
||||||
|
"\t-d\t\tSelect the output device to use [/dev/lcd]\n"
|
||||||
|
"\t-t\t\tSelect the LCD type (size) [20x4]\n"
|
||||||
|
/* "\t-b\t--backlight\tSelect the backlight state [on]\n" */
|
||||||
|
"\t-c\t\tSet the initial contrast [140]\n"
|
||||||
|
"\t-s\t\tSet the communication speed [19200]\n"
|
||||||
|
"\t-h\t\tShow this help information\n"
|
||||||
|
"\t-b\t\tdisplay type: lcd, lkd, vfd, vkd\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MtxOrb_parse_contrast (Driver *drvthis, char * str) {
|
MtxOrb_parse_contrast (Driver *drvthis, char * str) {
|
||||||
int contrast;
|
int contrast;
|
||||||
@@ -294,6 +328,21 @@ MtxOrb_init (Driver *drvthis, char *args)
|
|||||||
char size[256] = DEFAULT_SIZE;
|
char size[256] = DEFAULT_SIZE;
|
||||||
char buf[256] = "";
|
char buf[256] = "";
|
||||||
int tmp, w, h;
|
int tmp, w, h;
|
||||||
|
PrivateData *p;
|
||||||
|
|
||||||
|
/* int def[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 }; */
|
||||||
|
/* int use[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; */
|
||||||
|
/* Alocate and store private data */
|
||||||
|
|
||||||
|
p = (PrivateData *) malloc( sizeof( PrivateData) );
|
||||||
|
if( ! p )
|
||||||
|
return -1;
|
||||||
|
if( drvthis->store_private_ptr( drvthis, p ) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memset( p->def, -1, sizeof(p->def) );
|
||||||
|
memset( p->use, 0, sizeof(p->use) );
|
||||||
|
|
||||||
|
|
||||||
MtxOrb_type = MTXORB_LKD; /* Assume it's an LCD w/keypad */
|
MtxOrb_type = MTXORB_LKD; /* Assume it's an LCD w/keypad */
|
||||||
|
|
||||||
@@ -503,12 +552,16 @@ MtxOrb_clear (Driver *drvthis)
|
|||||||
MODULE_EXPORT void
|
MODULE_EXPORT void
|
||||||
MtxOrb_close (Driver *drvthis)
|
MtxOrb_close (Driver *drvthis)
|
||||||
{
|
{
|
||||||
|
PrivateData * p = drvthis->private_data;
|
||||||
|
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
if (framebuf)
|
if (framebuf)
|
||||||
free (framebuf);
|
free (framebuf);
|
||||||
framebuf = NULL;
|
framebuf = NULL;
|
||||||
|
|
||||||
|
free( p );
|
||||||
|
|
||||||
debug(RPT_DEBUG, "MtxOrb: closed");
|
debug(RPT_DEBUG, "MtxOrb: closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1204,6 +1257,8 @@ MtxOrb_ask_bar (Driver *drvthis, int type)
|
|||||||
|
|
||||||
static int circular = -1;
|
static int circular = -1;
|
||||||
|
|
||||||
|
PrivateData * p = drvthis->private_data;
|
||||||
|
|
||||||
/* fprintf(stderr, "GLU: MtxOrb_ask_bar(%d).\n", type); */
|
/* fprintf(stderr, "GLU: MtxOrb_ask_bar(%d).\n", type); */
|
||||||
|
|
||||||
/* This bypass the search for WHITE and BLACK */
|
/* This bypass the search for WHITE and BLACK */
|
||||||
@@ -1212,14 +1267,14 @@ MtxOrb_ask_bar (Driver *drvthis, int type)
|
|||||||
|
|
||||||
/* If the screen was clear then no graphic caracter are in use yet. */
|
/* If the screen was clear then no graphic caracter are in use yet. */
|
||||||
if (clear) {
|
if (clear) {
|
||||||
for (pos = 0; pos < 8; pos++) use[pos] = 0;
|
for (pos = 0; pos < 8; pos++) p->use[pos] = 0;
|
||||||
clear = 0;
|
clear = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for a match with caracter already defined. */
|
/* Search for a match with caracter already defined. */
|
||||||
pos = 8; /* Not found. */
|
pos = 8; /* Not found. */
|
||||||
for (i = 0; i < 8; i++) { /* For all including heartbeat. */
|
for (i = 0; i < 8; i++) { /* For all including heartbeat. */
|
||||||
if (def[i] == type) pos = i; /* Founded (should break now). */
|
if (p->def[i] == type) pos = i; /* Founded (should break now). */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos == 8) {
|
if (pos == 8) {
|
||||||
@@ -1228,7 +1283,7 @@ MtxOrb_ask_bar (Driver *drvthis, int type)
|
|||||||
circular = (circular + 1) % 8;
|
circular = (circular + 1) % 8;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if (!use[(i + circular) % 8])
|
if (!p->use[(i + circular) % 8])
|
||||||
last_not_in_use = (i + circular) % 8;
|
last_not_in_use = (i + circular) % 8;
|
||||||
}
|
}
|
||||||
pos = last_not_in_use;
|
pos = last_not_in_use;
|
||||||
@@ -1238,16 +1293,16 @@ MtxOrb_ask_bar (Driver *drvthis, int type)
|
|||||||
/* A caracter is found (Best match could solve our problem).
|
/* A caracter is found (Best match could solve our problem).
|
||||||
* REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar| found at %d.\n", pos);
|
* REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar| found at %d.\n", pos);
|
||||||
*/
|
*/
|
||||||
if (def[pos] != type) {
|
if (p->def[pos] != type) {
|
||||||
MtxOrb_set_known_char (drvthis, pos, type);
|
MtxOrb_set_known_char (drvthis, pos, type);
|
||||||
/* fprintf(stderr, "GLU: MtxOrb_ask_bar [Set a char] pos: %d.\n", pos); */
|
/* fprintf(stderr, "GLU: MtxOrb_ask_bar [Set a char] pos: %d.\n", pos); */
|
||||||
/* Define a new graphic caracter. */
|
/* Define a new graphic caracter. */
|
||||||
def[pos] = type;
|
p->def[pos] = type;
|
||||||
/* Remember that now the caracter is available. */
|
/* Remember that now the caracter is available. */
|
||||||
}
|
}
|
||||||
if (!use[pos]) {
|
if (!p->use[pos]) {
|
||||||
/* If the caracter is no yet in use (but defined). */
|
/* If the caracter is no yet in use (but defined). */
|
||||||
use[pos] = 1;
|
p->use[pos] = 1;
|
||||||
/* Remember it is in use (so protect it from re-use). */
|
/* Remember it is in use (so protect it from re-use). */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user