v0.5 kick-off

This commit is contained in:
robijn
2001-12-30 00:15:25 +00:00
parent c28d25b795
commit 71056ec551
88 changed files with 6638 additions and 5469 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT(clients/lcdproc/batt.c) AC_INIT(clients/lcdproc/batt.c)
AM_INIT_AUTOMAKE(lcdproc, dev) AM_INIT_AUTOMAKE(lcdproc, 0.5beta)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST AC_CANONICAL_HOST
@@ -132,7 +132,7 @@ AC_DEFINE_UNQUOTED(LCDPORT, $LCDPORT)
AC_DEFINE_UNQUOTED(PROTOCOL_VERSION, "0.3") AC_DEFINE_UNQUOTED(PROTOCOL_VERSION, "0.3")
AC_DEFINE_UNQUOTED(API_VERSION, "0.4") AC_DEFINE_UNQUOTED(API_VERSION, "0.5beta")
AC_ARG_WITH(loadmax, AC_ARG_WITH(loadmax,
+158 -62
View File
@@ -1,5 +1,3 @@
DG: David GLAUDE as added a few comment for discussing this document.
This document describes the driver API of v0.5 of LCDproc. This document describes the driver API of v0.5 of LCDproc.
At time of this writing, this version is not released and some things might At time of this writing, this version is not released and some things might
be changed. be changed.
@@ -17,31 +15,44 @@ The use of the API has changed from v0.4 to v0.5. The default functions that
the server put in the pointers in v0.4 do no longer exist. Instead empty the server put in the pointers in v0.4 do no longer exist. Instead empty
functions are the default. If a driver implements a function, the function functions are the default. If a driver implements a function, the function
will be detected by the server. The driver should at least implement all will be detected by the server. The driver should at least implement all
basic functions like driver_chr and driver_str itself. basic functions like driver_chr and driver_str itself, and should also have
defined a number of other symbols for the server.
Because the drivers are loadable, some kind of version checking should be done. I will walk through the driver struct here.
Therefor the server expects the correct version number to be returned from the
version function. For the v0.5 version this should be "0.5". If it is wrong,
the driver will not be loaded. This version number can be found in the define
API_VERSION.
#define drvthis struct lcd_logical_driver * driver
DG: This is very C++ and it is meaningfull in C++ to have
DG: DATA + FUNCTION in the "this" because we have polymorph
DG: and heritage. But in our case we only need private data
DG: in order to support multiple instances.
DG: Or do we want the driver to provide different function
DG: based on the detected hardware (or something like that)?
DG: Except for init and close, I don't see why we don't give
DG: the private data rather than drvthis???
DG: Please explain (again).
typedef struct lcd_logical_driver { typedef struct lcd_logical_driver {
char * name; // Name of this driver. Filled by server. //////// Variables in the driver module
// The driver loader will look for symbols with these names !
char *api_version;
int *stay_in_foreground; // Does this driver require to be in foreground ?
int *does_input; // Does this driver do output ?
int *does_output; // Does this driver do output ?
The programmer should define the following symbols:
char * api_version = API_VERSION; // <-- this symbol is defined by make
int stay_in_foreground = 0; // This driver does not need to be in foreground
int does_input = 0; // This driver does not do input
int does_output = 1; // But only output
And fill these values with the correct values. Upon loading the driver module,
the server will locate these symbols and store pointers to them in the
driver struct.
Because the drivers are loadable, some kind of version checking should be
done. Therefor the server expects the correct version number to be found in
the api_version symbol (a string). For the v0.5 version this should be "0.5".
If the version is incompatible, the driver will not be loaded. The current
API version can always be determined by inserting the compiler define
API_VERSION in the code.
//////// Functions in the driver module
// Basic functions // Basic functions
char *(*version); // OR CAN WE RETRIEVE A STRING FROM THE MODULE
All these Basic functions should be implemented !
int (*init) (drvthis, char *args); int (*init) (drvthis, char *args);
void (*close) (drvthis); void (*close) (drvthis);
int (*width) (drvthis); int (*width) (drvthis);
@@ -51,34 +62,78 @@ typedef struct lcd_logical_driver {
void (*string) (drvthis, int x, int y, char *str); void (*string) (drvthis, int x, int y, char *str);
void (*chr) (drvthis, int x, int y, char c); void (*chr) (drvthis, int x, int y, char c);
// Extended functions // Extended functions
void (*vbar) (drvthis, int x, int y, int len, int promille, int pattern); void (*vbar) (drvthis, int x, int y, int len, int promille, int options);
void (*hbar) (drvthis, int x, int y, int len, int promille, int pattern); void (*hbar) (drvthis, int x, int y, int len, int promille, int options);
These functions have been extended since v0.4. They now now expext complete
coordinates, a length (in chars, not pixels!) a promillage (0 to 1000) and an
option.
void (*num) (drvthis, int x, int num); void (*num) (drvthis, int x, int num);
Draw big numbers on your display. Only 6 positions exist, 1 to 6.
void (*heartbeat) (drvthis, int state); void (*heartbeat) (drvthis, int state);
char (*set_icon) (drvthis, int icon);
DG: I don't like this function... Should be called to animate the heartbeat. The driver should thererfor
DG: I would prefer the following definition (like chr) probably call the icon function below.
DG: void (*set_icon) (drvthis, int x, int y, int icon);
void (*icon) (drvthis, int x, int y, int icon);
Tells to place a certain icon at a position.
// Userdef characters
void (*set_char) (drvthis, char ch, char *dat);
int (*get_free_chars) (drvthis);
int (*cellwidth) (drvthis);
int (*cellheight) (drvthis);
Functions to define a character. It is currently unclear how this system
should exactly work. The set_char function expects a simple block of data
with 1 byte for each pixel-line. So that is 8 bytes for a 5x8 char.
// Hardware functions // Hardware functions
int (*contrast) (drvthis, int contrast); int (*contrast) (drvthis, int contrast);
void (*backlight) (drvthis, int on); void (*backlight) (drvthis, int brightness);
void (*output) (drvthis, int on); void (*output) (drvthis, int state);
// Userdef characters, are those still supported ?
//void (*set_char) (drvthis, int n, char *dat);
//int (*cellwidth) (drvthis);
//int (*cellheight) (drvthis);
// Key functions // Key functions
char *(*get_key) (drvthis); char *(*get_key) (drvthis);
// Returns a string. Server cannot modify
// this string. Returns a string. This string is withing driver's memory space and the server
should therefor never try to modify this string.
char * (*get_info) ();
Returns a string describing the driver and it's features.
//////// Variables in server core available for drivers
char * name; // Name of this driver.
void * private_data;
These variables should be taken read-only for the drivers. The name variable
should be used to access the driver's own section in the config file.
The private_data pointer is the pointer to the driver's own data block. This
pointer should be stored using the store_private_ptr function below. The
driver should cast this to it's own private structure pointer.
//////// Functions in server core available for drivers
int (*store_private_ptr) (struct lcd_logical_driver * driver, void * private_data);
Store the driver's private data:
// Config file functions, filled by server // Config file functions, filled by server
// DO THESE NEED TO BE IN THIS STRUCTURE ?
// LOADABLE MODULES CAN CALL FUNCS IN THE MAIN MODULE ...
char (*config_get_bool) (char * sectionname, char * keyname, char (*config_get_bool) (char * sectionname, char * keyname,
int skip, char default_value); int skip, char default_value);
int (*config_get_int) (char * sectionname, char * keyname, int (*config_get_int) (char * sectionname, char * keyname,
@@ -86,36 +141,50 @@ DG: void (*set_icon) (drvthis, int x, int y, int icon);
double (*config_get_float) (char * sectionname, char * keyname, double (*config_get_float) (char * sectionname, char * keyname,
int skip, double default_value); int skip, double default_value);
char *(*config_get_string) (char * sectionname, char * keyname, char *(*config_get_string) (char * sectionname, char * keyname,
int skip, char * default); int skip, char * default_value);
// Returns a string in server memory space. // Returns a string in server memory space.
// Copy this string. // Copy this string.
int config_has_section (char *sectionname); int config_has_section (char *sectionname);
int config_has_key (char *sectionname, char *keyname); int config_has_key (char *sectionname, char *keyname);
See configfile.h on how to use these functions. As sectionname, always use the
driver name: drvthis->name
// Reporting function
void (*report) ( const int level, const char *format, .../*args*/ );
Easily usable report functions by including drivers/report.h. See that file
for details.
// Display properties functions (for drivers that adapt to other loaded drivers)
int (*get_display_width) ();
int (*get_display_height) ();
If you have a driver that can adapt its size to the size of an other driver,
it should read these values. If there is no other driver loaded yet, the
returned values will be 0.
// Driver private data // Driver private data
int (*store_private_ptr) (void * private_data);
void * private_data; // Filled by server by calling store_private_ptr() void * private_data; // Filled by server by calling store_private_ptr()
DG: I think it is the driver that should take care of using the right
DG: private data.
DG: The server need to remember two thing about a driver,
DG: 1) The drvthis wich contain what function to call and is a well define
DG: structure that we get at init time.
DG: drvthis should be the same for every instances of the driver.
DG: 2) private_data wich we remember and receave as a pointer to a black box
DG: and we give it back to the driver in EVERY call.
DG:
DG: Implicitly the driver knows about wich function is what...
DG: But the driver need to know only wich instance is currently "active".
DG:
DG: It does not change much, but we don't need store_private_ptr anymore.
// Driver should cast this to it's own } Driver;
// private structure pointer
} lcd_logical_driver;
The flush_box and draw_frame functions have been removed for v0.5. The flush_box and draw_frame functions have been removed for v0.5.
In the private structure will probably at least be:
PRIVATE DATA
With the introduction of loadable modules it is necesary to stop using global
variables to store a driver's data in. Instead, you should store it in a
structure, that you allocate abd store on driver's init. If you don't use
this system, but use globals, you get queer results if you run two LCDd
daemons on one machine. They will then use the same variables !
In the driver's private structure will probably at least be something like:
typedef struct my_driver_private { typedef struct my_driver_private {
@@ -125,23 +194,43 @@ typedef struct my_driver_private {
int cellwidth, cellheight; int cellwidth, cellheight;
// Frame buffer... // Frame buffer...
char *framebuf; char *framebuf;
}; } PrivateData;
You allocate and store this structure like this:
PrivateData * p;
// Alocate and store private data
p = (PrivateData *) malloc( sizeof(PrivateData) );
if( p == NULL )
return -1;
if( drvthis->store_private_ptr( drvthis, p ) < 0 )
return -1;
(... continue with the rest of your init routine)
You retrieve this private data pointer by adding the following code to the
beginning of your functions:
PrivateData * p = (PrivateData*) drvthis->private_data;
Then you can access your data like:
p->framebuf
FUNCTIONS IN DETAIL FUNCTIONS IN DETAIL
char *(*version);
// Return the API version string as the driver knows it.
int (*init) (drvthis, char *args); int (*init) (drvthis, char *args);
// The init function // The init function
// Starts up the LCD, initializes all vars. Allocates private data space // Starts up the LCD, initializes all vars. Allocates private data space
// and stores the pointer by calling store_private_ptr(); // and stores the pointer by calling store_private_ptr();
// The init function should return the correct version number.
void (*close) (drvthis); void (*close) (drvthis);
// Shuts down the connection with the LCD. // Shuts down the connection with the LCD.
// Called just before unloading the driver.
int (*width) (drvthis); int (*width) (drvthis);
// Get the screen width. // Get the screen width.
@@ -158,9 +247,11 @@ void (*flush) (drvthis);
void (*string) (drvthis, int x, int y, char *str); void (*string) (drvthis, int x, int y, char *str);
// Places a string in the framebuffer // Places a string in the framebuffer
// All coordinates are 1-based, (1,1) is top left. // All coordinates are 1-based, (1,1) is top left.
// Driver should check for overflows
void (*chr) (drvthis, int x, int y, char c); void (*chr) (drvthis, int x, int y, char c);
// Places a char in the framebuffer // Places a char in the framebuffer
// Driver should check for overflows
void (*vbar) (drvthis, int x, int len); void (*vbar) (drvthis, int x, int len);
// Draws a vertical bar at horizontal position x and with length len. // Draws a vertical bar at horizontal position x and with length len.
@@ -178,8 +269,9 @@ void (*heartbeat) (drvthis, int state);
// 0=off 1=graph1 2=graph2 // 0=off 1=graph1 2=graph2
int (*contrast) (drvthis, int contrast); int (*contrast) (drvthis, int contrast);
// Sets the contrast to the given value. // Sets the contrast to the given value. Values should be 0 to 255.
// Many displays do not support software setting of contrast. // Many displays do not support software setting of contrast.
// Use -1 to get the current value returned.
void (*backlight) (drvthis, int on); void (*backlight) (drvthis, int on);
// Sets the backlight to brightness 'on'. // Sets the backlight to brightness 'on'.
@@ -196,6 +288,10 @@ char *(*getkey) ();
// Returns NULL for "no key pressed", or a string describing the pressd key. // Returns NULL for "no key pressed", or a string describing the pressd key.
// These characters should match the keypad-layout. // These characters should match the keypad-layout.
char *(*getinfo) ();
// Returns a string describing the driver and its features.
char (*config_get_bool) (char * sectionname, char * keyname, char (*config_get_bool) (char * sectionname, char * keyname,
int skip, char default_value); int skip, char default_value);
// Call to server. Retrieve a bool from the config file. // Call to server. Retrieve a bool from the config file.
+1 -1
View File
@@ -1,5 +1,5 @@
SUBDIRS=drivers SUBDIRS=drivers
sbin_PROGRAMS=LCDd sbin_PROGRAMS=LCDd
LCDd_SOURCES= client_data.c client_data.h client_functions.c client_functions.h client_menu.h clients.c clients.h input.c input.h main.c main.h menu.c menu.h menus.c menus.h parse.c parse.h render.c render.h screen.c screen.h screenlist.c screenlist.h serverscreens.c serverscreens.h sock.c sock.h widget.c widget.h configfile.c configfile.h drivers.c drivers.h LCDd_SOURCES= client_data.c client_data.h client_functions.c client_functions.h client_menu.h clients.c clients.h input.c input.h main.c main.h menu.c menu.h menus.c menus.h parse.c parse.h render.c render.h screen.c screen.h screenlist.c screenlist.h serverscreens.c serverscreens.h sock.c sock.h widget.c widget.h configfile.c configfile.h drivers.c drivers.h driver.c driver.h
LCDd_LDADD = drivers/libLCDdrivers.a ../shared/libLCDstuff.a @LIBCURSES@ @LIBIRMAN@ @LIBLIRC_CLIENT@ @LIBSVGA@ LCDd_LDADD = drivers/libLCDdrivers.a ../shared/libLCDstuff.a @LIBCURSES@ @LIBIRMAN@ @LIBLIRC_CLIENT@ @LIBSVGA@
INCLUDES = -I$(top_srcdir) INCLUDES = -I$(top_srcdir)
+8 -9
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Creates and destroys a client's data structures. These are mainly * Creates and destroys a client's data structures. These are mainly
@@ -68,15 +67,15 @@ client_data_destroy (client_data * d)
d->ack = 0; d->ack = 0;
// Clean up the name... /* Clean up the name...*/
if (d->name) if (d->name)
free (d->name); free (d->name);
// Clean up the key list... /* Clean up the key list...*/
if (d->client_keys) if (d->client_keys)
free (d->client_keys); free (d->client_keys);
// Clean up the screenlist... /* Clean up the screenlist...*/
debug( RPT_DEBUG, "client_data_destroy: Cleaning screenlist"); debug( RPT_DEBUG, "client_data_destroy: Cleaning screenlist");
ResetScreenList (d->screenlist); ResetScreenList (d->screenlist);
do { do {
@@ -84,20 +83,20 @@ client_data_destroy (client_data * d)
if (s) { if (s) {
debug( RPT_DEBUG, "client_data_destroy: removing screen %s", s->id); debug( RPT_DEBUG, "client_data_destroy: removing screen %s", s->id);
// FIXME? This shouldn't be handled here... /* FIXME? This shouldn't be handled here...
// Now, remove it from the screenlist... * Now, remove it from the screenlist...*/
if (screenlist_remove_all (s) < 0) { if (screenlist_remove_all (s) < 0) {
// Not a serious error.. /* Not a serious error..*/
report( RPT_ERR, "client_data_destroy: Error dequeueing screen"); report( RPT_ERR, "client_data_destroy: Error dequeueing screen");
return 0; return 0;
} }
// Free its memory... /* Free its memory...*/
screen_destroy (s); screen_destroy (s);
} }
} while (MoreScreens(d->screenlist)); } while (MoreScreens(d->screenlist));
DestroyScreenList(d->screenlist); DestroyScreenList(d->screenlist);
// TODO: clean up the rest of the data... /* TODO: clean up the rest of the data...*/
return 0; return 0;
} }
+4 -5
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -20,17 +19,17 @@
typedef struct client_data { typedef struct client_data {
int ack; int ack;
char *name; char *name;
// and other stuff... doesn't matter yet /* and other stuff... doesn't matter yet*/
LinkedList *screenlist; LinkedList *screenlist;
// list of requested keys... /* list of requested keys...*/
char *client_keys ; char *client_keys ;
LinkedList *menulist; LinkedList *menulist;
} client_data; } client_data;
// sets up an existing (empty) client_data struct /* sets up an existing (empty) client_data struct*/
int client_data_init (client_data * d); int client_data_init (client_data * d);
// destroys members of a client's data /* destroys members of a client's data*/
int client_data_destroy (client_data * d); int client_data_destroy (client_data * d);
#endif #endif
+295 -285
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -23,7 +22,7 @@ typedef struct client_function {
int (*function) (client * c, int argc, char **argv); int (*function) (client * c, int argc, char **argv);
} client_function; } client_function;
// FIXME? Do these really need to be visible from other sources? /* FIXME? Do these really need to be visible from other sources?*/
int test_func_func (client * c, int argc, char **argv); int test_func_func (client * c, int argc, char **argv);
int hello_func (client * c, int argc, char **argv); int hello_func (client * c, int argc, char **argv);
int client_set_func (client * c, int argc, char **argv); int client_set_func (client * c, int argc, char **argv);
+4 -5
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -27,10 +26,10 @@ typedef struct client_menu {
typedef struct client_menu_item { typedef struct client_menu_item {
char id[]; char id[];
int type; // Title, function, submenu, slider, checkbox, etc... int type; /* Title, function, submenu, slider, checkbox, etc...*/
int value; // Holds stuff like "true", 43, etc... int value; /* Holds stuff like "true", 43, etc...*/
char text[]; // Text to display here... char text[]; /* Text to display here...*/
char child[]; // For the "submenu" type char child[]; /* For the "submenu" type*/
} client_menu; } client_menu;
#endif #endif
+40 -38
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Inits/shuts down client system, * Inits/shuts down client system,
@@ -31,7 +30,7 @@
LinkedList *clients; LinkedList *clients;
// Initialize and kill client list... /* Initialize and kill client list...*/
int int
client_init () client_init ()
{ {
@@ -53,9 +52,10 @@ client_shutdown ()
debug (RPT_INFO, "client_shutdown()"); debug (RPT_INFO, "client_shutdown()");
// Free all client structures... /* Free all client structures...
// Note that the regular list loop doesn't work here, because * Note that the regular list loop doesn't work here, because
// client_destroy() calls LL_Remove() * client_destroy() calls LL_Remove()
*/
for (c = LL_Pop (clients); c; c = LL_Pop (clients)) { for (c = LL_Pop (clients); c; c = LL_Pop (clients)) {
debug (RPT_DEBUG, "client_shutdown: ..."); debug (RPT_DEBUG, "client_shutdown: ...");
if (c) { if (c) {
@@ -70,7 +70,7 @@ client_shutdown ()
} }
} }
// Then, free the list... /* Then, free the list...*/
LL_Destroy (clients); LL_Destroy (clients);
debug (RPT_DEBUG, "client_shutdown: done"); debug (RPT_DEBUG, "client_shutdown: done");
@@ -78,10 +78,11 @@ client_shutdown ()
return 0; return 0;
} }
// A client is identified by the file descriptor /* A client is identified by the file descriptor
// associated with it. + associated with it.
// *
// Create and destroy clients.... * Create and destroy clients....
*/
client * client *
client_create (int sock) client_create (int sock)
{ {
@@ -89,28 +90,28 @@ client_create (int sock)
debug (RPT_DEBUG, "client_create(%i)", sock); debug (RPT_DEBUG, "client_create(%i)", sock);
// Allocate new client... /* Allocate new client...*/
c = malloc (sizeof (client)); c = malloc (sizeof (client));
if (!c) { if (!c) {
report (RPT_ERR, "client_create: error allocating new client"); report (RPT_ERR, "client_create: error allocating new client");
return NULL; return NULL;
} }
// Init struct members /* Init struct members*/
c->sock = 0; c->sock = 0;
c->data = NULL; c->data = NULL;
c->messages = NULL; c->messages = NULL;
c->sock = sock; c->sock = sock;
c->backlight_state = backlight; //By default we get the server setting c->backlight_state = backlight; /*By default we get the server setting*/
// Set up message list... /*Set up message list...*/
c->messages = LL_new (); c->messages = LL_new ();
if (!c->messages) { if (!c->messages) {
report (RPT_ERR, "client_create: error allocating message list"); report (RPT_ERR, "client_create: error allocating message list");
free (c); free (c);
return NULL; return NULL;
} }
// TODO: allocate and init client data... /*TODO: allocate and init client data...*/
c->data = malloc (sizeof (client_data)); c->data = malloc (sizeof (client_data));
if (!c->data) { if (!c->data) {
report (RPT_ERR, "client_create: error allocating client data"); report (RPT_ERR, "client_create: error allocating client data");
@@ -120,7 +121,7 @@ client_create (int sock)
} else if (client_data_init (c->data) < 0) { } else if (client_data_init (c->data) < 0) {
return NULL; return NULL;
} }
// TODO: Check for errors while adding the client to the list? /*TODO: Check for errors while adding the client to the list?*/
LL_Push (clients, (void *) c); LL_Push (clients, (void *) c);
return c; return c;
@@ -138,7 +139,7 @@ client_destroy (client * c)
if (!c) if (!c)
return -1; return -1;
// Eat the rest of the incoming requests... /*Eat the rest of the incoming requests...*/
debug (RPT_DEBUG, "client_destroy: get_messages"); debug (RPT_DEBUG, "client_destroy: get_messages");
while ((str = client_get_message (c))) { while ((str = client_get_message (c))) {
if (str) { if (str) {
@@ -147,19 +148,19 @@ client_destroy (client * c)
} }
} }
// close socket... /*close socket...*/
if (c->sock) { if (c->sock) {
// sock_send_string (c->sock, "bye\n"); /*sock_send_string (c->sock, "bye\n");*/
close(c->sock); close(c->sock);
report(RPT_NOTICE, "closed socket for #%d", c->sock); report(RPT_NOTICE, "closed socket for #%d", c->sock);
} }
err = LL_Destroy (c->messages); err = LL_Destroy (c->messages);
// Free client's other data /*Free client's other data*/
client_data_destroy (c->data); client_data_destroy (c->data);
// Remove the client from the clients list... /*Remove the client from the clients list...*/
LL_Remove (clients, c); LL_Remove (clients, c);
free (c); free (c);
@@ -167,7 +168,7 @@ client_destroy (client * c)
return 0; return 0;
} }
// Add and remove messages from the client's queue... /*Add and remove messages from the client's queue...*/
int int
client_add_message (client * c, char *message) client_add_message (client * c, char *message)
{ {
@@ -175,7 +176,7 @@ client_add_message (client * c, char *message)
char *dup; char *dup;
char *str, *cp; char *str, *cp;
char delimiters[] = "\n\r\0"; char delimiters[] = "\n\r\0";
// int len; /* int len;*/
debug(RPT_DEBUG, "client_add_message(%s)", message); debug(RPT_DEBUG, "client_add_message(%s)", message);
@@ -184,31 +185,32 @@ client_add_message (client * c, char *message)
if (!message) if (!message)
return -1; return -1;
// len = strlen(message); /* len = strlen(message);
// if(len < 1) return 0; * if(len < 1) return 0;
*/
// Copy the string to avoid overwriting the original... /* Copy the string to avoid overwriting the original...*/
dup = strdup (message); dup = strdup (message);
if (!dup) { if (!dup) {
report(RPT_ERR, "client_add_message: Error allocating new string"); report(RPT_ERR, "client_add_message: Error allocating new string");
return -1; return -1;
} }
// Now split the string into lines and enqueue each one... /* Now split the string into lines and enqueue each one...*/
for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) { for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) {
cp = strdup (str); cp = strdup (str);
debug (RPT_DEBUG, "client_add_message: %s", cp); debug (RPT_DEBUG, "client_add_message: %s", cp);
err += LL_Enqueue (c->messages, (void *) cp); err += LL_Enqueue (c->messages, (void *) cp);
} }
//debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err); /*debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err);*/
free (dup); // Fixed memory leak... free (dup); /* Fixed memory leak...*/
// Err is the number of errors encountered... /* Err is the number of errors encountered...*/
return err; return err;
} }
// Woo-hoo! A simple function. :) /* Woo-hoo! A simple function. :)*/
char * char *
client_get_message (client * c) client_get_message (client * c)
{ {
@@ -221,23 +223,23 @@ client_get_message (client * c)
str = (char *) LL_Dequeue (c->messages); str = (char *) LL_Dequeue (c->messages);
//debug(RPT_DEBUG, "client_get_message: \"%s\"", str); /*debug(RPT_DEBUG, "client_get_message: \"%s\"", str);*/
return str; return str;
} }
// Get and set the client's data... /* Get and set the client's data...*/
int int
client_set (client * c, void *data) client_set (client * c, void *data)
{ {
// You know, I really doubt this function will be useful... /* You know, I really doubt this function will be useful...*/
return 0; return 0;
} }
void * void *
client_get (client * c) client_get (client * c)
{ {
// But this one might be handy... /* But this one might be handy...*/
return NULL; return NULL;
} }
@@ -247,14 +249,14 @@ client_find_sock (int sock)
{ {
client *c; client *c;
// debug(RPT_INFO, "client_find_sock(%i)", sock); /* debug(RPT_INFO, "client_find_sock(%i)", sock);*/
LL_Rewind (clients); LL_Rewind (clients);
do { do {
c = (client *) LL_Get (clients); c = (client *) LL_Get (clients);
// debug(RPT_DEBUG, "client_find_sock: ... %i ...", c->sock); /* debug(RPT_DEBUG, "client_find_sock: ... %i ...", c->sock);*/
if (c->sock == sock) { if (c->sock == sock) {
// debug(RPT_DEBUG, "client_find_sock: ..! %i !..", c->sock); /* debug(RPT_DEBUG, "client_find_sock: ..! %i !..", c->sock);*/
return c; return c;
} }
} while (LL_Next (clients) == 0); } while (LL_Next (clients) == 0);
+7 -7
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -27,24 +26,25 @@ typedef struct client {
extern LinkedList *clients; extern LinkedList *clients;
// Initialize and kill client list... /* Initialize and kill client list...*/
int client_init (); int client_init ();
int client_shutdown (); int client_shutdown ();
// Create and destroy clients.... /* Create and destroy clients....*/
client *client_create (int sock); client *client_create (int sock);
int client_destroy (client * c); int client_destroy (client * c);
// Add and remove messages from the client's queue... /* Add and remove messages from the client's queue...*/
int client_add_message (client * c, char *message); int client_add_message (client * c, char *message);
char *client_get_message (client * c); char *client_get_message (client * c);
// Get and set the client's data... /* Get and set the client's data...
// Not used at all yet, and may never be. Oh, well. * Not used at all yet, and may never be. Oh, well.
*/
int client_set (client * c, void *data); int client_set (client * c, void *data);
void *client_get (client * c); void *client_get (client * c);
// Search for a client with a particular filedescriptor... /* Search for a client with a particular filedescriptor...*/
client *client_find_sock (int sock); client *client_find_sock (int sock);
#endif #endif
+28 -27
View File
@@ -34,7 +34,7 @@ typedef struct section {
static section * first_section = NULL; static section * first_section = NULL;
// Yes there is a static. It's C after all :) /* Yes there is a static. It's C after all :)*/
section * find_section( char * sectionname ); section * find_section( char * sectionname );
@@ -44,7 +44,7 @@ key * add_key( section * s, char * keyname, char * value );
int process_config( section ** current_section, char (*get_next_char)(), char modify_section_allowed, char * source_descr ); int process_config( section ** current_section, char (*get_next_char)(), char modify_section_allowed, char * source_descr );
//// EXTERNAL FUNCTIONS //// /**** EXTERNAL FUNCTIONS ****/
#define FILECHUNKSIZE 10 #define FILECHUNKSIZE 10
@@ -56,11 +56,11 @@ int config_read_file( char *filename )
int pos=0; int pos=0;
section * curr_section = NULL; section * curr_section = NULL;
// We use a nested fuction to transfer the characters from buffer to parser /* We use a nested fuction to transfer the characters from buffer to parser*/
char get_next_char() { char get_next_char() {
if( pos>=bytesread ) { if( pos>=bytesread ) {
if( !( bytesread = fread( buf, 1, FILECHUNKSIZE, f ))) { if( !( bytesread = fread( buf, 1, FILECHUNKSIZE, f ))) {
// We're at the end /* We're at the end*/
return 0; return 0;
} }
pos = 0; pos = 0;
@@ -82,12 +82,12 @@ int config_read_file( char *filename )
int config_read_string( char *sectionname, char *str ) int config_read_string( char *sectionname, char *str )
// All the config parameters are placed in the given section in memory. /* All the config parameters are placed in the given section in memory.*/
{ {
int pos=0; int pos=0;
section * s; section * s;
// We use a nested fuction to transfer the characters from buffer to parser /* We use a nested fuction to transfer the characters from buffer to parser*/
char get_next_char() { char get_next_char() {
return str[pos++]; return str[pos++];
} }
@@ -115,9 +115,10 @@ char *config_get_string( char * sectionname, char * keyname,
return k->value; return k->value;
/* This is the safer way: /* This is the safer way:*/
// Reallocate memory space for the return value /* Reallocate memory space for the return value*/
/*
string_storage = realloc( string_storage, ( strlen( k->value ) / 256 + 1) * 256 ); string_storage = realloc( string_storage, ( strlen( k->value ) / 256 + 1) * 256 );
strcpy( string_storage, k->value ); strcpy( string_storage, k->value );
@@ -164,7 +165,7 @@ long int config_get_int( char *sectionname, char *keyname,
v = strtol( k->value, &v_end, 0 ); v = strtol( k->value, &v_end, 0 );
if( v_end-(k->value) != strlen(k->value) ) { if( v_end-(k->value) != strlen(k->value) ) {
// Conversion not succesful /* Conversion not succesful*/
return default_value; return default_value;
} }
return v; return v;
@@ -186,7 +187,7 @@ double config_get_float( char *sectionname, char *keyname,
v = strtod( k->value, &v_end ); v = strtod( k->value, &v_end );
if( v_end-(k->value) != strlen(k->value) ) { if( v_end-(k->value) != strlen(k->value) ) {
// Conversion not succesful /* Conversion not succesful*/
return default_value; return default_value;
} }
return v; return v;
@@ -214,7 +215,7 @@ int config_has_key( char *sectionname, char *keyname )
for( k=s->first_key; k; k=k->next_key ) { for( k=s->first_key; k; k=k->next_key ) {
// Did we find the right key ? /* Did we find the right key ?*/
if( strcasecmp( k->name, keyname ) == 0 ) { if( strcasecmp( k->name, keyname ) == 0 ) {
count ++; count ++;
} }
@@ -229,7 +230,7 @@ void config_clear()
} }
//// INTERNAL FUNCTIONS //// /**** INTERNAL FUNCTIONS ****/
section * find_section( char * sectionname ) section * find_section( char * sectionname )
{ {
@@ -240,7 +241,7 @@ section * find_section( char * sectionname )
return s; return s;
} }
} }
return NULL; // not found return NULL; /* not found*/
} }
section * add_section( char * sectionname ) section * add_section( char * sectionname )
@@ -266,12 +267,12 @@ key * find_key( section * s, char * keyname, int skip )
int count = 0; int count = 0;
key * last_key = NULL; key * last_key = NULL;
// Check for NULL section /* Check for NULL section*/
if(!s) return NULL; if(!s) return NULL;
for( k=s->first_key; k; k=k->next_key ) { for( k=s->first_key; k; k=k->next_key ) {
// Did we find the right key ? /* Did we find the right key ?*/
if( strcasecmp( k->name, keyname ) == 0 ) { if( strcasecmp( k->name, keyname ) == 0 ) {
if( count == skip ) { if( count == skip ) {
return k; return k;
@@ -284,7 +285,7 @@ key * find_key( section * s, char * keyname, int skip )
if( skip == -1 ) { if( skip == -1 ) {
return last_key; return last_key;
} }
return NULL; // not found return NULL; /* not found*/
} }
key * add_key( section * s, char * keyname, char * value ) key * add_key( section * s, char * keyname, char * value )
@@ -307,7 +308,7 @@ key * add_key( section * s, char * keyname, char * value )
} }
// Parser states /* Parser states*/
#define ST_INITIAL 0 #define ST_INITIAL 0
#define ST_IGNORE 1 #define ST_IGNORE 1
#define ST_SECTIONNAME 2 #define ST_SECTIONNAME 2
@@ -321,7 +322,7 @@ key * add_key( section * s, char * keyname, char * value )
#define ST_INVALID_QUOTEDVALUE 31 #define ST_INVALID_QUOTEDVALUE 31
#define ST_END 99 #define ST_END 99
// Limits /* Limits*/
#define MAXSECTIONNAMELENGTH 40 #define MAXSECTIONNAMELENGTH 40
#define MAXKEYNAMELENGTH 40 #define MAXKEYNAMELENGTH 40
#define MAXVALUELENGTH 200 #define MAXVALUELENGTH 200
@@ -346,7 +347,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
ch = get_next_char(); ch = get_next_char();
// Secretly keep count of the line numbers /* Secretly keep count of the line numbers*/
if( ch == '\n' ) { if( ch == '\n' ) {
line_nr ++; line_nr ++;
} }
@@ -363,11 +364,11 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case ';': case ';':
case '=': case '=':
case ']': case ']':
// It's a comment or an error /* It's a comment or an error*/
state = ST_IGNORE; state = ST_IGNORE;
break; break;
case '[': case '[':
// It's a section name /* It's a section name*/
state = ST_SECTIONNAME; state = ST_SECTIONNAME;
sectionname[0] = 0; sectionname[0] = 0;
sectionname_pos = 0; sectionname_pos = 0;
@@ -375,7 +376,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case 0: case 0:
break; break;
default: default:
// It's a keyname /* It's a keyname*/
state = ST_KEYNAME; state = ST_KEYNAME;
keyname[0] = ch; keyname[0] = ch;
keyname[1] = 0; keyname[1] = 0;
@@ -465,7 +466,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
switch( ch ) { switch( ch ) {
case '\n': case '\n':
state = ST_INITIAL; state = ST_INITIAL;
//case ' ': /*case ' ':*/
} }
break; break;
case ST_VALUE: case ST_VALUE:
@@ -486,15 +487,15 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case '\r': case '\r':
case '\t': case '\t':
case ' ': case ' ':
// Value complete ! /* Value complete !*/
if( ! *current_section ) { if( ! *current_section ) {
report( RPT_WARNING, "Data before any section on line %d of %s with key: %s", line_nr, source_descr, keyname ); report( RPT_WARNING, "Data before any section on line %d of %s with key: %s", line_nr, source_descr, keyname );
} }
else { else {
// Store the value /* Store the value*/
k = add_key( *current_section, keyname, value ); k = add_key( *current_section, keyname, value );
} }
// And be ready for next thing... /* And be ready for next thing...*/
state = ST_INITIAL; state = ST_INITIAL;
break; break;
default: default:
@@ -539,7 +540,7 @@ int process_config( section ** current_section, char (*get_next_char)(), char mo
case 'n': ch = '\n'; break; case 'n': ch = '\n'; break;
case 'r': ch = '\r'; break; case 'r': ch = '\r'; break;
case 't': ch = '\t'; break; case 't': ch = '\t'; break;
// default: litteral /* default: litteral*/
} }
quote = 0; quote = 0;
} }
+34 -27
View File
@@ -20,52 +20,59 @@
#endif #endif
int config_read_file( char *filename ); int config_read_file( char *filename );
// Opens the specified file and reads everything into memory. /* Opens the specified file and reads everything into memory.
// Returns -1 on parsing errors. * Returns -1 on parsing errors.
// Returns -2 if the file could not be opened or a read error occured. * Returns -2 if the file could not be opened or a read error occured.
// Returns -16 if a malloc went wrong. * Returns -16 if a malloc went wrong.
*/
int config_read_string( char *sectionname, char *str ); int config_read_string( char *sectionname, char *str );
// Reads everything in the string into memory. /* Reads everything in the string into memory.
// Returns -1 on parsing errors. * Returns -1 on parsing errors.
// Returns -16 if a malloc went wrong. * Returns -16 if a malloc went wrong.
*/
unsigned char config_get_bool( char *sectionname, char *keyname, unsigned char config_get_bool( char *sectionname, char *keyname,
int skip, unsigned char default_value ); int skip, unsigned char default_value );
// Tries to interpret a value in the config file as a boolean. /* Tries to interpret a value in the config file as a boolean.
// 0, false, no, n = false * 0, false, no, n = false
// 1, true, yes, y = true * 1, true, yes, y = true
// If the key is not found or cannot be interpreted, the given default value is * If the key is not found or cannot be interpreted, the given default value is
// returned. * returned.
// The skip value can be used to iterate over multiple values with the same * The skip value can be used to iterate over multiple values with the same
// key. Should be 0 to get the first one, 1 for the second etc. and -1 for the * key. Should be 0 to get the first one, 1 for the second etc. and -1 for the
// last. * last.
*/
long int config_get_int( char *sectionname, char *keyname, long int config_get_int( char *sectionname, char *keyname,
int skip, long int default_value ); int skip, long int default_value );
// Tries to interpret a value in the config file as an integer. /* Tries to interpret a value in the config file as an integer.*/
double config_get_float( char *sectionname, char *keyname, double config_get_float( char *sectionname, char *keyname,
int skip, double default_value ); int skip, double default_value );
// Tries to interpret a value in the config file as a float. /* Tries to interpret a value in the config file as a float.*/
char *config_get_string( char * sectionname, char * keyname, char *config_get_string( char * sectionname, char * keyname,
int skip, char * default_value ); int skip, char * default_value );
// Returns a pointer to the string associated with the specified key. /* Returns a pointer to the string associated with the specified key.
// The string should never be modified, and used only short-term. You can * The string should never be modified, and used only short-term. You can
// for example scan it or copy it. In successive calls this function can * for example scan it or copy it. In successive calls this function can
// re-use the data space ! * re-use the data space !
*/
int config_has_section( char *sectionname ); int config_has_section( char *sectionname );
// Checks if a specified section exists. /* Checks if a specified section exists.
// Returns whether it exists. * Returns whether it exists.
*/
int config_has_key( char *sectionname, char *keyname ); int config_has_key( char *sectionname, char *keyname );
// Checks if a specified key within the specified section exists. /* Checks if a specified key within the specified section exists.
// Returns the number of times the key exists. * Returns the number of times the key exists.
*/
void config_clear(); void config_clear();
// Clears all data stored by the config_read_* functions. /* Clears all data stored by the config_read_* functions.
// Should be called if the config should be reread. * Should be called if the config should be reread.
*/
#endif #endif
+247
View File
@@ -0,0 +1,247 @@
/*
* driver.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 2001, Joris Robijn
*
*
* This code does all actions on the driver object.
*
*/
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/errno.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "shared/report.h"
#include "configfile.h"
#include "driver.h"
#include "drivers.h"
#include "drivers/lcd.h"
/* lcd.h is used for the driver API definition */
void * lcd_find_init (char *driver); /* HACK TO USE THIS WHILE NO LOADABLE DRIVERS */
/* Functions for the driver */
static int request_display_width();
static int request_display_height();
static int driver_store_private_ptr(Driver * driver, void * private_data);
Driver *
driver_load( char * name, char * filename, char * args )
{
void (*driver_init)();
Driver * driver = NULL;
int res;
debug( RPT_DEBUG, "Loading driver [%.40s]", name );
/* Allocate memory for new driver struct */
driver = malloc( sizeof( Driver ));
memset( driver, 0, sizeof (Driver));
/* Load the driver modules and fill the symbols */
if( driver_bind_module( driver ) < 0 ) {
report( RPT_ERR, "Driver [%.40s] load failed", name );
free( driver );
return NULL;
}
/* Find the driver in the array of driver types OLD CODE IS CALLED HERE */
if ((driver_init = lcd_find_init(name)) == NULL) {
/* Driver not found */
report( RPT_ERR, "Unknown driver [%.40s]", name);
return NULL;
}
driver->init = (int (*)(Driver*,char*)) driver_init;
/* And store its name and filename */
driver->name = malloc( strlen( name ) + 1 );
strcpy( driver->name, name );
driver->filename = malloc( strlen( filename ) + 1 );
strcpy( driver->filename, filename );
/* Call the init function */
report( RPT_DEBUG, "Calling driver [%.40s] init function", driver->name );
res = driver->init( driver, args );
if( res < 0 ) {
report( RPT_ERR, "Driver [%.40s] init failed, return code < 0", driver->name );
/* Driver load failed, don't add driver to list
* Free driver structure again
*/
free( driver->name );
free( driver->filename );
free( driver );
return NULL;
}
/* Check if necesary functions are filled
* SHOULD BE DONE BEFORE CALLING INIT WHEN WE HAVE LOADABLE DRIVERS
*/
if( ! driver_has_obligatory_symbols( driver ) ) {
report( RPT_ERR, "Driver [%.40s] does not have all obligatory symbols", driver->name );
driver_unload( driver );
return NULL;
}
debug( RPT_NOTICE, "Driver [%.40s] loaded", driver->name );
return driver;
}
int
driver_unload( Driver * driver )
{
debug( RPT_NOTICE, "Closing driver [%.40s]", driver->name );
if( driver->close )
driver->close (driver);
/* FUTURE: UNLOAD THE LOADED MODULE */
driver_unbind_module( driver );
/* Free its data */
free( driver->filename );
free( driver->name );
free( driver );
debug( RPT_DEBUG, "Driver unloaded" );
return 0;
}
int
driver_bind_module( Driver * driver )
{
/* Clear the struct, including all functions */
memset( driver, 0, sizeof(Driver) );
/* FUTURE: GET THE SYMBOLS FROM THE DRIVER MODULE */
/* Add our exported functions */
/* Config file functions */
driver->config_get_bool = config_get_bool;
driver->config_get_int = config_get_int;
driver->config_get_float = config_get_float;
driver->config_get_string = config_get_string;
driver->config_has_section = config_has_section;
driver->config_has_key = config_has_key;
/* Reporting */
driver->report = report;
/* Driver private data */
driver->store_private_ptr = driver_store_private_ptr;
/* Display size request */
driver->request_display_width = request_display_width;
driver->request_display_height = request_display_height;
return 0;
}
int
driver_unbind_module( Driver * driver )
{
return 0;
}
bool
driver_has_obligatory_symbols( Driver * driver )
{
if( driver->api_version == NULL
|| driver->stay_in_foreground == NULL
|| driver->supports_multiple == NULL ) {
report( RPT_ERR, "Driver [%.40s] misses symbols", driver->name );
return 0;
}
if( driver_does_output(driver)
&& ( driver->width == NULL
|| driver->height == NULL
|| driver->clear == NULL
|| driver->string == NULL
|| driver->chr == NULL )) {
report( RPT_ERR, "Driver [%.40s] does output but misses a obligatory function", driver->name );
return 0;
}
return 1;
}
bool
driver_does_output( Driver * driver )
{
return (driver->width != NULL
|| driver->height != NULL
|| driver->clear != NULL
|| driver->string != NULL
|| driver->chr != NULL ) ? 1 : 0;
}
bool
driver_does_input( Driver * driver )
{
return (driver->getkey != NULL
|| driver->get_key != NULL ) ? 1 : 0;
}
bool
driver_stay_in_foreground( Driver * driver )
{
return *driver->stay_in_foreground;
}
bool
driver_supports_multiple( Driver * driver )
{
return *driver->supports_multiple;
}
static int
driver_store_private_ptr(Driver * driver, void * private_data)
{
report( RPT_INFO, "driver_store_private_ptr( driver=%p, ptr=%p )", driver, private_data );
driver->private_data = private_data;
return 0;
}
static int
request_display_width()
{
if( !display_props )
return 0;
return display_props->width;
}
static int
request_display_height()
{
if( !display_props )
return 0;
return display_props->height;
}
+47
View File
@@ -0,0 +1,47 @@
/*
* driver.h
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 2001, Joris Robijn
*
*/
#ifndef DRIVER_H
#define DRIVER_H
#include "drivers/lcd.h"
#define bool int
Driver *
driver_load( char * name, char * filename, char * args );
int
driver_unload( Driver * driver );
int
driver_bind_module( Driver * driver );
int
driver_unbind_module( Driver * driver );
bool
driver_has_obligatory_symbols( Driver * driver );
bool
driver_does_output( Driver * driver );
bool
driver_does_input( Driver * driver );
bool
driver_support_multiple( Driver * driver );
bool
driver_stay_in_foreground( Driver * driver );
#endif
+388 -117
View File
@@ -1,15 +1,14 @@
/* /*
* driver.c * drivers.c
* This file is part of LCDd, the lcdproc server. * This file is part of LCDd, the lcdproc server.
* *
* This file is released under the GNU General Public License. Refer to the * This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 2001, Joris Robijn
* 2001, Joris Robijn
* *
* *
* This code does all driver handling, loading, initializing, unloading. * This code manages the lists of loaded drivers and does actions on all drivers.
* *
*/ */
@@ -26,32 +25,29 @@
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/report.h" #include "shared/report.h"
#include "configfile.h"
#include "drivers.h"
#include "driver.h"
#include "drivers/lcd.h" #include "drivers/lcd.h"
// lcd.h is used for the driver API definition /* lcd.h is used for the driver API definition */
LinkedList * loaded_drivers = NULL; LinkedList * loaded_drivers = NULL;
DisplayProps * display_props = NULL;
long int empty_function() { return 0; } #define ForAllDrivers(drv) for( drv = LL_GetFirst(loaded_drivers); drv; drv = LL_GetNext(loaded_drivers) )
static int fill_driver_functions( lcd_logical_driver * driver );
static int store_private_ptr(struct lcd_logical_driver * driver, void * private_data);
int int
load_driver ( char * name, char * filename, char * args ) drivers_load_driver( char * name, char * filename, char * args )
{ {
int res; Driver * driver;
void (*driver_init)();
lcd_logical_driver * driver;
report( RPT_INFO, "load_driver(%s,%s,%s)", name, filename, args ); report( RPT_INFO, "drivers_load_driver( name=\"%.40s\", filename=\"%.80s\", args=\"%.80s\")", name, filename, args );
// First driver ? /* First driver ? */
if( !loaded_drivers ) { if( !loaded_drivers ) {
// Create linked list /* Create linked list */
loaded_drivers = LL_new (); loaded_drivers = LL_new ();
if( !loaded_drivers ) { if( !loaded_drivers ) {
report( RPT_ERR, "Error allocating driver list." ); report( RPT_ERR, "Error allocating driver list." );
@@ -59,133 +55,408 @@ load_driver ( char * name, char * filename, char * args )
} }
} }
/* Load the module */
// Find the driver in the array of driver types driver = driver_load( name, filename, args );
if ((driver_init = (void *) lcd_find_init(name)) == NULL) { if( driver == NULL )
// Driver not found /* It failed. The message has already been given by driver_load() */
report( RPT_ERR, "invalid driver: %s", name);
return -1; return -1;
}
/* Add driver to list */
// Allocate memory for new driver struct
driver = malloc( sizeof( lcd_logical_driver ));
//memset( driver, 0, sizeof (lcd_logical_driver ));
lcd_ptr = driver;
fill_driver_functions( driver );
// Rebind the init function and call it
driver->init = driver_init;
res = driver->init( driver, args );
if( res < 0 ) {
report( RPT_ERR, "Driver load failed, return code < 0" );
// driver load failed, don't add driver to list
return -1;
}
// Add driver to list
LL_Push( loaded_drivers, driver ); LL_Push( loaded_drivers, driver );
// Check the driver type /* If first driver, store display properties */
if( !driver->daemonize ) { if( driver_does_output(driver) && !display_props ) {
return 2; if( driver->width(driver) <= 0 || driver->width(driver) > LCD_MAX_WIDTH
|| driver->height(driver) <= 0 || driver->height(driver) > LCD_MAX_HEIGHT ) {
report( RPT_ERR, "Driver [%.40s] has invalid display size", driver->name );
}
/* Allocate new DisplayProps structure */
display_props = malloc( sizeof( DisplayProps ));
display_props->width = driver->width(driver);
display_props->height = driver->height(driver);
if( driver->cellwidth != NULL && display_props->cellwidth > 0 )
display_props->cellwidth = driver->cellwidth(driver);
else
display_props->cellwidth = LCD_DEFAULT_CELLWIDTH;
if( driver->cellheight != NULL && driver->cellheight(driver) > 0 )
display_props->cellheight = driver->cellheight(driver);
else
display_props->cellheight = LCD_DEFAULT_CELLHEIGHT;
} }
return 1; // We can't see if it's an input driver only... /* Return the driver type */
if( driver_does_output(driver) ) {
if( driver_stay_in_foreground(driver) )
return 2;
else
return 1;
}
return 0;
} }
int int
unload_all_drivers () drivers_unload_all()
{ {
lcd_logical_driver * driver; Driver * driver;
report( RPT_INFO, "unload_all_driver()"); report( RPT_INFO, "unload_all_driver()");
while( (driver = LL_Pop( loaded_drivers )) != NULL ) { while( (driver = LL_Pop( loaded_drivers )) != NULL ) {
debug( RPT_DEBUG, "driver->close %p", driver ); driver_unload( driver );
driver->close();
} }
return 0; return 0;
} }
static int char *
fill_driver_functions( lcd_logical_driver * driver ) drivers_get_info()
{ {
driver->wid = LCD_STD_WIDTH; Driver *drv;
driver->hgt = LCD_STD_HEIGHT;
driver->cellwid = LCD_STD_CELL_WIDTH; report( RPT_INFO, "drivers_getinfo()" );
driver->cellhgt = LCD_STD_CELL_HEIGHT;
driver->framebuf = NULL; ForAllDrivers(drv) {
driver->nextkey = NULL; if( drv->get_info ) {
return drv->get_info( drv );
driver->daemonize = 1; }
}
// Set pointers to empty function return "";
// Basic functions
driver->init = empty_function;
driver->close = empty_function;
driver->getinfo = empty_function;
// and don't forget other get_* functions later...
driver->clear = empty_function;
driver->flush = empty_function;
driver->string = empty_function;
driver->chr = empty_function;
// Extended functions
driver->init_vbar = empty_function;
driver->vbar = empty_function;
driver->init_hbar = empty_function;
driver->hbar = empty_function;
driver->init_num = empty_function;
driver->num = empty_function;
driver->heartbeat = empty_function;
// Hardware functions
driver->contrast = empty_function;
driver->backlight = empty_function;
driver->output = empty_function;
// Uesrdef character functions
driver->set_char = empty_function;
driver->icon = empty_function;
// Key functions
driver->getkey = empty_function;
// Ancient functions
driver->flush_box = empty_function;
driver->draw_frame = empty_function;
// Config file functions
driver->config_get_bool = config_get_bool;
driver->config_get_int = config_get_int;
driver->config_get_float = config_get_float;
driver->config_get_string = config_get_string;
driver->config_has_section = config_has_section;
driver->config_has_key = config_has_key;
// Driver private data
driver->store_private_ptr = store_private_ptr;
return 0;
} }
static int void
store_private_ptr(struct lcd_logical_driver * driver, void * private_data) drivers_clear()
{ {
driver->private_data = private_data; Driver *drv;
report( RPT_INFO, "drivers_clear()" );
ForAllDrivers(drv) {
if( drv->clear )
drv->clear( drv );
}
}
void
drivers_flush()
{
Driver *drv;
report( RPT_INFO, "drivers_flush()" );
ForAllDrivers(drv) {
if( drv->flush )
drv->flush( drv );
}
}
void
drivers_string( int x, int y, char * string )
{
Driver *drv;
report( RPT_INFO, "drivers_string( x=%d, y=%d, string=\"%.40s\" )", x, y, string );
ForAllDrivers(drv) {
if( drv->string )
drv->string( drv, x, y, string );
}
}
void
drivers_chr( int x, int y, char c )
{
Driver *drv;
report( RPT_INFO, "drivers_chr( x=%d, y=%d, c='%c' )", x, y, c );
ForAllDrivers(drv) {
if( drv->chr )
drv->chr( drv, x, y, c );
}
}
void
drivers_init_vbar() /* TO BE REMOVED */
{
Driver *drv;
report( RPT_INFO, "drivers_init_vbar()" );
ForAllDrivers(drv) {
if( drv->init_vbar )
drv->init_vbar(drv);
}
}
void
drivers_init_hbar() /* TO BE REMOVED */
{
Driver *drv;
report( RPT_INFO, "drivers_init_hbar()" );
ForAllDrivers(drv) {
if( drv->init_hbar )
drv->init_hbar(drv);
}
}
void
drivers_init_num() /* TO BE REMOVED */
{
Driver *drv;
report( RPT_INFO, "drivers_init_num()" );
ForAllDrivers(drv) {
if( drv->init_num )
drv->init_num( drv );
}
}
void
drivers_vbar( int x, int y, int len, int promille, int pattern )
{
Driver *drv;
int old_len;
report( RPT_INFO, "drivers_vbar( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", x, y, len, promille, pattern );
/* NEW FUNCTIONS
*
* We need more data in the widget. Requires language update...
*/
ForAllDrivers(drv) {
if( drv->vbar ) {
drv->vbar( drv, x, y, len, promille, pattern );
}
}
/* OLD FUNCTIONS
*
* We need to convert the bar lengths, because the displays can
* have different pixels per char
*/
old_len = (long) - display_props->cellheight * len * promille / 1000;
ForAllDrivers(drv) {
if( drv->old_vbar ) {
drv->old_vbar( drv, x, old_len );
}
}
}
void
drivers_hbar( int x, int y, int len, int promille, int pattern )
{
Driver *drv;
int old_len;
report( RPT_INFO, "drivers_hbar( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", x, y, len, promille, pattern );
/* NEW FUNCTIONS */
ForAllDrivers(drv) {
if( drv->hbar ) {
drv->hbar( drv, x, y, len, promille, pattern );
}
}
/* OLD FUNCTIONS
*
* We need to convert the bar lengths, because the displays can
* have different pixels per char
*/
old_len = (long) display_props->cellwidth * len * promille / 1000;
ForAllDrivers(drv) {
if( drv->old_hbar ) {
drv->old_hbar( drv, x, y, old_len );
}
}
}
void
drivers_num( int x, int num )
{
Driver *drv;
report( RPT_INFO, "drivers_num( x=%d, num=%d )", x, num );
ForAllDrivers(drv) {
if( drv->num )
drv->num( drv, x, num );
}
}
void
drivers_heartbeat( int state )
{
Driver *drv;
report( RPT_INFO, "drivers_heartbeat( state=%d )", state );
ForAllDrivers(drv) {
if( drv->heartbeat )
drv->heartbeat( drv, state );
}
}
void
drivers_icon( int x, int y, int icon )
{
Driver *drv;
report( RPT_INFO, "drivers_icon( x=%d, y=%d, icon=%d )", x, y, icon );
ForAllDrivers(drv) {
if( drv->icon )
drv->icon( drv, x, y, icon );
}
}
void
drivers_set_char( char ch, char *dat )
{
Driver *drv;
report( RPT_INFO, "drivers_set_char( ch=%d, dat=%p )", ch, dat );
ForAllDrivers(drv) {
if( drv->set_char )
drv->set_char( drv, ch, dat );
}
}
int
drivers_get_contrast()
{
Driver *drv;
int res;
report( RPT_INFO, "drivers_get_contrast()" );
ForAllDrivers(drv) {
if( drv->get_contrast ) {
res = drv->get_contrast( drv );
report( RPT_INFO, "Driver [%.40s] gave contrast value %d", drv->name, res );
return res;
}
}
report( RPT_INFO, "Did not get any contrast value" );
return -1;
}
void
drivers_set_contrast( int promille )
{
Driver *drv;
report( RPT_INFO, "drivers_contrast( contrast=%d )", promille );
ForAllDrivers(drv) {
if( drv->set_contrast )
drv->set_contrast( drv, promille );
}
}
void
drivers_backlight( int brightness )
{
Driver *drv;
report( RPT_INFO, "drivers_backlight( brightness=%d )", brightness );
ForAllDrivers(drv) {
if( drv->backlight )
drv->backlight( drv, brightness );
}
}
void
drivers_output( int state )
{
Driver *drv;
report( RPT_INFO, "drivers_output( state=%d )", state );
ForAllDrivers(drv) {
if( drv->output )
drv->output( drv, state );
}
}
char *
drivers_get_key()
{
/* Find the first input keystroke, if any */
Driver *drv;
char * keystroke;
report( RPT_INFO, "drivers_get_key()" );
ForAllDrivers(drv) {
if( drv->get_key ) {
keystroke = drv->get_key( drv );
if( keystroke != NULL ) {
report( RPT_INFO, "Driver [%.40s] generated keystroke %.40s", drv->name, keystroke );
return keystroke;
}
}
}
return NULL;
}
char
drivers_getkey() /* TO BE REMOVED AS SOON AS INPUT ROUTINES ACCEPT STRINGS */
{
Driver *drv;
char * s;
char ch;
report( RPT_INFO, "drivers_getkey()" );
ForAllDrivers(drv) {
if( drv->get_key ) {
s = drv->get_key(drv);
if( s )
return s[0]; /* It returns the first char only ! a hack ! */
}
else if( drv->getkey ) {
ch = drv->getkey(drv);
if( ch )
return ch;
}
}
return 0; return 0;
} }
+87 -10
View File
@@ -5,18 +5,95 @@
* This file is released under the GNU General Public License. Refer to the * This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 2001, Joris Robijn
* 2001, Joris Robijn
* *
*/ */
int #ifndef DRIVERS_H
load_driver( char * name, char * filename, char * args ); #define DRIVERS_H
// returns:
// <0 error #include "drivers/lcd.h"
// 0 ok, driver is an input driver only
// 1 ok, driver is an output driver typedef struct DisplayProps {
// 2 ok, driver is an output driver that needs to run in the foreground int width, height;
int cellwidth, cellheight;
} DisplayProps;
extern DisplayProps * display_props;
#define bool int
int int
unload_all_drivers(); drivers_load_driver( char * name, char * filename, char * args );
/* returns:
* <0 error
* 0 ok, driver is an input driver only
* 1 ok, driver is an output driver
* 2 ok, driver is an output driver that needs to run in the foreground
*/
int
drivers_unload_all();
char *
drivers_get_info();
void
drivers_clear();
void
drivers_flush();
void
drivers_string( int x, int y, char * string );
void
drivers_chr( int x, int y, char c );
void
drivers_init_vbar(); /* TO BE REMOVED */
void
drivers_init_hbar(); /* TO BE REMOVED */
void
drivers_init_num(); /* TO BE REMOVED */
void
drivers_vbar( int x, int y, int len, int promille, int pattern );
void
drivers_hbar( int x, int y, int len, int promille, int pattern );
void
drivers_num( int x, int num );
void
drivers_heartbeat( int state );
void
drivers_icon( int x, int y, int icon );
void
drivers_set_char( char ch, char *dat );
int
drivers_get_contrast();
void
drivers_set_contrast( int contrast );
void
drivers_backlight( int brightness );
void
drivers_output( int state );
char *
drivers_get_key();
char
drivers_getkey();
#endif
+186 -179
View File
@@ -35,10 +35,12 @@
#include "lcd.h" #include "lcd.h"
#include "CFontz.h" #include "CFontz.h"
#include "render.h" //#include "drv_base.h"
//#include "shared/debug.h"
#include "shared/str.h" #include "shared/str.h"
#include "shared/report.h" #include "report.h"
#include "server/configfile.h" //#include "server/configfile.h"
static int custom = 0; static int custom = 0;
typedef enum { typedef enum {
@@ -49,25 +51,36 @@ typedef enum {
} custom_type; } custom_type;
static int fd; static int fd;
static char *framebuf = NULL;
static int width = 0;
static int height = 0;
static int cellwidth = DEFAULT_CELL_WIDTH;
static int cellheight = DEFAULT_CELL_HEIGHT;
static int contrast = DEFAULT_CONTRAST;
static int brightness = DEFAULT_BRIGHTNESS; static int brightness = DEFAULT_BRIGHTNESS;
static int offbrightness = DEFAULT_OFFBRIGHTNESS; static int offbrightness = DEFAULT_OFFBRIGHTNESS;
static int newfirmware = 0; static int newfirmware = 0;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "CFontz_";
// Internal functions
static void CFontz_linewrap (int on); static void CFontz_linewrap (int on);
static void CFontz_autoscroll (int on); static void CFontz_autoscroll (int on);
static void CFontz_hidecursor (); static void CFontz_hidecursor ();
static void CFontz_reboot (); static void CFontz_reboot ();
static void CFontz_heartbeat (int type);
// TODO: Get rid of this variable?
lcd_logical_driver *CFontz;
// TODO: Get the frame buffers working right // TODO: Get the frame buffers working right
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int int
CFontz_init (lcd_logical_driver * driver, char *args) CFontz_init (Driver * drvthis, char *args)
{ {
struct termios portset; struct termios portset;
int tmp, w, h; int tmp, w, h;
@@ -78,57 +91,52 @@ CFontz_init (lcd_logical_driver * driver, char *args)
int speed = DEFAULT_SPEED; int speed = DEFAULT_SPEED;
char size[200] = DEFAULT_SIZE; char size[200] = DEFAULT_SIZE;
CFontz = driver; debug(RPT_INFO, "CFontz: init(%p,%s)", drvthis, args );
debug(RPT_INFO, "CFontz: init(%p,%s)", driver, args );
// TODO: replace DriverName with driver->name when that field exists.
#define DriverName "CFontz"
/*Read config file*/ /*Read config file*/
/*Which serial device should be used*/ /*Which serial device should be used*/
strncpy(device, config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE),sizeof(device)); strncpy(device, drvthis->config_get_string ( drvthis->name , "Device" , 0 , DEFAULT_DEVICE),sizeof(device));
device[sizeof(device)-1]=0; device[sizeof(device)-1]=0;
debug (RPT_INFO,"CFontz: Using device: %s", device); debug (RPT_INFO,"CFontz: Using device: %s", device);
/*Which size*/ /*Which size*/
strncpy(size, config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE),sizeof(size)); strncpy(size, drvthis->config_get_string ( drvthis->name , "Size" , 0 , DEFAULT_SIZE),sizeof(size));
size[sizeof(size)-1]=0; size[sizeof(size)-1]=0;
if( sscanf(size , "%dx%d", &w, &h ) != 2 if( sscanf(size , "%dx%d", &w, &h ) != 2
|| (w <= 0) || (w > LCD_MAX_WIDTH) || (w <= 0) || (w > LCD_MAX_WIDTH)
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) { || (h <= 0) || (h > LCD_MAX_HEIGHT)) {
report (RPT_WARNING, "CFontz_init: Cannot read size: %s. Using default value.\n", size); report (RPT_WARNING, "CFontz_init: Cannot read size: %s. Using default value.\n", size);
sscanf( DEFAULT_SIZE , "%dx%d", &w, &h ); sscanf( DEFAULT_SIZE , "%dx%d", &w, &h );
} else {
width = w;
height = h;
} }
driver->wid = w;
driver->hgt = h;
/*Which contrast*/ /*Which contrast*/
if (0<=config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) && config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) <= 255) { if (0<=drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) && drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) <= 255) {
contrast = config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST); contrast = drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST);
} else { } else {
report (RPT_WARNING, "CFontz_init: Contrast must between 0 and 255. Using default value.\n"); report (RPT_WARNING, "CFontz_init: Contrast must between 0 and 255. Using default value.\n");
} }
/*Which backlight brightness*/ /*Which backlight brightness*/
if (0<=config_get_int ( DriverName , "Brightness" , 0 , DEFAULT_BRIGHTNESS) && config_get_int ( DriverName , "Brightness" , 0 , DEFAULT_BRIGHTNESS) <= 255) { if (0<=drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) && drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) <= 255) {
brightness = config_get_int ( DriverName , "Brightness" , 0 , DEFAULT_BRIGHTNESS); brightness = drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS);
} else { } else {
report (RPT_WARNING, "CFontz_init: Brightness must between 0 and 255. Using default value.\n"); report (RPT_WARNING, "CFontz_init: Brightness must between 0 and 255. Using default value.\n");
} }
/*Which backlight-off "brightness"*/ /*Which backlight-off "brightness"*/
if (0<=config_get_int ( DriverName , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) && config_get_int ( DriverName , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) <= 255) { if (0<=drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) && drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) <= 255) {
offbrightness = config_get_int ( DriverName , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS); offbrightness = drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS);
} else { } else {
report (RPT_WARNING, "CFontz_init: OffBrightness must between 0 and 255. Using default value.\n"); report (RPT_WARNING, "CFontz_init: OffBrightness must between 0 and 255. Using default value.\n");
} }
/*Which speed*/ /*Which speed*/
tmp = config_get_int ( DriverName , "Speed" , 0 , DEFAULT_SPEED); tmp = drvthis->config_get_int ( drvthis->name , "Speed" , 0 , DEFAULT_SPEED);
if (tmp == 1200) speed = B1200; if (tmp == 1200) speed = B1200;
else if (tmp == 2400) speed = B2400; else if (tmp == 2400) speed = B2400;
else if (tmp == 9600) speed = B9600; else if (tmp == 9600) speed = B9600;
@@ -136,12 +144,12 @@ CFontz_init (lcd_logical_driver * driver, char *args)
} }
/*New firmware version?*/ /*New firmware version?*/
if(config_get_bool( DriverName , "NewFirmware" , 0 , 0)) { if(drvthis->config_get_bool( drvthis->name , "NewFirmware" , 0 , 0)) {
newfirmware = 1; newfirmware = 1;
} }
/*Reboot display?*/ /*Reboot display?*/
if (config_get_bool( DriverName , "Reboot" , 0 , 0)) { if (drvthis->config_get_bool( drvthis->name , "Reboot" , 0 , 0)) {
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n"); report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n");
reboot = 1; reboot = 1;
} }
@@ -178,10 +186,8 @@ CFontz_init (lcd_logical_driver * driver, char *args)
tcsetattr (fd, TCSANOW, &portset); tcsetattr (fd, TCSANOW, &portset);
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
if (!CFontz->framebuf) framebuf = (unsigned char *) malloc (width * height);
CFontz->framebuf = (unsigned char *) memset (framebuf, ' ', width * height);
malloc (CFontz->wid * CFontz->hgt);
memset (CFontz->framebuf, ' ', CFontz->wid * CFontz->hgt);
// Set display-specific stuff.. // Set display-specific stuff..
if (reboot) { if (reboot) {
@@ -193,84 +199,107 @@ CFontz_init (lcd_logical_driver * driver, char *args)
CFontz_hidecursor (); CFontz_hidecursor ();
CFontz_linewrap (1); CFontz_linewrap (1);
CFontz_autoscroll (0); CFontz_autoscroll (0);
CFontz_backlight (backlight_brightness); //CFontz_backlight (drvthis, backlight_brightness); // render.c variables should not be used in drivers !
// Set the functions the driver supports... // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = CFontz_clear; // Set the functions the driver supports
driver->string = CFontz_string;
driver->chr = CFontz_chr;
driver->vbar = CFontz_vbar;
driver->init_vbar = CFontz_init_vbar;
driver->hbar = CFontz_hbar;
driver->init_hbar = CFontz_init_hbar;
driver->num = CFontz_num;
driver->init = CFontz_init; drvthis->clear = CFontz_clear;
driver->close = CFontz_close; drvthis->string = CFontz_string;
driver->flush = CFontz_flush; drvthis->chr = CFontz_chr;
driver->flush_box = CFontz_flush_box; drvthis->old_vbar = CFontz_vbar;
driver->contrast = CFontz_contrast; drvthis->init_vbar = CFontz_init_vbar;
driver->backlight = CFontz_backlight; drvthis->old_hbar = CFontz_hbar;
driver->set_char = CFontz_set_char; drvthis->init_hbar = CFontz_init_hbar;
driver->icon = CFontz_icon; drvthis->num = CFontz_num;
driver->draw_frame = CFontz_draw_frame;
CFontz_contrast (contrast); drvthis->init = CFontz_init;
drvthis->close = CFontz_close;
drvthis->flush = CFontz_flush;
drvthis->get_contrast = CFontz_get_contrast;
drvthis->set_contrast = CFontz_set_contrast;
drvthis->backlight = CFontz_backlight;
drvthis->set_char = CFontz_set_char;
drvthis->old_icon = CFontz_icon;
drvthis->heartbeat = CFontz_heartbeat;
driver->cellwid = DEFAULT_CELL_WIDTH; CFontz_set_contrast (drvthis, contrast);
driver->cellhgt = DEFAULT_CELL_HEIGHT;
driver->heartbeat = CFontz_heartbeat;
report (RPT_DEBUG, "CFontz_init: done\n"); report (RPT_DEBUG, "CFontz_init: done\n");
return fd; return 0;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clean-up // Clean-up
// //
void MODULE_EXPORT void
CFontz_close () CFontz_close (Driver * drvthis)
{ {
close (fd); close (fd);
if (CFontz->framebuf) if(framebuf) free (framebuf);
free (CFontz->framebuf); framebuf = NULL;
CFontz->framebuf = NULL;
} }
void /////////////////////////////////////////////////////////////////
CFontz_flush () // Returns the display width
//
MODULE_EXPORT int
CFontz_width (Driver *drvthis)
{ {
CFontz_draw_frame (CFontz->framebuf); return width;
} }
void /////////////////////////////////////////////////////////////////
CFontz_flush_box (int lft, int top, int rgt, int bot) // Returns the display height
//
MODULE_EXPORT int
CFontz_height (Driver *drvthis)
{ {
int y; return height;
char out[LCD_MAX_WIDTH]; }
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
MODULE_EXPORT void
CFontz_flush (Driver * drvthis)
{
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i;
for (y = top; y <= bot; y++) { // Custom characters start at 128, not at 0.
snprintf (out, sizeof(out), "%c%c%c", 17, lft, y); /*
write (fd, out, 4); for(i=0; i<width*height; i++)
write (fd, CFontz->framebuf + (y * CFontz->wid) + lft, rgt - lft + 1); {
if(framebuf[i] < 32 && framebuf[i] >= 0) framebuf[i] += 128;
}
*/
for (i = 0; i < height; i++) {
snprintf (out, sizeof(out), "%c%c%c", 17, 0, i);
write (fd, out, 3);
write (fd, framebuf + (width * i), width);
} }
/*
snprintf(out, sizeof(out), "%c", 1);
write(fd, out, 1);
write(fd, framebuf, width*height);
*/
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
CFontz_chr (int x, int y, char c) CFontz_chr (Driver * drvthis, int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -280,38 +309,51 @@ CFontz_chr (int x, int y, char c)
// For V2 of the firmware to get the block to display right // For V2 of the firmware to get the block to display right
if (newfirmware && c==-1) { if (newfirmware && c==-1) {
c=214; c=214;
} }
CFontz->framebuf[(y * CFontz->wid) + x] = c; framebuf[(y * width) + x] = c;
}
/////////////////////////////////////////////////////////////////
// Returns current contrast
// This is only the locally stored contrast, the contrast value
// cannot be retrieved from the LCD.
// Value 0 to 1000.
//
MODULE_EXPORT int
CFontz_get_contrast (Driver * drvthis)
{
return contrast;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good) // Changes screen contrast (0-255; 140 seems good)
// Value 0 to 100.
// //
int MODULE_EXPORT void
CFontz_contrast (int contrast) CFontz_set_contrast (Driver * drvthis, int promille)
{ {
int realcontrast;
char out[4]; char out[4];
static int status = 140;
if (contrast > 0) { // Check it
status = contrast; if( promille < 0 || promille > 1000 )
realcontrast = (((int) (status)) * 100) / 255; return;
snprintf (out, sizeof(out), "%c%c", 15, realcontrast);
write (fd, out, 3);
}
return status; // Store it
contrast = promille;
// And do it
snprintf (out, sizeof(out), "%c%c", 15, (unsigned char) (promille / 10) ); // converted to be 0 to 100
write (fd, out, 3);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets the backlight on or off -- can be done quickly for // Sets the backlight on or off -- can be done quickly for
// an intermediate brightness... // an intermediate brightness...
// //
void MODULE_EXPORT void
CFontz_backlight (int on) CFontz_backlight (Driver * drvthis, int on)
{ {
char out[4]; char out[4];
if (on) { if (on) {
@@ -375,8 +417,8 @@ CFontz_reboot ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before CFontz->vbar() // Sets up for vertical bars. Call before CFontz->vbar()
// //
void MODULE_EXPORT void
CFontz_init_vbar () CFontz_init_vbar (Driver * drvthis)
{ {
char a[] = { char a[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -450,13 +492,13 @@ CFontz_init_vbar ()
}; };
if (custom != vbar) { if (custom != vbar) {
CFontz_set_char (1, a); CFontz_set_char (drvthis, 1, a);
CFontz_set_char (2, b); CFontz_set_char (drvthis, 2, b);
CFontz_set_char (3, c); CFontz_set_char (drvthis, 3, c);
CFontz_set_char (4, d); CFontz_set_char (drvthis, 4, d);
CFontz_set_char (5, e); CFontz_set_char (drvthis, 5, e);
CFontz_set_char (6, f); CFontz_set_char (drvthis, 6, f);
CFontz_set_char (7, g); CFontz_set_char (drvthis, 7, g);
custom = vbar; custom = vbar;
} }
} }
@@ -464,8 +506,8 @@ CFontz_init_vbar ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void MODULE_EXPORT void
CFontz_init_hbar () CFontz_init_hbar (Driver * drvthis)
{ {
char a[] = { char a[] = {
@@ -530,12 +572,12 @@ CFontz_init_hbar ()
}; };
if (custom != hbar) { if (custom != hbar) {
CFontz_set_char (1, a); CFontz_set_char (drvthis, 1, a);
CFontz_set_char (2, b); CFontz_set_char (drvthis, 2, b);
CFontz_set_char (3, c); CFontz_set_char (drvthis, 3, c);
CFontz_set_char (4, d); CFontz_set_char (drvthis, 4, d);
CFontz_set_char (5, e); CFontz_set_char (drvthis, 5, e);
CFontz_set_char (6, f); CFontz_set_char (drvthis, 6, f);
custom = hbar; custom = hbar;
} }
} }
@@ -543,19 +585,19 @@ CFontz_init_hbar ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar... // Draws a vertical bar...
// //
void MODULE_EXPORT void
CFontz_vbar (int x, int len) CFontz_vbar (Driver * drvthis, int x, int len)
{ {
char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 }; char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y; int y;
for (y = CFontz->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
if (len >= CFontz->cellhgt) if (len >= cellheight)
CFontz_chr (x, y, 255); CFontz_chr (drvthis, x, y, 255);
else else
CFontz_chr (x, y, map[len]); CFontz_chr (drvthis, x, y, map[len]);
len -= CFontz->cellhgt; len -= cellheight;
} }
} }
@@ -563,18 +605,18 @@ CFontz_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void MODULE_EXPORT void
CFontz_hbar (int x, int y, int len) CFontz_hbar (Driver * drvthis, int x, int y, int len)
{ {
char map[7] = { 32, 1, 2, 3, 4, 5, 6 }; char map[7] = { 32, 1, 2, 3, 4, 5, 6 };
for (; x <= CFontz->wid && len > 0; x++) { for (; x <= width && len > 0; x++) {
if (len >= CFontz->cellwid) if (len >= cellwidth)
CFontz_chr (x, y, map[6]); CFontz_chr (drvthis, x, y, map[6]);
else else
CFontz_chr (x, y, map[len]); CFontz_chr (drvthis, x, y, map[len]);
len -= CFontz->cellwid; len -= cellwidth;
} }
@@ -584,8 +626,8 @@ CFontz_hbar (int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void MODULE_EXPORT void
CFontz_num (int x, int num) CFontz_num (Driver * drvthis, int x, int num)
{ {
char out[5]; char out[5];
snprintf (out, sizeof(out), "%c%c%c", 28, x, num); snprintf (out, sizeof(out), "%c%c%c", 28, x, num);
@@ -599,8 +641,8 @@ CFontz_num (int x, int num)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void MODULE_EXPORT void
CFontz_set_char (int n, char *dat) CFontz_set_char (Driver * drvthis, int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
@@ -614,18 +656,18 @@ CFontz_set_char (int n, char *dat)
snprintf (out, sizeof(out), "%c%c", 25, n); snprintf (out, sizeof(out), "%c%c", 25, n);
write (fd, out, 2); write (fd, out, 2);
for (row = 0; row < CFontz->cellhgt; row++) { for (row = 0; row < cellheight; row++) {
letter = 0; letter = 0;
for (col = 0; col < CFontz->cellwid; col++) { for (col = 0; col < cellheight; col++) {
letter <<= 1; letter <<= 1;
letter |= (dat[(row * CFontz->cellwid) + col] > 0); letter |= (dat[(row * cellheight) + col] > 0);
} }
write (fd, &letter, 1); write (fd, &letter, 1);
} }
} }
void MODULE_EXPORT void
CFontz_icon (int which, char dest) CFontz_icon (Driver * drvthis, int which, char dest)
{ {
char icons[3][6 * 8] = { char icons[3][6 * 8] = {
{ {
@@ -665,51 +707,16 @@ CFontz_icon (int which, char dest)
if (custom == bign) if (custom == bign)
custom = beat; custom = beat;
CFontz_set_char (dest, &icons[which][0]); CFontz_set_char (drvthis, dest, &icons[which][0]);
}
/////////////////////////////////////////////////////////////
// Blasts a single frame onscreen, to the lcd...
//
// Input is a character array, sized CFontz->wid*CFontz->hgt
//
void
CFontz_draw_frame (char *dat)
{
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i;
if (!dat)
return;
// Custom characters start at 128, not at 0.
/*
for(i=0; i<CFontz->wid*CFontz->hgt; i++)
{
if(dat[i] < 32 && dat[i] >= 0) dat[i] += 128;
}
*/
for (i = 0; i < CFontz->hgt; i++) {
snprintf (out, sizeof(out), "%c%c%c", 17, 0, i);
write (fd, out, 3);
write (fd, dat + (CFontz->wid * i), CFontz->wid);
}
/*
snprintf(out, sizeof(out), "%c", 1);
write(fd, out, 1);
write(fd, dat, CFontz->wid*CFontz->hgt);
*/
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
CFontz_clear () CFontz_clear (Driver * drvthis)
{ {
memset (CFontz->framebuf, ' ', CFontz->wid * CFontz->hgt); memset (framebuf, ' ', width * height);
} }
@@ -717,8 +724,8 @@ CFontz_clear ()
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
CFontz_string (int x, int y, char string[]) CFontz_string (Driver * drvthis, int x, int y, char string[])
{ {
int i; int i;
@@ -735,17 +742,17 @@ CFontz_string (int x, int y, char string[])
// Check for buffer overflows... // Check for buffer overflows...
if ((y * CFontz->wid) + x + i > (CFontz->wid * CFontz->hgt)) if ((y * width) + x + i > (width * height))
break; break;
CFontz->framebuf[(y * CFontz->wid) + x + i] = string[i]; framebuf[(y * width) + x + i] = string[i];
} }
} }
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Does the heartbeat... // Does the heartbeat...
// //
static void MODULE_EXPORT void
CFontz_heartbeat (int type) CFontz_heartbeat (Driver *drvthis, int type)
{ {
static int timer = 0; static int timer = 0;
int whichIcon; int whichIcon;
@@ -760,13 +767,13 @@ CFontz_heartbeat (int type)
// This defines a custom character EVERY time... // This defines a custom character EVERY time...
// not efficient... is this necessary? // not efficient... is this necessary?
CFontz_icon (whichIcon, 0); CFontz_icon (drvthis, whichIcon, 0);
// Put character on screen... // Put character on screen...
CFontz_chr (CFontz->wid, 1, 0); CFontz_chr (drvthis, width, 1, 0);
// change display... // change display...
CFontz_flush (); CFontz_flush (drvthis);
} }
timer++; timer++;
+27 -21
View File
@@ -1,34 +1,40 @@
#ifndef CFONTZ_H #ifndef CFONTZ_H
#define CFONTZ_H #define CFONTZ_H
extern lcd_logical_driver *CFontz; #include "lcd.h"
int CFontz_init (lcd_logical_driver * driver, char *device);
void CFontz_close ();
void CFontz_flush ();
void CFontz_flush_box (int lft, int top, int rgt, int bot);
void CFontz_chr (int x, int y, char c);
int CFontz_contrast (int contrast);
void CFontz_backlight (int on);
void CFontz_init_vbar ();
void CFontz_init_hbar ();
void CFontz_vbar (int x, int len);
void CFontz_hbar (int x, int y, int len);
void CFontz_init_num ();
void CFontz_num (int x, int num);
void CFontz_set_char (int n, char *dat);
void CFontz_icon (int which, char dest);
void CFontz_draw_frame (char *dat);
void CFontz_clear (void);
void CFontz_string (int x, int y, char string[]);
#define DEFAULT_CELL_WIDTH 6 #define DEFAULT_CELL_WIDTH 6
#define DEFAULT_CELL_HEIGHT 8 #define DEFAULT_CELL_HEIGHT 8
#define DEFAULT_CONTRAST 140 #define DEFAULT_CONTRAST 560
#define DEFAULT_DEVICE "/dev/lcd" #define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_SPEED B9600 #define DEFAULT_SPEED B9600
#define DEFAULT_BRIGHTNESS 60 #define DEFAULT_BRIGHTNESS 60
#define DEFAULT_OFFBRIGHTNESS 0 #define DEFAULT_OFFBRIGHTNESS 0
#define DEFAULT_SIZE "20x4" #define DEFAULT_SIZE "20x4"
int CFontz_init (Driver * drvthis, char *device);
MODULE_EXPORT void CFontz_close (Driver * drvthis);
MODULE_EXPORT int CFontz_width (Driver * drvthis);
MODULE_EXPORT int CFontz_height (Driver * drvthis);
MODULE_EXPORT void CFontz_clear (Driver * drvthis);
MODULE_EXPORT void CFontz_flush (Driver * drvthis);
MODULE_EXPORT void CFontz_string (Driver * drvthis, int x, int y, char string[]);
MODULE_EXPORT void CFontz_chr (Driver * drvthis, int x, int y, char c);
MODULE_EXPORT void CFontz_vbar (Driver * drvthis, int x, int len);
MODULE_EXPORT void CFontz_hbar (Driver * drvthis, int x, int y, int len);
MODULE_EXPORT void CFontz_num (Driver * drvthis, int x, int num);
MODULE_EXPORT void CFontz_heartbeat (Driver *drvthis, int type);
MODULE_EXPORT void CFontz_icon (Driver * drvthis, int which, char dest);
MODULE_EXPORT void CFontz_set_char (Driver * drvthis, int n, char *dat);
MODULE_EXPORT int CFontz_get_contrast (Driver * drvthis);
MODULE_EXPORT void CFontz_set_contrast (Driver * drvthis, int contrast);
MODULE_EXPORT void CFontz_backlight (Driver * drvthis, int on);
MODULE_EXPORT void CFontz_init_vbar (Driver * drvthis);
MODULE_EXPORT void CFontz_init_hbar (Driver * drvthis);
#endif #endif
+274 -272
View File
@@ -25,11 +25,10 @@
# include "config.h" # include "config.h"
#endif #endif
#include "render.h"
#include "lcd.h" #include "lcd.h"
#include "lcd_lib.h" #include "lcd_lib.h"
#include "MtxOrb.h" #include "MtxOrb.h"
#include "drv_base.h" //#include "drv_base.h"
// I don't want to break anything here so let's do it step by step // I don't want to break anything here so let's do it step by step
//#define USE_REPORT //#define USE_REPORT
@@ -42,6 +41,7 @@
#endif #endif
#include "shared/str.h" #include "shared/str.h"
#include "input.h"
#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)
@@ -107,44 +107,29 @@ static int clear = 1;
static int def[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static int def[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
static int use[9] = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; static int use[9] = { 1, 0, 0, 0, 0, 0, 0, 0, 0 };
static void MtxOrb_linewrap (int on); static char *framebuf = NULL;
static void MtxOrb_autoscroll (int on); static int width = LCD_DEFAULT_WIDTH;
static void MtxOrb_cursorblink (int on); static int height = LCD_DEFAULT_HEIGHT;
static void MtxOrb_string (int x, int y, char *string); static int cellwidth = LCD_DEFAULT_CELLWIDTH;
static int cellheight = LCD_DEFAULT_CELLHEIGHT;
static int contrast = DEFAULT_CONTRAST;
/* // Vars for the server core
* This does not belong to MtxOrb.h except if used externaly MODULE_EXPORT char *api_version = API_VERSION;
* Having them here reduce the number of warning. MODULE_EXPORT int stay_in_foreground = 0;
*/ MODULE_EXPORT int supports_multiple = 0;
static void MtxOrb_clear (); MODULE_EXPORT char *symbol_prefix = "MtxOrb_";
static void MtxOrb_close ();
static void MtxOrb_flush ();
static void MtxOrb_flush_box (int lft, int top, int rgt, int bot); static int MtxOrb_ask_bar (Driver *drvthis, int type);
static void MtxOrb_chr (int x, int y, char c); static void MtxOrb_set_known_char (Driver * drvthis, int car, int type);
static int MtxOrb_contrast (int contrast); static void MtxOrb_linewrap (Driver *drvthis, int on);
static void MtxOrb_backlight (int on); static void MtxOrb_autoscroll (Driver *drvthis, int on);
static void MtxOrb_output (int on); static void MtxOrb_cursorblink (Driver *drvthis, 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 ();
static void MtxOrb_heartbeat (int type);
static int MtxOrb_ask_bar (int type);
static void MtxOrb_set_known_char (int car, int type);
/*
* End of what was in MtxOrb.h
*/
// Very private function that clear internal definition. // Very private function that clear internal definition.
static void static void
MtxOrb_clear_custom () MtxOrb_clear_custom (Driver *drvthis)
{ {
int pos; int pos;
@@ -155,7 +140,7 @@ MtxOrb_clear_custom ()
} }
static int static int
MtxOrb_set_type (char * str) { MtxOrb_parse_type (char * str) {
char c; char c;
c = str[0]; c = str[0];
@@ -182,7 +167,7 @@ MtxOrb_set_type (char * str) {
} }
static int static int
MtxOrb_get_speed (char *arg) { MtxOrb_parse_speed (char *arg) {
int speed; int speed;
switch (atoi(arg)) { switch (atoi(arg)) {
@@ -218,7 +203,7 @@ MtxOrb_usage (void) {
} }
int int
MtxOrb_set_contrast (char * str) { MtxOrb_parse_contrast (char * str) {
int contrast; int contrast;
contrast = atoi (str); contrast = atoi (str);
@@ -229,8 +214,6 @@ MtxOrb_set_contrast (char * str) {
return contrast; return contrast;
} }
// 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 // TODO: Get the frame buffers working right
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -239,7 +222,7 @@ lcd_logical_driver *MtxOrb; // set by MtxOrb_init(); doesn't seem to be used any
// Called to initialize driver settings // Called to initialize driver settings
// //
int int
MtxOrb_init (lcd_logical_driver * driver, char *args) MtxOrb_init (Driver *drvthis, char *args)
{ {
char *argv[64]; // Notice: 64 arguments - overflows? char *argv[64]; // Notice: 64 arguments - overflows?
int argc; int argc;
@@ -254,8 +237,6 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
MtxOrb_type = MTXORB_LKD; // Assume it's an LCD w/keypad MtxOrb_type = MTXORB_LKD; // Assume it's an LCD w/keypad
MtxOrb = driver;
//debug("MtxOrb_init: Args(all): %s\n", args); //debug("MtxOrb_init: Args(all): %s\n", args);
argc = get_args (argv, args, 64); argc = get_args (argv, args, 64);
@@ -274,16 +255,16 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
strncpy(device, optarg, sizeof(device)); strncpy(device, optarg, sizeof(device));
break; break;
case 's': case 's':
speed = MtxOrb_get_speed(optarg); speed = MtxOrb_parse_speed(optarg);
break; break;
case 'c': case 'c':
contrast = MtxOrb_set_contrast(optarg); contrast = MtxOrb_parse_contrast(optarg);
break; break;
case 'h': case 'h':
MtxOrb_usage(); MtxOrb_usage();
return -1; return -1;
case 't': case 't':
MtxOrb_set_type(optarg); MtxOrb_type = MtxOrb_parse_type(optarg);
default: default:
MtxOrb_usage(); MtxOrb_usage();
return -1; return -1;
@@ -312,14 +293,14 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]); fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]);
return -1; return -1;
} }
contrast = MtxOrb_set_contrast (argv[++i]); contrast = MtxOrb_parse_contrast (argv[++i]);
break; break;
case 's': case 's':
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]); fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]);
return -1; return -1;
} }
speed = MtxOrb_get_speed (argv[++i]); speed = MtxOrb_parse_speed (argv[++i]);
break; break;
case 'h': case 'h':
MtxOrb_usage(); MtxOrb_usage();
@@ -348,8 +329,8 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
hgt = (*p - '0'); hgt = (*p - '0');
MtxOrb->wid = wid; width = wid;
MtxOrb->hgt = hgt; height = hgt;
} }
break; break;
case 'b': case 'b':
@@ -358,7 +339,7 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
return -1; return -1;
} }
i++; i++;
MtxOrb_type = MtxOrb_set_type(argv[i]); MtxOrb_type = MtxOrb_parse_type(argv[i]);
break; break;
default: default:
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
@@ -408,54 +389,61 @@ MtxOrb_init (lcd_logical_driver * driver, char *args)
tcsetattr (fd, TCSANOW, &portset); tcsetattr (fd, TCSANOW, &portset);
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
if (!MtxOrb->framebuf) if (!framebuf)
MtxOrb->framebuf = (unsigned char *) framebuf = (unsigned char *)
malloc (MtxOrb->wid * MtxOrb->hgt); malloc (width * height);
memset (MtxOrb->framebuf, ' ', MtxOrb->wid * MtxOrb->hgt); memset (framebuf, ' ', width * height);
/* /*
* Configure display * Configure display
*/ */
MtxOrb_linewrap (DEFAULT_LINEWRAP); MtxOrb_linewrap (drvthis, DEFAULT_LINEWRAP);
MtxOrb_autoscroll (DEFAULT_AUTOSCROLL); MtxOrb_autoscroll (drvthis, DEFAULT_AUTOSCROLL);
MtxOrb_cursorblink (DEFAULT_CURSORBLINK); MtxOrb_cursorblink (drvthis, DEFAULT_CURSORBLINK);
MtxOrb_contrast (contrast); MtxOrb_set_contrast (drvthis, contrast);
/* /*
* Configure the display functions * Configure the display functions
*/ */
driver->clear = MtxOrb_clear; // Set variables for server
driver->string = MtxOrb_string; drvthis->api_version = api_version;
driver->chr = MtxOrb_chr; drvthis->stay_in_foreground = &stay_in_foreground;
driver->vbar = MtxOrb_vbar; drvthis->supports_multiple = &supports_multiple;
driver->init_vbar = MtxOrb_init_vbar;
driver->hbar = MtxOrb_hbar;
driver->init_hbar = MtxOrb_init_hbar;
driver->num = MtxOrb_num;
driver->init_num = MtxOrb_init_num;
driver->init = MtxOrb_init; // Set the functions the driver supports
driver->close = MtxOrb_close; drvthis->clear = MtxOrb_clear;
driver->flush = MtxOrb_flush; drvthis->string = MtxOrb_string;
driver->flush_box = MtxOrb_flush_box; drvthis->chr = MtxOrb_chr;
driver->contrast = MtxOrb_contrast; drvthis->old_vbar = MtxOrb_vbar;
driver->backlight = MtxOrb_backlight; drvthis->init_vbar = MtxOrb_init_vbar;
driver->output = MtxOrb_output; drvthis->old_hbar = MtxOrb_hbar;
driver->set_char = MtxOrb_set_char; drvthis->init_hbar = MtxOrb_init_hbar;
driver->icon = MtxOrb_icon; drvthis->num = MtxOrb_num;
driver->draw_frame = MtxOrb_draw_frame; drvthis->init_num = MtxOrb_init_num;
driver->getkey = MtxOrb_getkey; drvthis->init = MtxOrb_init;
driver->getinfo = MtxOrb_getinfo; drvthis->close = MtxOrb_close;
driver->heartbeat = MtxOrb_heartbeat; drvthis->width = MtxOrb_width;
drvthis->height = MtxOrb_height;
drvthis->flush = MtxOrb_flush;
drvthis->get_contrast = MtxOrb_get_contrast;
drvthis->set_contrast = MtxOrb_set_contrast;
drvthis->backlight = MtxOrb_backlight;
drvthis->output = MtxOrb_output;
drvthis->set_char = MtxOrb_set_char;
drvthis->old_icon = MtxOrb_icon;
return fd; drvthis->getkey = MtxOrb_getkey;
drvthis->get_info = MtxOrb_get_info;
drvthis->heartbeat = MtxOrb_heartbeat;
return 0;
} }
#define ValidX(x) if ((x) > MtxOrb->wid) { (x) = MtxOrb->wid; } else (x) = (x) < 1 ? 1 : (x); #define ValidX(x) if ((x) > width) { (x) = width; } else (x) = (x) < 1 ? 1 : (x);
#define ValidY(y) if ((y) > MtxOrb->hgt) { (y) = MtxOrb->hgt; } else (y) = (y) < 1 ? 1 : (y); #define ValidY(y) if ((y) > height) { (y) = height; } else (y) = (y) < 1 ? 1 : (y);
// TODO: Check this quick hack to detect clear of the screen. // TODO: Check this quick hack to detect clear of the screen.
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -463,11 +451,11 @@ 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.
// //
static void MODULE_EXPORT void
MtxOrb_clear () MtxOrb_clear (Driver *drvthis)
{ {
if (MtxOrb->framebuf != NULL) if (framebuf != NULL)
memset (MtxOrb->framebuf, ' ', (MtxOrb->wid * MtxOrb->hgt)); memset (framebuf, ' ', (width * height));
//write(fd, "\x0FE" "X", 2); // instant clear... //write(fd, "\x0FE" "X", 2); // instant clear...
clear = 1; clear = 1;
@@ -483,15 +471,14 @@ MtxOrb_clear ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clean-up // Clean-up
// //
static void MODULE_EXPORT void
MtxOrb_close () MtxOrb_close (Driver *drvthis)
{ {
close (fd); close (fd);
if (MtxOrb->framebuf) if (framebuf)
free (MtxOrb->framebuf); free (framebuf);
framebuf = NULL;
MtxOrb->framebuf = NULL;
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: closed"); debug(RPT_DEBUG, "MtxOrb: closed");
@@ -501,8 +488,26 @@ MtxOrb_close ()
#endif #endif
} }
static void /////////////////////////////////////////////////////////////////
MtxOrb_string (int x, int y, char *string) // Returns the display width
//
MODULE_EXPORT int
MtxOrb_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
MtxOrb_height (Driver *drvthis)
{
return height;
}
MODULE_EXPORT void
MtxOrb_string (Driver *drvthis, int x, int y, char *string)
{ {
int offset, siz; int offset, siz;
@@ -510,11 +515,11 @@ MtxOrb_string (int x, int y, char *string)
ValidY(y); ValidY(y);
x--; y--; // Convert 1-based coords to 0-based... x--; y--; // Convert 1-based coords to 0-based...
offset = (y * MtxOrb->wid) + x; offset = (y * width) + x;
siz = (MtxOrb->wid * MtxOrb->hgt) - offset - 1; siz = (width * height) - offset - 1;
siz = siz > strlen(string) ? strlen(string) : siz; siz = siz > strlen(string) ? strlen(string) : siz;
memcpy(MtxOrb->framebuf + offset, string, siz); memcpy(framebuf + offset, string, siz);
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: printed string at (%d,%d)", x, y); debug(RPT_DEBUG, "MtxOrb: printed string at (%d,%d)", x, y);
@@ -524,10 +529,65 @@ MtxOrb_string (int x, int y, char *string)
#endif #endif
} }
static void MODULE_EXPORT void
MtxOrb_flush () MtxOrb_flush (Driver *drvthis)
{ {
MtxOrb_draw_frame (MtxOrb->framebuf); char out[12];
int i,j,mv = 1;
static char *old = NULL;
char *p, *q;
if (old == NULL) {
old = malloc(width * height);
write(fd, "\x0FEG\x01\x01", 4);
write(fd, framebuf, width * height);
strncpy(old, framebuf, width * height);
return;
} else {
/* CODE TEMPORARY DISABLED (joris)
UNSURE IF IT STILL WORKS NOW
if (! new_framebuf(drvthis, old))
return;
*/
}
p = framebuf;
q = old;
for (i = 1; i <= height; i++) {
for (j = 1; j <= width; j++) {
if ((*p == *q) && (*p > 8))
mv = 1;
else {
// Draw characters that have changed, as well
// as custom characters. We know not if a custom
// character has changed.
if (mv == 1) {
snprintf(out, sizeof(out), "\x0FEG%c%c", j, i);
write (fd, out, 4);
mv = 0;
}
write (fd, p, 1);
}
p++;
q++;
}
}
//for (i = 0; i < height; i++) {
// snprintf (out, sizeof(out), "\x0FEG\x001%c", i + 1);
// write (fd, out, 4);
// write (fd, framebuf + (width * i), width);
//}
strncpy(old, framebuf, width * height);
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: frame buffer flushed"); debug(RPT_DEBUG, "MtxOrb: frame buffer flushed");
@@ -537,33 +597,12 @@ MtxOrb_flush ()
#endif #endif
} }
static void
MtxOrb_flush_box (int lft, int top, int rgt, int bot)
{
int y;
char out[LCD_MAX_WIDTH];
for (y = top; y <= bot; y++) {
snprintf (out, sizeof(out), "\x0FEG%c%c", lft, y);
write (fd, out, 4);
write (fd, MtxOrb->framebuf + (y * MtxOrb->wid) + lft, rgt - lft + 1);
#ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: frame buffer box flushed");
#else
if (debug_level > 4)
syslog(LOG_DEBUG, "MtxOrb: frame buffer box flushed");
#endif
}
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
static void MODULE_EXPORT void
MtxOrb_chr (int x, int y, char c) MtxOrb_chr (Driver *drvthis, int x, int y, char c)
{ {
#ifdef USE_REPORT #ifdef USE_REPORT
#else #else
@@ -584,8 +623,8 @@ MtxOrb_chr (int x, int y, char c)
// write to frame buffer // write to frame buffer
y--; x--; // translate to 0-index y--; x--; // translate to 0-index
offset = (y * MtxOrb->wid) + x; offset = (y * width) + x;
MtxOrb->framebuf[offset] = c; framebuf[offset] = c;
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "writing character %02X to position (%d,%d)", c, x, y); debug(RPT_DEBUG, "writing character %02X to position (%d,%d)", c, x, y);
@@ -601,42 +640,52 @@ MtxOrb_chr (int x, int y, char c)
#endif #endif
} }
MODULE_EXPORT int
MtxOrb_get_contrast (Driver *drvthis)
{
return contrast;
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good) // Changes screen contrast (0-255; 140 seems good)
// note: works only for LCD displays // note: works only for LCD displays
// Is it better to use the brightness for VFD/VKD displays ? // Is it better to use the brightness for VFD/VKD displays ?
// //
static int MODULE_EXPORT void
MtxOrb_contrast (int contrast) MtxOrb_set_contrast (Driver *drvthis, int promille)
{ {
char out[4]; char out[4];
int real_contrast;
// validate contrast value // Check it
if (contrast > 255) if( promille < 0 || promille > 1000 )
contrast = 255; return;
if (contrast < 0)
contrast = 0; // Store it
contrast = promille;
real_contrast = (int) ((long)promille * 255 / 1000 );
// And do it
if (IS_LCD_DISPLAY || IS_LKD_DISPLAY) { if (IS_LCD_DISPLAY || IS_LKD_DISPLAY) {
snprintf (out, sizeof(out), "\x0FEP%c", contrast); snprintf (out, sizeof(out), "\x0FEP%c", real_contrast);
write (fd, out, 3); write (fd, out, 3);
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: contrast set to %d", contrast); debug(RPT_DEBUG, "MtxOrb: contrast set to %d", real_contrast);
#else #else
if (debug_level > 3) if (debug_level > 3)
syslog(LOG_DEBUG, "MtxOrb: contrast set to %d", contrast); syslog(LOG_DEBUG, "MtxOrb: contrast set to %d", real_contrast);
#endif #endif
} else { } else {
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: contrast not set to %d - not LCD or LKD display", contrast); debug(RPT_DEBUG, "MtxOrb: contrast not set to %d - not LCD or LKD display", real_contrast);
#else #else
if (debug_level > 3) if (debug_level > 3)
syslog(LOG_DEBUG, "MtxOrb: contrast not set to %d - not LCD or LKD display", contrast); syslog(LOG_DEBUG, "MtxOrb: contrast not set to %d - not LCD or LKD display", real_contrast);
#endif #endif
} }
return contrast;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -652,8 +701,8 @@ MtxOrb_contrast (int contrast)
#define BACKLIGHT_OFF 0 #define BACKLIGHT_OFF 0
#define BACKLIGHT_ON 1 #define BACKLIGHT_ON 1
static void MODULE_EXPORT void
MtxOrb_backlight (int on) MtxOrb_backlight (Driver *drvthis, int on)
{ {
static int backlight_state = 1; static int backlight_state = 1;
@@ -707,8 +756,8 @@ MtxOrb_backlight (int on)
// displays with keypad have 6 outputs but the one without kepad // displays with keypad have 6 outputs but the one without kepad
// have only one output // have only one output
// NOTE: length of command are different // NOTE: length of command are different
static void MODULE_EXPORT void
MtxOrb_output (int on) MtxOrb_output (Driver *drvthis, int on)
{ {
char out[5]; char out[5];
static int output_state = -1; static int output_state = -1;
@@ -752,7 +801,7 @@ MtxOrb_output (int on)
// Toggle the built-in linewrapping feature // Toggle the built-in linewrapping feature
// //
static void static void
MtxOrb_linewrap (int on) MtxOrb_linewrap (Driver *drvthis, int on)
{ {
if (on) { if (on) {
write (fd, "\x0FE" "C", 2); write (fd, "\x0FE" "C", 2);
@@ -779,7 +828,7 @@ MtxOrb_linewrap (int on)
// Toggle the built-in automatic scrolling feature // Toggle the built-in automatic scrolling feature
// //
static void static void
MtxOrb_autoscroll (int on) MtxOrb_autoscroll (Driver *drvthis, int on)
{ {
if (on) { if (on) {
write (fd, "\x0FEQ", 2); write (fd, "\x0FEQ", 2);
@@ -807,7 +856,7 @@ MtxOrb_autoscroll (int on)
// Toggle cursor blink on/off // Toggle cursor blink on/off
// //
static void static void
MtxOrb_cursorblink (int on) MtxOrb_cursorblink (Driver *drvthis, int on)
{ {
if (on) { if (on) {
write (fd, "\x0FES", 2); write (fd, "\x0FES", 2);
@@ -833,8 +882,8 @@ MtxOrb_cursorblink (int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before lcd.vbar() // Sets up for vertical bars. Call before lcd.vbar()
// //
static void MODULE_EXPORT void
MtxOrb_init_vbar () MtxOrb_init_vbar (Driver *drvthis)
{ {
custom = bar; custom = bar;
} }
@@ -842,8 +891,8 @@ MtxOrb_init_vbar ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
static void MODULE_EXPORT void
MtxOrb_init_hbar () MtxOrb_init_hbar (Driver *drvthis)
{ {
custom = bar; custom = bar;
} }
@@ -851,8 +900,8 @@ MtxOrb_init_hbar ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Returns string with general information about the display // Returns string with general information about the display
// //
static char * MODULE_EXPORT char *
MtxOrb_getinfo (void) MtxOrb_get_info (Driver *drvthis)
{ {
char in = 0; char in = 0;
static char info[255]; static char info[255];
@@ -864,10 +913,10 @@ MtxOrb_getinfo (void)
int retval; int retval;
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: getinfo"); debug(RPT_DEBUG, "MtxOrb: get_info");
#else #else
if (debug_level > 3) if (debug_level > 3)
syslog(LOG_DEBUG, "MtxOrb: getinfo"); syslog(LOG_DEBUG, "MtxOrb: get_info");
#endif #endif
memset(info, '\0', sizeof(info)); memset(info, '\0', sizeof(info));
@@ -983,8 +1032,8 @@ MtxOrb_getinfo (void)
// Draws a vertical bar... // Draws a vertical bar...
// This is the new version ussing dynamic icon alocation // This is the new version ussing dynamic icon alocation
// //
static void MODULE_EXPORT void
MtxOrb_vbar (int x, int len) MtxOrb_vbar (Driver *drvthis, int x, int len)
{ {
unsigned char mapu[9] = { barw, baru1, baru2, baru3, baru4, baru5, baru6, baru7, barb }; unsigned char mapu[9] = { barw, baru1, baru2, baru3, baru4, baru5, baru6, baru7, barb };
unsigned char mapd[9] = { barw, bard1, bard2, bard3, bard4, bard5, bard6, bard7, barb }; unsigned char mapd[9] = { barw, bard1, bard2, bard3, bard4, bard5, bard6, bard7, barb };
@@ -1003,23 +1052,23 @@ MtxOrb_vbar (int x, int len)
// REMOVE THE PREVIOUS LINE FOR TESTING ONLY... // REMOVE THE PREVIOUS LINE FOR TESTING ONLY...
if (len > 0) { if (len > 0) {
for (y = MtxOrb->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
if (len >= MtxOrb->cellhgt) if (len >= cellheight)
MtxOrb_chr (x, y, 255); MtxOrb_chr (drvthis, x, y, 255);
else else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapu[len])); MtxOrb_chr (drvthis, x, y, MtxOrb_ask_bar (drvthis, mapu[len]));
len -= MtxOrb->cellhgt; len -= cellheight;
} }
} else { } else {
len = -len; len = -len;
for (y = 2; y <= MtxOrb->hgt && len > 0; y++) { for (y = 2; y <= height && len > 0; y++) {
if (len >= MtxOrb->cellhgt) if (len >= cellheight)
MtxOrb_chr (x, y, 255); MtxOrb_chr (drvthis, x, y, 255);
else else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapd[len])); MtxOrb_chr (drvthis, x, y, MtxOrb_ask_bar (drvthis, mapd[len]));
len -= MtxOrb->cellhgt; len -= cellheight;
} }
} }
@@ -1030,8 +1079,8 @@ MtxOrb_vbar (int x, int len)
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// This is the new version ussing dynamic icon alocation // This is the new version ussing dynamic icon alocation
// //
static void MODULE_EXPORT void
MtxOrb_hbar (int x, int y, int len) MtxOrb_hbar (Driver *drvthis, int x, int y, int len)
{ {
unsigned char mapr[6] = { barw, barr1, barr2, barr3, barr4, barb }; unsigned char mapr[6] = { barw, barr1, barr2, barr3, barr4, barb };
unsigned char mapl[6] = { barw, barl1, barl2, barl3, barl4, barb }; unsigned char mapl[6] = { barw, barl1, barl2, barl3, barl4, barb };
@@ -1047,24 +1096,24 @@ MtxOrb_hbar (int x, int y, int len)
#endif #endif
if (len > 0) { if (len > 0) {
for (; x <= MtxOrb->wid && len > 0; x++) { for (; x <= width && len > 0; x++) {
if (len >= MtxOrb->cellwid) if (len >= cellwidth)
MtxOrb_chr (x, y, 255); MtxOrb_chr (drvthis, x, y, 255);
else else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapr[len])); MtxOrb_chr (drvthis, x, y, MtxOrb_ask_bar (drvthis, mapr[len]));
len -= MtxOrb->cellwid; len -= cellwidth;
} }
} else { } else {
len = -len; len = -len;
for (; x > 0 && len > 0; x--) { for (; x > 0 && len > 0; x--) {
if (len >= MtxOrb->cellwid) if (len >= cellwidth)
MtxOrb_chr (x, y, 255); MtxOrb_chr (drvthis, x, y, 255);
else else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapl[len])); MtxOrb_chr (drvthis, x, y, MtxOrb_ask_bar (drvthis, mapl[len]));
len -= MtxOrb->cellwid; len -= cellwidth;
} }
} }
@@ -1079,8 +1128,8 @@ MtxOrb_hbar (int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
static void MODULE_EXPORT void
MtxOrb_init_num () MtxOrb_init_num (Driver *drvthis)
{ {
#ifdef USE_REPORT #ifdef USE_REPORT
debug(RPT_DEBUG, "MtxOrb: init for big numbers"); debug(RPT_DEBUG, "MtxOrb: init for big numbers");
@@ -1092,7 +1141,7 @@ MtxOrb_init_num ()
if (custom != bign) { if (custom != bign) {
write (fd, "\x0FEn", 2); write (fd, "\x0FEn", 2);
custom = bign; custom = bign;
MtxOrb_clear_custom (); MtxOrb_clear_custom (drvthis);
} }
} }
@@ -1112,8 +1161,8 @@ MtxOrb_init_num ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
static void MODULE_EXPORT void
MtxOrb_num (int x, int num) MtxOrb_num (Driver *drvthis, int x, int num)
{ {
int y, dx; int y, dx;
char out[5]; char out[5];
@@ -1131,7 +1180,7 @@ MtxOrb_num (int x, int num)
// Make this space dirty as far as frame buffer knows. // Make this space dirty as far as frame buffer knows.
for (y = 1; y < 5; y++) for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++) for (dx = 0; dx < 3; dx++)
MtxOrb_chr (x + dx, y, DIRTY_CHAR); MtxOrb_chr (drvthis, x + dx, y, DIRTY_CHAR);
} }
@@ -1147,7 +1196,7 @@ MtxOrb_num (int x, int num)
// TODO: _icon should not call this directly, this is why we define // TODO: _icon should not call this directly, this is why we define
// so frequently the heartbeat custom char. GLU // so frequently the heartbeat custom char. GLU
// //
// TODO: We make one 3 bytes write folowed by MtxOrb->cellhgt one byte // TODO: We make one 3 bytes write folowed by cellheight one byte
// write. This should be done in one single write. GLU // write. This should be done in one single write. GLU
#define MAX_CUSTOM_CHARS 7 #define MAX_CUSTOM_CHARS 7
@@ -1157,8 +1206,8 @@ MtxOrb_num (int x, int num)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
static void MODULE_EXPORT void
MtxOrb_set_char (int n, char *dat) MtxOrb_set_char (Driver *drvthis, int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
@@ -1172,15 +1221,15 @@ MtxOrb_set_char (int n, char *dat)
snprintf (out, sizeof(out), "\x0FEN%c", n); snprintf (out, sizeof(out), "\x0FEN%c", n);
write (fd, out, 3); write (fd, out, 3);
for (row = 0; row < MtxOrb->cellhgt; row++) { for (row = 0; row < cellheight; row++) {
letter = 0; letter = 0;
for (col = 0; col < MtxOrb->cellwid; col++) { for (col = 0; col < cellwidth; col++) {
// shift to make room for new scan line data // shift to make room for new scan line data
letter <<= 1; letter <<= 1;
// Now read a single bit of data // Now read a single bit of data
// -- one entry in dat[] -- // -- one entry in dat[] --
// and add it to the binary data in "letter" // and add it to the binary data in "letter"
letter |= (dat[(row * MtxOrb->cellwid) + col] > 0); letter |= (dat[(row * cellwidth) + col] > 0);
} }
write (fd, &letter, 1); // write one character for each row write (fd, &letter, 1); // write one character for each row
} }
@@ -1191,78 +1240,12 @@ MtxOrb_set_char (int n, char *dat)
// //
// TODO (DONE): Don't make direct call to caracter definition if the caracter is // TODO (DONE): Don't make direct call to caracter definition if the caracter is
// already defined. GLU // already defined. GLU
static void MODULE_EXPORT void
MtxOrb_icon (int which, char dest) MtxOrb_icon (Driver *drvthis, int which, char dest)
{ {
if (custom == bign) if (custom == bign)
custom = beat; custom = beat;
MtxOrb_set_known_char (dest, START_ICON+which); MtxOrb_set_known_char (drvthis, dest, START_ICON+which);
}
/////////////////////////////////////////////////////////////
// Blasts a single frame onscreen, to the lcd...
//
// Input is a character array, sized lcd.wid*lcd.hgt
//
static void
MtxOrb_draw_frame (char *dat)
{
char out[12];
int i,j,mv = 1;
static char *old = NULL;
char *p, *q;
if (!dat)
return;
if (old == NULL) {
old = malloc(MtxOrb->wid * MtxOrb->hgt);
write(fd, "\x0FEG\x01\x01", 4);
write(fd, dat, MtxOrb->wid * MtxOrb->hgt);
strncpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
return;
} else {
if (! new_framebuf(MtxOrb, old))
return;
}
p = dat;
q = old;
for (i = 1; i <= MtxOrb->hgt; i++) {
for (j = 1; j <= MtxOrb->wid; j++) {
if ((*p == *q) && (*p > 8))
mv = 1;
else {
// Draw characters that have changed, as well
// as custom characters. We know not if a custom
// character has changed.
if (mv == 1) {
snprintf(out, sizeof(out), "\x0FEG%c%c", j, i);
write (fd, out, 4);
mv = 0;
}
write (fd, p, 1);
}
p++;
q++;
}
}
//for (i = 0; i < MtxOrb->hgt; i++) {
// snprintf (out, sizeof(out), "\x0FEG\x001%c", i + 1);
// write (fd, out, 4);
// write (fd, dat + (MtxOrb->wid * i), MtxOrb->wid);
//}
strncpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
} }
// TODO: Recover the code for I2C connectivity to MtxOrb // TODO: Recover the code for I2C connectivity to MtxOrb
@@ -1273,12 +1256,31 @@ MtxOrb_draw_frame (char *dat)
// returns one character from the keypad... // returns one character from the keypad...
// (A-Z) on success, 0 on failure... // (A-Z) on success, 0 on failure...
// //
static char MODULE_EXPORT char
MtxOrb_getkey () MtxOrb_getkey (Driver *drvthis)
{ {
char in = 0; char in = 0;
read (fd, &in, 1); read (fd, &in, 1);
switch (in) {
case KEY_LEFT:
in = INPUT_BACK_KEY;
break;
case KEY_RIGHT:
in = INPUT_FORWARD_KEY;
break;
case KEY_DOWN:
in = INPUT_MAIN_MENU_KEY;
break;
case KEY_F1:
in = INPUT_PAUSE_KEY;
break;
/*TODO: add more translations here (if neccessary)*/
default:
in = 0;
break;
}
return in; return in;
} }
@@ -1292,7 +1294,7 @@ MtxOrb_getkey ()
// completely tested, just a quick hack. // completely tested, just a quick hack.
// //
static int static int
MtxOrb_ask_bar (int type) MtxOrb_ask_bar (Driver *drvthis, int type)
{ {
int i; int i;
int last_not_in_use; int last_not_in_use;
@@ -1331,7 +1333,7 @@ MtxOrb_ask_bar (int type)
if (pos != 8) { // A caracter is found (Best match could solve our problem). if (pos != 8) { // 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 (def[pos] != type) {
MtxOrb_set_known_char (pos, type); // Define a new graphic caracter. MtxOrb_set_known_char (drvthis, pos, type); // Define a new graphic caracter.
def[pos] = type; // Remember that now the caracter is available. def[pos] = type; // Remember that now the caracter is available.
} }
if (!use[pos]) { // If the caracter is no yet in use (but defined). if (!use[pos]) { // If the caracter is no yet in use (but defined).
@@ -1433,8 +1435,8 @@ MtxOrb_ask_bar (int type)
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Does the heartbeat... // Does the heartbeat...
// //
static void MODULE_EXPORT void
MtxOrb_heartbeat (int type) MtxOrb_heartbeat (Driver *drvthis, int type)
{ {
int the_icon=255; int the_icon=255;
static int timer = 0; static int timer = 0;
@@ -1451,13 +1453,13 @@ MtxOrb_heartbeat (int type)
// This defines a custom character EVERY time... // This defines a custom character EVERY time...
// not efficient... is this necessary? // not efficient... is this necessary?
// MtxOrb_icon (whichIcon, 0); // MtxOrb_icon (whichIcon, 0);
the_icon=MtxOrb_ask_bar (whichIcon+START_ICON); the_icon=MtxOrb_ask_bar (drvthis, whichIcon+START_ICON);
// Put character on screen... // Put character on screen...
MtxOrb_chr (MtxOrb->wid, 1, the_icon); MtxOrb_chr (drvthis, width, 1, the_icon);
// change display... // change display...
MtxOrb_flush (); MtxOrb_flush (drvthis);
} }
timer++; timer++;
@@ -1468,7 +1470,7 @@ MtxOrb_heartbeat (int type)
// Sets up a well known character for use. // Sets up a well known character for use.
// //
static void static void
MtxOrb_set_known_char (int car, int type) MtxOrb_set_known_char (Driver *drvthis, int car, int type)
{ {
char all_bar[25][5 * 8] = { char all_bar[25][5 * 8] = {
{ {
@@ -1699,6 +1701,6 @@ MtxOrb_set_known_char (int car, int type)
} }
}; };
MtxOrb_set_char (car, &all_bar[type][0]); MtxOrb_set_char (drvthis, car, &all_bar[type][0]);
} }
+40 -28
View File
@@ -1,41 +1,53 @@
#ifndef MTXORB_H #ifndef MTXORB_H
#define MTXORB_H #define MTXORB_H
extern lcd_logical_driver *MtxOrb; #include "lcd.h"
int MtxOrb_init (lcd_logical_driver * driver, char *device); int MtxOrb_init (Driver *drvthis, char *device);
/* MODULE_EXPORT void MtxOrb_close (Driver *drvthis);
* Just like in hd44780 those function are assing by _init ... MODULE_EXPORT int MtxOrb_width (Driver *drvthis);
static void MtxOrb_clear (); MODULE_EXPORT int MtxOrb_height (Driver *drvthis);
static void MtxOrb_close (); MODULE_EXPORT void MtxOrb_clear (Driver *drvthis);
static void MtxOrb_flush (); MODULE_EXPORT void MtxOrb_flush (Driver *drvthis);
static void MtxOrb_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT void MtxOrb_string (Driver *drvthis, int x, int y, char *string);
static void MtxOrb_chr (int x, int y, char c); MODULE_EXPORT void MtxOrb_chr (Driver *drvthis, 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 ();
static void MtxOrb_heartbeat (int type);
static int MtxOrb_ask_bar (int type); MODULE_EXPORT void MtxOrb_vbar (Driver *drvthis, int x, int len);
static void MtxOrb_set_known_char (int car, int type); MODULE_EXPORT void MtxOrb_hbar (Driver *drvthis, int x, int y, int len);
*/ MODULE_EXPORT void MtxOrb_num (Driver *drvthis, int x, int num);
MODULE_EXPORT void MtxOrb_icon (Driver *drvthis, int which, char dest);
MODULE_EXPORT void MtxOrb_heartbeat (Driver *drvthis, int type);
#define DEFAULT_CONTRAST 120 MODULE_EXPORT void MtxOrb_set_char (Driver *drvthis, int n, char *dat);
MODULE_EXPORT int MtxOrb_get_contrast (Driver *drvthis);
MODULE_EXPORT void MtxOrb_set_contrast (Driver *drvthis, int promille);
MODULE_EXPORT void MtxOrb_backlight (Driver *drvthis, int on);
MODULE_EXPORT void MtxOrb_output (Driver *drvthis, int on);
MODULE_EXPORT char MtxOrb_getkey (Driver *drvthis);
MODULE_EXPORT char * MtxOrb_get_info (Driver *drvthis);
MODULE_EXPORT void MtxOrb_init_vbar (Driver *drvthis);
MODULE_EXPORT void MtxOrb_init_hbar (Driver *drvthis);
MODULE_EXPORT void MtxOrb_init_num (Driver *drvthis);
#define DEFAULT_CONTRAST 480
#define DEFAULT_DEVICE "/dev/lcd" #define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_SPEED B19200 #define DEFAULT_SPEED B19200
#define DEFAULT_LINEWRAP 1 #define DEFAULT_LINEWRAP 1
#define DEFAULT_AUTOSCROLL 1 #define DEFAULT_AUTOSCROLL 1
#define DEFAULT_CURSORBLINK 0 #define DEFAULT_CURSORBLINK 0
/* These are the keys for a (possibly) broken LK202-25...*/
#define KEY_UP 'I'
#define KEY_DOWN 'F'
#define KEY_LEFT 'K'
#define KEY_RIGHT 'A'
#define KEY_F1 'N'
/* TODO: add more if you've got any more ;) or correct the settings
* the actual translation is done in MtxOrb_getkey()
*/
#endif #endif
+132 -118
View File
@@ -30,16 +30,19 @@
#endif #endif
#include "lcd.h" #include "lcd.h"
#include "bayrad.h" #include "bayrad.h"
#include "drv_base.h" //#include "drv_base.h"
#include "shared/str.h" #include "shared/str.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// Base "class" to derive from /////////////////////// ////////////////////// Base "class" to derive from ///////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
lcd_logical_driver *bayrad;
static int fd; static int fd;
static int width = 0;
static int height = 0;
static int cellwidth = 5;
static int cellheight = 8;
static char *framebuf = NULL;
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
/* Declare a bunch of global, static custom character data */ /* Declare a bunch of global, static custom character data */
@@ -295,12 +298,18 @@ char icons[3][5*8] = {
}; };
// Vars for the server core
MODULE_EXPORT char * api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "bayrad_";
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int bayrad_init(struct lcd_logical_driver *driver, char *args) int
bayrad_init(Driver *drvthis, char *args)
{ {
char device[256]; char device[256];
@@ -312,26 +321,23 @@ int bayrad_init(struct lcd_logical_driver *driver, char *args)
int tmp; int tmp;
//printf("bayrad_init()\n"); //printf("bayrad_init()\n");
bayrad = driver;
strcpy(device, "/dev/lcd"); strcpy(device, "/dev/lcd");
driver->wid = 20; width = 20;
driver->hgt = 2; height = 2;
// You must use driver->framebuf here, but may use lcd.framebuf later. framebuf = malloc(width * height);
if(!driver->framebuf)
driver->framebuf = malloc(driver->wid * driver->hgt);
if(!driver->framebuf) if(!framebuf)
{ {
bayrad_close(); bayrad_close(drvthis);
fprintf(stderr, "\nError: unable to create BayRAD framebuffer.\n"); fprintf(stderr, "\nError: unable to create BayRAD framebuffer.\n");
return -1; return -1;
} }
memset(driver->framebuf, ' ', driver->wid*driver->hgt); memset(framebuf, ' ', width * height);
driver->cellwid = 5; //cellheight = 5;
driver->cellhgt = 8; //cellwidth = 8;
/*-----------------------------------------------------*/ /*-----------------------------------------------------*/
@@ -442,55 +448,79 @@ int bayrad_init(struct lcd_logical_driver *driver, char *args)
write(fd, "\x80\x86\x00\x1a\x1e", 5); // sync,reset to type 0, clear screen, home write(fd, "\x80\x86\x00\x1a\x1e", 5); // sync,reset to type 0, clear screen, home
driver->clear = bayrad_clear; // Set variables for server
driver->string = bayrad_string; drvthis->api_version = api_version;
driver->chr = bayrad_chr; drvthis->stay_in_foreground = &stay_in_foreground;
driver->vbar = bayrad_vbar; drvthis->supports_multiple = &supports_multiple;
driver->init_vbar = bayrad_init_vbar;
driver->hbar = bayrad_hbar;
driver->init_hbar = bayrad_init_hbar;
//driver->num = NULL; //bayrad_num;
//driver->init_num = NULL; //bayrad_init_num;
driver->init = bayrad_init;
driver->close = bayrad_close;
driver->flush = bayrad_flush;
driver->flush_box = bayrad_flush_box;
//driver->contrast = NULL;
driver->backlight = bayrad_backlight;
driver->set_char = bayrad_set_char;
driver->icon = bayrad_icon;
driver->draw_frame = bayrad_draw_frame;
driver->getkey = bayrad_getkey; // Set the functions the driver supports
drvthis->clear = bayrad_clear;
drvthis->string = bayrad_string;
drvthis->chr = bayrad_chr;
drvthis->old_vbar = bayrad_vbar;
drvthis->init_vbar = bayrad_init_vbar;
drvthis->old_hbar = bayrad_hbar;
drvthis->init_hbar = bayrad_init_hbar;
//drvthis->num = NULL; //bayrad_num;
//drvthis->init_num = NULL; //bayrad_init_num;
drvthis->init = bayrad_init;
drvthis->close = bayrad_close;
drvthis->flush = bayrad_flush;
drvthis->backlight = bayrad_backlight;
drvthis->set_char = bayrad_set_char;
drvthis->old_icon = bayrad_icon;
drvthis->getkey = bayrad_getkey;
return fd; return 0;
} }
// Below here, you may use either lcd.framebuf or driver->framebuf.. // Below here, you may use either lcd.framebuf or drvthis->framebuf..
// lcd.framebuf will be set to the appropriate buffer before calling // lcd.framebuf will be set to the appropriate buffer before calling
// your driver. // your driver.
void bayrad_close() MODULE_EXPORT void
bayrad_close(Driver * drvthis)
{ {
if(bayrad->framebuf != NULL) //fprintf(stderr, "\nClosing BayRAD.\n");
free(bayrad->framebuf);
bayrad->framebuf = NULL;
write(fd, "\x8e\x00", 2); // Backlight OFF write(fd, "\x8e\x00", 2); // Backlight OFF
//fprintf(stderr, "\nClosing BayRAD.\n"); if(framebuf) free(framebuf);
framebuf = NULL;
close(fd); close(fd);
} }
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
bayrad_width(Driver * drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
bayrad_height(Driver * drvthis)
{
return height;
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void bayrad_clear() MODULE_EXPORT void
bayrad_clear(Driver * drvthis)
{ {
memset(bayrad->framebuf, ' ', bayrad->wid*bayrad->hgt); memset(framebuf, ' ', width * height);
} }
@@ -498,15 +528,16 @@ void bayrad_clear()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void bayrad_flush() MODULE_EXPORT void
bayrad_flush(Driver * drvthis)
{ {
//fprintf(stderr, "\nBayRAD flush"); //fprintf(stderr, "\nBayRAD flush");
write(fd, "\x80\x1e", 2); //sync, home write(fd, "\x80\x1e", 2); //sync, home
write(fd, bayrad->framebuf, 20); write(fd, framebuf, 20);
write(fd, "\x1e\x0a", 2); //home, LF write(fd, "\x1e\x0a", 2); //home, LF
write(fd, bayrad->framebuf+20, 20); write(fd, framebuf+20, 20);
return; return;
} }
@@ -515,7 +546,8 @@ void bayrad_flush()
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void bayrad_string(int x, int y, char string[]) MODULE_EXPORT void
bayrad_string(Driver * drvthis, int x, int y, char string[])
{ {
int i; int i;
unsigned char c; unsigned char c;
@@ -528,7 +560,7 @@ void bayrad_string(int x, int y, char string[])
for(i=0; string[i]; i++) for(i=0; string[i]; i++)
{ {
// Check for buffer overflows... // Check for buffer overflows...
if((y*bayrad->wid) + x + i > (bayrad->wid*bayrad->hgt)) if((y*width) + x + i > (width*height))
break; break;
c = (unsigned char) string[i]; c = (unsigned char) string[i];
@@ -545,7 +577,7 @@ void bayrad_string(int x, int y, char string[])
c += 0x98; /* as 0x07 makes a beep instead of printing a character */ c += 0x98; /* as 0x07 makes a beep instead of printing a character */
bayrad->framebuf[(y*bayrad->wid) + x + i] = c; framebuf[(y*width) + x + i] = c;
} }
} }
@@ -553,7 +585,8 @@ void bayrad_string(int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,2). // upper-left is (1,1), and the lower right should be (20,2).
// //
void bayrad_chr(int x, int y, char c) MODULE_EXPORT void
bayrad_chr(Driver * drvthis, int x, int y, char c)
{ {
unsigned char ch; unsigned char ch;
@@ -571,13 +604,14 @@ void bayrad_chr(int x, int y, char c)
/* No shifting the custom chars here, so bayrad_chr() can beep */ /* No shifting the custom chars here, so bayrad_chr() can beep */
bayrad->framebuf[(y*bayrad->wid) + x] = ch; framebuf[(y*width) + x] = ch;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Turns the lcd backlight on or off... // Turns the lcd backlight on or off...
// //
void bayrad_backlight(int on) MODULE_EXPORT void
bayrad_backlight(Driver * drvthis, int on)
{ {
/* This violates the LCDd driver model, but it does leave the /* This violates the LCDd driver model, but it does leave the
@@ -601,17 +635,18 @@ void bayrad_backlight(int on)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for vertical bargraphs. // Tells the driver to get ready for vertical bargraphs.
// //
void bayrad_init_vbar() MODULE_EXPORT void
bayrad_init_vbar(Driver * drvthis)
{ {
//printf("Init Vertical bars.\n"); //printf("Init Vertical bars.\n");
bayrad_set_char(1, bar_up[0]); bayrad_set_char(drvthis, 1, bar_up[0]);
bayrad_set_char(2, bar_up[1]); bayrad_set_char(drvthis, 2, bar_up[1]);
bayrad_set_char(3, bar_up[2]); bayrad_set_char(drvthis, 3, bar_up[2]);
bayrad_set_char(4, bar_up[3]); bayrad_set_char(drvthis, 4, bar_up[3]);
bayrad_set_char(5, bar_up[4]); bayrad_set_char(drvthis, 5, bar_up[4]);
bayrad_set_char(6, bar_up[5]); bayrad_set_char(drvthis, 6, bar_up[5]);
bayrad_set_char(7, bar_up[6]); bayrad_set_char(drvthis, 7, bar_up[6]);
return; return;
@@ -620,14 +655,15 @@ void bayrad_init_vbar()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for horizontal bargraphs. // Tells the driver to get ready for horizontal bargraphs.
// //
void bayrad_init_hbar() MODULE_EXPORT void
bayrad_init_hbar(Driver * drvthis)
{ {
//printf("Init Horizontal bars.\n"); //printf("Init Horizontal bars.\n");
bayrad_set_char(1, bar_right[0]); bayrad_set_char(drvthis, 1, bar_right[0]);
bayrad_set_char(2, bar_right[1]); bayrad_set_char(drvthis, 2, bar_right[1]);
bayrad_set_char(3, bar_right[2]); bayrad_set_char(drvthis, 3, bar_right[2]);
bayrad_set_char(4, bar_right[3]); bayrad_set_char(drvthis, 4, bar_right[3]);
return; return;
} }
@@ -635,7 +671,8 @@ return;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for big numbers, if possible. // Tells the driver to get ready for big numbers, if possible.
// //
void bayrad_init_num() MODULE_EXPORT void
bayrad_init_num(Driver * drvthis)
{ {
// printf("Big Numbers.\n"); // printf("Big Numbers.\n");
} }
@@ -643,7 +680,8 @@ void bayrad_init_num()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Draws a big (4-row) number. // Draws a big (4-row) number.
// //
void bayrad_num(int x, int num) MODULE_EXPORT void
bayrad_num(Driver * drvthis, int x, int num)
{ {
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
} }
@@ -651,7 +689,8 @@ void bayrad_num(int x, int num)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Changes the font data of character n. // Changes the font data of character n.
// //
void bayrad_set_char(int n, char *dat) MODULE_EXPORT void
bayrad_set_char(Driver * drvthis, int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
@@ -672,13 +711,13 @@ void bayrad_set_char(int n, char *dat)
snprintf(out, sizeof(out), "\x88%c", n); snprintf(out, sizeof(out), "\x88%c", n);
write(fd, out, 2); write(fd, out, 2);
for(row=0; row<bayrad->cellhgt; row++) for(row=0; row<cellheight; row++)
{ {
letter = 0; letter = 0;
for(col=0; col<bayrad->cellwid; col++) for(col=0; col<cellwidth; col++)
{ {
letter <<= 1; letter <<= 1;
letter |= (dat[(row*bayrad->cellwid) + col] > 0); letter |= (dat[(row*cellwidth) + col] > 0);
} }
write(fd, &letter, 1); write(fd, &letter, 1);
} }
@@ -692,33 +731,34 @@ return;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up. // Draws a vertical bar, from the bottom of the screen up.
// //
void bayrad_vbar(int x, int len) MODULE_EXPORT void
bayrad_vbar(Driver * drvthis, int x, int len)
{ {
int y = 2; int y = 2;
//fprintf(stderr, "\nVbar at %i, length %i", x, len); //fprintf(stderr, "\nVbar at %i, length %i", x, len);
if(len >= bayrad->cellhgt) if(len >= cellheight)
{ {
bayrad_chr(x, y, 0xFF); bayrad_chr(drvthis, x, y, 0xFF);
len -= bayrad->cellhgt; len -= cellheight;
y = 1; y = 1;
} }
if(!len) if(!len)
return; return;
if(len > bayrad->cellhgt) if(len > cellheight)
{ {
bayrad_chr(x, y, '^'); /* Show we've gone off the chart */ bayrad_chr(drvthis, x, y, '^'); /* Show we've gone off the chart */
return; return;
} }
/* init_vbar sets custom chars 1 - 7. Height 8 is char 0xFF. */ /* init_vbar sets custom chars 1 - 7. Height 8 is char 0xFF. */
if(len == 8) if(len == 8)
bayrad_chr(x, y, 0xFF); bayrad_chr(drvthis, x, y, 0xFF);
else else
bayrad_chr(x, y, (len+0x98)); bayrad_chr(drvthis, x, y, (len+0x98));
return; return;
} }
@@ -726,21 +766,22 @@ return;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void bayrad_hbar(int x, int y, int len) MODULE_EXPORT void
bayrad_hbar(Driver * drvthis, int x, int y, int len)
{ {
//fprintf(stderr, "\nHbar at %i,%i; length %i", x, y, len); //fprintf(stderr, "\nHbar at %i,%i; length %i", x, y, len);
while((x <= bayrad->wid) && (len > 0)) while((x <= cellwidth) && (len > 0))
{ {
if(len < bayrad->cellwid) if(len < cellwidth)
{ {
bayrad_chr(x, y, 0x98 + len); bayrad_chr(drvthis, x, y, 0x98 + len);
break; break;
} }
bayrad_chr(x, y, 0xFF); bayrad_chr(drvthis, x, y, 0xFF);
len -= bayrad->cellwid; len -= cellwidth;
x++; x++;
} }
@@ -751,51 +792,24 @@ void bayrad_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void bayrad_icon(int which, char dest) MODULE_EXPORT void
bayrad_icon(Driver * drvthis, int which, char dest)
{ {
//printf("Char %i set to icon %i\n", dest, which); //printf("Char %i set to icon %i\n", dest, which);
bayrad_set_char(dest, &icons[which][0]); bayrad_set_char(drvthis, dest, &icons[which][0]);
return; return;
} }
//////////////////////////////////////////////////////////////////////
// Send a rectangular area to the display.
//
// I've just called bayrad_flush() because there's not much point yet
// in flushing less than the entire framebuffer.
//
void bayrad_flush_box(int lft, int top, int rgt, int bot)
{
bayrad_flush();
}
//////////////////////////////////////////////////////////////////////
// Draws the framebuffer on the display.
//
void bayrad_draw_frame(char *dat)
{
//fprintf(stderr, "\nBayRAD draw frame");
write(fd, "\x80\x1e", 2); // NOP, home
write(fd, bayrad->framebuf, 20);
write(fd, "\n", 1);
write(fd, bayrad->framebuf+20, 20);
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device... // Tries to read a character from an input device...
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char bayrad_getkey() MODULE_EXPORT char
bayrad_getkey(Driver * drvthis)
{ {
fd_set brfdset; fd_set brfdset;
struct timeval twait; struct timeval twait;
+22 -18
View File
@@ -8,24 +8,28 @@
#ifndef _BAYRAD_H #ifndef _BAYRAD_H
#define _BAYRAD_H #define _BAYRAD_H
extern lcd_logical_driver *bayrad; #include "lcd.h"
int bayrad_init(struct lcd_logical_driver *driver, char *args); int bayrad_init(Driver * drvthis, char *args);
void bayrad_close(); MODULE_EXPORT void bayrad_close(Driver * drvthis);
void bayrad_clear(); MODULE_EXPORT int bayrad_width(Driver * drvthis);
void bayrad_flush(); MODULE_EXPORT int bayrad_height(Driver * drvthis);
void bayrad_string(int x, int y, char string[]); MODULE_EXPORT void bayrad_clear(Driver * drvthis);
void bayrad_chr(int x, int y, char c); MODULE_EXPORT void bayrad_flush(Driver * drvthis);
int bayrad_contrast(int contrast); MODULE_EXPORT void bayrad_string(Driver * drvthis, int x, int y, char string[]);
void bayrad_backlight(int on); MODULE_EXPORT void bayrad_chr(Driver * drvthis, int x, int y, char c);
void bayrad_vbar(int x, int len);
void bayrad_init_vbar(); MODULE_EXPORT void bayrad_vbar(Driver * drvthis, int x, int len);
void bayrad_hbar(int x, int y, int len); MODULE_EXPORT void bayrad_hbar(Driver * drvthis, int x, int y, int len);
void bayrad_init_hbar(); MODULE_EXPORT void bayrad_icon(Driver * drvthis, int which, char dest);
void bayrad_set_char(int n, char *dat);
void bayrad_icon(int which, char dest); MODULE_EXPORT void bayrad_set_char(Driver * drvthis, int n, char *dat);
void bayrad_flush_box(int lft, int top, int rgt, int bot);
void bayrad_draw_frame(char *dat); MODULE_EXPORT void bayrad_backlight(Driver * drvthis, int promille);
char bayrad_getkey();
MODULE_EXPORT char bayrad_getkey(Driver * drvthis);
MODULE_EXPORT void bayrad_init_vbar(Driver * drvthis);
MODULE_EXPORT void bayrad_init_hbar(Driver * drvthis);
#endif #endif
+154 -136
View File
@@ -63,11 +63,10 @@ SunOS (5.5.1):
#include "shared/str.h" #include "shared/str.h"
#include "render.h"
#include "lcd.h" #include "lcd.h"
#include "curses_drv.h" #include "curses_drv.h"
#include "shared/report.h" #include "report.h"
#include "configfile.h" //#include "configfile.h"
// ACS_S9 and ACS_S1 are defined as part of XSI Curses standard, Issue 4. // ACS_S9 and ACS_S1 are defined as part of XSI Curses standard, Issue 4.
// However, ACS_S3 and ACS_S7 are not; these definitions were created to support // However, ACS_S3 and ACS_S7 are not; these definitions were created to support
@@ -100,14 +99,13 @@ SunOS (5.5.1):
# endif # endif
#endif #endif
lcd_logical_driver *curses_drv;
// Character used for title bars... // Character used for title bars...
#define PAD '#' #define PAD '#'
// #define PAD ACS_BLOCK // #define PAD ACS_BLOCK
int ELLIPSIS = 7; int ELLIPSIS = 7; // Should this go in PrivateData ?
void curses_drv_restore_screen (void); void curses_drv_restore_screen (Driver *drvthis);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Curses Terminal Output //////////////////////// ////////////////////// For Curses Terminal Output ////////////////////////
@@ -117,7 +115,7 @@ static char icon_char = '@';
static WINDOW *lcd_win; static WINDOW *lcd_win;
/*this is really ugly ;) but works ;)*/ /*this is really ugly ;) but works ;)*/
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{'|',' ','|'}, {'|',' ','|'},
{'|','_','|'}, {'|','_','|'},
{' ',' ',' '}}, {' ',' ',' '}},
@@ -222,13 +220,22 @@ set_background_color (char * buf) {
#define TOP_LEFT_X 7 #define TOP_LEFT_X 7
#define TOP_LEFT_Y 7 #define TOP_LEFT_Y 7
int current_color_pair, current_border_pair, curses_backlight_state = 0; static int current_color_pair, current_border_pair, curses_backlight_state = 0;
static int width, height;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "curses_drv_";
int int
curses_drv_init (struct lcd_logical_driver *driver, char *args) curses_drv_init (Driver *drvthis, char *args)
{ {
char buf[256]; char buf[256];
int wid=0, hgt=0; int w, h;
// Colors.... // Colors....
chtype back_color = DEFAULT_BACKGROUND_COLOR, chtype back_color = DEFAULT_BACKGROUND_COLOR,
@@ -239,26 +246,34 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
int screen_begx = CONF_DEF_TOP_LEFT_X, int screen_begx = CONF_DEF_TOP_LEFT_X,
screen_begy = CONF_DEF_TOP_LEFT_Y; screen_begy = CONF_DEF_TOP_LEFT_Y;
curses_drv = driver; // Set display sizes
if( drvthis->request_display_width() > 0
// TODO: replace DriverName with driver->name when that field exists. && drvthis->request_display_height() > 0 ) {
#define DriverName "curses" // Use size from primary driver
width = drvthis->request_display_width();
height = drvthis->request_display_height();
}
else {
// Use default size
width = LCD_DEFAULT_WIDTH;
height = LCD_DEFAULT_HEIGHT;
}
/*Get settings from config file*/ /*Get settings from config file*/
/*Get color settings*/ /*Get color settings*/
/*foreground color*/ /*foreground color*/
strncpy(buf, config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR),sizeof(buf)); strncpy(buf, drvthis->config_get_string ( drvthis->name , "foreground" , 0 , CONF_DEF_FOREGR),sizeof(buf));
buf[sizeof(buf)-1]=0; buf[sizeof(buf)-1]=0;
fore_color = set_foreground_color(buf); fore_color = set_foreground_color(buf);
debug( RPT_DEBUG, "CURSES: using foreground color: %s", buf); debug( RPT_DEBUG, "CURSES: using foreground color: %s", buf);
/*background color*/ /*background color*/
strncpy(buf, config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR),sizeof(buf)); strncpy(buf, drvthis->config_get_string ( drvthis->name , "background" , 0 , CONF_DEF_BACKGR),sizeof(buf));
buf[sizeof(buf)-1]=0; buf[sizeof(buf)-1]=0;
back_color = set_background_color(buf); back_color = set_background_color(buf);
debug( RPT_DEBUG, "CURSES: using background color: %s", buf); debug( RPT_DEBUG, "CURSES: using background color: %s", buf);
/*backlight color*/ /*backlight color*/
strncpy(buf, config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT), sizeof(buf)); strncpy(buf, drvthis->config_get_string ( drvthis->name , "backlight" , 0 , CONF_DEF_BACKLIGHT), sizeof(buf));
buf[sizeof(buf)-1]=0; buf[sizeof(buf)-1]=0;
backlight_color = set_background_color(buf); backlight_color = set_background_color(buf);
debug( RPT_DEBUG, "CURSES: using backlight color: %s", buf); debug( RPT_DEBUG, "CURSES: using backlight color: %s", buf);
@@ -267,25 +282,28 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
// Or maybe don't do so? - Rene Wagner // Or maybe don't do so? - Rene Wagner
/*Get size settings*/ /*Get size settings*/
strncpy(buf, config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE), sizeof(buf)); strncpy(buf, drvthis->config_get_string ( drvthis->name , "size" , 0 , CONF_DEF_SIZE), sizeof(buf));
buf[sizeof(buf)-1]=0; buf[sizeof(buf)-1]=0;
if( sscanf(buf , "%dx%d", &wid, &hgt ) != 2 if( sscanf(buf , "%dx%d", &w, &h ) != 2
|| (wid <= 0) || (w <= 0)
|| (hgt <= 0)) { || (h <= 0)) {
report (RPT_WARNING, "CURSES: Cannot read size: %s. Using default value %s.\n", buf, CONF_DEF_SIZE); report (RPT_WARNING, "CURSES: Cannot read size: %s. Using default value.\n", buf);
sscanf( CONF_DEF_SIZE , "%dx%d", &wid, &hgt ); //sscanf( CONF_DEF_SIZE , "%dx%d", &width, &height );
// default value is already set
}
else {
width = w;
height = h;
} }
driver->wid = wid;
driver->hgt = hgt;
/*Get position settings*/ /*Get position settings*/
if (0<=config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) && config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) <= 255) { if (0<=drvthis->config_get_int ( drvthis->name , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) && drvthis->config_get_int ( drvthis->name , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) <= 255) {
screen_begx = config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X); screen_begx = drvthis->config_get_int ( drvthis->name , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X);
} else { } else {
report (RPT_WARNING, "CURSES: topleftx must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_X); report (RPT_WARNING, "CURSES: topleftx must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_X);
} }
if (0<=config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) && config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) <= 255) { if (0<=drvthis->config_get_int ( drvthis->name , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) && drvthis->config_get_int ( drvthis->name , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) <= 255) {
screen_begy = config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y); screen_begy = drvthis->config_get_int ( drvthis->name , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y);
} else { } else {
report (RPT_WARNING, "CURSES: toplefty must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_Y); report (RPT_WARNING, "CURSES: toplefty must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_Y);
} }
@@ -302,8 +320,8 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
intrflush (stdscr, FALSE); intrflush (stdscr, FALSE);
keypad (stdscr, TRUE); keypad (stdscr, TRUE);
lcd_win = newwin(curses_drv->hgt + 2, lcd_win = newwin(height + 2,
curses_drv->wid + 2, width + 2,
screen_begy, screen_begy,
screen_begx); screen_begx);
@@ -325,38 +343,41 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
current_border_pair = 3; current_border_pair = 3;
} }
curses_drv_clear (); curses_drv_clear (drvthis);
driver->daemonize = 0; // don't daemonize... // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
// Override output functions... // Set the functions the driver supports
driver->clear = curses_drv_clear; drvthis->init = curses_drv_init;
driver->string = curses_drv_string; drvthis->close = curses_drv_close;
driver->chr = curses_drv_chr; drvthis->width = curses_drv_width;
driver->vbar = curses_drv_vbar; drvthis->height = curses_drv_height;
//driver->init_vbar = NULL; drvthis->clear = curses_drv_clear;
driver->hbar = curses_drv_hbar; drvthis->flush = curses_drv_flush;
//driver->init_hbar = NULL; drvthis->string = curses_drv_string;
driver->num = curses_drv_num; drvthis->chr = curses_drv_chr;
driver->init_num = curses_drv_init_num;
driver->init = curses_drv_init; drvthis->old_vbar = curses_drv_vbar;
driver->close = curses_drv_close; //drvthis->init_vbar = NULL;
driver->flush = curses_drv_flush; drvthis->old_hbar = curses_drv_hbar;
driver->flush_box = curses_drv_flush_box; //drvthis->init_hbar = NULL;
//driver->contrast = NULL; drvthis->num = curses_drv_num;
driver->backlight = curses_drv_backlight; //drvthis->init_num = curses_drv_init_num;
//driver->set_char = NULL;
driver->icon = curses_drv_icon;
driver->draw_frame = curses_drv_draw_frame;
driver->getkey = curses_drv_getkey; drvthis->backlight = curses_drv_backlight;
driver->heartbeat = curses_drv_heartbeat; //drvthis->set_char = NULL;
drvthis->old_icon = curses_drv_icon; // NEEDS TO BE CHANGED !
drvthis->getkey = curses_drv_getkey;
drvthis->heartbeat = curses_drv_heartbeat;
// Change the character used for "..." // Change the character used for "..."
ELLIPSIS = '~'; ELLIPSIS = '~';
return 200; // 200 is arbitrary. (must be 1 or more) return 0;
} }
static void static void
@@ -383,8 +404,8 @@ curses_drv_wborder (WINDOW *win) {
#endif #endif
} }
void MODULE_EXPORT void
curses_drv_close () curses_drv_close (Driver *drvthis)
{ {
// Note that the program leaves a screen on // Note that the program leaves a screen on
// the display to be left behind after closing; // the display to be left behind after closing;
@@ -397,62 +418,69 @@ curses_drv_close ()
move (0, 0); move (0, 0);
endwin (); endwin ();
curs_set(1); curs_set(1);
}
if (curses_drv->framebuf != NULL) /////////////////////////////////////////////////////////////////
free (curses_drv->framebuf); // Returns the display width
//
curses_drv->framebuf = NULL; MODULE_EXPORT int
curses_drv_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
curses_drv_height (Driver *drvthis)
{
return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
curses_drv_clear () curses_drv_clear (Driver *drvthis)
{ {
wbkgdset(lcd_win, COLOR_PAIR(current_color_pair) | ' '); wbkgdset(lcd_win, COLOR_PAIR(current_color_pair) | ' ');
curses_drv_wborder (lcd_win); curses_drv_wborder (lcd_win);
werase (lcd_win); werase (lcd_win);
} }
#define ValidX(x) { if ((x) > curses_drv->wid) { (x) = curses_drv->wid; } else (x) = (x) < 1 ? 1 : x; } #define ValidX(x) { if ((x) > width) { (x) = width; } else (x) = (x) < 1 ? 1 : x; }
#define ValidY(y) { if ((y) > curses_drv->hgt) { (y) = curses_drv->hgt; } else (y) = (y) < 1 ? 1 : y; } #define ValidY(y) { if ((y) > height) { (y) = height; } else (y) = (y) < 1 ? 1 : y; }
void MODULE_EXPORT void
curses_drv_backlight (int on) curses_drv_backlight (Driver *drvthis, int promille)
{ {
if (curses_backlight_state == on) if (curses_backlight_state == promille)
return; return;
// no backlight: pairs 2, 3 // no backlight: pairs 2, 3
// backlight: pairs 4, 5 // backlight: pairs 4, 5
switch (on) { curses_backlight_state = promille;
case 0:
curses_backlight_state = 0; if (promille) {
current_color_pair = 2; current_color_pair = 4;
current_border_pair = 3; current_border_pair = 5;
break; }
case 1: else {
curses_backlight_state = 1; current_color_pair = 2;
current_color_pair = 4; current_border_pair = 3;
current_border_pair = 5;
break;
default:
return;
break;
} }
curses_drv_clear(); curses_drv_clear(drvthis);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
curses_drv_string (int x, int y, char *string) curses_drv_string (Driver *drvthis, int x, int y, char *string)
{ {
//int i; //int i;
unsigned char *p; unsigned char *p;
@@ -483,8 +511,8 @@ curses_drv_string (int x, int y, char *string)
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
curses_drv_chr (int x, int y, char c) curses_drv_chr (Driver *drvthis, int x, int y, char c)
{ {
int ch; int ch;
@@ -504,7 +532,7 @@ curses_drv_chr (int x, int y, char c)
if ((ch = getch ()) != ERR) if ((ch = getch ()) != ERR)
if (ch == 0x0C) { if (ch == 0x0C) {
curses_drv_restore_screen(); curses_drv_restore_screen(drvthis);
ungetch(ch); ungetch(ch);
} }
@@ -514,8 +542,8 @@ curses_drv_chr (int x, int y, char c)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void MODULE_EXPORT void
curses_drv_init_num () curses_drv_init_num (Driver *drvthis)
{ {
; ;
} }
@@ -523,47 +551,47 @@ curses_drv_init_num ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void MODULE_EXPORT void
curses_drv_num (int x, int num) curses_drv_num (Driver *drvthis, int x, int num)
{ {
int y, dx; int y, dx;
for (y = 1; y < 5; y++) for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++) for (dx = 0; dx < 3; dx++)
curses_drv_chr (x + dx, y, num_icon[num][y-1][dx]); curses_drv_chr (drvthis, x + dx, y, num_icon[num][y-1][dx]);
// printf("%1d",num); // printf("%1d",num);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void MODULE_EXPORT void
curses_drv_vbar (int x, int len) curses_drv_vbar (Driver *drvthis, int x, int len)
{ {
int y; int y;
char map[] = { ACS_S9, ACS_S9, ACS_S7, ACS_S7, ACS_S3, ACS_S3, ACS_S1, ACS_S1 }; char map[] = { ACS_S9, ACS_S9, ACS_S7, ACS_S7, ACS_S3, ACS_S3, ACS_S1, ACS_S1 };
ValidX(x); ValidX(x);
#define MAX_LINES (curses_drv->cellhgt * curses_drv->hgt) #define MAX_LINES (LCD_DEFAULT_CELLHEIGHT * height)
len = len > (MAX_LINES - 1) ? (MAX_LINES - 1) : len; len = len > (MAX_LINES - 1) ? (MAX_LINES - 1) : len;
len = len < 0 ? 0 : len; len = len < 0 ? 0 : len;
// len is the length of the bar (in pixels/scanlines) // len is the length of the bar (in pixels/scanlines)
// y is one character line (cellhgt pixels/scanlines) // y is one character line (cellheight pixels/scanlines)
for (y = curses_drv->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
if (len >= curses_drv->cellhgt) { if (len >= LCD_DEFAULT_CELLHEIGHT) {
// write a "full" block to the screen... // write a "full" block to the screen...
//curses_drv_chr (x, y, '8'); //curses_drv_chr (x, y, '8');
curses_drv_chr (x, y, ACS_BLOCK); curses_drv_chr (drvthis, x, y, ACS_BLOCK);
len -= curses_drv->cellhgt; len -= LCD_DEFAULT_CELLHEIGHT;
} }
else { else {
// write a partial block... // write a partial block...
curses_drv_chr (x, y, map[len-1]); curses_drv_chr (drvthis, x, y, map[len-1]);
break; break;
} }
@@ -577,16 +605,16 @@ curses_drv_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void MODULE_EXPORT void
curses_drv_hbar (int x, int y, int len) curses_drv_hbar (Driver *drvthis, int x, int y, int len)
{ {
for (; x <= curses_drv->wid && len > 0; x++) { for (; x <= width && len > 0; x++) {
if (len >= curses_drv->cellwid) if (len >= LCD_DEFAULT_CELLWIDTH)
curses_drv_chr (x, y, '='); curses_drv_chr (drvthis, x, y, '=');
else else
curses_drv_chr (x, y, '-'); curses_drv_chr (drvthis, x, y, '-');
len -= curses_drv->cellwid; len -= LCD_DEFAULT_CELLWIDTH;
} }
// move(y-1, x-1); // move(y-1, x-1);
@@ -596,8 +624,8 @@ curses_drv_hbar (int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void MODULE_EXPORT void
curses_drv_icon (int which, char dest) curses_drv_icon (Driver *drvthis, int which, char dest)
{ {
if (dest == 0) if (dest == 0)
switch (which) { switch (which) {
@@ -617,8 +645,8 @@ curses_drv_icon (int which, char dest)
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Does the heartbeat... // Does the heartbeat...
// //
void MODULE_EXPORT void
curses_drv_heartbeat (int type) curses_drv_heartbeat (Driver *drvthis, int type)
{ {
static int timer = 0; static int timer = 0;
int whichIcon; int whichIcon;
@@ -633,13 +661,13 @@ curses_drv_heartbeat (int type)
// This defines a custom character EVERY time... // This defines a custom character EVERY time...
// not efficient... is this necessary? // not efficient... is this necessary?
curses_drv_icon (whichIcon, 0); curses_drv_icon (drvthis, whichIcon, 0);
// Put character on screen... // Put character on screen...
curses_drv_chr (curses_drv->wid, 1, 0); curses_drv_chr (drvthis, width, 1, 0);
// change display... // change display...
curses_drv_flush (); curses_drv_flush (drvthis);
} }
timer++; timer++;
@@ -649,26 +677,14 @@ curses_drv_heartbeat (int type)
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
curses_drv_flush () curses_drv_flush (Driver *drvthis)
{
curses_drv_draw_frame (curses_drv->framebuf);
}
void
curses_drv_flush_box (int lft, int top, int rgt, int bot)
{
curses_drv_flush ();
}
void
curses_drv_draw_frame (char *dat)
{ {
int c; int c;
if ((c = getch ()) != ERR) if ((c = getch ()) != ERR)
if (c == 0x0C) { if (c == 0x0C) {
curses_drv_restore_screen(); curses_drv_restore_screen(drvthis);
ungetch (c); ungetch (c);
} }
@@ -676,8 +692,9 @@ curses_drv_draw_frame (char *dat)
wrefresh (lcd_win); wrefresh (lcd_win);
} }
char
curses_drv_getkey () MODULE_EXPORT char
curses_drv_getkey (Driver *drvthis)
{ {
int i; int i;
@@ -685,7 +702,7 @@ curses_drv_getkey ()
switch(i) { switch(i) {
case 0x0C: case 0x0C:
curses_drv_restore_screen(); curses_drv_restore_screen(drvthis);
return 0; return 0;
break; break;
case KEY_LEFT: case KEY_LEFT:
@@ -710,7 +727,8 @@ curses_drv_getkey ()
} }
void void
curses_drv_restore_screen () { curses_drv_restore_screen (Driver *drvthis) {
erase(); erase();
refresh(); refresh();
#ifdef CURSES_HAS_REDRAWWIN #ifdef CURSES_HAS_REDRAWWIN
+22 -19
View File
@@ -1,31 +1,34 @@
#ifndef LCD_CURSES_H #ifndef LCD_CURSES_H
#define LCD_CURSES_H #define LCD_CURSES_H
extern lcd_logical_driver *curses_drv; #include "lcd.h"
int curses_drv_init (struct lcd_logical_driver *driver, char *args); int curses_drv_init (Driver * drvthis, char *args);
void curses_drv_backlight (int on); MODULE_EXPORT void curses_drv_close (Driver *drvthis);
void curses_drv_close (); MODULE_EXPORT int curses_drv_width (Driver *drvthis);
void curses_drv_clear (); MODULE_EXPORT int curses_drv_height (Driver *drvthis);
void curses_drv_flush (); MODULE_EXPORT void curses_drv_clear (Driver *drvthis);
void curses_drv_string (int x, int y, char string[]); MODULE_EXPORT void curses_drv_flush (Driver *drvthis);
void curses_drv_chr (int x, int y, char c); MODULE_EXPORT void curses_drv_string (Driver *drvthis, int x, int y, char string[]);
void curses_drv_vbar (int x, int len); MODULE_EXPORT void curses_drv_chr (Driver *drvthis, int x, int y, char c);
void curses_drv_hbar (int x, int y, int len);
void curses_drv_icon (int which, char dest); MODULE_EXPORT void curses_drv_vbar (Driver *drvthis, int x, int len);
void curses_drv_flush (); MODULE_EXPORT void curses_drv_hbar (Driver *drvthis, int x, int y, int len);
void curses_drv_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT void curses_drv_num (Driver *drvthis, int x, int num);
void curses_drv_draw_frame (char *dat); MODULE_EXPORT void curses_drv_heartbeat (Driver *drvthis, int type);
char curses_drv_getkey (); MODULE_EXPORT void curses_drv_icon (Driver *drvthis, int which, char dest);
void curses_drv_init_num ();
void curses_drv_num (int x, int num); MODULE_EXPORT void curses_drv_backlight (Driver *drvthis, int on);
void curses_drv_heartbeat (int type);
MODULE_EXPORT char curses_drv_getkey (Driver *drvthis);
MODULE_EXPORT void curses_drv_init_num (Driver *drvthis);
/*Default settings for config file parsing*/ /*Default settings for config file parsing*/
#define CONF_DEF_FOREGR "blue" #define CONF_DEF_FOREGR "blue"
#define CONF_DEF_BACKGR "cyan" #define CONF_DEF_BACKGR "cyan"
#define CONF_DEF_BACKLIGHT "red" #define CONF_DEF_BACKLIGHT "red"
#define CONF_DEF_SIZE "20x4" #define CONF_DEF_SIZE "20x4" // currently not used, LCD_DEFAULT_WIDTH etc. is used
#define CONF_DEF_TOP_LEFT_X 7 #define CONF_DEF_TOP_LEFT_X 7
#define CONF_DEF_TOP_LEFT_Y 7 #define CONF_DEF_TOP_LEFT_Y 7
+139 -122
View File
@@ -6,9 +6,28 @@
#include <string.h> #include <string.h>
#include <sys/errno.h> #include <sys/errno.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "lcd.h" #include "lcd.h"
#include "debug.h" #include "debug.h"
#include "shared/report.h" #include "report.h"
// Variables
static char *framebuf = NULL;
static int width = LCD_DEFAULT_WIDTH;
static int height = LCD_DEFAULT_HEIGHT;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "debug_";
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Debugging Output ////////////////////////////// ////////////////////// For Debugging Output //////////////////////////////
@@ -17,86 +36,127 @@
// TODO: somehow allow access to the driver->framebuffer to each // TODO: somehow allow access to the driver->framebuffer to each
// function... // function...
static lcd_logical_driver *debug_drv;
int int
debug_init (struct lcd_logical_driver *driver, char *args) debug_init (Driver *drvthis, char *args)
{ {
report (RPT_INFO, "debug_init()"); report (RPT_INFO, "debug_init()");
debug_drv = driver; framebuf = malloc (width * height);
debug_clear (); debug_clear (drvthis);
driver->daemonize = 0; // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = debug_clear; // Set the functions the driver supports
driver->string = debug_string; drvthis->clear = debug_clear;
driver->chr = debug_chr; drvthis->string = debug_string;
driver->vbar = debug_vbar; drvthis->chr = debug_chr;
driver->hbar = debug_hbar; drvthis->old_vbar = debug_vbar;
driver->init_num = debug_init_num; drvthis->old_hbar = debug_hbar;
driver->num = debug_num; drvthis->init_num = debug_init_num;
drvthis->num = debug_num;
driver->init = debug_init; drvthis->init = debug_init;
driver->close = debug_close; drvthis->close = debug_close;
driver->flush = debug_flush; drvthis->width = debug_width;
driver->flush_box = debug_flush_box; drvthis->height = debug_height;
driver->contrast = debug_contrast; drvthis->flush = debug_flush;
driver->backlight = debug_backlight; drvthis->set_contrast = debug_set_contrast;
driver->set_char = debug_set_char; drvthis->backlight = debug_backlight;
driver->icon = debug_icon; drvthis->set_char = debug_set_char;
driver->init_vbar = debug_init_vbar; drvthis->old_icon = debug_icon;
driver->init_hbar = debug_init_hbar; drvthis->init_vbar = debug_init_vbar;
driver->draw_frame = debug_draw_frame; drvthis->init_hbar = debug_init_hbar;
driver->getkey = debug_getkey; drvthis->getkey = debug_getkey;
return 200; // 200 is arbitrary. (must be 1 or more) return 0;
} }
void /////////////////////////////////////////////////////////////////
debug_close () // Closes the driver
//
MODULE_EXPORT void
debug_close (Driver *drvthis)
{ {
report (RPT_INFO, "debug_close()"); report (RPT_INFO, "debug_close()");
if (debug_drv->framebuf) { if(framebuf) free (framebuf);
report (RPT_DEBUG, "frame buffer: %010X", (int) debug_drv->framebuf); framebuf = NULL;
free (debug_drv->framebuf); }
}
debug_drv->framebuf = NULL; /////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
debug_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
debug_height (Driver *drvthis)
{
return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
debug_clear () debug_clear (Driver *drvthis)
{ {
report (RPT_INFO, "clear()"); report (RPT_INFO, "clear()");
memset (debug_drv->framebuf, ' ', debug_drv->wid * debug_drv->hgt); memset (framebuf, ' ', width * height);
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
debug_flush () debug_flush (Driver *drvthis)
{ {
int i, j;
char out[LCD_MAX_WIDTH];
report (RPT_INFO, "flush()"); report (RPT_INFO, "flush()");
debug_drv->draw_frame (); for (i = 0; i < width; i++) {
out[i] = '-';
}
out[width] = 0;
//report (RPT_DEBUG, "+%s+", out);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
out[j] = framebuf[j + (i * width)];
}
out[width] = 0;
//report (RPT_DEBUG, "|%s|", out);
}
for (i = 0; i < width; i++) {
out[i] = '-';
}
out[width] = 0;
//report (RPT_DEBUG, "+%s+", out);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
debug_string (int x, int y, char string[]) debug_string (Driver *drvthis, int x, int y, char string[])
{ {
int i; int i;
@@ -106,7 +166,7 @@ debug_string (int x, int y, char string[])
y --; x --; // Convert 1-based coords to 0-based... y --; x --; // Convert 1-based coords to 0-based...
for (i = 0; string[i]; i++) { for (i = 0; string[i]; i++) {
debug_drv->framebuf[(y * debug_drv->wid) + x + i] = string[i]; framebuf[(y * width) + x + i] = string[i];
} }
} }
@@ -114,54 +174,53 @@ debug_string (int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
debug_chr (int x, int y, char c) debug_chr (Driver *drvthis, int x, int y, char c)
{ {
report (RPT_DEBUG, "char(%i,%i,%c)", x, y, c); report (RPT_DEBUG, "char(%i,%i,%c)", x, y, c);
x--; y--; x--; y--;
debug_drv->framebuf[(y * debug_drv->wid) + x] = c; framebuf[(y * width) + x] = c;
} }
int MODULE_EXPORT void
debug_contrast (int contrast) debug_set_contrast (Driver *drvthis, int promille)
{ {
report (RPT_INFO, "contrast(%i)", contrast); report (RPT_INFO, "set_contrast(%i)", promille);
return 0;
} }
void MODULE_EXPORT void
debug_backlight (int on) debug_backlight (Driver *drvthis, int on)
{ {
report (RPT_INFO, "backlight(%i)", on); report (RPT_INFO, "backlight(%i)", on);
} }
void MODULE_EXPORT void
debug_init_vbar () debug_init_vbar (Driver *drvthis)
{ {
report (LOG_INFO, "init_vbar()"); report (RPT_INFO, "init_vbar()");
} }
void MODULE_EXPORT void
debug_init_hbar () debug_init_hbar (Driver *drvthis)
{ {
report (RPT_INFO, "init_hbar()"); report (RPT_INFO, "init_hbar()");
} }
void MODULE_EXPORT void
debug_init_num () debug_init_num (Driver *drvthis)
{ {
report (RPT_INFO, "init_bignum()"); report (RPT_INFO, "init_bignum()");
} }
void MODULE_EXPORT void
debug_num (int x, int num) debug_num (Driver *drvthis, int x, int num)
{ {
report (RPT_INFO, "big number(%i,%i)", x, num); report (RPT_INFO, "big number(%i,%i)", x, num);
} }
void MODULE_EXPORT void
debug_set_char (int n, char *dat) debug_set_char (Driver *drvthis, int n, char *dat)
{ {
report (RPT_INFO, "set_char(%i,data)", n); report (RPT_INFO, "set_char(%i,data)", n);
} }
@@ -169,17 +228,17 @@ debug_set_char (int n, char *dat)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void MODULE_EXPORT void
debug_vbar (int x, int len) debug_vbar (Driver *drvthis, int x, int len)
{ {
int y; int y;
report (RPT_INFO, "vbar(%i,%i)", x, len); report (RPT_INFO, "vbar(%i,%i)", x, len);
for (y = debug_drv->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
debug_chr (x, y, '|'); debug_chr (drvthis, x, y, '|');
len -= debug_drv->cellhgt; len -= LCD_DEFAULT_CELLHEIGHT;
} }
} }
@@ -187,15 +246,15 @@ debug_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void MODULE_EXPORT void
debug_hbar (int x, int y, int len) debug_hbar (Driver *drvthis, int x, int y, int len)
{ {
report (RPT_INFO, "hbar(%i,%i,%i)", x, y, len); report (RPT_INFO, "hbar(%i,%i,%i)", x, y, len);
for (; x < debug_drv->wid && len > 0; x++) { for (; x < width && len > 0; x++) {
debug_chr (x, y, '-'); debug_chr (drvthis, x, y, '-');
len -= debug_drv->cellwid; len -= LCD_DEFAULT_CELLWIDTH;
} }
} }
@@ -203,59 +262,17 @@ debug_hbar (int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void MODULE_EXPORT void
debug_icon (int which, char dest) debug_icon (Driver *drvthis, int which, char dest)
{ {
report (RPT_INFO, "icon(%i,%i", which, dest); report (RPT_INFO, "icon(%i,%i", which, dest);
} }
void /////////////////////////////////////////////////////////////////
debug_flush_box (int lft, int top, int rgt, int bot) // Return a keypress
{ //
report (RPT_INFO, "flush_box(%i,%i,%i,%i)", lft, top, rgt, bot); MODULE_EXPORT char
debug_getkey (Driver *drvthis)
debug_flush ();
}
void
debug_draw_frame (char *dat)
{
int i, j;
char out[LCD_MAX_WIDTH];
report (RPT_INFO, "draw_frame(data)");
if (!dat)
return;
// report (RPT_DEBUG, "Frame (%ix%i): %s", debug_drv->wid, debug_drv->hgt, dat);
for (i = 0; i < debug_drv->wid; i++) {
out[i] = '-';
}
out[debug_drv->wid] = 0;
//report (RPT_DEBUG, "+%s+", out);
for (i = 0; i < debug_drv->hgt; i++) {
for (j = 0; j < debug_drv->wid; j++) {
out[j] = dat[j + (i * debug_drv->wid)];
}
out[debug_drv->wid] = 0;
//report (RPT_DEBUG, "|%s|", out);
}
for (i = 0; i < debug_drv->wid; i++) {
out[i] = '-';
}
out[debug_drv->wid] = 0;
//report (RPT_DEBUG, "+%s+", out);
}
char
debug_getkey ()
{ {
report (RPT_INFO, "getkey()"); report (RPT_INFO, "getkey()");
return 0; return 0;
+26 -19
View File
@@ -1,24 +1,31 @@
#ifndef LCD_DEBUG_H #ifndef LCD_DEBUG_H
#define LCD_DEBUG_H #define LCD_DEBUG_H
int debug_init (struct lcd_logical_driver *driver, char *args); #include "lcd.h"
void debug_close ();
void debug_clear (); int debug_init (Driver *drvthis, char *args);
void debug_flush (); MODULE_EXPORT void debug_close (Driver *drvthis);
void debug_string (int x, int y, char string[]); MODULE_EXPORT int debug_width (Driver *drvthis);
void debug_chr (int x, int y, char c); MODULE_EXPORT int debug_height (Driver *drvthis);
int debug_contrast (int contrast); MODULE_EXPORT void debug_clear (Driver *drvthis);
void debug_backlight (int on); MODULE_EXPORT void debug_flush (Driver *drvthis);
void debug_init_vbar (); MODULE_EXPORT void debug_string (Driver *drvthis, int x, int y, char string[]);
void debug_init_hbar (); MODULE_EXPORT void debug_chr (Driver *drvthis, int x, int y, char c);
void debug_init_num ();
void debug_vbar (int x, int len); MODULE_EXPORT void debug_vbar (Driver *drvthis, int x, int len);
void debug_hbar (int x, int y, int len); MODULE_EXPORT void debug_hbar (Driver *drvthis, int x, int y, int len);
void debug_num (int x, int num); MODULE_EXPORT void debug_num (Driver *drvthis, int x, int num);
void debug_set_char (int n, char *dat); MODULE_EXPORT void debug_icon (Driver *drvthis, int which, char dest);
void debug_icon (int which, char dest);
void debug_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT void debug_set_char (Driver *drvthis, int n, char *dat);
void debug_draw_frame (char *dat);
char debug_getkey (); MODULE_EXPORT void debug_set_contrast (Driver *drvthis, int promille);
MODULE_EXPORT void debug_backlight (Driver *drvthis, int promille);
MODULE_EXPORT char debug_getkey (Driver *drvthis);
MODULE_EXPORT void debug_init_vbar (Driver *drvthis);
MODULE_EXPORT void debug_init_hbar (Driver *drvthis);
MODULE_EXPORT void debug_init_num (Driver *drvthis);
#endif #endif
+192 -163
View File
@@ -40,34 +40,40 @@ static unsigned char CGRAM[8] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0
//////////////////// Matrix Orbital Graphical Driver ///////////////////// //////////////////// Matrix Orbital Graphical Driver /////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
lcd_logical_driver *glk;
static unsigned char * screen_contents = NULL ; static unsigned char * screen_contents = NULL ;
int fontselected = 0 ; static int fontselected = 0 ;
int gpo_count = 0 ; static int gpo_count = 0 ;
static char *framebuf = NULL;
static int width = 0;
static int height = 0;
static int cellwidth = LCD_DEFAULT_CELLWIDTH;
static int cellheight = LCD_DEFAULT_CELLHEIGHT;
static int contrast;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "glk_";
// TODO: Get lcd.framebuf to properly work as whatever driver is running...
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int glk_init(struct lcd_logical_driver *driver, char *args) int
glk_init(Driver *drvthis, char *args)
{ {
char * argv[64]; char * argv[64];
int argc; int argc;
char * device = "/dev/lcd" ; char * device = "/dev/lcd" ;
int contrast = 140;
speed_t speed = B19200 ; speed_t speed = B19200 ;
int i ; int i ;
int width ; contrast = 560;
int height ;
// printf("glk_init()\n"); // printf("glk_init()\n");
glk = driver;
argc = get_args( argv, args, 64 ); argc = get_args( argv, args, 64 );
for( i = 0 ; i < argc; ++i ) { for( i = 0 ; i < argc; ++i ) {
if( 0 == strcmp( argv[i], "-d") if( 0 == strcmp( argv[i], "-d")
@@ -120,7 +126,7 @@ int glk_init(struct lcd_logical_driver *driver, char *args)
"LCDproc Matrix-Orbital GLK Graphical LCD driver\n" "LCDproc Matrix-Orbital GLK Graphical LCD driver\n"
"\n" "\n"
"-d, --device select the serial device to use [/dev/lcd]\n" "-d, --device select the serial device to use [/dev/lcd]\n"
"-c, --contrast set the initial contrast value [140]\n" "-c, --contrast set the initial contrast value [560]\n"
"-s, --speed set the serial port speed [19200]\n" "-s, --speed set the serial port speed [19200]\n"
"-h, --help display this help text\n" "-h, --help display this help text\n"
); );
@@ -168,22 +174,17 @@ int glk_init(struct lcd_logical_driver *driver, char *args)
return( -1 ); return( -1 );
}; };
}; };
driver->wid = width ;
driver->hgt = height ;
// You must use driver->framebuf here, but may use lcd.framebuf later. framebuf = malloc(width * height);
if(!driver->framebuf) { screen_contents = malloc( width * height );
driver->framebuf = malloc(driver->wid * driver->hgt);
};
screen_contents = malloc( driver->wid * driver->hgt );
if(driver->framebuf == NULL || screen_contents == NULL ) { if(framebuf == NULL || screen_contents == NULL ) {
fprintf( stderr, "glk: Unable to allocate memory for screen buffers\n" ); fprintf( stderr, "glk: Unable to allocate memory for screen buffers\n" );
glk_close(); glk_close(drvthis);
return -1; return -1;
} }
memset(driver->framebuf, ' ', driver->wid*driver->hgt); memset(framebuf, ' ', width*height);
// glk_clear(); // glk_clear();
// glkputl( PortFD, GLKCommand, 0x58, EOF ); // glkputl( PortFD, GLKCommand, 0x58, EOF );
@@ -203,70 +204,92 @@ int glk_init(struct lcd_logical_driver *driver, char *args)
glkputl( PortFD, GLKCommand, 0x7e, 1, GLKCommand, 0x41, EOF ); glkputl( PortFD, GLKCommand, 0x7e, 1, GLKCommand, 0x41, EOF );
// Set contrast // Set contrast
glk_contrast( contrast ); glk_set_contrast( drvthis, contrast );
driver->cellwid = 5; // Set variables for server
driver->cellhgt = 8; drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = glk_clear; // Set the functions the driver supports
driver->string = glk_string; drvthis->clear = glk_clear;
driver->chr = glk_chr; drvthis->string = glk_string;
driver->vbar = glk_vbar; drvthis->chr = glk_chr;
driver->init_vbar = glk_init_vbar; drvthis->old_vbar = glk_vbar;
driver->hbar = glk_hbar; drvthis->init_vbar = glk_init_vbar;
driver->init_hbar = glk_init_hbar; drvthis->old_hbar = glk_hbar;
driver->num = glk_num ; drvthis->init_hbar = glk_init_hbar;
driver->init_num = glk_init_num ; drvthis->num = glk_num ;
drvthis->init_num = glk_init_num ;
driver->init = glk_init; drvthis->init = glk_init;
driver->close = glk_close; drvthis->close = glk_close;
driver->flush = glk_flush; drvthis->flush = glk_flush;
driver->flush_box = glk_flush_box; drvthis->get_contrast = glk_get_contrast;
driver->contrast = glk_contrast; drvthis->set_contrast = glk_set_contrast;
driver->backlight = glk_backlight; drvthis->backlight = glk_backlight;
driver->output = glk_output; drvthis->output = glk_output;
driver->set_char = glk_set_char; drvthis->set_char = glk_set_char;
driver->icon = glk_icon; drvthis->old_icon = glk_icon;
driver->draw_frame = glk_draw_frame;
driver->getkey = glk_getkey; drvthis->getkey = glk_getkey;
return 0;
return 200; // 200 is arbitrary. (must be 1 or more)
} }
// Below here, you may use either lcd.framebuf or driver->framebuf.. /////////////////////////////////////////////////////////////////
// lcd.framebuf will be set to the appropriate buffer before calling // Close the driver
// your driver. //
MODULE_EXPORT void
void glk_close() glk_close(Driver *drvthis)
{ {
if(glk->framebuf != NULL) free(glk->framebuf);
glk->framebuf = NULL;
glkclose( PortFD ) ; glkclose( PortFD ) ;
if(framebuf) free(framebuf);
framebuf = NULL;
} }
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
glk_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
glk_height (Driver *drvthis)
{
return height;
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
#define CLEARCOUNT (1000000) #define CLEARCOUNT (1000000)
static int clearcount = 0 ; static int clearcount = 0 ;
void glk_clear_forced() void glk_clear_forced(Driver *drvthis)
{ {
// puts( "REALLY CLEARING the display" ); // puts( "REALLY CLEARING the display" );
clearcount = CLEARCOUNT ; clearcount = CLEARCOUNT ;
glkputl( PortFD, GLKCommand, 0x58, EOF ); glkputl( PortFD, GLKCommand, 0x58, EOF );
memset(screen_contents, ' ', glk->wid*glk->hgt); memset(screen_contents, ' ', width*height);
} }
void glk_clear() MODULE_EXPORT void
glk_clear(Driver *drvthis)
{ {
// puts( "glk_clear( )" ); // puts( "glk_clear( )" );
memset(glk->framebuf, ' ', glk->wid*glk->hgt); memset(framebuf, ' ', width*height);
if( --clearcount < 0 ) { if( --clearcount < 0 ) {
glk_clear_forced( ); glk_clear_forced(drvthis);
}; };
} }
@@ -274,10 +297,47 @@ void glk_clear()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void glk_flush() MODULE_EXPORT void
glk_flush(Driver *drvthis)
{ {
// puts( "glk_flush( )" ); // puts( "glk_flush( )" );
glk->draw_frame(glk->framebuf); char * p ;
char * q ;
int x, y ;
int xs ;
char * ps = NULL ;
// printf( "flush()\n" );
p = framebuf ;
q = screen_contents ;
for( y = 0 ; y < height ; ++y ) {
xs = -1 ; /* XStart not set */
for( x = 0 ; x < width ; ++x ) {
if( *q == *p && xs >= 0 ) {
/* Write accumulated string */
glkputl( PortFD, GLKCommand, 0x79, xs*6+1, y*8, EOF );
glkputa( PortFD, x - xs, ps );
// printf( "draw_frame: Writing at (%d,%d) for %d\n", xs, y, x-xs );
xs = -1 ;
} else if( *q != *p && xs < 0 ) {
/* Start new string of changes */
ps = p ;
xs = x ;
};
*q++ = *p++ ; /* Update screen_contents from framebuf */
};
if( xs >= 0 ) {
/* Write accumulated line */
glkputl( PortFD, GLKCommand, 0x79, xs*6+1, y*8, EOF );
glkputa( PortFD, width - xs, ps );
// printf( "draw_frame: Writing at (%d,%d) for %d\n", xs, y, width-xs );
};
}; /* For y */
return ;
} }
@@ -285,18 +345,19 @@ void glk_flush()
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void glk_string(int x, int y, char string[]) MODULE_EXPORT void
glk_string(Driver *drvthis, int x, int y, char string[])
{ {
char * p ; char * p ;
// printf( "glk_string( %d, %d, \"%s\" )\n", x, y, string ); // printf( "glk_string( %d, %d, \"%s\" )\n", x, y, string );
if( x > glk->wid || y > glk->hgt ) { if( x > width || y > height ) {
return ; return ;
}; };
for( p = string ; *p && x <= glk->wid ; ++x, ++p ) { for( p = string ; *p && x <= width ; ++x, ++p ) {
glk_chr( x, y, *p ); glk_chr( drvthis, x, y, *p );
}; };
} }
@@ -305,7 +366,8 @@ void glk_string(int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void glk_chr(int x, int y, char c) MODULE_EXPORT void
glk_chr(Driver *drvthis, int x, int y, char c)
{ {
int myc = (unsigned char) c ; int myc = (unsigned char) c ;
x -= 1; // Convert 1-based coords to 0-based... x -= 1; // Convert 1-based coords to 0-based...
@@ -319,7 +381,7 @@ void glk_chr(int x, int y, char c)
/* Set font metrics */ /* Set font metrics */
glkputl( PortFD, GLKCommand, 0x32, 1, 0, 1, 1, 32, EOF ); glkputl( PortFD, GLKCommand, 0x32, 1, 0, 1, 1, 32, EOF );
/* Clear the screen */ /* Clear the screen */
glk_clear_forced( ); glk_clear_forced(drvthis);
}; };
if( myc >= 0 && myc <= 15 ) { if( myc >= 0 && myc <= 15 ) {
@@ -336,31 +398,48 @@ void glk_chr(int x, int y, char c)
myc = 133 ; myc = 133 ;
}; };
glk->framebuf[(y*glk->wid) + x] = myc; framebuf[(y*width) + x] = myc;
} }
/////////////////////////////////////////////////////////////////
// Returns current contrast
// This is only the locally stored contrast, the contrast value
// cannot be retrieved from the LCD.
// Value 0 to 1000.
//
MODULE_EXPORT int
glk_get_contrast(Driver *drvthis)
{
return contrast;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Sets the contrast of the display. Value is 0-255, where 140 is // Sets the contrast of the display. Value is 0-255, where 140 is
// what I consider "just right". // what I consider "just right".
// //
int glk_contrast(int contrast) MODULE_EXPORT void
glk_set_contrast(Driver *drvthis, int promille)
{ {
static int saved_contrast = 140 ; // Check it
if( contrast < 0 || contrast > 1000 )
return;
if( contrast > 0 && contrast < 256 ) { // Store it
saved_contrast = contrast ; contrast = promille;
// Do it
// printf("Contrast: %i\n", contrast); // printf("Contrast: %i\n", contrast);
glkputl( PortFD, GLKCommand, 0x50, contrast, EOF ); glkputl( PortFD, GLKCommand, 0x50, (int) ((long)promille * 255 / 1000), EOF );
};
return( saved_contrast );
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Turns the lcd backlight on or off... // Turns the lcd backlight on or off...
// //
void glk_backlight(int on) MODULE_EXPORT void
glk_backlight(Driver *drvthis, int on)
{ {
if(on) { if(on) {
// printf("Backlight ON\n"); // printf("Backlight ON\n");
@@ -373,8 +452,8 @@ void glk_backlight(int on)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Sets general purpose outputs on or off // Sets general purpose outputs on or off
void MODULE_EXPORT void
glk_output(int on) glk_output(Driver *drvthis, int on)
{ {
if( gpo_count < 2 ) { if( gpo_count < 2 ) {
if( on ) { glkputl( PortFD, GLKCommand, 'W', EOF ); if( on ) { glkputl( PortFD, GLKCommand, 'W', EOF );
@@ -395,7 +474,8 @@ glk_output(int on)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for vertical bargraphs. // Tells the driver to get ready for vertical bargraphs.
// //
void glk_init_vbar() MODULE_EXPORT void
glk_init_vbar(Driver *drvthis)
{ {
// printf("Vertical bars.\n"); // printf("Vertical bars.\n");
} }
@@ -403,7 +483,8 @@ void glk_init_vbar()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for horizontal bargraphs. // Tells the driver to get ready for horizontal bargraphs.
// //
void glk_init_hbar() MODULE_EXPORT void
glk_init_hbar(Driver *drvthis)
{ {
// printf("Horizontal bars.\n"); // printf("Horizontal bars.\n");
} }
@@ -411,7 +492,8 @@ void glk_init_hbar()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for big numbers, if possible. // Tells the driver to get ready for big numbers, if possible.
// //
void glk_init_num() MODULE_EXPORT void
glk_init_num(Driver *drvthis)
{ {
// printf("Big Numbers.\n"); // printf("Big Numbers.\n");
if( fontselected != 3 ) { if( fontselected != 3 ) {
@@ -421,23 +503,25 @@ void glk_init_num()
/* Set font metrics */ /* Set font metrics */
glkputl( PortFD, GLKCommand, 0x32, 1, 0, 1, 1, 32, EOF ); glkputl( PortFD, GLKCommand, 0x32, 1, 0, 1, 1, 32, EOF );
/* Clear the screen */ /* Clear the screen */
glk_clear_forced( ); glk_clear_forced(drvthis);
}; };
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Draws a big (4-row) number. // Draws a big (4-row) number.
// //
void glk_num(int x, int num) MODULE_EXPORT void
glk_num(Driver *drvthis, int x, int num)
{ {
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
glk->framebuf[x-1] = num + '0' ; framebuf[x-1] = num + '0' ;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Changes the font data of character n. // Changes the font data of character n.
// //
void glk_set_char(int n, char *dat) MODULE_EXPORT void
glk_set_char(Driver *drvthis, int n, char *dat)
{ {
printf("Set Character %i\n", n); printf("Set Character %i\n", n);
} }
@@ -445,15 +529,16 @@ void glk_set_char(int n, char *dat)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up. // Draws a vertical bar, from the bottom of the screen up.
// //
void glk_vbar(int x, int len) MODULE_EXPORT void
glk_vbar(Driver *drvthis, int x, int len)
{ {
int y = glk->hgt ; int y = height ;
// printf( "glk_vbar( %d, %d )\n", x, len ); // printf( "glk_vbar( %d, %d )\n", x, len );
while( len > glk->cellhgt ) { while( len > cellheight ) {
glk_chr( x, y, 255 ); glk_chr( drvthis, x, y, 255 );
--y ; --y ;
len -= glk->cellhgt ; len -= cellheight ;
}; };
if( y >= 0 ) { if( y >= 0 ) {
@@ -468,23 +553,24 @@ void glk_vbar(int x, int len)
case 6 : lastc = 143 ; break ; case 6 : lastc = 143 ; break ;
default: lastc = 133 ; break ; default: lastc = 133 ; break ;
}; };
glk_chr( x, y, lastc ); glk_chr( drvthis, x, y, lastc );
}; };
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void glk_hbar(int x, int y, int len) MODULE_EXPORT void
glk_hbar(Driver *drvthis, int x, int y, int len)
{ {
// printf( "glk_hbar( %d, %d, %d )\n", x, y, len ); // printf( "glk_hbar( %d, %d, %d )\n", x, y, len );
while( len > glk->cellwid ) { while( len > cellwidth ) {
glk_chr( x, y, 255 ); glk_chr( drvthis, x, y, 255 );
++x ; ++x ;
len -= glk->cellwid ; len -= cellwidth ;
}; };
if( x <= glk->wid ) { if( x <= width ) {
int lastc ; int lastc ;
switch( len ) { switch( len ) {
case 0 : lastc = ' ' ; break ; case 0 : lastc = ' ' ; break ;
@@ -494,7 +580,7 @@ void glk_hbar(int x, int y, int len)
case 4 : lastc = 137 ; break ; case 4 : lastc = 137 ; break ;
default: lastc = 133 ; break ; default: lastc = 133 ; break ;
}; };
glk_chr( x, y, lastc ); glk_chr( drvthis, x, y, lastc );
}; };
} }
@@ -502,7 +588,8 @@ void glk_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void glk_icon(int which, char dest) MODULE_EXPORT void
glk_icon(Driver *drvthis, int which, char dest)
{ {
unsigned char old, new ; unsigned char old, new ;
unsigned char * p ; unsigned char * p ;
@@ -529,11 +616,11 @@ void glk_icon(int which, char dest)
old = CGRAM[(int)dest] ; old = CGRAM[(int)dest] ;
CGRAM[(int)dest] = new ; CGRAM[(int)dest] = new ;
p = glk->framebuf ; p = framebuf ;
q = screen_contents ; q = screen_contents ;
/* Replace all old icons with new icon in new frame */ /* Replace all old icons with new icon in new frame */
for( count = glk->wid * glk->hgt ; count ; --count ) { for( count = width * height ; count ; --count ) {
if( *q == old ) { if( *q == old ) {
// printf( "icon %d to %d at %d\n", old, new, q - screen_contents ); // printf( "icon %d to %d at %d\n", old, new, q - screen_contents );
*p = new ; *p = new ;
@@ -545,71 +632,13 @@ void glk_icon(int which, char dest)
} }
//////////////////////////////////////////////////////////////////////
// Send a rectangular area to the display.
//
// I've just called glk_flush() because there's not much point yet
// in flushing less than the entire framebuffer.
//
void glk_flush_box(int lft, int top, int rgt, int bot)
{
// printf("glk_flush_box( %d, %d, %d, %d )\n", lft, top, rgt, bot );
glk_flush( );
}
//////////////////////////////////////////////////////////////////////
// Draws the framebuffer on the display.
//
// The commented-out code is from the text driver.
//
void glk_draw_frame(char *dat)
{
char * p ;
char * q ;
int x, y ;
int xs ;
char * ps = NULL ;
// printf( "glk_draw_frame( %p ) glk->framebuf = %p\n", dat, glk->framebuf );
p = glk->framebuf ;
q = screen_contents ;
for( y = 0 ; y < glk->hgt ; ++y ) {
xs = -1 ; /* XStart not set */
for( x = 0 ; x < glk->wid ; ++x ) {
if( *q == *p && xs >= 0 ) {
/* Write accumulated string */
glkputl( PortFD, GLKCommand, 0x79, xs*6+1, y*8, EOF );
glkputa( PortFD, x - xs, ps );
// printf( "draw_frame: Writing at (%d,%d) for %d\n", xs, y, x-xs );
xs = -1 ;
} else if( *q != *p && xs < 0 ) {
/* Start new string of changes */
ps = p ;
xs = x ;
};
*q++ = *p++ ; /* Update screen_contents from glk->framebuf */
};
if( xs >= 0 ) {
/* Write accumulated line */
glkputl( PortFD, GLKCommand, 0x79, xs*6+1, y*8, EOF );
glkputa( PortFD, glk->wid - xs, ps );
// printf( "draw_frame: Writing at (%d,%d) for %d\n", xs, y, glk->wid-xs );
};
}; /* For y */
return ;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device... // Tries to read a character from an input device...
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char glk_getkey() MODULE_EXPORT char
glk_getkey(Driver *drvthis)
{ {
int c ; int c ;
static int key = -1 ; static int key = -1 ;
+22 -108
View File
@@ -1,119 +1,33 @@
#ifndef GLK_H #ifndef GLK_H
#define GLK_H #define GLK_H
/******************************************************************** #include "lcd.h"
How to make a driver for LCDproc
Note: Insert the name of your driver in place of the phrase "new_driver". int glk_init(Driver *drvthis, char *args);
MODULE_EXPORT void glk_close(Driver *drvthis);
MODULE_EXPORT int glk_width(Driver *drvthis);
MODULE_EXPORT int glk_height(Driver *drvthis);
MODULE_EXPORT void glk_clear(Driver *drvthis);
MODULE_EXPORT void glk_flush(Driver *drvthis);
MODULE_EXPORT void glk_string(Driver *drvthis, int x, int y, char string[]);
MODULE_EXPORT void glk_chr(Driver *drvthis, int x, int y, char c);
1. Copy drv_base.c and drv_base.h to new_driver.c and new_driver.h. MODULE_EXPORT void glk_vbar(Driver *drvthis, int x, int len);
MODULE_EXPORT void glk_hbar(Driver *drvthis, int x, int y, int len);
MODULE_EXPORT void glk_num(Driver *drvthis, int x, int num);
MODULE_EXPORT void glk_icon(Driver *drvthis, int which, char dest);
2. Decide which functions you want to override, which ones you want MODULE_EXPORT void glk_set_char(Driver *drvthis, int n, char *dat);
to leave alone, and which ones you don't want at all. If you
write your own driver functions, they will get called when
appropriate. Or, you can let the default driver "drv_base"
handle a function for you. But, if you really don't want a
function, you can completely prevent your driver from providing
it. This is discussed in step 5.
2.1. Remove all functions which you don't want to override, and the MODULE_EXPORT int glk_get_contrast(Driver *drvthis);
ones you don't want at all. MODULE_EXPORT void glk_set_contrast(Driver *drvthis, int promille);
MODULE_EXPORT void glk_backlight(Driver *drvthis, int on);
MODULE_EXPORT void glk_output(Driver *drvthis, int on);
3. Rename all functions from "drv_base_*" to "new_driver_*". MODULE_EXPORT char glk_getkey(Driver *drvthis);
4. Write the new driver functions.
Be sure to do one of the following in/for your new_driver_close():
- free the framebuffer lcd.framebuf
- let the default driver handle close()
- call drv_base_close()
This will ensure that the frame buffer gets freed.
5. Register your functions in your new_driver_init(), like the following:
driver->clear = new_driver_clear; // We want to handle this one
driver->string = (void *)-1; // Leave this to the default
driver->getkey = NULL; // This should never get called
The convention here is to set NULL for all the functions which
your driver doesn't handle (and which you don't want the default
functions to be called for). Or, set -1 to indicate that the
driver should support the function but can use the default
behavior in drv_base.c. Or, to indicate that your driver should
handle a function, just set it like clear() above.
6. Add the driver to lcd.c, in the physical drivers section, protected
by an #ifdef like the rest of the drivers are.
7. Add your driver to the Makefile, and Makefile.config, in the same
style as the existing ones.
Notes:
Don't call lcd.whatever() functions within your driver. This causes
a lot of potentially puzzling problems.
However, feel free to access lcd.framebuf in your driver (but not in
your init() function!). It will always point to the frame buffer
you should be writing to. This will usually be your own frame
buffer, but could potentially be another frame buffer, if another
driver wants to access your functions.
Your driver will be provided with a frame buffer which contains one
byte per character on the LCD. The default is a 20x4, so that's 80
bytes. You can free this and reallocate it to something else if you
need to. A graphical driver may want to do this, for example.
If you don't set a function pointer, it will default to NULL, since
they get nullified before the driver's init() is called.
Assume that your driver may be added or removed dynamically, and
that more than one instance may exist at a time. In other words, it
should init and close cleanly, and not depend on global variables.
Special arguments will be passed through the "args" variable to your
_init() function. This is just a string, and you determine the
syntax of it. Please document the syntax so that it can easily be
included in the lcdproc config file. I suggest arguments such as
"port=0x378" or "-device /dev/ttyS0". These come directly from the
lcdproc server config file, so they should be human-readable. An
example may look like this:
# Set up two MtxOrb LCD's and a curses display on VT 2
Driver MtxOrb -device /dev/ttyS0 -keypad on
Driver curses -color off -size 20x4 -vt 2
Driver MtxOrb -device /dev/ttyS3 -size 20x2 -keypad off
# Before you ask, no, not all of these options are implemented yet.
Also, the driver API (if it can be called that) may change soon.
There seem to be several functions which just don't do anything
important... and there are other potential improvements too.
And... When in doubt, look at how the other drivers do it. :)
******************************************************************/
extern lcd_logical_driver *glk;
int glk_init(struct lcd_logical_driver *driver, char *args);
void glk_close();
void glk_clear();
void glk_flush();
void glk_string(int x, int y, char string[]);
void glk_chr(int x, int y, char c);
int glk_contrast(int contrast);
void glk_backlight(int on);
void glk_output(int on);
void glk_vbar(int x, int len);
void glk_init_vbar();
void glk_hbar(int x, int y, int len);
void glk_init_hbar();
void glk_num(int x, int num);
void glk_init_num();
void glk_set_char(int n, char *dat);
void glk_icon(int which, char dest);
void glk_flush_box(int lft, int top, int rgt, int bot);
void glk_draw_frame(char *dat);
char glk_getkey();
MODULE_EXPORT void glk_init_vbar(Driver *drvthis);
MODULE_EXPORT void glk_init_hbar(Driver *drvthis);
MODULE_EXPORT void glk_init_num(Driver *drvthis);
#endif #endif
+89 -91
View File
@@ -61,7 +61,7 @@
*/ */
#include "hd44780-4bit.h" #include "hd44780-4bit.h"
#include "hd44780.h" #include "hd44780-low.h"
#include "lpt-port.h" #include "lpt-port.h"
#include "port.h" #include "port.h"
@@ -76,9 +76,9 @@
// HD44780_senddata // HD44780_senddata
// HD44780_readkeypad // HD44780_readkeypad
void lcdstat_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch); void lcdstat_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcdstat_HD44780_backlight (unsigned char state); void lcdstat_HD44780_backlight (PrivateData *p, unsigned char state);
unsigned char lcdstat_HD44780_readkeypad (unsigned int YData); unsigned char lcdstat_HD44780_readkeypad (PrivateData *p, unsigned int YData);
#define RS 0x10 #define RS 0x10
#define RW 0x20 #define RW 0x20
@@ -88,88 +88,86 @@ unsigned char lcdstat_HD44780_readkeypad (unsigned int YData);
#define BL 0x20 #define BL 0x20
// note that the above bits are all meant for the data port of LPT // note that the above bits are all meant for the data port of LPT
static unsigned char EnMask[] = { EN1, EN2, EN3, STRB, LF, INIT, SEL }; static const unsigned char EnMask[] = { EN1, EN2, EN3, STRB, LF, INIT, SEL };
#define ALLEXT (STRB|LF|INIT|SEL) #define ALLEXT (STRB|LF|INIT|SEL)
// The above bits are on the control port of LPT // The above bits are on the control port of LPT
static unsigned int lptPort;
static char stuckinputs = 0; // if an input line is stuck, it will be ignored
static char backlight_bit = 0; // default to low to enable three displays
// initialisation function // initialisation function
int int
hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port) hd_init_4bit (Driver *drvthis)
{ {
PrivateData *p = (PrivateData*) drvthis->private_data;
HD44780_functions *hd44780_functions = p->hd44780_functions;
int enableLines = EN1 | EN2; int enableLines = EN1 | EN2;
// Reserve the port registers // Reserve the port registers
lptPort = port; port_access(p->port);
port_access(lptPort); port_access(p->port+1);
port_access(lptPort+1); port_access(p->port+2);
port_access(lptPort+2);
hd44780_functions->senddata = lcdstat_HD44780_senddata; hd44780_functions->senddata = lcdstat_HD44780_senddata;
hd44780_functions->backlight = lcdstat_HD44780_backlight; hd44780_functions->backlight = lcdstat_HD44780_backlight;
hd44780_functions->readkeypad = lcdstat_HD44780_readkeypad; hd44780_functions->readkeypad = lcdstat_HD44780_readkeypad;
// powerup the lcd now // powerup the lcd now
if (extIF) { if (p->extIF) {
enableLines |= EN3; enableLines |= EN3;
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
} }
port_out (lptPort, 0x03); port_out (p->port, 0x03);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, enableLines | 0x03); port_out (p->port, enableLines | 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, ALLEXT ^ OUTMASK); port_out (p->port + 2, ALLEXT ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, 0x03); port_out (p->port, 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (4100); hd44780_functions->uPause (p, 4100);
port_out (lptPort, enableLines | 0x03); port_out (p->port, enableLines | 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, ALLEXT ^ OUTMASK); port_out (p->port + 2, ALLEXT ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, 0x03); port_out (p->port, 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 100);
port_out (lptPort, enableLines | 0x03); port_out (p->port, enableLines | 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, ALLEXT ^ OUTMASK); port_out (p->port + 2, ALLEXT ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, 0x03); port_out (p->port, 0x03);
if (extIF) if (p->extIF)
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (40); hd44780_functions->uPause (p, 40);
// now in 8-bit mode... set 4-bit mode // now in 8-bit mode... set 4-bit mode
port_out (lptPort, 0x02); port_out (p->port, 0x02);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, enableLines | 0x02); port_out (p->port, enableLines | 0x02);
if (extIF) if (p->extIF)
port_out (lptPort + 2, ALLEXT ^ OUTMASK); port_out (p->port + 2, ALLEXT ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) hd44780_functions->uPause (p, 1);
port_out (lptPort, 0x02); port_out (p->port, 0x02);
if (extIF) if (p->extIF)
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (40); hd44780_functions->uPause (p, 40);
// Set up two-line, small character (5x8) mode // Set up two-line, small character (5x8) mode
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | TWOLINE | SMALLCHAR ); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | TWOLINE | SMALLCHAR );
hd44780_functions->uPause (40); hd44780_functions->uPause (p, 40);
common_init (); common_init (p);
if (have_keypad) { if (p->have_keypad) {
// Remember which input lines are stuck // Remember which input lines are stuck
stuckinputs = lcdstat_HD44780_readkeypad (0); p->stuckinputs = lcdstat_HD44780_readkeypad (p, 0);
} }
return 0; return 0;
@@ -177,7 +175,7 @@ hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver
// lcdstat_HD44780_senddata // lcdstat_HD44780_senddata
void void
lcdstat_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch) lcdstat_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{ {
unsigned char enableLines = 0, portControl = 0; unsigned char enableLines = 0, portControl = 0;
unsigned char h = (ch >> 4) & 0x0f; // high and low nibbles unsigned char h = (ch >> 4) & 0x0f; // high and low nibbles
@@ -188,7 +186,7 @@ lcdstat_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned
else //if (flags == RS_DATA) else //if (flags == RS_DATA)
portControl = RS; portControl = RS;
portControl |= backlight_bit; portControl |= p->backlight_bit;
if (displayID <= 3) { if (displayID <= 3) {
if (displayID == 0) if (displayID == 0)
@@ -196,64 +194,64 @@ lcdstat_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned
else else
enableLines = EnMask[displayID - 1]; enableLines = EnMask[displayID - 1];
port_out (lptPort, portControl | h); port_out (p->port, portControl | h);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort, enableLines | portControl | h); port_out (p->port, enableLines | portControl | h);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort, portControl | h); port_out (p->port, portControl | h);
port_out (lptPort, portControl | l); port_out (p->port, portControl | l);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort, enableLines | portControl | l); port_out (p->port, enableLines | portControl | l);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort, portControl | l); port_out (p->port, portControl | l);
} }
if (extIF && (displayID == 0 || displayID >= 4)) { if (p->extIF && (displayID == 0 || displayID >= 4)) {
if (displayID == 0) if (displayID == 0)
enableLines = ALLEXT; enableLines = ALLEXT;
else else
enableLines = EnMask[(displayID - 1)]; enableLines = EnMask[(displayID - 1)];
port_out (lptPort, portControl | h); port_out (p->port, portControl | h);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, enableLines ^ OUTMASK); port_out (p->port + 2, enableLines ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
port_out (lptPort, portControl | l); port_out (p->port, portControl | l);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, enableLines ^ OUTMASK); port_out (p->port + 2, enableLines ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (p->port + 2, 0 ^ OUTMASK);
} }
} }
void lcdstat_HD44780_backlight (unsigned char state) void lcdstat_HD44780_backlight (PrivateData *p, unsigned char state)
{ {
backlight_bit = (state?0:0x20); // D5 line p->backlight_bit = (state?0:0x20); // D5 line
port_out (lptPort, backlight_bit); port_out (p->port, p->backlight_bit);
} }
unsigned char lcdstat_HD44780_readkeypad (unsigned int YData) unsigned char lcdstat_HD44780_readkeypad (PrivateData *p, unsigned int YData)
{ {
unsigned char readval; unsigned char readval;
// 10 bits output or 6 bits if >=3 displays // 10 bits output or 6 bits if >=3 displays
// Convert the positive logic to the negative logic on the LPT port // Convert the positive logic to the negative logic on the LPT port
port_out (lptPort, ~YData & 0x003F ); port_out (p->port, ~YData & 0x003F );
if (!extIF) { if (!p->extIF) {
port_out (lptPort + 2, ( ((~YData & 0x03C0) << 6 )) ^ OUTMASK); port_out (p->port + 2, ( ((~YData & 0x03C0) << 6 )) ^ OUTMASK);
} }
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
// Read inputs // Read inputs
readval = ~ port_in (lptPort + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
// Put port back into idle state for backlight // Put port back into idle state for backlight
port_out (lptPort, backlight_bit); port_out (p->port, p->backlight_bit);
// And convert value back. // And convert value back.
return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~stuckinputs; return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~p->stuckinputs;
} }
+2 -3
View File
@@ -1,10 +1,9 @@
#ifndef HD_LCDSTAT_H #ifndef HD_LCDSTAT_H
#define HD_LCDSTAT_H #define HD_LCDSTAT_H
#include "lcd.h" /* for lcd_logical_driver */ #include "lcd.h" /* for Driver */
#include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port); int hd_init_4bit (Driver *drvthis);
#endif #endif
+6 -17
View File
@@ -17,31 +17,20 @@
#include "hd44780-winamp.h" #include "hd44780-winamp.h"
// add new connection type header files here // add new connection type header files here
enum connectionType { HD_4bit, HD_8bit, HD_serialLpt, HD_winamp, static const ConnectionMapping connectionMapping[] = {
// add new connection types here
HD_unknown
};
static struct ConnectionMapping {
enum connectionType type;
char *connectionTypeStr;
int (*init_fn) (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
const char *helpMsg;
} connectionMapping[] = {
// connectionType enumerator // connectionType enumerator
// string to identify connection on command line // string to identify connection on command line
// your initialisation function // your initialisation function
// help string for your particular connection // help string for your particular connection
{ {
HD_4bit, "4bit", hd_init_4bit, "\t-e\t--extended\tEnable three or more displays\n"}, { "4bit", hd_init_4bit, "\tnone\n"}, {
HD_8bit, "8bit", hd_init_ext8bit, "\tnone\n"}, { "8bit", hd_init_ext8bit, "\tnone\n"}, {
HD_serialLpt, "serialLpt", hd_init_serialLpt, "\tnone\n"}, { "serialLpt", hd_init_serialLpt, "\tnone\n"}, {
HD_winamp, "winamp", hd_init_winamp, "\t-e\t--extended\tEnable three or more displays\n"}, "winamp", hd_init_winamp, "\tnone\n"},
// add new connection types and their string specifier here // add new connection types and their string specifier here
// default, end of structure element (do not delete) // default, end of structure element (do not delete)
{ {
HD_unknown, "", NULL, ""} NULL, NULL, NULL}
}; };
#endif #endif
+39 -41
View File
@@ -52,7 +52,7 @@
*/ */
#include "hd44780-ext8bit.h" #include "hd44780-ext8bit.h"
#include "hd44780.h" #include "hd44780-low.h"
#include "lpt-port.h" #include "lpt-port.h"
#include "port.h" #include "port.h"
@@ -67,57 +67,55 @@
// HD44780_senddata // HD44780_senddata
// HD44780_readkeypad // HD44780_readkeypad
void lcdtime_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch); void lcdtime_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcdtime_HD44780_backlight (unsigned char state); void lcdtime_HD44780_backlight (PrivateData *p, unsigned char state);
unsigned char lcdtime_HD44780_readkeypad (unsigned int YData); unsigned char lcdtime_HD44780_readkeypad (PrivateData *p, unsigned int YData);
#define RS STRB #define RS STRB
#define RW LF #define RW LF
#define EN1 INIT #define EN1 INIT
#define BL SEL #define BL SEL
static unsigned int lptPort;
static char stuckinputs = 0; // if an input line is stuck, it will be ignored
static char backlight_bit = 0;
static int semid; static int semid;
// initialise the driver // initialise the driver
int int
hd_init_ext8bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port) hd_init_ext8bit (Driver *drvthis)
{ {
PrivateData *p = (PrivateData*) drvthis->private_data;
HD44780_functions *hd44780_functions = p->hd44780_functions;
semid = sem_get (); semid = sem_get ();
// Reserve the port registers // Reserve the port registers
lptPort = port; port_access(p->port);
port_access(lptPort); port_access(p->port+1);
port_access(lptPort+1); port_access(p->port+2);
port_access(lptPort+2);
hd44780_functions->senddata = lcdtime_HD44780_senddata; hd44780_functions->senddata = lcdtime_HD44780_senddata;
hd44780_functions->backlight = lcdtime_HD44780_backlight; hd44780_functions->backlight = lcdtime_HD44780_backlight;
hd44780_functions->readkeypad = lcdtime_HD44780_readkeypad; hd44780_functions->readkeypad = lcdtime_HD44780_readkeypad;
// setup the lcd in 8 bit mode // setup the lcd in 8 bit mode
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (4100); hd44780_functions->uPause (p, 4100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR);
hd44780_functions->uPause (40); hd44780_functions->uPause (p, 40);
common_init (); common_init (p);
if (have_keypad) { if (p->have_keypad) {
// Remember which input lines are stuck // Remember which input lines are stuck
stuckinputs = lcdtime_HD44780_readkeypad (0); p->stuckinputs = lcdtime_HD44780_readkeypad (p, 0);
} }
return 0; return 0;
} }
// lcdtime_HD44780_senddata // lcdtime_HD44780_senddata
void void
lcdtime_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch) lcdtime_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{ {
unsigned char enableLines = 0, portControl; unsigned char enableLines = 0, portControl;
@@ -129,28 +127,28 @@ lcdtime_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned
else //if (iflags == RS_DATA) else //if (iflags == RS_DATA)
portControl = RS; portControl = RS;
portControl |= backlight_bit; portControl |= p->backlight_bit;
sem_wait (semid); sem_wait (semid);
port_out (lptPort + 2, portControl ^ OUTMASK); port_out (p->port + 2, portControl ^ OUTMASK);
port_out (lptPort, ch); port_out (p->port, ch);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, (enableLines|portControl) ^ OUTMASK); port_out (p->port + 2, (enableLines|portControl) ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
port_out (lptPort + 2, portControl ^ OUTMASK); port_out (p->port + 2, portControl ^ OUTMASK);
sem_signal (semid); sem_signal (semid);
} }
void lcdtime_HD44780_backlight (unsigned char state) void lcdtime_HD44780_backlight (PrivateData *p, unsigned char state)
{ {
backlight_bit = (state?0:SEL); p->backlight_bit = (state?0:SEL);
// Semaphores not needed because backlight will not go together with // Semaphores not needed because backlight will not go together with
// the bacrgraph anyway... // the bacrgraph anyway...
port_out (lptPort + 2, backlight_bit ^ OUTMASK); port_out (p->port + 2, p->backlight_bit ^ OUTMASK);
} }
unsigned char lcdtime_HD44780_readkeypad (unsigned int YData) unsigned char lcdtime_HD44780_readkeypad (PrivateData *p, unsigned int YData)
{ {
unsigned char readval; unsigned char readval;
@@ -158,19 +156,19 @@ unsigned char lcdtime_HD44780_readkeypad (unsigned int YData)
// 10 bits output or 8 bits if >=3 displays // 10 bits output or 8 bits if >=3 displays
// Convert the positive logic to the negative logic on the LPT port // Convert the positive logic to the negative logic on the LPT port
port_out (lptPort, ~YData & 0x00FF ); port_out (p->port, ~YData & 0x00FF );
if (!extIF) { if (!p->extIF) {
port_out (lptPort + 2, ( ((~YData & 0x0100) >> 8) | ((~YData & 0x0200) >> 6)) ^ OUTMASK); port_out (p->port + 2, ( ((~YData & 0x0100) >> 8) | ((~YData & 0x0200) >> 6)) ^ OUTMASK);
} }
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
// Read inputs // Read inputs
readval = ~ port_in (lptPort + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
// Put port back into idle state for backlight // Put port back into idle state for backlight
port_out (lptPort, backlight_bit ^ OUTMASK); port_out (p->port, p->backlight_bit ^ OUTMASK);
sem_signal (semid); sem_signal (semid);
// And convert value back. // And convert value back.
return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~stuckinputs; return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~p->stuckinputs;
} }
+2 -3
View File
@@ -1,10 +1,9 @@
#ifndef HD_EXT8BIT_H #ifndef HD_EXT8BIT_H
#define HD_EXT8BIT_H #define HD_EXT8BIT_H
#include "lcd.h" /* for lcd_logical_driver */ #include "lcd.h" /* for Driver */
#include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_ext8bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port); int hd_init_ext8bit (Driver *driver);
#endif #endif
+92 -8
View File
@@ -6,40 +6,124 @@
enum ifWidth { IF_4bit, IF_8bit }; enum ifWidth { IF_4bit, IF_8bit };
//void common_init (enum ifWidth ifwidth); #ifdef HAVE_CONFIG_H
void common_init (); # include "config.h"
#endif
# if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
//struct hwDependentFns;
// Maximum sizes of the keypad
// DO NOT CHANGE THESE 2 VALUES, unless you change the functions too
#define KEYPAD_MAXX 5
#define KEYPAD_MAXY 11
typedef struct ConnectionMapping {
char *name;
int (*init_fn) (Driver *drvthis);
const char *helpMsg;
} ConnectionMapping;
typedef struct driver_private_data {
unsigned int port;
int width, height;
int cellwidth, cellheight;
// The framebuffer
char *framebuf;
// For incremental updates store last lcd contents
char *lcd_contents;
// Connection type data
int connectiontype_index;
struct hwDependentFns *hd44780_functions;
// spanList[line number] = display line number is in
int *spanList;
int numLines;
// dispVOffset is a cumulative sized array of line numbers for each display.
// use this to determine the vertical positioning on a given display
int *dispVOffset;
int numDisplays;
// dispSizes is the vertical size of each display. This is the same as the
// input span list but is kept to save some cpu cycles.
int *dispSizes;
// Keypad, backlight extended interface and delay options
char have_keypad; // off by default
char have_backlight; // off by default
char extIF; // off by default
int delayMult; // Delay multiplier for slow displays
char delayBus; // Delay if the computer can send data too fast over
// its bus to LPT port
// keyMapDirect contains an array of the ascii-codes that should be generated
// when a directly connected key is pressed (not in matrix).
char *keyMapDirect[KEYPAD_MAXX];
// keyMapMatrix contrains an array with arrays of the ascii-codes that should be generated
// when a key in the matrix is pressed.
char *keyMapMatrix[KEYPAD_MAXY][KEYPAD_MAXX];
char pressed_key;
int pressed_key_repetitions;
struct timeval pressed_key_time;
int stuckinputs;
int backlight_bit;
} PrivateData;
// Structures holding pointers to HD44780 specific functions // Structures holding pointers to HD44780 specific functions
typedef struct hwDependentFns { typedef struct hwDependentFns {
// microsec pauses // microsec pauses
void (*uPause) (int microSecondsTenths); void (*uPause) (PrivateData *p, int usecs);
// Senddata to the LCD // Senddata to the LCD
// dispID - display to send data to (0 = all displays) // dispID - display to send data to (0 = all displays)
// flags - data or instruction command (RS_DATA | RS_INSTR) // flags - data or instruction command (RS_DATA | RS_INSTR)
// ch - character to display or instruction value // ch - character to display or instruction value
void (*senddata) (unsigned char dispID, unsigned char flags, unsigned char ch); void (*senddata) (PrivateData *p, unsigned char dispID, unsigned char flags, unsigned char ch);
// Switch the backlight on or off // Switch the backlight on or off
// state - to be or not to be on // state - to be or not to be on
void (*backlight) (unsigned char state); void (*backlight) (PrivateData *p, unsigned char state);
// Read the keypad // Read the keypad
// Ydata - the up to 11 bits that should be put on the Y side of the matrix // Ydata - the up to 11 bits that should be put on the Y side of the matrix
// return - the up to 5 bits that are read out on the X side of the matrix // return - the up to 5 bits that are read out on the X side of the matrix
unsigned char (*readkeypad) (unsigned int Ydata); unsigned char (*readkeypad) (PrivateData *p, unsigned int Ydata);
// Scan the keypad and return a scancode. // Scan the keypad and return a scancode.
// The code is the Yvalue in the high nibble and the Xvalue in the low nibble. // The code is the Yvalue in the high nibble and the Xvalue in the low nibble.
// A subdriver should do only one of two things: // A subdriver should do only one of two things:
// - set readkeypad; or // - set readkeypad; or
// - override scankeypad. // - override scankeypad.
unsigned char (*scankeypad) (); unsigned char (*scankeypad) (PrivateData *p);
} HD44780_functions; /* for want of a better name :-) */ } HD44780_functions; /* for want of a better name :-) */
extern HD44780_functions *hd44780_functions;
void common_init (PrivateData *p);
// commands for senddata // commands for senddata
#define RS_DATA 0x00 #define RS_DATA 0x00
+59 -58
View File
@@ -50,7 +50,7 @@
*/ */
#include "hd44780-serialLpt.h" #include "hd44780-serialLpt.h"
#include "hd44780.h" #include "hd44780-low.h"
#include "lpt-port.h" #include "lpt-port.h"
#include "port.h" #include "port.h"
@@ -60,12 +60,12 @@
#include <errno.h> #include <errno.h>
// Hardware specific functions // Hardware specific functions
void lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch); void lcdserLpt_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcdserLpt_HD44780_backlight (unsigned char state); void lcdserLpt_HD44780_backlight (PrivateData *p, unsigned char state);
unsigned char lcdserLpt_HD44780_scankeypad (); unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p);
void rawshift (unsigned char r); void rawshift (PrivateData *p, unsigned char r);
void shiftreg (unsigned char displayID, unsigned char r); void shiftreg (PrivateData *p, unsigned char displayID, unsigned char r);
#define RS 32 #define RS 32
#define LCDDATA 8 #define LCDDATA 8
@@ -73,50 +73,46 @@ void shiftreg (unsigned char displayID, unsigned char r);
#define EN1 4 #define EN1 4
#define EN2 32 #define EN2 32
static unsigned int lptPort;
static char backlight_bit = 0;
// Initialisation // Initialisation
int int
hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port) hd_init_serialLpt (Driver *drvthis)
{ {
PrivateData *p = (PrivateData*) drvthis->private_data;
HD44780_functions *hd44780_functions = p->hd44780_functions;
unsigned char enableLines = EN1 | EN2; unsigned char enableLines = EN1 | EN2;
// Reserve the port registers // Reserve the port registers
lptPort = port; port_access(p->port);
port_access(lptPort); port_access(p->port+1);
port_access(lptPort+1); port_access(p->port+2);
port_access(lptPort+2);
hd44780_functions->senddata = lcdserLpt_HD44780_senddata; hd44780_functions->senddata = lcdserLpt_HD44780_senddata;
hd44780_functions->backlight = lcdserLpt_HD44780_backlight; hd44780_functions->backlight = lcdserLpt_HD44780_backlight;
hd44780_functions->scankeypad = lcdserLpt_HD44780_scankeypad; hd44780_functions->scankeypad = lcdserLpt_HD44780_scankeypad;
// setup the lcd in 4 bit mode // setup the lcd in 4 bit mode
shiftreg (enableLines, 3); shiftreg (p, enableLines, 3);
hd44780_functions->uPause (15000); hd44780_functions->uPause (p, 15000);
shiftreg (enableLines, 3); shiftreg (p, enableLines, 3);
hd44780_functions->uPause (5000); hd44780_functions->uPause (p, 5000);
shiftreg (enableLines, 3); shiftreg (p, enableLines, 3);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 150);
shiftreg (enableLines, 3); shiftreg (p, enableLines, 2);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 100);
shiftreg (enableLines, 2); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 40);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR); common_init (p);
common_init ();
return 0; return 0;
} }
void void
lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch) lcdserLpt_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{ {
unsigned char enableLines; unsigned char enableLines;
unsigned char portControl = 0; unsigned char portControl = 0;
@@ -134,24 +130,24 @@ lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
else else
portControl = 0; portControl = 0;
shiftreg (enableLines, portControl | h); shiftreg (p, enableLines, portControl | h);
shiftreg (enableLines, portControl | l); shiftreg (p, enableLines, portControl | l);
// Restore line status for backlight // Restore line status for backlight
port_out (lptPort, backlight_bit ); port_out (p->port, p->backlight_bit );
} }
void void
lcdserLpt_HD44780_backlight (unsigned char state) lcdserLpt_HD44780_backlight (PrivateData *p, unsigned char state)
{ {
// Store new state // Store new state
backlight_bit = (state?LCDDATA:0); p->backlight_bit = (state?LCDDATA:0);
// Set line status for backlight // Set line status for backlight
port_out (lptPort, backlight_bit ); port_out (p->port, p->backlight_bit );
} }
unsigned char lcdserLpt_HD44780_scankeypad () unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p)
{ {
// Unfortunately just bit shifting does not work with the 2-wire version... // Unfortunately just bit shifting does not work with the 2-wire version...
@@ -162,36 +158,41 @@ unsigned char lcdserLpt_HD44780_scankeypad ()
int i; int i;
unsigned int scancode = 0; unsigned int scancode = 0;
// While scanning the keypad, the 2-wire version executes the 0xFF // While scanning the keypad, the 2-wire version will place the
// command. This command sets the cursor position, so it's harmless. // character 0xFF on the current cursor position. Therefor we fisrt
// set the cursor position to -1, so it's harmless.
// I could not prevent this, while staying compatible with both // I could not prevent this, while staying compatible with both
// wiring versions. // wiring versions.
// Clear the shiftregister, needed for 3-wire version // Clear the shiftregister, needed for 3-wire version
rawshift(0); rawshift(p, 0);
hd44780_functions->uPause (2); p->hd44780_functions->uPause (p, 1);
readval = ~ port_in (lptPort + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
inputs_zero = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ); inputs_zero = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) );
if( inputs_zero == 0 ) { if( inputs_zero == 0 ) {
// No keys were pressed // No keys were pressed
// Restore line status for backlight. // Restore line status for backlight.
port_out (lptPort, backlight_bit ); port_out (p->port, p->backlight_bit );
return 0; return 0;
} }
// Set cursor position to -1
p->hd44780_functions->senddata (p, 0, RS_INSTR, POSITION | 127);
p->hd44780_functions->uPause (p, 40);
// Scan the keypad while sending the first half of the command (high nibble) // Scan the keypad while sending the first half of the command (high nibble)
for (i = 7; i >= 0; i--) { /* MSB first */ for (i = 7; i >= 0; i--) { /* MSB first */
port_out (lptPort, LCDDATA); /*set up data */ port_out (p->port, LCDDATA); /*set up data */
port_out (lptPort, LCDDATA | LCDCLOCK); /*rising edge of clock */ port_out (p->port, LCDDATA | LCDCLOCK); /*rising edge of clock */
hd44780_functions->uPause (2); p->hd44780_functions->uPause (p, 2);
if( !scancode ) { if( !scancode ) {
// Read input line(s) // Read input line(s)
readval = ~ port_in (lptPort + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
keybits = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ); keybits = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) );
if( keybits != inputs_zero ) { if( keybits != inputs_zero ) {
shiftingbit = 1; shiftingbit = 1;
@@ -207,40 +208,40 @@ unsigned char lcdserLpt_HD44780_scankeypad ()
} }
// Wait for 2-wire version to clear the latch... // Wait for 2-wire version to clear the latch...
hd44780_functions->uPause (6); p->hd44780_functions->uPause (p, 6);
// And again for the second half of the command (low nibble). // And again for the second half of the command (low nibble).
// Needed for 2-wire version. // Needed for 2-wire version.
rawshift (0xFF); rawshift (p, 0xFF);
// Wait for 2-wire version to clear the latch... // Wait for 2-wire version to clear the latch...
hd44780_functions->uPause (6); p->hd44780_functions->uPause (p, 6);
// Restore line status for backlight. // Restore line status for backlight.
port_out (lptPort, backlight_bit ); port_out (p->port, p->backlight_bit );
return scancode; return scancode;
} }
/* this function sends r out onto the shift register */ /* this function sends r out onto the shift register */
void void
rawshift (unsigned char r) rawshift (PrivateData *p, unsigned char r)
{ {
int i; int i;
for (i = 7; i >= 0; i--) { /* MSB first */ for (i = 7; i >= 0; i--) { /* MSB first */
port_out (lptPort, ((r >> i) & 1) * LCDDATA); /*set up data */ port_out (p->port, ((r >> i) & 1) * LCDDATA); /*set up data */
port_out (lptPort, (((r >> i) & 1) * LCDDATA) | LCDCLOCK); /*rising edge of clock */ port_out (p->port, (((r >> i) & 1) * LCDDATA) | LCDCLOCK); /*rising edge of clock */
} }
} }
// enableLines = value on parallel port to toggle the correct display // enableLines = value on parallel port to toggle the correct display
void void
shiftreg (unsigned char enableLines, unsigned char r) shiftreg (PrivateData *p, unsigned char enableLines, unsigned char r)
{ {
rawshift (r | 0x80); // highest bit always set to 1 for Clear for 2-wire version rawshift (p, r | 0x80); // highest bit always set to 1 for Clear for 2-wire version
port_out (lptPort, enableLines); // latch it, to correct display port_out (p->port, enableLines); // latch it, to correct display
hd44780_functions->uPause (1); p->hd44780_functions->uPause (p, 1);
port_out (lptPort, 0); // for 3-wire version port_out (p->port, 0); // for 3-wire version
hd44780_functions->uPause (5); // wait for 2-wire version to clear the latch... p->hd44780_functions->uPause (p, 5); // wait for 2-wire version to clear the latch...
} }
+2 -3
View File
@@ -1,10 +1,9 @@
#ifndef HD_SERIALLPT_H #ifndef HD_SERIALLPT_H
#define HD_SERIALLPT_H #define HD_SERIALLPT_H
#include "lcd.h" /* for lcd_logical_driver */ #include "lcd.h" /* for Driver */
#include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port); int hd_init_serialLpt (Driver *drvthis);
#endif #endif
+43 -39
View File
@@ -59,7 +59,7 @@
*/ */
#include "hd44780-winamp.h" #include "hd44780-winamp.h"
#include "hd44780.h" #include "hd44780-low.h"
#include "lpt-port.h" #include "lpt-port.h"
#include "port.h" #include "port.h"
@@ -74,9 +74,9 @@
// HD44780_senddata // HD44780_senddata
// HD44780_readkeypad // HD44780_readkeypad
void lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch); void lcdwinamp_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcdwinamp_HD44780_backlight (unsigned char state); void lcdwinamp_HD44780_backlight (PrivateData *p, unsigned char state);
unsigned char lcdwinamp_HD44780_readkeypad (unsigned int YData); unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData);
#define EN1 STRB #define EN1 STRB
#define EN2 SEL #define EN2 SEL
@@ -85,41 +85,45 @@ unsigned char lcdwinamp_HD44780_readkeypad (unsigned int YData);
#define RS INIT #define RS INIT
#define BL SEL #define BL SEL
static unsigned char EnMask[] = { EN1, EN2, EN3 }; static const unsigned char EnMask[] = { EN1, EN2, EN3 };
static unsigned int lptPort;
static char stuckinputs = 0; // if an input line is stuck, it will be ignored
static char backlight_bit = 0; // default to low to enable two displays
// initialise the driver // initialise the driver
int int
hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port) hd_init_winamp (Driver *drvthis)
{ {
PrivateData *p = (PrivateData*) drvthis->private_data;
HD44780_functions *hd44780_functions = p->hd44780_functions;
// Reserve the port registers // Reserve the port registers
lptPort = port; port_access(p->port);
port_access(lptPort); port_access(p->port+1);
port_access(lptPort+1); port_access(p->port+2);
port_access(lptPort+2);
hd44780_functions->senddata = lcdwinamp_HD44780_senddata; hd44780_functions->senddata = lcdwinamp_HD44780_senddata;
hd44780_functions->backlight = lcdwinamp_HD44780_backlight; hd44780_functions->backlight = lcdwinamp_HD44780_backlight;
hd44780_functions->readkeypad = lcdwinamp_HD44780_readkeypad; hd44780_functions->readkeypad = lcdwinamp_HD44780_readkeypad;
// setup the lcd in 8 bit mode // setup the lcd in 8 bit mode
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (4100); hd44780_functions->uPause (p, 4100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (100); hd44780_functions->uPause (p, 100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR); hd44780_functions->senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR);
hd44780_functions->uPause (40); hd44780_functions->uPause (p, 40);
common_init (p);
if (p->have_keypad) {
// Remember which input lines are stuck
p->stuckinputs = lcdwinamp_HD44780_readkeypad (p, 0);
}
common_init ();
return 0; return 0;
} }
// lcdwinamp_HD44780_senddata // lcdwinamp_HD44780_senddata
void void
lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch) lcdwinamp_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{ {
unsigned char enableLines = 0, portControl; unsigned char enableLines = 0, portControl;
@@ -128,25 +132,25 @@ lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
else else
portControl = 0; portControl = 0;
portControl |= backlight_bit; portControl |= p->backlight_bit;
if (displayID == 0) if (displayID == 0)
enableLines = EnMask[0] | EnMask[1] | ((extIF) ? EnMask[2] : 0); enableLines = EnMask[0] | EnMask[1] | ((p->extIF) ? EnMask[2] : 0);
else else
enableLines = EnMask[displayID - 1]; enableLines = EnMask[displayID - 1];
// 40 nS setup time for RS valid to EN high, so set RS // 40 nS setup time for RS valid to EN high, so set RS
port_out (lptPort + 2, portControl ^ OUTMASK); port_out (p->port + 2, portControl ^ OUTMASK);
// Output the actual data // Output the actual data
port_out (lptPort, ch); port_out (p->port, ch);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
// then set EN high // then set EN high
port_out (lptPort + 2, (enableLines|portControl) ^ OUTMASK); port_out (p->port + 2, (enableLines|portControl) ^ OUTMASK);
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
// 80 nS setup from valid data to EN low will be met without any delay // 80 nS setup from valid data to EN low will be met without any delay
// unless you are running a REALLY FAST ISA bus (like 75 MHZ!) // unless you are running a REALLY FAST ISA bus (like 75 MHZ!)
@@ -155,34 +159,34 @@ lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
// ABOVE TEXT ignored now, using delays if delayBus is specified // ABOVE TEXT ignored now, using delays if delayBus is specified
// Set EN low and we're done... // Set EN low and we're done...
port_out (lptPort + 2, portControl ^ OUTMASK); port_out (p->port + 2, portControl ^ OUTMASK);
// 10 nS data hold time provided by the length of ISA write for EN // 10 nS data hold time provided by the length of ISA write for EN
} }
void lcdwinamp_HD44780_backlight (unsigned char state) void lcdwinamp_HD44780_backlight (PrivateData *p, unsigned char state)
{ {
backlight_bit = (state?0:nSEL); p->backlight_bit = (state?0:nSEL);
port_out (lptPort + 2, backlight_bit ^ OUTMASK); port_out (p->port + 2, p->backlight_bit ^ OUTMASK);
} }
unsigned char lcdwinamp_HD44780_readkeypad (unsigned int YData) unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData)
{ {
unsigned char readval; unsigned char readval;
// 8 bits output // 8 bits output
// Convert the positive logic to the negative logic on the LPT port // Convert the positive logic to the negative logic on the LPT port
port_out (lptPort, ~YData & 0x00FF ); port_out (p->port, ~YData & 0x00FF );
if( delayBus ) hd44780_functions->uPause (1); if( p->delayBus ) p->hd44780_functions->uPause (p, 1);
// Read inputs // Read inputs
readval = ~ port_in (lptPort + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
// Set output back to idle state for backlight // Set output back to idle state for backlight
port_out (lptPort + 2, backlight_bit ^ OUTMASK ); port_out (p->port + 2, p->backlight_bit ^ OUTMASK );
// And convert value back. // And convert value back.
return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~stuckinputs; return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~p->stuckinputs;
} }
+3 -5
View File
@@ -1,11 +1,9 @@
#ifndef HD_WINAMP_H #ifndef HD_WINAMP_H
#define HD_WINAMP_H #define HD_WINAMP_H
#include "lcd.h" /* for lcd_logical_driver */ #include "lcd.h" /* for Driver */
#include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver, args is probably not used but keep // initialise this particular driver
// for consistency int hd_init_winamp (Driver *drvthis);
int hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
#endif #endif
+374 -327
View File
File diff suppressed because it is too large Load Diff
+22 -26
View File
@@ -16,33 +16,29 @@
#ifndef HD44780_H #ifndef HD44780_H
#define HD44780_H #define HD44780_H
// Maximum sizes of the keypad int HD44780_init (struct lcd_logical_driver *driver, char *args);
// DO NOT CHANGE THESE 2 VALUES, unless you change the functions too MODULE_EXPORT void HD44780_close (Driver *drvthis);
#define KEYPAD_MAXX 5 MODULE_EXPORT int HD44780_width (Driver *drvthis);
#define KEYPAD_MAXY 11 MODULE_EXPORT int HD44780_height (Driver *drvthis);
MODULE_EXPORT void HD44780_clear (Driver *drvthis);
MODULE_EXPORT void HD44780_flush (Driver *drvthis);
MODULE_EXPORT void HD44780_string (Driver *drvthis, int x, int y, char *s);
MODULE_EXPORT void HD44780_chr (Driver *drvthis, int x, int y, char ch);
extern char have_keypad; // non-zero if the keypad code is activated MODULE_EXPORT void HD44780_vbar (Driver *drvthis, int x, int len);
extern char have_backlight; // non-zero if we can control the backlight MODULE_EXPORT void HD44780_hbar (Driver *drvthis, int x, int y, int len);
extern char extIF; // non-zero if we should control > 2 LCDs MODULE_EXPORT void HD44780_num (Driver *drvthis, int x, int num);
extern char delayBus; // non-zero if axtra delays for the bus speed MODULE_EXPORT void HD44780_heartbeat (Driver *drvthis, int type);
// should be inserted. MODULE_EXPORT void HD44780_icon (Driver *drvthis, int which, char dest);
int HD44780_init (struct lcd_logical_driver *driver, char *args); MODULE_EXPORT void HD44780_set_char (Driver *drvthis, int n, char *dat);
/* The following methods can all be hidden. They are used through function ptrs
void HD44780_close(); MODULE_EXPORT void HD44780_backlight (Driver *drvthis, int on);
void HD44780_flush();
void HD44780_flush_box(int lft, int top, int rgt, int bot); MODULE_EXPORT char HD44780_getkey (Driver *drvthis);
int HD44780_contrast(int contrast);
void HD44780_backlight(int on); MODULE_EXPORT void HD44780_init_vbar (Driver *drvthis);
void HD44780_init_vbar(); MODULE_EXPORT void HD44780_init_hbar (Driver *drvthis);
void HD44780_init_hbar(); MODULE_EXPORT void HD44780_init_num (Driver *drvthis);
void HD44780_vbar(int x, int len);
void HD44780_hbar(int x, int y, int len);
void HD44780_init_num();
void HD44780_num(int x, int num);
void HD44780_set_char(int n, char *dat);
void HD44780_icon(int which, char dest);
void HD44780_draw_frame(char *dat);
*/
#endif #endif
+38 -35
View File
@@ -21,26 +21,25 @@
#include <sys/errno.h> #include <sys/errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
#include <syslog.h>
#include <linux/joystick.h> #include <linux/joystick.h>
#ifndef JSIOCGNAME #ifndef JSIOCGNAME
#define JSIOCGNAME(len) _IOC(_IOC_READ, 'j', 0x13, len) /* get identifier string */ #define JSIOCGNAME(len) _IOC(_IOC_READ, 'j', 0x13, len) /* get identifier string */
#endif #endif
#include "shared/debug.h" #ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "lcd.h"
#include "joy.h"
#include "report.h"
#include "shared/str.h" #include "shared/str.h"
#define NAME_LENGTH 128 #define NAME_LENGTH 128
#define JOY_DEFAULT_DEVICE "/dev/js0" #define JOY_DEFAULT_DEVICE "/dev/js0"
#include "lcd.h"
#include "joy.h"
lcd_logical_driver *joy;
int fd; int fd;
extern int debug_level;
struct js_event js; struct js_event js;
@@ -49,25 +48,30 @@ char buttons = 2;
int jsversion = 0x000800; int jsversion = 0x000800;
char jsname[NAME_LENGTH] = "Unknown"; char jsname[NAME_LENGTH] = "Unknown";
int *axis; int *axis = NULL;
int *button; int *button = NULL;
// Configured for a Gravis Gamepad (2 axis, 4 button) // Configured for a Gravis Gamepad (2 axis, 4 button)
char *axismap = "EFGHIJKLMNOPQRST"; char *axismap = "EFGHIJKLMNOPQRST";
char *buttonmap = "BDACEFGHIJKLMNOP"; char *buttonmap = "BDACEFGHIJKLMNOP";
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "joy_";
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int int
joy_init (struct lcd_logical_driver *driver, char *args) joy_init (Driver *drvthis, char *args)
{ {
char device[256]; char device[256];
char *argv[64]; char *argv[64];
int argc, i; int argc, i;
joy = driver;
strcpy (device, JOY_DEFAULT_DEVICE); strcpy (device, JOY_DEFAULT_DEVICE);
argc = get_args (argv, args, 64); argc = get_args (argv, args, 64);
@@ -101,8 +105,14 @@ joy_init (struct lcd_logical_driver *driver, char *args)
} }
driver->getkey = joy_getkey; // Set variables for server
driver->close = joy_close; drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
// Set the functions the driver supports
drvthis->getkey = joy_getkey;
drvthis->close = joy_close;
if ((fd = open (device, O_RDONLY)) < 0) if ((fd = open (device, O_RDONLY)) < 0)
return -1; return -1;
@@ -113,40 +123,33 @@ joy_init (struct lcd_logical_driver *driver, char *args)
ioctl (fd, JSIOCGBUTTONS, &buttons); ioctl (fd, JSIOCGBUTTONS, &buttons);
ioctl (fd, JSIOCGNAME (NAME_LENGTH), jsname); ioctl (fd, JSIOCGNAME (NAME_LENGTH), jsname);
if (debug_level > 2) { report (RPT_NOTICE, "Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
syslog(LOG_DEBUG, "Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n", jsname, axes, buttons,
jsname, axes, buttons, jsversion >> 16, (jsversion >> 8) & 0xff, jsversion & 0xff);
jsversion >> 16, (jsversion >> 8) & 0xff, jsversion & 0xff);
}
if ((axis = calloc (axes, sizeof (int))) == NULL) { if ((axis = calloc (axes, sizeof (int))) == NULL) {
syslog(LOG_ERR, "joystick: could not allocate memory for axes"); report (RPT_ERR, "joystick: could not allocate memory for axes");
return -1; return -1;
} }
if ((button = calloc (buttons, sizeof (char))) == NULL) { if ((button = calloc (buttons, sizeof (char))) == NULL) {
syslog(LOG_ERR, "joystick: could not allocate memory for buttons"); report (RPT_ERR, "joystick: could not allocate memory for buttons");
return -1; return -1;
} }
return fd; // 200 is arbitrary. (must be 1 or more) return 0;
} }
void MODULE_EXPORT void
joy_close () joy_close (Driver *drvthis)
{ {
if (joy->framebuf != NULL)
free (joy->framebuf);
close (fd); close (fd);
joy->framebuf = NULL;
// Why do I have so much trouble getting memory freed without segfaults?? // Why do I have so much trouble getting memory freed without segfaults??
// Use gdb and find out :) In preliminary testing, this seemed to work... // Use gdb and find out :) In preliminary testing, this seemed to work...
if (axis) free(axis); if(axis) free(axis);
if (button) free(button); if(button) free(button);
} }
@@ -155,8 +158,8 @@ joy_close ()
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char MODULE_EXPORT char
joy_getkey () joy_getkey (Driver *drvthis)
{ {
int i; int i;
int err; int err;
@@ -165,7 +168,7 @@ joy_getkey ()
return 0; return 0;
} else } else
if (err != sizeof (struct js_event)) { if (err != sizeof (struct js_event)) {
syslog(LOG_ERR, "error reading joystick input"); report(RPT_ERR, "error reading joystick input");
return 0; return 0;
} }
+5 -4
View File
@@ -1,10 +1,11 @@
#ifndef LCD_JOY_H #ifndef LCD_JOY_H
#define LCD_JOY_H #define LCD_JOY_H
extern lcd_logical_driver *joy; #include "lcd.h"
int joy_init (struct lcd_logical_driver *driver, char *args); int joy_init (Driver *drvthis, char *args);
void joy_close (); MODULE_EXPORT void joy_close (Driver *drvthis);
char joy_getkey ();
MODULE_EXPORT char joy_getkey (Driver *drvthis);
#endif #endif
+144 -119
View File
@@ -26,18 +26,17 @@
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_NCURSES_H //#ifdef HAVE_NCURSES_H
# include <ncurses.h> //# include <ncurses.h>
#else //#else
# include <curses.h> //# include <curses.h>
#endif //#endif
#include "shared/str.h"
#include "shared/debug.h"
#include "lcd.h" #include "lcd.h"
#include "lb216.h" #include "lb216.h"
#include "drv_base.h" #include "shared/str.h"
#include "render.h" #include "report.h"
//#include "drv_base.h"
static int custom=0; static int custom=0;
typedef enum { typedef enum {
@@ -47,20 +46,30 @@ typedef enum {
beat = 8 } custom_type; beat = 8 } custom_type;
static int fd; static int fd;
static char *framebuf = NULL;
static int width = LCD_DEFAULT_WIDTH;
static int height = LCD_DEFAULT_HEIGHT;
static int cellwidth = LCD_DEFAULT_CELLWIDTH;
static int cellheight = LCD_DEFAULT_CELLHEIGHT;
static void LB216_hidecursor(); static void LB216_hidecursor();
static void LB216_reboot(); static void LB216_reboot();
// TODO: Get rid of this variable? // Vars for the server core
lcd_logical_driver *LB216; MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "LB216_";
// TODO: Get the frame buffers working right // TODO: Get the frame buffers working right
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int LB216_init(lcd_logical_driver *driver, char *args) int
LB216_init(Driver * drvthis, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -71,8 +80,8 @@ int LB216_init(lcd_logical_driver *driver, char *args)
char device[256] = "/dev/lcd"; char device[256] = "/dev/lcd";
int speed=B9600; int speed=B9600;
int backlight_brightness = 255;
LB216 = driver;
//debug("LB216_init: Args(all): %s\n", args); //debug("LB216_init: Args(all): %s\n", args);
@@ -153,6 +162,7 @@ int LB216_init(lcd_logical_driver *driver, char *args)
} }
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) if (fd == -1)
@@ -184,12 +194,11 @@ int LB216_init(lcd_logical_driver *driver, char *args)
// Do it... // Do it...
tcsetattr(fd, TCSANOW, &portset); tcsetattr(fd, TCSANOW, &portset);
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
if (!LB216->framebuf) if (framebuf)
LB216->framebuf = (unsigned char *) framebuf = (unsigned char *)
malloc (LB216->wid * LB216->hgt); malloc (width * height);
memset (LB216->framebuf, ' ', LB216->wid * LB216->hgt); memset (framebuf, ' ', width * height);
// Set display-specific stuff.. // Set display-specific stuff..
if(reboot) if(reboot)
@@ -200,36 +209,34 @@ int LB216_init(lcd_logical_driver *driver, char *args)
} }
sleep(1); sleep(1);
LB216_hidecursor(); LB216_hidecursor();
LB216_backlight(backlight_brightness); LB216_backlight(drvthis, backlight_brightness);
// Set the functions the driver supports... // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = LB216_clear; // Set the functions the driver supports
driver->string = LB216_string; drvthis->clear = LB216_clear;
driver->chr = LB216_chr; drvthis->string = LB216_string;
driver->vbar = LB216_vbar; drvthis->chr = LB216_chr;
driver->init_vbar = LB216_init_vbar; drvthis->old_vbar = LB216_vbar;
driver->hbar = LB216_hbar; drvthis->init_vbar = LB216_init_vbar;
driver->init_hbar = LB216_init_hbar; drvthis->old_hbar = LB216_hbar;
//driver->num = NULL; drvthis->init_hbar = LB216_init_hbar;
//driver->init_num = NULL; //drvthis->num = NULL;
//drvthis->init_num = NULL;
driver->init = LB216_init; drvthis->init = LB216_init;
driver->close = LB216_close; drvthis->close = LB216_close;
driver->flush = LB216_flush; drvthis->width = LB216_width;
//driver->flush_box = NULL; drvthis->height = LB216_height;
//driver->contrast = NULL; drvthis->flush = LB216_flush;
driver->backlight = LB216_backlight; drvthis->backlight = LB216_backlight;
driver->set_char = LB216_set_char; drvthis->set_char = LB216_set_char;
driver->icon = LB216_icon; drvthis->old_icon = LB216_icon;
driver->draw_frame = LB216_draw_frame;
LB216->cellwid = 5; return 0;
LB216->cellhgt = 8;
debug("LB216: foo!\n");
return fd;
} }
@@ -237,28 +244,66 @@ int LB216_init(lcd_logical_driver *driver, char *args)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clean-up // Clean-up
// //
void LB216_close() MODULE_EXPORT void
LB216_close(Driver * drvthis)
{ {
close (fd); close (fd);
if(LB216->framebuf) free(LB216->framebuf); if(framebuf) free(framebuf);
framebuf = NULL;
}
LB216->framebuf = NULL; /////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
LB216_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
LB216_height (Driver *drvthis)
{
return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
LB216_clear () LB216_clear (Driver * drvthis)
{ {
memset (LB216->framebuf, ' ', LB216->wid * LB216->hgt); memset (framebuf, ' ', width * height);
} }
void LB216_flush()
/////////////////////////////////////////////////////////////////
// Flushes the framebuffer to the LCD
//
MODULE_EXPORT void
LB216_flush(Driver * drvthis)
{ {
LB216_draw_frame(LB216->framebuf); char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i,j;
snprintf (out, sizeof(out), "%c%c", 254,80);
write(fd, out, 2);
for(j=0; j<height; j++) {
if (j>=2) {
snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2)));
} else {
snprintf (out, sizeof(out),"%c%c",254,128+(64*(j)));
}
write(fd, out, 2);
for(i=0; i<width; i++) {
write(fd, framebuf + i+(j*width), 1);
}
}
} }
@@ -267,13 +312,14 @@ void LB216_flush()
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (16,2). // upper-left is (1,1), and the lower right should be (16,2).
// //
void LB216_chr(int x, int y, char c) MODULE_EXPORT void
LB216_chr(Driver * drvthis, int x, int y, char c)
{ {
//y--; //y--;
// x--; // x--;
//if(c < 32 && c >= 0) c += 128; //if(c < 32 && c >= 0) c += 128;
// LB216->framebuf[(y*LB216->wid) + x] = c; // framebuf[(y*width) + x] = c;
// char chr[1]; // char chr[1];
// snprintf (chr, sizeof(chr), "%c", c); // snprintf (chr, sizeof(chr), "%c", c);
@@ -282,7 +328,7 @@ void LB216_chr(int x, int y, char c)
char chr[2]; char chr[2];
chr[0] = c; chr[0] = c;
chr[1] = 0; chr[1] = 0;
LB216_string (x, y, chr); LB216_string (drvthis, x, y, chr);
} }
@@ -290,7 +336,8 @@ void LB216_chr(int x, int y, char c)
// Sets the backlight on or off -- can be done quickly for // Sets the backlight on or off -- can be done quickly for
// an intermediate brightness... // an intermediate brightness...
// //
void LB216_backlight(int on) MODULE_EXPORT void
LB216_backlight(Driver * drvthis, int on)
{ {
char out[4]; char out[4];
if(on) if(on)
@@ -326,36 +373,8 @@ static void LB216_reboot()
} }
///////////////////////////////////////////////////////////// MODULE_EXPORT void
// Blasts a single frame onscreen, to the lcd... LB216_string (Driver * drvthis, int x, int y, char string[])
//
// Input is a character array, sized LB216->wid*LB216->hgt
//
void LB216_draw_frame(char *dat)
{
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i,j;
if(!dat) return;
snprintf (out, sizeof(out), "%c%c", 254,80);
write(fd, out, 2);
for(j=0; j<LB216->hgt; j++) {
if (j>=2) {
snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2)));
} else {
snprintf (out, sizeof(out),"%c%c",254,128+(64*(j)));
}
write(fd, out, 2);
for(i=0; i<LB216->wid; i++) {
snprintf (out, sizeof(out),"%c",dat[i+(j*LB216->wid)]);
write(fd, out, 1);
}
}
}
void LB216_string (int x, int y, char string[])
{ {
int i; int i;
char c; char c;
@@ -369,7 +388,7 @@ void LB216_string (int x, int y, char string[])
{ {
case '\254': c = '#'; break; case '\254': c = '#'; break;
} }
LB216->framebuf[(y*LB216->wid) + x+i] = c; framebuf[(y*width) + x+i] = c;
} }
} }
@@ -377,7 +396,8 @@ void LB216_string (int x, int y, char string[])
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before LB216->vbar() // Sets up for vertical bars. Call before LB216->vbar()
// //
void LB216_init_vbar() MODULE_EXPORT void
LB216_init_vbar(Driver * drvthis)
{ {
char a[] = { char a[] = {
0,0,0,0,0, 0,0,0,0,0,
@@ -451,13 +471,13 @@ void LB216_init_vbar()
}; };
if(custom!=vbar) { if(custom!=vbar) {
LB216_set_char(1,a); LB216_set_char(drvthis, 1,a);
LB216_set_char(2,b); LB216_set_char(drvthis, 2,b);
LB216_set_char(3,c); LB216_set_char(drvthis, 3,c);
LB216_set_char(4,d); LB216_set_char(drvthis, 4,d);
LB216_set_char(5,e); LB216_set_char(drvthis, 5,e);
LB216_set_char(6,f); LB216_set_char(drvthis, 6,f);
LB216_set_char(7,g); LB216_set_char(drvthis, 7,g);
custom=vbar; custom=vbar;
} }
} }
@@ -465,7 +485,8 @@ void LB216_init_vbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void LB216_init_hbar() MODULE_EXPORT void
LB216_init_hbar(Driver * drvthis)
{ {
char a[] = { char a[] = {
@@ -520,11 +541,11 @@ void LB216_init_hbar()
}; };
if(custom!=hbar) { if(custom!=hbar) {
LB216_set_char(1,a); LB216_set_char(drvthis, 1,a);
LB216_set_char(2,b); LB216_set_char(drvthis, 2,b);
LB216_set_char(3,c); LB216_set_char(drvthis, 3,c);
LB216_set_char(4,d); LB216_set_char(drvthis, 4,d);
LB216_set_char(5,e); LB216_set_char(drvthis, 5,e);
custom=hbar; custom=hbar;
} }
} }
@@ -532,18 +553,19 @@ void LB216_init_hbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar... // Draws a vertical bar...
// //
void LB216_vbar(int x, int len) MODULE_EXPORT void
LB216_vbar(Driver * drvthis, int x, int len)
{ {
char map[9] = {32, 1, 2, 3, 4, 5, 6, 7, 255 }; char map[9] = {32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y; int y;
for(y=LB216->hgt; y > 0 && len>0; y--) for(y=height; y > 0 && len>0; y--)
{ {
if(len >= LB216->cellhgt) LB216_chr(x, y, 255); if(len >= cellheight) LB216_chr(drvthis, x, y, 255);
else LB216_chr(x, y, map[len]); else LB216_chr(drvthis, x, y, map[len]);
len -= LB216->cellhgt; len -= cellheight;
} }
} }
@@ -551,17 +573,18 @@ void LB216_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void LB216_hbar(int x, int y, int len) MODULE_EXPORT void
LB216_hbar(Driver * drvthis, int x, int y, int len)
{ {
char map[7] = { 32, 1, 2, 3, 4, 5 }; char map[7] = { 32, 1, 2, 3, 4, 5 };
for(; x<=LB216->wid && len>0; x++) for(; x<=width && len>0; x++)
{ {
if(len >= LB216->cellwid) LB216_chr(x,y,map[5]); if(len >= cellwidth) LB216_chr(drvthis, x,y,map[5]);
else LB216_chr(x, y, map[len]); else LB216_chr(drvthis, x, y, map[len]);
//printf ("%d,",len); //printf ("%d,",len);
len -= LB216->cellwid; len -= cellwidth;
} }
// printf ("\n"); // printf ("\n");
@@ -576,7 +599,8 @@ void LB216_hbar(int x, int y, int len)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void LB216_set_char(int n, char *dat) MODULE_EXPORT void
LB216_set_char(Driver * drvthis, int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
@@ -589,20 +613,21 @@ void LB216_set_char(int n, char *dat)
snprintf (out, sizeof(out), "%c%c", 254, n); snprintf (out, sizeof(out), "%c%c", 254, n);
write(fd, out, 2); write(fd, out, 2);
for(row=0; row<LB216->cellhgt; row++) for(row=0; row<cellheight; row++)
{ {
letter = 1; letter = 1;
for(col=0; col<LB216->cellwid; col++) for(col=0; col<cellwidth; col++)
{ {
letter <<= 1; letter <<= 1;
letter |= (dat[(row*LB216->cellwid) + col] > 0); letter |= (dat[(row*cellwidth) + col] > 0);
} }
snprintf (out, sizeof(out),"%c",letter); snprintf (out, sizeof(out),"%c",letter);
write(fd, out, 1); write(fd, out, 1);
} }
} }
void LB216_icon(int which, char dest) MODULE_EXPORT void
LB216_icon(Driver * drvthis, int which, char dest)
{ {
char icons[3][8*8] = { char icons[3][8*8] = {
{ {
@@ -641,5 +666,5 @@ void LB216_icon(int which, char dest)
}; };
if(custom==bign) custom=beat; if(custom==bign) custom=beat;
LB216_set_char(dest, &icons[which][0]); LB216_set_char(drvthis, dest, &icons[which][0]);
} }
+21 -18
View File
@@ -1,25 +1,28 @@
#ifndef LB216_H #ifndef LB216_H
#define LB216_H #define LB216_H
#include "lcd.h"
extern lcd_logical_driver *LB216; int LB216_init(Driver * drvthis, char *device);
MODULE_EXPORT void LB216_close(Driver * drvthis);
MODULE_EXPORT int LB216_width (Driver *drvthis);
MODULE_EXPORT int LB216_height (Driver *drvthis);
MODULE_EXPORT void LB216_clear (Driver * drvthis);
MODULE_EXPORT void LB216_flush(Driver * drvthis);
MODULE_EXPORT void LB216_string (Driver * drvthis, int x, int y, char string[]);
MODULE_EXPORT void LB216_chr(Driver * drvthis, int x, int y, char c) ;
int LB216_init(lcd_logical_driver *driver, char *device); MODULE_EXPORT void LB216_vbar(Driver * drvthis, int x, int len);
void LB216_clear (); MODULE_EXPORT void LB216_hbar(Driver * drvthis, int x, int y, int len);
void LB216_close(); MODULE_EXPORT void LB216_num(Driver * drvthis, int x, int num);
void LB216_string (int x, int y, char string[]); MODULE_EXPORT void LB216_icon(Driver * drvthis, int which, char dest);
void LB216_flush();
void LB216_flush_box(int lft, int top, int rgt, int bot); MODULE_EXPORT void LB216_set_char(Driver * drvthis, int n, char *dat);
void LB216_chr(int x, int y, char c) ;
void LB216_backlight(int on); MODULE_EXPORT void LB216_backlight(Driver * drvthis, int on);
void LB216_init_vbar();
void LB216_init_hbar(); MODULE_EXPORT void LB216_init_vbar(Driver * drvthis);
void LB216_vbar(int x, int len); MODULE_EXPORT void LB216_init_hbar(Driver * drvthis);
void LB216_hbar(int x, int y, int len); MODULE_EXPORT void LB216_init_num(Driver * drvthis);
void LB216_init_num();
void LB216_num(int x, int num);
void LB216_set_char(int n, char *dat);
void LB216_icon(int which, char dest);
void LB216_draw_frame(char *dat);
#endif #endif
+22 -18
View File
@@ -36,6 +36,7 @@
#include "lcd.h" #include "lcd.h"
/*
static int lcd_drv_init (lcd_logical_driver * driver, char *args); static int lcd_drv_init (lcd_logical_driver * driver, char *args);
static void lcd_drv_close (); static void lcd_drv_close ();
static void lcd_drv_clear (); static void lcd_drv_clear ();
@@ -59,6 +60,7 @@ static char lcd_drv_getkey ();
static char lcd_drv_getkey_loop (); static char lcd_drv_getkey_loop ();
static char *lcd_drv_getinfo (); static char *lcd_drv_getinfo ();
static void lcd_drv_heartbeat (int type); static void lcd_drv_heartbeat (int type);
*/
/* /*
* Add all of the driver's header files in... * Add all of the driver's header files in...
@@ -153,7 +155,8 @@ static void lcd_drv_heartbeat (int type);
// TODO: Make a Windows server, and clients...? // TODO: Make a Windows server, and clients...?
lcd_logical_driver lcd, *lcd_root = NULL, *lcd_ptr = NULL; //Driver *lcd_root = NULL;
//Driver *lcd_ptr = NULL;
// TODO: Add multiple names for the same driver? // TODO: Add multiple names for the same driver?
// //
@@ -267,15 +270,20 @@ lcd_list_drivers (void) {
// //
// This was eliminated; everything // This was eliminated; everything
// done here is to be replaced by the use of lcd_add_driver()... // done here is to be replaced by the use of lcd_add_driver()...
/*
int int
lcd_init (char *args) lcd_init (char *args)
{ {
return 0; return 0;
} }
*/
// This sets up all of the "wrapper" driver functions // This sets up all of the "wrapper" driver functions
// which call all of the drivers in turn. // which call all of the drivers in turn.
// //
/*
static int static int
lcd_drv_init (struct lcd_logical_driver *driver, char *args) lcd_drv_init (struct lcd_logical_driver *driver, char *args)
{ {
@@ -379,6 +387,7 @@ lcd_drv_patch_init (struct lcd_logical_driver *driver)
return 0; return 0;
} }
*/
/* /*
* This function can be replaced later with something * This function can be replaced later with something
@@ -386,6 +395,7 @@ lcd_drv_patch_init (struct lcd_logical_driver *driver)
* *
*/ */
void * void *
lcd_find_init (char *driver) { lcd_find_init (char *driver) {
int i; int i;
@@ -401,11 +411,13 @@ lcd_find_init (char *driver) {
return NULL; return NULL;
} }
// TODO: lcd_remove_driver() // TODO: lcd_remove_driver()
struct lcd_logical_driver * /*
Driver *
lcd_allocate_driver () { lcd_allocate_driver () {
struct lcd_logical_driver *driver; Driver *driver;
//int driver_size; //int driver_size;
// This bit of fakery allows us to use lcd as the first // This bit of fakery allows us to use lcd as the first
@@ -414,7 +426,7 @@ lcd_allocate_driver () {
#define FirstTime (lcd_ptr->framebuf == NULL) #define FirstTime (lcd_ptr->framebuf == NULL)
if ((driver = malloc(sizeof(lcd_logical_driver))) == NULL) { if ((driver = malloc(sizeof(Driver))) == NULL) {
syslog(LOG_ERR, "error allocating driver space!"); syslog(LOG_ERR, "error allocating driver space!");
return NULL; return NULL;
} }
@@ -432,6 +444,7 @@ lcd_allocate_driver () {
// it. This is the function which calls, for example, // it. This is the function which calls, for example,
// MtxOrb_init. The specifics come from the drivers[] array. // MtxOrb_init. The specifics come from the drivers[] array.
static char (*main_getkey) () = NULL; static char (*main_getkey) () = NULL;
int int
@@ -507,19 +520,7 @@ lcd_add_driver (char *driver, char *args)
} }
return -1; return -1;
} }
*/
// TODO: Put lcd_shutdown in the shutdown function...
int
lcd_shutdown ()
{
//lcd_logical_driver *driver;
// This does not shutdown any input sources;
// is that sufficient?
lcd_root->close ();
return 0;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// All functions below here call their respective driver functions... // All functions below here call their respective driver functions...
@@ -563,6 +564,7 @@ lcd_shutdown ()
// lcd_drv_getkey () // lcd_drv_getkey ()
// lcd_drv_getinfo () // lcd_drv_getinfo ()
/*
static void static void
lcd_drv_close () lcd_drv_close ()
{ {
@@ -686,9 +688,10 @@ lcd_drv_getkey ()
// This loops through all defined getkeys, returning // This loops through all defined getkeys, returning
// the first input that it finds, if any. // the first input that it finds, if any.
static char static char
lcd_drv_getkey_loop () { lcd_drv_getkey_loop () {
lcd_logical_driver *driver; Driver *driver;
char c; char c;
if ((c = main_getkey()) != 0) if ((c = main_getkey()) != 0)
@@ -708,3 +711,4 @@ lcd_drv_heartbeat (int type)
; ;
} }
*/
+169 -73
View File
@@ -1,104 +1,200 @@
/*
* client.h
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
*
*
* This file defines the LCDd-driver API
* It is written to facilitate loadable driver modules.
* There should be no further interaction between driver and server core
* other that via this API.
*
* DO NOT MIX DRIVER ALLOCATED AND CORE ALLOCATED MEMORY.
* With this I mean that the server core should NEVER WRITE in memory
* allocated by the driver, and vice versa. Also the driver resp. core
* should free or realloc the memory that it has allocated. You can always
* simply copy a string if its data space is not 'yours'.
*/
#ifndef LCD_H #ifndef LCD_H
#define LCD_H #define LCD_H
// Maximum supported sizes /* Maximum supported sizes */
#define LCD_MAX_WIDTH 256 #define LCD_MAX_WIDTH 256
#define LCD_MAX_HEIGHT 256 #define LCD_MAX_HEIGHT 256
// Standard supported sizes /* Standard supported sizes */
#define LCD_STD_WIDTH 20 #define LCD_DEFAULT_WIDTH 20
#define LCD_STD_HEIGHT 4 #define LCD_DEFAULT_HEIGHT 4
#define LCD_STD_CELL_WIDTH 5 #define LCD_DEFAULT_CELLWIDTH 5
#define LCD_STD_CELL_HEIGHT 8 #define LCD_DEFAULT_CELLHEIGHT 8
void lcd_list_drivers (void); /* Backlight data */
int lcd_init (char *args); #define BACKLIGHT_OFF 0
int lcd_add_driver (char *driver, char *args); #define BACKLIGHT_ON 1
int lcd_shutdown (); #define BACKLIGHT_WARNING 2
#define BACKLIGHT_RED_ALERT 3
// Icons for icon function
#define ICON_BLOCK_FILLED 0
#define ICON_HEART_OPEN 8
#define ICON_HEART_FILLED 9
/* Heartbeat data, taken from render.h */
/* ??? What do all these mean ? */
#define HEART_OFF 1
#define HEART_ON 2
#define HEART_OPEN 3
#define HEARTBEAT_OFF HEART_OFF
#define HEARTBEAT_ON HEART_ON
#define HEARTBEAT_OPEN HEART_OPEN
/* Patterns for hbar / vbar */
#define BAR_POS 0x001 /* default */
#define BAR_NEG 0x002
#define BAR_POS_AND_NEG 0x003
#define BAR_PATTERN_FILLED 0x000
#define BAR_PATTERN_OPEN 0x010
#define BAR_PATTERN_STRIPED 0x020
#define BAR_WITH_PERCENTAGE 0x100
/* Cursor types */
#define CURSOR_OFF 0
#define CURSOR_DEFAULT_ON 1
#define CURSOR_BLOCK 4
#define CURSOR_UNDER 5
/* What does the shared module handle look like on the current platform? */
#define MODULE_HANDLE void*
/* And how do we define the exported functions */
#define MODULE_EXPORT static
/* WHILE NOT MODULES static BECAUSE OTHERWISE WE HAVE MULTIPLE IDENTICAL SYMBOLS */
/////////////////////////////////////////////////////////////////
// Driver functions / info held here...
//
// Feel free to override any/all functions here with real driver
// functions...
//
typedef struct lcd_logical_driver { typedef struct lcd_logical_driver {
// Size in cells of the LCD
int wid, hgt;
// Size of each LCD cell, in pixels
int cellwid, cellhgt;
// Frame buffer...
char *framebuf;
// Daemonizable? Usually yes... /* Ancient variables */
int daemonize;
// Pointer to next input function... /* For explanation of variables and functions see docs/API-v0.5.txt */
//lcd_logical_driver *nextkey;
void *nextkey;
// Functions which might be the same for all drivers... /******** Variables in the driver module ********/
void (*clear) (); /* The driver loader will look for symbols with these names ! */
void (*string) (int x, int y, char lcd[]);
void (*chr) (int x, int y, char c); char *api_version;
void (*vbar) (int x, int len); int *stay_in_foreground; /* Does this driver require to be in foreground ? */
void (*hbar) (int x, int y, int len); int *supports_multiple; /* Does this driver support multiple instances ? */
void (*init_num) (); char *func_prefix; /* What should be prepended to the function names ? */
void (*num) (int x, int num);
/******** Functions in the driver module ********/
/* The driver loader will look for symbols with these names ! */
/* Basic functions */
int (*init) (struct lcd_logical_driver* drvthis, char *args);
void (*close) (struct lcd_logical_driver* drvthis);
int (*width) (struct lcd_logical_driver* drvthis);
int (*height) (struct lcd_logical_driver* drvthis);
void (*clear) (struct lcd_logical_driver* drvthis);
void (*flush) (struct lcd_logical_driver* drvthis);
void (*string) (struct lcd_logical_driver* drvthis, int x, int y, char *str);
void (*chr) (struct lcd_logical_driver* drvthis, int x, int y, char c);
/* Extended functions */
void (*vbar) (struct lcd_logical_driver* drvthis, int x, int y, int len, int promille, int pattern);
void (*hbar) (struct lcd_logical_driver* drvthis, int x, int y, int len, int promille, int pattern);
void (*num) (struct lcd_logical_driver* drvthis, int x, int num);
void (*heartbeat) (struct lcd_logical_driver* drvthis, int state);
void (*icon) (struct lcd_logical_driver* drvthis, int x, int y, int icon);
void (*cursor) (struct lcd_logical_driver* drvthis, int x, int y, int state);
/* Userdef characters, are those still supported ? */
void (*set_char) (struct lcd_logical_driver* drvthis, int n, char *dat);
int (*get_free_chars) (struct lcd_logical_driver* drvthis);
int (*cellwidth) (struct lcd_logical_driver* drvthis);
int (*cellheight) (struct lcd_logical_driver* drvthis);
/* Hardware functions */
int (*get_contrast) (struct lcd_logical_driver* drvthis);
void (*set_contrast) (struct lcd_logical_driver* drvthis, int promille);
int (*get_brightness) (struct lcd_logical_driver* drvthis, int state);
void (*set_brightness) (struct lcd_logical_driver* drvthis, int state, int promille);
void (*backlight) (struct lcd_logical_driver* drvthis, int on);
void (*output) (struct lcd_logical_driver* drvthis, int state);
/* Key functions */
char *(*get_key) (struct lcd_logical_driver* drvthis);
/* Returns a string. Server cannot modify
this string. */
char * (*get_info) ();
/* OLD FUNCTIONS */
void (*old_vbar) (struct lcd_logical_driver* drvthis, int x, int len);
void (*old_hbar) (struct lcd_logical_driver* drvthis, int x, int y, int len);
void (*old_icon) (struct lcd_logical_driver* drvthis, int which, char dest);
/* THESE 3 TO BE REMOVED */
// Functions which should probably be implemented in each driver...
int (*init) (struct lcd_logical_driver * driver, char *args);
void (*close) ();
void (*flush) ();
void (*flush_box) (int lft, int top, int rgt, int bot);
int (*contrast) (int contrast);
void (*backlight) (int on);
void (*output) (int on);
void (*set_char) (int n, char *dat);
void (*icon) (int which, char dest);
void (*init_vbar) (); void (*init_vbar) ();
void (*init_hbar) (); void (*init_hbar) ();
void (*init_num) ();
void (*draw_frame) (); void (*draw_frame) ();
void (*flush_box) (int lft, int top, int rgt, int bot);
/* THESE 4 TO BE REMOVED */
// Returns 0 for "no key pressed", or (A-Z). /* Returns 0 for "no key pressed", or (A-Z). */
char (*getkey) (); char (*getkey) ();
/* TO BE REMOVED, IS RENAMED AND CHANGED */
// Returns pointer to static string.
char * (*getinfo) ();
// Puts up a heartbeat... /******** Variables in server core available for drivers ********/
void (*heartbeat) (int type);
// more?
// Config file functions, filled by server char * name; /* Name of this driver */
char (*config_get_bool) (char * sectionname, char * keyname, char * filename; /* Filename of the shared module */
int skip, char default_value);
int (*config_get_int) (char * sectionname, char * keyname, MODULE_HANDLE module_handle; /* The handle of the loaded shared module
int skip, int default_value); Is platform specific */
double (*config_get_float) (char * sectionname, char * keyname,
int skip, double default_value); void * private_data; /* Filled by server by calling store_private_ptr()
char *(*config_get_string) (char * sectionname, char * keyname, Driver should cast this to it's own
int skip, char * default_value); private structure pointer */
// Returns a string in server memory space.
// Copy this string.
int (*config_has_section) (char *sectionname); /******** Functions in server core available for drivers ********/
int (*config_has_key) (char *sectionname, char *keyname);
// Driver private data
int (*store_private_ptr) (struct lcd_logical_driver * driver, void * private_data); int (*store_private_ptr) (struct lcd_logical_driver * driver, void * private_data);
void * private_data; // Filled by server by calling store_private_ptr() /* Store the driver's private data */
// Driver should cast this to it's own
// private structure pointer
} lcd_logical_driver; /* Configfile functions */
/* See configfile.h for descriptions and usage. */
typedef struct lcd_physical_driver { unsigned char (*config_get_bool)( char *sectionname, char *keyname, int skip, unsigned char default_value );
long int (*config_get_int) ( char *sectionname, char *keyname, int skip, long int default_value );
double (*config_get_float) ( char *sectionname, char *keyname, int skip, double default_value );
char *( *config_get_string) ( char *sectionname, char *keyname, int skip, char *default_value );
int (*config_has_section) ( char *sectionname );
int (*config_has_key) ( char *sectionname, char *keyname );
/* Reporting function */
/* Easily usable by including drivers/report.h */
void (*report) ( const int level, const char *format, .../*args*/ );
/* Display properties functions (for drivers that adapt to other loaded drivers) */
int (*request_display_width) ();
int (*request_display_height) ();
} Driver;
void lcd_list_drivers (void); /* TO BE REMOVED WHEN WE HAVE LOADABLE MODULES */
typedef struct lcd_physical_driver { /* TO BE REMOVED WHEN WE HAVE LOADABLE MODULES */
char *name; char *name;
int (*init) (struct lcd_logical_driver * driver, char *device); int (*init) (struct lcd_logical_driver * driver, char *device);
} lcd_physical_driver; } lcd_physical_driver;
//extern lcd_logical_driver lcd;
extern lcd_logical_driver *lcd_ptr;
#endif #endif
+29 -4
View File
@@ -20,6 +20,9 @@
// driver code or headers or something... // driver code or headers or something...
#define MAX_CUSTOM_CHARS 16 #define MAX_CUSTOM_CHARS 16
/*
ANY DRIVER SHOULD SIMPLY FREE ITS FRAMEBUFFER AT CLOSE()
NO CHECKING FOR NULL NEEDED
void void
free_framebuf (struct lcd_logical_driver *driver) { free_framebuf (struct lcd_logical_driver *driver) {
if (!driver) if (!driver)
@@ -30,7 +33,10 @@ free_framebuf (struct lcd_logical_driver *driver) {
driver->framebuf = NULL; driver->framebuf = NULL;
} }
*/
/*
NEED TO BE ADAPTED TO NEW SITUATION
void void
clear_framebuf (struct lcd_logical_driver *driver) { clear_framebuf (struct lcd_logical_driver *driver) {
int framebuf_size; int framebuf_size;
@@ -41,7 +47,10 @@ clear_framebuf (struct lcd_logical_driver *driver) {
framebuf_size = driver->wid * driver->hgt; framebuf_size = driver->wid * driver->hgt;
memset (driver->framebuf, ' ', framebuf_size); memset (driver->framebuf, ' ', framebuf_size);
} }
*/
/*
NEED TO BE ADAPTED TO NEW SITUATION
int int
new_framebuf (struct lcd_logical_driver *driver, char *oldbuf) { new_framebuf (struct lcd_logical_driver *driver, char *oldbuf) {
int i; int i;
@@ -59,7 +68,10 @@ new_framebuf (struct lcd_logical_driver *driver, char *oldbuf) {
} }
return 0; return 0;
} }
*/
/*
NEED TO BE ADAPTED TO NEW SITUATION
void void
insert_str_framebuf (struct lcd_logical_driver *driver, int x, int y, char *string) { insert_str_framebuf (struct lcd_logical_driver *driver, int x, int y, char *string) {
//int i; //int i;
@@ -85,7 +97,10 @@ insert_str_framebuf (struct lcd_logical_driver *driver, int x, int y, char *stri
pos = (driver->framebuf + (y * driver->wid) + x); pos = (driver->framebuf + (y * driver->wid) + x);
strcpy(pos, buf); strcpy(pos, buf);
} }
*/
/*
NEED TO BE ADAPTED TO NEW SITUATION
void void
insert_chr_framebuf (struct lcd_logical_driver *driver, int x, int y, char c) { insert_chr_framebuf (struct lcd_logical_driver *driver, int x, int y, char c) {
if (!driver) if (!driver)
@@ -101,6 +116,7 @@ insert_chr_framebuf (struct lcd_logical_driver *driver, int x, int y, char c) {
driver->framebuf[(y * driver->wid) + x] = c; driver->framebuf[(y * driver->wid) + x] = c;
} }
*/
void void
output_heartbeat (struct lcd_logical_driver *driver, int type) { output_heartbeat (struct lcd_logical_driver *driver, int type) {
@@ -113,17 +129,26 @@ output_heartbeat (struct lcd_logical_driver *driver, int type) {
if (type == HEARTBEAT_ON) { if (type == HEARTBEAT_ON) {
// Set this to pulsate like a real heart beat... // Set this to pulsate like a real heart beat...
whichIcon = (! ((timer + 4) & 5)); if ( (timer + 4) & 5 ) {
whichIcon = ICON_HEART_OPEN;
}
else {
whichIcon = ICON_HEART_FILLED;
}
driver->icon (driver, driver->width(driver), 1, whichIcon);
/* OLD CODE
// This defines a custom character EVERY time... // This defines a custom character EVERY time...
// not efficient... is this necessary? // not efficient... is this necessary?
driver->icon (whichIcon, 0); driver->icon (driver, whichIcon, 0);
// Put character on screen... // Put character on screen...
driver->chr (driver->wid, 1, 0); driver->chr (driver, driver->wid, 1, 0);
*/
// change display... // change display...
driver->flush (); driver->flush (driver);
} }
timer++; timer++;
+142 -180
View File
@@ -42,6 +42,11 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <syslog.h> #include <syslog.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
# if TIME_WITH_SYS_TIME # if TIME_WITH_SYS_TIME
# include <sys/time.h> # include <sys/time.h>
# include <time.h> # include <time.h>
@@ -56,37 +61,24 @@
#include "lcd.h" #include "lcd.h"
#include "lcdm001.h" #include "lcdm001.h"
#include "shared/str.h" #include "shared/str.h"
#include "shared/report.h" #include "report.h"
#include "configfile.h" //#include "configfile.h"
#include "render.h"
// Moved here from lcdm001.h to reduce the number of warning.
static void lcdm001_close ();
static void lcdm001_clear ();
static void lcdm001_flush ();
static void lcdm001_string (int x, int y, char string[]);
static void lcdm001_chr (int x, int y, char c);
static void lcdm001_output (int on);
static void lcdm001_vbar (int x, int len);
static void lcdm001_hbar (int x, int y, int len);
static void lcdm001_num (int x, int num);
static void lcdm001_icon (int which, char dest);
static void lcdm001_flush_box (int lft, int top, int rgt, int bot);
static void lcdm001_draw_frame (char *dat);
static char lcdm001_getkey ();
// End of extract from lcdm001.h by David GLAUDE.
static void lcdm001_heartbeat (int type);
#define NotEnoughArgs (i + 1 > argc)
lcd_logical_driver *lcdm001;
int fd; int fd;
static int clear = 1; static int clear = 1;
static char icon_char = '@'; static char icon_char = '@';
static char pause_key = DOWN_KEY, back_key = LEFT_KEY, forward_key = RIGHT_KEY, main_menu_key = UP_KEY; static char pause_key = DOWN_KEY, back_key = LEFT_KEY, forward_key = RIGHT_KEY, main_menu_key = UP_KEY;
static char *framebuf = NULL;
static int width = LCD_DEFAULT_WIDTH;
static int height = LCD_DEFAULT_HEIGHT;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "lcdm001_";
/*this is really ugly ;) but works ;)*/
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{'|',' ','|'}, {'|',' ','|'},
{'|','_','|'}, {'|','_','|'},
@@ -127,27 +119,25 @@ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{'|','_','|'}, {'|','_','|'},
{' ','_','|'}, {' ','_','|'},
{' ',' ',' '}}}; {' ',' ',' '}}};
/*end of ugly code ;) Rene Wagner*/
static void lcdm001_cursorblink (int on); static void lcdm001_cursorblink (Driver *drvthis, int on);
static void lcdm001_string (int x, int y, char *string); static char lcdm001_parse_keypad_setting ( Driver *drvthis, char * keyname, char * default_value );
static char lcdm001_parse_keypad_setting ( char * sectionname, char * keyname, char * default_value );
#define ValidX(x) if ((x) > lcdm001->wid) { (x) = lcdm001->wid; } else (x) = (x) < 1 ? 1 : (x); #define ValidX(x) if ((x) > width) { (x) = width; } 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) > height) { (y) = height; } else (y) = (y) < 1 ? 1 : (y);
// Parse one key from the configfile // Parse one key from the configfile
static char lcdm001_parse_keypad_setting (char * sectionname, char * keyname, char * default_value) static char lcdm001_parse_keypad_setting (Driver *drvthis, char * keyname, char * default_value)
{ {
char return_val = 0; char return_val = 0;
if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "LeftKey")==0) { if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "LeftKey")==0) {
return_val=LEFT_KEY; return_val=LEFT_KEY;
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "RightKey")==0) { } else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "RightKey")==0) {
return_val=RIGHT_KEY; return_val=RIGHT_KEY;
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "UpKey")==0) { } else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "UpKey")==0) {
return_val=UP_KEY; return_val=UP_KEY;
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "DownKey")==0) { } else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "DownKey")==0) {
return_val=DOWN_KEY; return_val=DOWN_KEY;
} else { } else {
report (RPT_WARNING, "LCDM001: Invalid config file setting for %s. Using default value %s.\n", keyname, default_value); report (RPT_WARNING, "LCDM001: Invalid config file setting for %s. Using default value %s.\n", keyname, default_value);
@@ -164,10 +154,9 @@ static char lcdm001_parse_keypad_setting (char * sectionname, char * keyname, ch
return return_val; return return_val;
} }
// Set cursorblink on/off /* Set cursorblink on/off */
//
static void static void
lcdm001_cursorblink (int on) lcdm001_cursorblink (Driver *drvthis, int on)
{ {
if (on) { if (on) {
write (fd, "~K1", 3); write (fd, "~K1", 3);
@@ -179,13 +168,14 @@ lcdm001_cursorblink (int on)
} }
// TODO: Get lcd.framebuf to properly work as whatever driver is running... /* TODO: Get lcd.framebuf to properly work as whatever driver is running...*/
//////////////////////////////////////////////////////////// /*********************************************************************
// init() should set up any device-specific stuff, and * init() should set up any device-specific stuff, and
// point all the function pointers. * point all the function pointers.
*/
int int
lcdm001_init (struct lcd_logical_driver *driver, char *args) lcdm001_init (Driver *drvthis, char *args)
{ {
char device[200]; char device[200];
int speed=B38400; int speed=B38400;
@@ -193,48 +183,28 @@ lcdm001_init (struct lcd_logical_driver *driver, char *args)
char out[5]=""; char out[5]="";
lcdm001 = driver; debug( RPT_INFO, "LCDM001: init(%p,%s)", drvthis, args );
debug( RPT_INFO, "LCDM001: init(%p,%s)", driver, args ); framebuf = malloc (width * height);
driver->wid = 20; if (!framebuf) {
driver->hgt = 4;
// You must use driver->framebuf here, but may use lcd.framebuf later.
if (!driver->framebuf) {
driver->framebuf = malloc (driver->wid * driver->hgt);
}
if (!driver->framebuf) {
lcdm001_close ();
report(RPT_ERR, "\nError: unable to create LCDM001 framebuffer.\n"); report(RPT_ERR, "\nError: unable to create LCDM001 framebuffer.\n");
return -1; return -1;
} }
// Debugging... memset (framebuf, ' ', width * height);
// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf);
memset (driver->framebuf, ' ', driver->wid * driver->hgt);
// lcdm001_clear();
driver->cellwid = 5;
driver->cellhgt = 8;
// TODO: replace DriverName with driver->name when that field exists.
#define DriverName "lcdm001"
// READ CONFIG FILE: // READ CONFIG FILE:
// which serial device should be used // which serial device should be used
strncpy(device, config_get_string ( DriverName , "Device" , 0 , "/dev/lcd"), sizeof(device)); strncpy(device, drvthis->config_get_string ( drvthis->name , "Device" , 0 , "/dev/lcd"),sizeof(device));
device[sizeof(device)-1]=0; device[sizeof(device)-1]=0;
report (RPT_INFO,"LCDM001: Using device: %s", device); report (RPT_INFO,"LCDM001: Using device: %s", device);
// keypad settings // keypad settings
pause_key = lcdm001_parse_keypad_setting (DriverName, "PauseKey", "DownKey"); pause_key = lcdm001_parse_keypad_setting (drvthis, "PauseKey", "DownKey");
back_key = lcdm001_parse_keypad_setting (DriverName, "BackKey", "LeftKey"); back_key = lcdm001_parse_keypad_setting (drvthis, "BackKey", "LeftKey");
forward_key = lcdm001_parse_keypad_setting (DriverName, "ForwardKey", "RightKey"); forward_key = lcdm001_parse_keypad_setting (drvthis, "ForwardKey", "RightKey");
main_menu_key = lcdm001_parse_keypad_setting (DriverName, "MainMenuKey", "UpKey"); main_menu_key = lcdm001_parse_keypad_setting (drvthis, "MainMenuKey", "UpKey");
// 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); debug( RPT_DEBUG, "LCDM001: Opening serial device: %s", device);
@@ -256,10 +226,10 @@ lcdm001_init (struct lcd_logical_driver *driver, char *args)
} }
tcgetattr(fd, &portset); tcgetattr(fd, &portset);
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
// The easy way /* The easy way: */
cfmakeraw( &portset ); cfmakeraw( &portset );
#else #else
// The hard way /* The hard way: */
portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON ); | INLCR | IGNCR | ICRNL | IXON );
portset.c_oflag &= ~OPOST; portset.c_oflag &= ~OPOST;
@@ -275,59 +245,60 @@ lcdm001_init (struct lcd_logical_driver *driver, char *args)
// Reset and clear the LCDM001 // Reset and clear the LCDM001
write (fd, "~C", 2); write (fd, "~C", 2);
//Set cursorblink default //Set cursorblink default
lcdm001_cursorblink (DEFAULT_CURSORBLINK); lcdm001_cursorblink (drvthis, DEFAULT_CURSORBLINK);
// Turn all LEDs off // Turn all LEDs off
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);
/* // Set variables for server
* Configure the display functions drvthis->api_version = api_version;
*/ drvthis->stay_in_foreground = &stay_in_foreground;
driver->daemonize = 1; // daemonize. drvthis->supports_multiple = &supports_multiple;
driver->clear = lcdm001_clear; // Set the functions the driver supports
driver->string = lcdm001_string; drvthis->clear = lcdm001_clear;
driver->chr = lcdm001_chr; drvthis->width = lcdm001_width;
driver->vbar =lcdm001_vbar; drvthis->height = lcdm001_height;
drvthis->string = lcdm001_string;
drvthis->chr = lcdm001_chr;
drvthis->old_vbar =lcdm001_vbar;
//init_vbar is not needed //init_vbar is not needed
driver->hbar = lcdm001_hbar; drvthis->old_hbar = lcdm001_hbar;
//init_hbar is not needed //init_hbar is not needed
driver->num = lcdm001_num; drvthis->num = lcdm001_num;
//init_num is not needed //init_num is not needed
driver->init = lcdm001_init; drvthis->init = lcdm001_init;
driver->close = lcdm001_close; drvthis->close = lcdm001_close;
driver->flush = lcdm001_flush; drvthis->flush = lcdm001_flush;
driver->flush_box = lcdm001_flush_box;
//contrast and backlight are not implemented as //contrast and backlight are not implemented as
//changing the contrast or the state of the backlight //changing the contrast or the state of the backlight
//is not supported by the device //is not supported by the device
//Well ... you could make use of your screw driver and //Well ... you could make use of your screw drvthis and
//soldering iron ;) //soldering iron ;)
driver->output = lcdm001_output; drvthis->output = lcdm001_output;
//set_char is not implemented as custom chars are not //set_char is not implemented as custom chars are not
//supported by the device //supported by the device
driver->icon = lcdm001_icon; drvthis->old_icon = lcdm001_icon;
driver->draw_frame = lcdm001_draw_frame;
driver->getkey = lcdm001_getkey; drvthis->getkey = lcdm001_getkey;
driver->heartbeat = lcdm001_heartbeat; drvthis->heartbeat = lcdm001_heartbeat;
return fd; return 0;
} }
// Below here, you may use either lcd.framebuf or driver->framebuf.. /* Below here, you may use either lcd.framebuf or driver->framebuf..
// lcd.framebuf will be set to the appropriate buffer before calling * lcd.framebuf will be set to the appropriate buffer before calling
// your driver. * your driver.
*/
static void MODULE_EXPORT void
lcdm001_close () lcdm001_close (Driver *drvthis)
{ {
char out[5]; char out[5];
if (lcdm001->framebuf != NULL) if(framebuf) free (framebuf);
free (lcdm001->framebuf); framebuf = NULL;
lcdm001->framebuf = NULL;
//switch off all LEDs //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);
@@ -336,14 +307,32 @@ lcdm001_close ()
report (RPT_INFO, "LCDM001: closed"); report (RPT_INFO, "LCDM001: closed");
} }
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
lcdm001_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
lcdm001_height (Driver *drvthis)
{
return height;
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
static void MODULE_EXPORT void
lcdm001_clear () lcdm001_clear (Driver *drvthis)
{ {
if (lcdm001->framebuf != NULL) if (framebuf != NULL)
memset (lcdm001->framebuf, ' ', (lcdm001->wid * lcdm001->hgt)); memset (framebuf, ' ', (width * height));
write (fd, "~C", 2); // instant clear... write (fd, "~C", 2); // instant clear...
clear = 1; clear = 1;
@@ -354,38 +343,24 @@ lcdm001_clear ()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
lcdm001_flush () lcdm001_flush (Driver *drvthis)
{ {
lcdm001_draw_frame(lcdm001->framebuf); // Next 4 lines are moved from draw_frame (Joris)
//TODO: Check whether this is still correct
write(fd,framebuf,80);
debug (RPT_DEBUG, "LCDM001: frame buffer flushed"); debug (RPT_DEBUG, "LCDM001: frame buffer flushed");
} }
//////////////////////////////////////////////////////////////////////
// Send a rectangular area to the display.
//
static void
lcdm001_flush_box (int lft, int top, int rgt, int bot)
{
int y;
char out[LCD_MAX_WIDTH];
for (y = top; y <= bot; y++) {
snprintf (out, sizeof(out), "%cP%c%c", 126, lft, y);
write (fd, out, 4);
write (fd, lcdm001->framebuf + (y * lcdm001->wid) + lft, rgt - lft + 1);
}
debug (RPT_DEBUG, "LCDM001: frame buffer box flushed");
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
static void MODULE_EXPORT void
lcdm001_chr (int x, int y, char c) lcdm001_chr (Driver *drvthis, int x, int y, char c)
{ {
char buf[64]; // char out[10]; char buf[64]; // char out[10];
int offset; int offset;
@@ -400,8 +375,8 @@ lcdm001_chr (int x, int y, char c)
// write to frame buffer // write to frame buffer
y--; x--; // translate to 0-coords y--; x--; // translate to 0-coords
offset = (y * lcdm001->wid) + x; offset = (y * width) + x;
lcdm001->framebuf[offset] = c; framebuf[offset] = c;
snprintf(buf, sizeof(buf), "LCDM001: writing character %02X to position (%d,%d)", c, x, y); snprintf(buf, sizeof(buf), "LCDM001: writing character %02X to position (%d,%d)", c, x, y);
debug (RPT_DEBUG, buf); debug (RPT_DEBUG, buf);
@@ -411,8 +386,8 @@ lcdm001_chr (int x, int y, char c)
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
static void MODULE_EXPORT void
lcdm001_string (int x, int y, char string[]) lcdm001_string (Driver *drvthis, int x, int y, char *string)
{ {
int offset, siz; int offset, siz;
@@ -420,53 +395,53 @@ lcdm001_string (int x, int y, char string[])
ValidY(y); ValidY(y);
x--; y--; // Convert 1-based coords to 0-based... x--; y--; // Convert 1-based coords to 0-based...
offset = (y * lcdm001->wid) + x; offset = (y * width) + x;
siz = (lcdm001->wid * lcdm001->hgt) - offset - 1; siz = (width * height) - offset - 1;
siz = siz > strlen(string) ? strlen(string) : siz; siz = siz > strlen(string) ? strlen(string) : siz;
memcpy(lcdm001->framebuf + offset, string, siz); memcpy(framebuf + offset, string, siz);
debug (RPT_DEBUG, "LCDM001: printed string at (%d,%d)", x, y); debug (RPT_DEBUG, "LCDM001: printed string at (%d,%d)", x, y);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Controls LEDs // Controls LEDs
static void MODULE_EXPORT void
lcdm001_output (int on) lcdm001_output (Driver *drvthis, int state)
{ {
char out[5]; char out[5];
int one = 0, two = 0; int one = 0, two = 0;
if (on<=255) if (state<=255)
{ {
one=on; one=state;
two=0; two=0;
} }
else else
{ {
one = on & 0xff; one = state & 0xff;
two = (on >> 8) & 0xff; two = (state >> 8) & 0xff;
} }
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);
debug (RPT_DEBUG, "LCDM001: current LED state: %d", on); debug (RPT_DEBUG, "LCDM001: current LED state: %d", state);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up. // Draws a vertical bar, from the bottom of the screen up.
// //
static void MODULE_EXPORT void
lcdm001_vbar(int x, int len) lcdm001_vbar(Driver *drvthis, int x, int len)
{ {
int y = 4; int y = 4;
debug (RPT_DEBUG , "LCDM001: vertical bar at %d set to %d", x, len); debug (RPT_DEBUG , "LCDM001: vertical bar at %d set to %d", x, len);
while (len >= 8) while (len >= LCD_DEFAULT_CELLHEIGHT)
{ {
lcdm001_chr(x, y, 0xFF); lcdm001_chr(drvthis, x, y, 0xFF);
len -= 8; len -= LCD_DEFAULT_CELLHEIGHT;
y--; y--;
} }
@@ -480,8 +455,8 @@ lcdm001_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
static void MODULE_EXPORT void
lcdm001_hbar(int x, int y, int len) lcdm001_hbar(Driver *drvthis, int x, int y, int len)
{ {
ValidX(x); ValidX(x);
@@ -491,16 +466,16 @@ lcdm001_hbar(int x, int y, int len)
//TODO: Improve this function //TODO: Improve this function
while((x <= lcdm001->wid) && (len > 0)) while((x <= width) && (len > 0))
{ {
if(len < lcdm001->cellwid) if(len < LCD_DEFAULT_CELLWIDTH)
{ {
//lcdm001_chr(x, y, 0x98 + len); //lcdm001_chr(x, y, 0x98 + len);
break; break;
} }
lcdm001_chr(x, y, 0xFF); lcdm001_chr(drvthis, x, y, 0xFF);
len -= lcdm001->cellwid; len -= LCD_DEFAULT_CELLWIDTH;
x++; x++;
} }
@@ -510,7 +485,8 @@ lcdm001_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
static void lcdm001_num (int x, int num) MODULE_EXPORT void
lcdm001_num (Driver *drvthis, int x, int num)
{ {
int y, dx; int y, dx;
@@ -520,14 +496,14 @@ static void lcdm001_num (int x, int num)
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 (drvthis, x + dx, y, num_icon[num][y-1][dx]);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void MODULE_EXPORT void
lcdm001_icon (int which, char dest) lcdm001_icon (Driver *drvthis, int which, char dest)
{ {
/*Heartbeat workaround: /*Heartbeat workaround:
@@ -549,27 +525,13 @@ lcdm001_icon (int which, char dest)
} }
} }
//////////////////////////////////////////////////////////////////////
// Draws the framebuffer on the display.
//
// The commented-out code is from the text driver.
//
void
lcdm001_draw_frame (char *dat)
{
//TODO: Check whether this is still correct
write(fd,lcdm001->framebuf,80);
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device... // Tries to read a character from an input device...
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
static char MODULE_EXPORT char
lcdm001_getkey () lcdm001_getkey (Driver *drvthis)
{ {
char in = 0; char in = 0;
read (fd, &in, 1); read (fd, &in, 1);
@@ -589,8 +551,8 @@ lcdm001_getkey ()
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Does the heartbeat... // Does the heartbeat...
// //
static void MODULE_EXPORT void
lcdm001_heartbeat (int type) lcdm001_heartbeat (Driver *drvthis, int type)
{ {
static int timer = 0; static int timer = 0;
int whichIcon; int whichIcon;
@@ -605,13 +567,13 @@ lcdm001_heartbeat (int type)
// This defines a custom character EVERY time... // This defines a custom character EVERY time...
// not efficient... is this necessary? // not efficient... is this necessary?
lcdm001_icon (whichIcon, 0); lcdm001_icon (drvthis, whichIcon, 0);
// Put character on screen... // Put character on screen...
lcdm001_chr (lcdm001->wid, 1, 0); lcdm001_chr (drvthis, width, 1, 0);
// change display... // change display...
lcdm001_flush (); lcdm001_flush (drvthis);
} }
timer++; timer++;
+21 -4
View File
@@ -30,10 +30,27 @@
lcdm001.h lcdm001.h
******************************************************************/ ******************************************************************/
// REMOVE: I don't thing this is actualy needed. /* REMOVE: I don't thing this is actualy needed. */
// extern lcd_logical_driver *lcdm001; /* extern lcd_logical_driver *lcdm001; */
int lcdm001_init (struct lcd_logical_driver *driver, char *args); int lcdm001_init (struct lcd_logical_driver *driver, char *args);
MODULE_EXPORT void lcdm001_close (Driver *drvthis);
MODULE_EXPORT int lcdm001_width (Driver *drvthis);
MODULE_EXPORT int lcdm001_height (Driver *drvthis);
MODULE_EXPORT void lcdm001_clear (Driver *drvthis);
MODULE_EXPORT void lcdm001_flush (Driver *drvthis);
MODULE_EXPORT void lcdm001_string (Driver *drvthis, int x, int y, char *string);
MODULE_EXPORT void lcdm001_chr (Driver *drvthis, int x, int y, char c);
MODULE_EXPORT void lcdm001_vbar (Driver *drvthis, int x, int len);
MODULE_EXPORT void lcdm001_hbar (Driver *drvthis, int x, int y, int len);
MODULE_EXPORT void lcdm001_num (Driver *drvthis, int x, int num);
MODULE_EXPORT void lcdm001_icon (Driver *drvthis, int which, char dest);
MODULE_EXPORT void lcdm001_heartbeat (Driver *drvthis, int type);
MODULE_EXPORT void lcdm001_output (Driver *drvthis, int on);
MODULE_EXPORT char lcdm001_getkey (Driver *drvthis);
#define DEFAULT_DEVICE "/dev/lcd" #define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_CURSORBLINK 0 #define DEFAULT_CURSORBLINK 0
@@ -41,7 +58,7 @@ int lcdm001_init (struct lcd_logical_driver *driver, char *args);
/*Heartbeat workaround /*Heartbeat workaround
set chars to be displayed instead of "normal" icons*/ set chars to be displayed instead of "normal" icons*/
#define OPEN_HEART ' ' //This combination is at least visible #define OPEN_HEART ' ' /* This combination is at least visible */
#define FILLED_HEART '*' #define FILLED_HEART '*'
#define PAD 255 #define PAD 255
+20 -12
View File
@@ -17,7 +17,6 @@
#define __u32 unsigned int #define __u32 unsigned int
#define __u8 unsigned char #define __u8 unsigned char
#include "shared/debug.h"
#include "shared/str.h" #include "shared/str.h"
#define NAME_LENGTH 128 #define NAME_LENGTH 128
@@ -33,12 +32,17 @@ struct sockaddr_un addr;
static struct lirc_config *config; static struct lirc_config *config;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "LB216_";
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// Base "class" to derive from /////////////////////// ////////////////////// Base "class" to derive from ///////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
lcd_logical_driver *lircin;
//void sigterm(int sig) //void sigterm(int sig)
//{ //{
// ir_free_commands(); // ir_free_commands();
@@ -46,8 +50,8 @@ lcd_logical_driver *lircin;
// raise(sig); // raise(sig);
//} //}
void MODULE_EXPORT void
lircin_close () lircin_close (Driver * drvthis)
{ {
lirc_freeconfig (config); lirc_freeconfig (config);
lirc_deinit (); lirc_deinit ();
@@ -58,8 +62,8 @@ lircin_close ()
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char MODULE_EXPORT char
lircin_getkey () lircin_getkey (Driver * drvthis)
{ {
char key; char key;
char *ir, *cmd; char *ir, *cmd;
@@ -84,15 +88,19 @@ lircin_getkey ()
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int int
lircin_init (struct lcd_logical_driver *driver, char *args) lircin_init (Driver * drvthis, char *args)
{ {
/* assign funktions */ /* assign funktions */
lircin = driver; // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->getkey = lircin_getkey; // Set the functions the driver supports
driver->close = lircin_close; drvthis->getkey = lircin_getkey;
drvthis->close = lircin_close;
/* open socket to lirc */ /* open socket to lirc */
@@ -113,5 +121,5 @@ lircin_init (struct lcd_logical_driver *driver, char *args)
fcntl (fd, F_SETFL, O_NONBLOCK); fcntl (fd, F_SETFL, O_NONBLOCK);
fcntl (fd, F_SETFD, FD_CLOEXEC); fcntl (fd, F_SETFD, FD_CLOEXEC);
return 1; // 200 is arbitrary. (must be 1 or more) return 0;
} }
+4 -4
View File
@@ -1,10 +1,10 @@
#ifndef LCD_LIRCIN_H #ifndef LCD_LIRCIN_H
#define LCD_LIRCIN_H #define LCD_LIRCIN_H
extern lcd_logical_driver *lircin; #include "lcd.h"
int lircin_init (struct lcd_logical_driver *driver, char *args); int lircin_init (Driver * drvthis, char *args);
void lircin_close (); MODULE_EXPORT void lircin_close (Driver * drvthis);
char lircin_getkey (); MODULE_EXPORT char lircin_getkey (Driver * drvthis);
#endif #endif
+37
View File
@@ -0,0 +1,37 @@
#ifndef REPORT_H
#define REPORT_H
/* DEBUGGING / REPORTING FOR DRIVERS
*
* This file uses the reporting functions from the server core.
* See the file shared/report.h for details.
*
* This file assumes that the drivers have a drvthis parameter that contains the
* current driver structure. It redefines report to make its use simple:
*
* report( RPT_ERR, "report this: %s", str );
* debug( RPT_ERR, "report this if debug enabled: %s", str );
*
*/
// Reporting levels
#define RPT_CRIT 0
#define RPT_ERR 1
#define RPT_WARNING 2
#define RPT_NOTICE 3
#define RPT_INFO 4
#define RPT_DEBUG 5
#define report drvthis->report
// This assumes drvthis is locally defined... Anyone has a better idea ?
static inline void dont_report( const int level, const char *format, .../*args*/ )
{} // The idea is that this gets optimized out
#ifdef DEBUG
# define debug report
#else
# define debug dont_report
#endif /*DEBUG*/
#endif
+246 -214
View File
@@ -18,6 +18,8 @@
* November 2001, Joris Robijn: * November 2001, Joris Robijn:
* - Created the driver * - Created the driver
* - Parts copied from HD44780 driver * - Parts copied from HD44780 driver
* December 2001, Joris Robijn:
* - Adapted to v0.5 API
* *
* *
* *
@@ -163,10 +165,11 @@
* *
*/ */
#include "lcd.h"
#include "sed1330.h" #include "sed1330.h"
#include "port.h" #include "port.h"
#include "lpt-port.h" #include "lpt-port.h"
#include "lcd.h"
#include "shared/str.h" #include "shared/str.h"
#include "shared/report.h" #include "shared/report.h"
#include "configfile.h" #include "configfile.h"
@@ -217,7 +220,7 @@
#define PIXELSPERBYTE CHARWIDTH #define PIXELSPERBYTE CHARWIDTH
// The above should be (CHARWIDTH/2) if CHARWIDTH > 8 // The above should be (CHARWIDTH/2) if CHARWIDTH > 8
typedef struct private_data { typedef struct p {
int type; int type;
int port; int port;
char * keymap[MAXKEYS]; char * keymap[MAXKEYS];
@@ -225,161 +228,172 @@ typedef struct private_data {
char * lcd_contents_text; char * lcd_contents_text;
char * framebuf_graph; char * framebuf_graph;
char * lcd_contents_graph; char * lcd_contents_graph;
int width, height;
//int cellwidth, cellheight;
int graph_width, graph_height; int graph_width, graph_height;
int cursor_x, cursor_y; int cursor_x, cursor_y;
char cursor_state; char cursor_state;
int bytesperline; int bytesperline;
} private_data; } PrivateData;
// Vars for the server core
MODULE_EXPORT char * api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 1; // yes, we have no global variables (except for constants)
MODULE_EXPORT char *symbol_prefix = "sed1330_";
// Local functions // Local functions
void uPause (int usecs); void uPause (int usecs);
void sed1330_command( char command, int datacount, char * data ); void sed1330_command( PrivateData * p, char command, int datacount, char * data );
void sed1330_update_cursor(); void sed1330_update_cursor( PrivateData * p );
void sed1330_rect ( int x1, int y1, int x2, int y2, char pattern ); void sed1330_rect( PrivateData * p, int x1, int y1, int x2, int y2, char pattern );
inline void sed1330_set_pixel( int x, int y ); inline void sed1330_set_pixel( PrivateData * p, int x, int y );
inline void sed1330_clear_pixel( int x, int y ); inline void sed1330_clear_pixel( PrivateData * p, int x, int y );
// Global vars
static lcd_logical_driver * sed1330;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Init the driver and display // Init the driver and display
// //
int int
sed1330_init( lcd_logical_driver * driver, char *args ) sed1330_init( Driver * drvthis, char *args )
{ {
char * s; char * s;
int port, i; int port, i;
private_data * data; PrivateData * p;
sed1330 = driver; debug( RPT_INFO, "SED1330: init(%p,%s)", drvthis, args );
debug( RPT_INFO, "SED1330: init(%p,%s)", driver, args );
// TODO: replace DriverName with driver->name when that field exists. // TODO: replace DriverName with driver->name when that field exists.
#define DriverName "sed1330"
// Alocate and store private data // Alocate and store private p
data = (private_data *) malloc( sizeof( private_data) ); p = (PrivateData *) malloc( sizeof(PrivateData) );
if( ! data ) if( ! p )
return -1; return -1;
if( driver->store_private_ptr( driver, data ) ) if( drvthis->store_private_ptr( drvthis, p ) )
return -1; return -1;
// Clear keymap // Clear keymap
memset( data->keymap, 0, sizeof(data->keymap) ); memset( p->keymap, 0, sizeof(p->keymap) );
// READ THE CONFIG FILE // READ THE CONFIG FILE
// Port // Port
port = config_get_int( DriverName, "port", 0, 0x278 ); port = config_get_int( drvthis->name, "port", 0, 0x278 );
data->port = port; p->port = port;
// Type // Type
s = driver->config_get_string( DriverName, "type", 0, NULL ); s = drvthis->config_get_string( drvthis->name, "type", 0, NULL );
if( !s ) { if( !s ) {
report( RPT_ERR, "SED1330: you need to specify the display type" ); report( RPT_ERR, "SED1330: you need to specify the display type" );
} else if( strcmp( s, "G321D" ) == 0 ) { } else if( strcmp( s, "G321D" ) == 0 ) {
data->type = TYPE_G321D; p->type = TYPE_G321D;
data->graph_width = 320; p->graph_width = 320;
data->graph_height = 200; p->graph_height = 200;
} else if( strcmp( s, "G121C" ) == 0 ) { } else if( strcmp( s, "G121C" ) == 0 ) {
data->type = TYPE_G121C; p->type = TYPE_G121C;
data->graph_width = 128; p->graph_width = 128;
data->graph_height = 128; p->graph_height = 128;
} else if( strcmp( s, "G242C" ) == 0 ) { } else if( strcmp( s, "G242C" ) == 0 ) {
data->type = TYPE_G242C; p->type = TYPE_G242C;
data->graph_width = 240; p->graph_width = 240;
data->graph_height = 128; p->graph_height = 128;
} else { } else {
report( RPT_ERR, "SED1330: Unknown display type: %s", s ); report( RPT_ERR, "SED1330: Unknown display type: %s", s );
return -1; return -1;
} }
driver->wid = data->graph_width / CHARWIDTH; p->width = p->graph_width / CHARWIDTH;
driver->hgt = data->graph_height / CHARHEIGHT; p->height = p->graph_height / CHARHEIGHT;
data->bytesperline = (data->graph_width - 1 ) / CHARWIDTH + 1; p->bytesperline = (p->graph_width - 1 ) / CHARWIDTH + 1;
report( RPT_INFO, "SED1330: Using LCD type: %s", s ); report( RPT_INFO, "SED1330: Using LCD type: %s", s );
report( RPT_INFO, "SED1330: Text size: %dx%d", driver->wid, driver->hgt ); report( RPT_INFO, "SED1330: Text size: %dx%d", p->width, p->height );
// Keymap // Keymap
for( i=0; i<MAXKEYS; i++ ) { for( i=0; i<MAXKEYS; i++ ) {
char buf[8]; char buf[8];
sprintf( buf, "key_%1d", i ); sprintf( buf, "key_%1d", i );
s = driver->config_get_string( DriverName, buf, 0, NULL ); s = drvthis->config_get_string( drvthis->name, buf, 0, NULL );
if( s ) { if( s ) {
data->keymap[i] = (char *) malloc( strlen(s)+1 ); p->keymap[i] = (char *) malloc( strlen(s)+1 );
strcpy( data->keymap[i], s ); strcpy( p->keymap[i], s );
report( RPT_INFO, "SED1330: Key %d: \"%s\"", i, s ); report( RPT_INFO, "SED1330: Key %d: \"%s\"", i, s );
} else { } else {
data->keymap[i] = ""; // Pointing to an constant empty string p->keymap[i] = ""; // Pointing to an constant empty string
} }
} }
// Init cursor data // Init cursor p
data->cursor_x = 1; p->cursor_x = 1;
data->cursor_y = 1; p->cursor_y = 1;
data->cursor_state = 1; p->cursor_state = 1;
// Allocate framebuffer // Allocate framebuffer
data->framebuf_text = (unsigned char *) malloc( data->bytesperline * driver->hgt ); p->framebuf_text = (unsigned char *) malloc( p->bytesperline * p->height );
if( ! data->framebuf_text ) if( ! p->framebuf_text )
return -1; return -1;
memset( data->framebuf_text, ' ', data->bytesperline * driver->hgt); memset( p->framebuf_text, ' ', p->bytesperline * p->height);
data->lcd_contents_text = (unsigned char *) malloc( data->bytesperline * driver->hgt ); p->lcd_contents_text = (unsigned char *) malloc( p->bytesperline * p->height );
if( ! data->lcd_contents_text ) if( ! p->lcd_contents_text )
return -1; return -1;
memset( data->lcd_contents_text, 0, data->bytesperline * driver->hgt); memset( p->lcd_contents_text, 0, p->bytesperline * p->height);
data->framebuf_graph = (unsigned char *) malloc( data->bytesperline * data->graph_height ); p->framebuf_graph = (unsigned char *) malloc( p->bytesperline * p->graph_height );
if( ! data->framebuf_graph ) if( ! p->framebuf_graph )
return -1; return -1;
memset( data->framebuf_graph, 0, data->bytesperline * data->graph_height ); memset( p->framebuf_graph, 0, p->bytesperline * p->graph_height );
data->lcd_contents_graph = (unsigned char *) malloc( data->bytesperline * data->graph_height ); p->lcd_contents_graph = (unsigned char *) malloc( p->bytesperline * p->graph_height );
if( ! data->lcd_contents_graph ) if( ! p->lcd_contents_graph )
return -1; return -1;
memset( data->lcd_contents_graph, 0xFF, data->bytesperline * data->graph_height ); memset( p->lcd_contents_graph, 0xFF, p->bytesperline * p->graph_height );
// Arrange for access to port // Arrange for access to port
debug( RPT_DEBUG, "SED1330: getting port access" ); debug( RPT_DEBUG, "SED1330: getting port access" );
port_access(data->port); port_access(p->port);
port_access(data->port+1); port_access(p->port+1);
port_access(data->port+2); port_access(p->port+2);
if (timing_init() == -1) if (timing_init() == -1)
return -1; return -1;
// Set variables for server
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->api_version = api_version;
drvthis->supports_multiple = &supports_multiple;
// Set the functions the driver supports... // Set the functions the driver supports...
driver->init = sed1330_init; drvthis->init = sed1330_init;
driver->close = sed1330_close; drvthis->close = sed1330_close;
driver->flush = sed1330_flush;
driver->clear = sed1330_clear;
driver->chr = sed1330_chr;
driver->string = sed1330_string;
//driver->init_vbar = sed1330_init_vbar;
//driver->init_hbar = sed1330_init_hbar;
driver->vbar = sed1330_vbar;
driver->hbar = sed1330_hbar;
//driver->init_num = sed1330_init_num;
driver->num = sed1330_num;
driver->heartbeat = sed1330_heartbeat;
//driver->set_char = sed1330_set_char;
//driver->icon = sed1330_icon;
// driver->contrast = sed1330_contrast; // contrast is set by potmeter we assume drvthis->width = sed1330_width;
// driver->output = sed1330_output; // not implemented drvthis->height = sed1330_height;
// driver->flush_box = sed1330_flush_box; // NOT SUPPORTED ANYMORE drvthis->flush = sed1330_flush;
// driver->draw_frame = sed1330_draw_frame; // NOT SUPPORTED ANYMORE drvthis->clear = sed1330_clear;
drvthis->chr = sed1330_chr;
drvthis->string = sed1330_string;
//drvthis->init_vbar = sed1330_init_vbar;
//drvthis->init_hbar = sed1330_init_hbar;
drvthis->vbar = sed1330_vbar;
drvthis->hbar = sed1330_hbar;
//drvthis->init_num = sed1330_init_num;
drvthis->num = sed1330_num;
drvthis->heartbeat = sed1330_heartbeat;
//drvthis->set_char = sed1330_set_char;
//drvthis->icon = sed1330_icon;
// drvthis->contrast = sed1330_contrast; // contrast is set by potmeter we assume
// drvthis->output = sed1330_output; // not implemented
// drvthis->flush_box = sed1330_flush_box; // NOT SUPPORTED ANYMORE
// drvthis->draw_frame = sed1330_draw_frame; // NOT SUPPORTED ANYMORE
// INITIALIZE THE LCD // INITIALIZE THE LCD
@@ -393,65 +407,63 @@ sed1330_init( lcd_logical_driver * driver, char *args )
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET
uPause( 3000 ); uPause( 3000 );
switch( data->type ) { switch( p->type ) {
case TYPE_G321D: case TYPE_G321D:
sed1330_command( CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x34,0x38,0xC7,0x36,0x00}) ); // Set textmode 53x20 sed1330_command( p, CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x34,0x38,0xC7,0x36,0x00}) ); // Set textmode 53x20
sed1330_command( CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations sed1330_command( p, CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations
break; break;
case TYPE_G121C: case TYPE_G121C:
sed1330_command( CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x14,0x18,0x7F,0x16,0x00}) ); // Set textmode 21x12 sed1330_command( p, CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x14,0x18,0x7F,0x16,0x00}) ); // Set textmode 21x12
sed1330_command( CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations sed1330_command( p, CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations
break; break;
case TYPE_G242C: case TYPE_G242C:
sed1330_command( CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x27,0x2B,0x7F,0x29,0x00}) ); // Set textmode 40x12 sed1330_command( p, CMD_SYSTEM_SET, 8, ((char[8]) {0x30,0x80+CHARWIDTH-1,CHARHEIGHT-1,0x27,0x2B,0x7F,0x29,0x00}) ); // Set textmode 40x12
sed1330_command( CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations sed1330_command( p, CMD_SCROLL, 10, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations
break; break;
default: default:
return -1; return -1;
} }
sed1330_command( CMD_CSR_FORM, 2, ((char[2]) {0x04,0x07}) ); // 5x8 cursor sed1330_command( p, CMD_CSR_FORM, 2, ((char[2]) {0x04,0x07}) ); // 5x8 cursor
sed1330_command( CMD_HDOT_SCR, 1, ((char[1]) {0x00}) ); // horizontal pixel shift=0 sed1330_command( p, CMD_HDOT_SCR, 1, ((char[1]) {0x00}) ); // horizontal pixel shift=0
sed1330_command( CMD_OVLAY, 1, ((char[1]) {0x01}) ); // XOR mode, screen1 text, screen3 text (screen2 and screen4 are always graph) sed1330_command( p, CMD_OVLAY, 1, ((char[1]) {0x01}) ); // XOR mode, screen1 text, screen3 text (screen2 and screen4 are always graph)
sed1330_command( CMD_DISP_DIS, 1, ((char[1]) {0x17}) ); // display off, set cursor slow, screen1 on, screen2 on, screen3 off sed1330_command( p, CMD_DISP_DIS, 1, ((char[1]) {0x17}) ); // display off, set cursor slow, screen1 on, screen2 on, screen3 off
sed1330_command( CMD_CSR_DIR_R, 0, NULL ); // cursor move right sed1330_command( p, CMD_CSR_DIR_R, 0, NULL ); // cursor move right
sed1330_flush(); // Clear the contents of the LCD sed1330_flush( drvthis ); // Clear the contents of the LCD
sed1330_command( CMD_DISP_EN, 0, NULL ); // And display on sed1330_command( p, CMD_DISP_EN, 0, NULL ); // And display on
return 0; return 0;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Send a command and accompanying data // Send a command and accompanying p
// INTERNAL // INTERNAL
// //
void void
sed1330_command( char command, int datacount, char * data ) sed1330_command( PrivateData * p, char command, int datacount, char * data )
{ {
private_data * private_data = sed1330->private_data;
int i; int i;
int port = private_data->port; int port = p->port;
debug( RPT_INFO, "sed1330_command %x #data=%d", command, datacount ); port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // set A0 to indicate command
port_out( port, command ); // set up p
port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // set A0 to indicate command
port_out( port, command ); // set up data
//uPause( 1 ); //uPause( 1 );
port_out( port+2, (nRESET|A0) ^ OUTMASK ); // activate ^WR port_out( port+2, (nRESET|A0) ^ OUTMASK ); // activate ^WR
uPause( 1 ); uPause( 1 );
port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // deactivate ^WR again port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // deactivate ^WR again
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // clear A0 to indicate data port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // clear A0 to indicate p
for( i=0; i<datacount; i ++ ) { for( i=0; i<datacount; i ++ ) {
port_out( port, data[i] ); // set up data port_out( port, data[i] ); // set up data
//uPause( 1 ); //uPause( 1 );
port_out( port+2, (nRESET) ^ OUTMASK ); // activate ^WR port_out( port+2, (nRESET) ^ OUTMASK ); // activate ^WR
uPause( 1 ); uPause( 1 );
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // deactivate ^WR again port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // deactivate ^WR again
} }
} }
@@ -460,22 +472,19 @@ sed1330_command( char command, int datacount, char * data )
// Update cursor showing // Update cursor showing
// INTERNAL // INTERNAL
// //
void sed1330_update_cursor() void sed1330_update_cursor( PrivateData * p )
{ {
private_data * data = sed1330->private_data;
int cursor_pos; int cursor_pos;
char csrloc[2]; char csrloc[2];
char csrform[2]; char csrform[2];
char disp_en; char disp_en;
char fc; // named after CF register in SED1330 char fc = 0; // named after FC register in SED1330
debug( RPT_INFO, "sed1330_update_cursor" ); cursor_pos = (p->cursor_y-1) * p->bytesperline + (p->cursor_x-1) + 256 * SCR1_H + SCR1_L;
cursor_pos = (data->cursor_y-1) * data->bytesperline + (data->cursor_x-1) + 256 * SCR1_H + SCR1_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
csrloc[1] = cursor_pos / 256; csrloc[1] = cursor_pos / 256;
switch( data->cursor_state ) { switch( p->cursor_state ) {
case 0: // Off case 0: // Off
fc = 0; fc = 0;
csrform[0] = 0x04; csrform[0] = 0x04;
@@ -494,63 +503,85 @@ void sed1330_update_cursor()
} }
disp_en = 0x14 + fc; disp_en = 0x14 + fc;
sed1330_command( CMD_CSRW, 2, csrloc ); sed1330_command( p, CMD_CSRW, 2, csrloc );
sed1330_command( CMD_DISP_EN, 1, &disp_en ); // cursor on sed1330_command( p, CMD_DISP_EN, 1, &disp_en ); // cursor on
sed1330_command( CMD_CSR_FORM, 2, csrform ); // 5x8 cursor sed1330_command( p, CMD_CSR_FORM, 2, csrform ); // 5x8 cursor
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Close the display // Close the display
// //
void MODULE_EXPORT void
sed1330_close() sed1330_close( Driver * drvthis )
{ {
PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_close" ); debug( RPT_INFO, "sed1330_close" );
//sed1330_command( CMD_DISP_DIS, 0, NULL ); // display off free( p );
//port_out( port+2, (nWR) ^ OUTMASK ); // give LCD reset signal }
// LCD now will not respond anymore
// We should take the -24V away before removing the 5V !
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
sed1330_width( Driver * drvthis )
{
PrivateData * p = drvthis->private_data;
return p->width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
sed1330_height( Driver * drvthis )
{
PrivateData * p = drvthis->private_data;
return p->height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clear the framebuffer // Clear the framebuffer
// //
void MODULE_EXPORT void
sed1330_clear() sed1330_clear( Driver * drvthis )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_clear" ); debug( RPT_INFO, "sed1330_clear" );
memset( data->framebuf_text, ' ', data->bytesperline * sed1330->hgt); memset( p->framebuf_text, ' ', p->bytesperline * p->height);
memset( data->framebuf_graph, 0, data->bytesperline * data->graph_height ); memset( p->framebuf_graph, 0, p->bytesperline * p->graph_height );
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Place a string in the framebuffer // Place a string in the framebuffer
// //
void MODULE_EXPORT void
sed1330_string( int x, int y, char *str ) sed1330_string( Driver * drvthis, int x, int y, char *str )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
char * start; char * start;
int len; int len;
debug( RPT_INFO, "sed1330_string x=%d y=%d s=\"%s\"", x, y, str ); debug( RPT_INFO, "sed1330_string x=%d y=%d s=\"%s\"", x, y, str );
if( y > sed1330->hgt ) { if( y > p->height ) {
return; // outside framebuf_textfer return; // outside framebuf_textfer
} }
// Calculate where to start and length to write // Calculate where to start and length to write
start = data->framebuf_text + (y-1)*data->bytesperline + (x-1); start = p->framebuf_text + (y-1)*p->bytesperline + (x-1);
len = strlen(str); len = strlen(str);
if( sed1330->wid < len ) { if( p->width < len ) {
len = sed1330->wid; len = p->width;
} }
memcpy( start, str, len ); memcpy( start, str, len );
@@ -560,39 +591,39 @@ sed1330_string( int x, int y, char *str )
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Place a character in the framebuffer // Place a character in the framebuffer
// //
void MODULE_EXPORT void
sed1330_chr( int x, int y, char c ) sed1330_chr( Driver * drvthis, int x, int y, char c )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_chr x=%d y=%d c='%c'", x, y, c ); debug( RPT_INFO, "sed1330_chr x=%d y=%d c='%c'", x, y, c );
if( y > sed1330->hgt || x > sed1330->wid ) { if( y > p->height || x > p->width ) {
return; // outside framebuf_textfer return; // outside framebuf_textfer
} }
data->framebuf_text[(y-1)*data->bytesperline + (x-1)] = c; p->framebuf_text[(y-1)*p->bytesperline + (x-1)] = c;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Flush the framebuffer to the display // Flush the framebuffer to the display
// //
void MODULE_EXPORT void
sed1330_flush() sed1330_flush( Driver * drvthis )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos; unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos;
char csrloc[2]; char csrloc[2];
debug( RPT_INFO, "sed1330_flush" ); debug( RPT_INFO, "sed1330_flush" );
sed1330_command( CMD_DISP_EN, 1, ((char[1]) {0x16}) ); // cursor off sed1330_command( p, CMD_DISP_EN, 1, ((char[1]) {0x16}) ); // cursor off
fblen = data->bytesperline * sed1330->hgt; fblen = p->bytesperline * p->height;
for( pos=0; pos<fblen; ) { for( pos=0; pos<fblen; ) {
start_pos = pos; start_pos = pos;
for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) { for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) {
if( data->lcd_contents_text[pos] == data->framebuf_text[pos] ) { if( p->lcd_contents_text[pos] == p->framebuf_text[pos] ) {
nr_equal ++; nr_equal ++;
} else { } else {
nr_equal = 0; nr_equal = 0;
@@ -603,17 +634,17 @@ sed1330_flush()
cursor_pos = start_pos + 256 * SCR1_H + SCR1_L; cursor_pos = start_pos + 256 * SCR1_H + SCR1_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
csrloc[1] = cursor_pos / 256; csrloc[1] = cursor_pos / 256;
sed1330_command( CMD_CSRW, 2, csrloc ); sed1330_command( p, CMD_CSRW, 2, csrloc );
sed1330_command( CMD_MWRITE, len, data->framebuf_text + start_pos ); sed1330_command( p, CMD_MWRITE, len, p->framebuf_text + start_pos );
memcpy( data->lcd_contents_text + start_pos, data->framebuf_text + start_pos, len ); memcpy( p->lcd_contents_text + start_pos, p->framebuf_text + start_pos, len );
} }
} }
fblen = data->bytesperline * data->graph_height; fblen = p->bytesperline * p->graph_height;
for( pos=0; pos<fblen; ) { for( pos=0; pos<fblen; ) {
start_pos = pos; start_pos = pos;
for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) { for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) {
if( data->lcd_contents_graph[pos] == data->framebuf_graph[pos] ) { if( p->lcd_contents_graph[pos] == p->framebuf_graph[pos] ) {
nr_equal ++; nr_equal ++;
} else { } else {
nr_equal = 0; nr_equal = 0;
@@ -624,41 +655,42 @@ sed1330_flush()
cursor_pos = start_pos + 256 * SCR2_H + SCR2_L; cursor_pos = start_pos + 256 * SCR2_H + SCR2_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
csrloc[1] = cursor_pos / 256; csrloc[1] = cursor_pos / 256;
sed1330_command( CMD_CSRW, 2, csrloc ); sed1330_command( p, CMD_CSRW, 2, csrloc );
sed1330_command( CMD_MWRITE, len, data->framebuf_graph + start_pos ); sed1330_command( p, CMD_MWRITE, len, p->framebuf_graph + start_pos );
memcpy( data->lcd_contents_graph + start_pos, data->framebuf_graph + start_pos, len ); memcpy( p->lcd_contents_graph + start_pos, p->framebuf_graph + start_pos, len );
} }
} }
sed1330_update_cursor(); sed1330_update_cursor( p );
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Let the cursor go to a certain location // Let the cursor go to a certain location
// //
void sed1330_cursor( int x, int y, char state ) MODULE_EXPORT void
sed1330_cursor( Driver * drvthis, int x, int y, char state )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_cursor x=%d y=%d state='%c'", x, y, state ); debug( RPT_INFO, "sed1330_cursor x=%d y=%d state='%c'", x, y, state );
data->cursor_x = x; p->cursor_x = x;
data->cursor_y = y; p->cursor_y = y;
data->cursor_state = state; p->cursor_state = state;
sed1330_update_cursor(); sed1330_update_cursor( p );
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets the backlight on or off // Sets the backlight on or off
// //
void MODULE_EXPORT void
sed1330_backlight( int on ) sed1330_backlight( Driver * drvthis, int on )
{ {
//private_data * data = sed1330->private_data; //PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_backlight on='%c'", on ); debug( RPT_INFO, "sed1330_backlight on='%c'", on );
// unimplemented // unimplemented
@@ -670,14 +702,11 @@ sed1330_backlight( int on )
// INTERNAL // INTERNAL
// //
void void
sed1330_rect ( int x1, int y1, int x2, int y2, char pattern ) sed1330_rect ( PrivateData * p, int x1, int y1, int x2, int y2, char pattern )
// pattern: 0=empty 1=filled later more patterns ? // pattern: 0=empty 1=filled later more patterns ?
{ {
//private_data * data = sed1330->private_data;
int x, y; int x, y;
debug( RPT_INFO, "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d", x1, y1, x2, y2, (int) pattern );
// Swap coordinates if needed // Swap coordinates if needed
if( x1>x2 ) { if( x1>x2 ) {
int swap; int swap;
@@ -693,25 +722,22 @@ sed1330_rect ( int x1, int y1, int x2, int y2, char pattern )
} }
for( x=x1; x<=x2; x++ ) { for( x=x1; x<=x2; x++ ) {
for( y=y1; y<=y2; y++ ) { for( y=y1; y<=y2; y++ ) {
sed1330_set_pixel( x, y ); sed1330_set_pixel( p, x, y );
} }
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a rectangle // Draws a line
// INTERNAL // INTERNAL
// //
void void
sed1330_line ( int x1, int y1, int x2, int y2, char pattern ) sed1330_line ( PrivateData * p, int x1, int y1, int x2, int y2, char pattern )
// pattern: 0=empty 1=filled later more patterns ? // pattern: 0=empty 1=filled later more patterns ?
{ {
//private_data * data = sed1330->private_data;
int x, y; int x, y;
debug( RPT_INFO, "sed1330_rect x1=%d y1=%d x2=%d y2=%d pattern=%d", x1, y1, x2, y2, (int) pattern );
// Swap coordinates if needed // Swap coordinates if needed
if( x1>x2 ) { if( x1>x2 ) {
int swap; int swap;
@@ -732,10 +758,10 @@ sed1330_line ( int x1, int y1, int x2, int y2, char pattern )
y = x * (y2-y1) / (x2-x1); y = x * (y2-y1) / (x2-x1);
switch( pattern ) { switch( pattern ) {
case 0: case 0:
sed1330_clear_pixel( x, y ); sed1330_clear_pixel( p, x, y );
break; break;
case 1: case 1:
sed1330_set_pixel( x, y ); sed1330_set_pixel( p, x, y );
break; break;
} }
} }
@@ -746,10 +772,10 @@ sed1330_line ( int x1, int y1, int x2, int y2, char pattern )
x = y * (x2-x1) / (y2-y1) ; x = y * (x2-x1) / (y2-y1) ;
switch( pattern ) { switch( pattern ) {
case 0: case 0:
sed1330_clear_pixel( x, y ); sed1330_clear_pixel( p, x, y );
break; break;
case 1: case 1:
sed1330_set_pixel( x, y ); sed1330_set_pixel( p, x, y );
break; break;
} }
} }
@@ -762,18 +788,15 @@ sed1330_line ( int x1, int y1, int x2, int y2, char pattern )
// INTERNAL // INTERNAL
// //
inline void inline void
sed1330_set_pixel( int x, int y ) sed1330_set_pixel( PrivateData * p, int x, int y )
// x, y are graph LCD coordinates, 0-based // x, y are graph LCD coordinates, 0-based
{ {
private_data * data = sed1330->private_data;
unsigned int bytepos; unsigned int bytepos;
char bitmask; char bitmask;
//debug( RPT_INFO, "sed1330_set_pixel x=%d y=%d", x, y ); bytepos = y*p->bytesperline + x/PIXELSPERBYTE;
bytepos = y*data->bytesperline + x/PIXELSPERBYTE;
bitmask = 0x80 >> (x % PIXELSPERBYTE); bitmask = 0x80 >> (x % PIXELSPERBYTE);
data->framebuf_graph[bytepos] |= bitmask; p->framebuf_graph[bytepos] |= bitmask;
} }
@@ -782,32 +805,29 @@ sed1330_set_pixel( int x, int y )
// INTERNAL // INTERNAL
// //
inline void inline void
sed1330_clear_pixel( int x, int y ) sed1330_clear_pixel( PrivateData * p, int x, int y )
// x, y are graph LCD coordinates, 0-based // x, y are graph LCD coordinates, 0-based
{ {
private_data * data = sed1330->private_data;
int bytepos; int bytepos;
char bitmask; char bitmask;
//debug( RPT_INFO, "sed1330_clear_pixel x=%d y=%d", x, y ); bytepos = y*p->bytesperline + x/PIXELSPERBYTE;
bytepos = y*data->bytesperline + x/PIXELSPERBYTE;
bitmask = 0x80 >> (x % PIXELSPERBYTE); bitmask = 0x80 >> (x % PIXELSPERBYTE);
data->framebuf_graph[bytepos] &= ~bitmask; p->framebuf_graph[bytepos] &= ~bitmask;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar at the bottom // Draws a vertical bar at the bottom
// //
void MODULE_EXPORT void
sed1330_vbar( int x, int len ) sed1330_vbar( Driver * drvthis, int x, int y, int len, int promille, int pattern )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_hbar x=%d len=%d", x, len ); debug( RPT_INFO, "sed1330_hbar x=%d len=%d", x, len );
sed1330_rect ( (x-1) * CHARWIDTH, data->graph_height-1, x * CHARWIDTH - 1, data->graph_height-1 - ((long) len * CHARHEIGHT / sed1330->cellhgt ), 1 ); sed1330_rect ( p, (x-1) * CHARWIDTH, y * CHARHEIGHT - CHARHEIGHT/2, x * CHARWIDTH - 1, y * CHARHEIGHT - CHARHEIGHT/2 + (long) len * CHARHEIGHT * promille / 1000 - 1, 1 );
} }
@@ -815,58 +835,70 @@ sed1330_vbar( int x, int len )
// Draws a horizontal bar to the right (len=pos) // Draws a horizontal bar to the right (len=pos)
// or to the left (len=neg) // or to the left (len=neg)
// //
void MODULE_EXPORT void
sed1330_hbar( int x, int y, int len ) sed1330_hbar( Driver * drvthis, int x, int y, int len, int promille, int pattern )
{ {
//private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_hbar x=%d y=%d len=%d", x, y, len ); debug( RPT_INFO, "sed1330_hbar x=%d y=%d len=%d", x, y, len );
sed1330_rect ( (x-1) * CHARWIDTH, (y-1) * CHARHEIGHT, x * CHARWIDTH + len, y * CHARHEIGHT - 1, 1 ); sed1330_rect ( p, x * CHARWIDTH, (y-1) * CHARHEIGHT, x * CHARWIDTH - CHARWIDTH/2 + (long) len * CHARWIDTH * promille / 1000 - 1, y * CHARHEIGHT - 1, 1 );
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void MODULE_EXPORT void
sed1330_num( int x, int num ) sed1330_num( Driver * drvthis, int x, int num )
{ {
//private_data * data = sed1330->private_data; //PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "sed1330_bignum x=%d num=%d", x, num ); debug( RPT_INFO, "sed1330_bignum x=%d num=%d", x, num );
} }
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Does the heartbeat... // Does the heartbeat...
// Or in fact a bouncing ball :)
// //
void MODULE_EXPORT void
sed1330_heartbeat( int type ) sed1330_heartbeat( Driver * drvthis, int type )
{ {
private_data * data = sed1330->private_data; PrivateData * p = drvthis->private_data;
static int timer = 0; static int timer = 0;
int pos; int pos;
int whichIcon; //int whichIcon;
int n; int n;
char heartdata[2][CHARHEIGHT] = { //char heartdata[2][CHARHEIGHT] = {
{ 0xFF, 0xFF, 0xAF, 0x07, 0x8F, 0xDF, 0xFF, 0xFF, 0x00, 0x00 }, // { 0xFF, 0xFF, 0xAF, 0x07, 0x8F, 0xDF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0xAF, 0x07, 0x07, 0x07, 0x8F, 0xDF, 0xFF, 0x00, 0x00 } // { 0xFF, 0xAF, 0x07, 0x07, 0x07, 0x8F, 0xDF, 0xFF, 0x00, 0x00 }
//};
char bouncing_ball[8][CHARHEIGHT] = {
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0x87, 0x87, 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0x87, 0x87, 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF, 0x00, 0x00 },
}; };
report( RPT_INFO, "sed1330_heartbeat type=%d", type ); report( RPT_INFO, "sed1330_heartbeat type=%d", type );
data->framebuf_text[sed1330->wid-1] = ' '; p->framebuf_text[p->width-1] = ' ';
whichIcon = (! ((timer + 4) & 5)); //whichIcon = (! ((timer + 4) & 5));
pos = sed1330->wid - 1; pos = p->width - 1;
for( n=0; n<CHARHEIGHT; n++ ) { for( n=0; n<CHARHEIGHT; n++ ) {
data->framebuf_graph[pos] = heartdata[whichIcon][n]; //p->framebuf_graph[pos] = heartdata[whichIcon][n];
pos += data->bytesperline; p->framebuf_graph[pos] = bouncing_ball[timer][n];
pos += p->bytesperline;
} }
timer++; timer++;
timer %= 8;
} }
+16 -12
View File
@@ -8,17 +8,21 @@
#include "lcd.h" #include "lcd.h"
int sed1330_init( lcd_logical_driver * driver, char *args ); int sed1330_init( Driver * drvthis, char *args );
void sed1330_close(); MODULE_EXPORT void sed1330_close( Driver * drvthis );
void sed1330_clear(); MODULE_EXPORT int sed1330_width( Driver * drvthis );
void sed1330_string( int x, int y, char lcd[] ); MODULE_EXPORT int sed1330_height( Driver * drvthis );
void sed1330_chr( int x, int y, char c ); MODULE_EXPORT void sed1330_clear( Driver * drvthis );
void sed1330_flush(); MODULE_EXPORT void sed1330_flush( Driver * drvthis );
void sed1330_cursor( int x, int y, char state ); MODULE_EXPORT void sed1330_string( Driver * drvthis, int x, int y, char lcd[] );
void sed1330_backlight( int on ); MODULE_EXPORT void sed1330_chr( Driver * drvthis, int x, int y, char c );
void sed1330_vbar( int x, int len );
void sed1330_hbar( int x, int y, int len ); MODULE_EXPORT void sed1330_vbar( Driver * drvthis, int x, int y, int len, int promille, int pattern );
void sed1330_num( int x, int num ); MODULE_EXPORT void sed1330_hbar( Driver * drvthis, int x, int y, int len, int promille, int pattern );
void sed1330_heartbeat( int type ); MODULE_EXPORT void sed1330_num( Driver * drvthis, int x, int num );
MODULE_EXPORT void sed1330_heartbeat( Driver * drvthis, int type );
MODULE_EXPORT void sed1330_cursor( Driver * drvthis, int x, int y, char state );
MODULE_EXPORT void sed1330_backlight( Driver * drvthis, int on );
#endif #endif
+115 -114
View File
@@ -53,8 +53,18 @@
unsigned int sed1520_lptport = LPTPORT; unsigned int sed1520_lptport = LPTPORT;
char *framebuf = NULL;
int width = LCD_DEFAULT_WIDTH;
int height = LCD_DEFAULT_HEIGHT;
int cellwidth = LCD_DEFAULT_CELLWIDTH;
int cellheight = LCD_DEFAULT_CELLHEIGHT;
lcd_logical_driver *sed1520;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "sed1520_";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// writes command value to one or both sed1520 selected by chip // writes command value to one or both sed1520 selected by chip
@@ -125,7 +135,7 @@ drawchar2fb (int x, int y, unsigned char z)
(((fontmap[(int) z][j] * 2) & (1 << i)) / (1 << i)) * (((fontmap[(int) z][j] * 2) & (1 << i)) / (1 << i)) *
(1 << j); (1 << j);
} }
sed1520->framebuf[(y * 122) + (x * 6) + (6 - i)] = k; framebuf[(y * 122) + (x * 6) + (6 - i)] = k;
} }
} }
@@ -135,13 +145,11 @@ drawchar2fb (int x, int y, unsigned char z)
// a command line argument. // a command line argument.
// //
int int
sed1520_init (struct lcd_logical_driver *driver, char *args) sed1520_init (Driver *drvthis, char *args)
{ {
char *argv[64], *str; char *argv[64], *str;
int argc, i; int argc, i;
sed1520 = driver;
if (args) if (args)
if ((str = (char *) malloc (strlen (args) + 1))) if ((str = (char *) malloc (strlen (args) + 1)))
strcpy (str, args); strcpy (str, args);
@@ -195,12 +203,23 @@ sed1520_init (struct lcd_logical_driver *driver, char *args)
} }
} }
driver->wid = 20; // driver->wid = 20;
driver->hgt = 4; // driver->hgt = 4;
if (timing_init() == -1) if (timing_init() == -1)
return -1; return -1;
// Allocate our framebuffer
framebuf = malloc (122 * 4);
if (!framebuf)
{
// sed1520_close ();
return -1;
}
// clear screen
memset (framebuf, 0, 122 * 4);
// Initialize the Port and the sed1520s // Initialize the Port and the sed1520s
if(port_access(sed1520_lptport)) return -1; if(port_access(sed1520_lptport)) return -1;
if(port_access(sed1520_lptport+2)) return -1; if(port_access(sed1520_lptport+2)) return -1;
@@ -212,87 +231,105 @@ sed1520_init (struct lcd_logical_driver *driver, char *args)
writecommand (0xC0, CS1 + CS2); writecommand (0xC0, CS1 + CS2);
selectpage (3); selectpage (3);
driver->cellwid = 6; cellwidth = 6;
driver->cellhgt = 8; cellheight = 8;
// The Framebuffer LCDproc allocates by default is too small,
// so we free() it (if it exists) and allocate one of adequate size.
if (!driver->framebuf)
free (driver->framebuf);
driver->framebuf = malloc (122 * 4); // Set variables for server
if (!driver->framebuf) drvthis->api_version = api_version;
{ drvthis->stay_in_foreground = &stay_in_foreground;
sed1520_close (); drvthis->supports_multiple = &supports_multiple;
return -1;
}
// clear screen // Set the functions the driver supports
memset (driver->framebuf, 0, 122 * 4); drvthis->clear = sed1520_clear;
drvthis->string = sed1520_string;
drvthis->chr = sed1520_chr;
drvthis->old_vbar = sed1520_vbar;
drvthis->old_hbar = sed1520_hbar;
drvthis->num = sed1520_num;
drvthis->init = sed1520_init;
drvthis->close = sed1520_close;
drvthis->flush = sed1520_flush;
drvthis->set_char = sed1520_set_char;
driver->clear = sed1520_clear; drvthis->old_icon = sed1520_icon;
driver->string = sed1520_string;
driver->chr = sed1520_chr;
driver->vbar = sed1520_vbar;
driver->hbar = sed1520_hbar;
driver->num = sed1520_num;
driver->init = sed1520_init;
driver->close = sed1520_close;
driver->flush = sed1520_flush;
driver->flush_box = sed1520_flush_box;
driver->set_char = sed1520_set_char;
driver->icon = sed1520_icon;
driver->draw_frame = sed1520_draw_frame;
// We dont't need init for vbar,hbar and friends. // We dont't need init for vbar,hbar and friends.
//driver->init_hbar = NULL; //drvthis->init_hbar = NULL;
//driver->init_vbar = NULL; //drvthis->init_vbar = NULL;
//driver->init_num = NULL; //drvthis->init_num = NULL;
// Neither contrast nor backlight are controllable. // Neither contrast nor backlight are controllable.
//driver->contrast = NULL; //drvthis->contrast = NULL;
//driver->backlight = NULL; //drvthis->backlight = NULL;
// There are some unused input lines that may be used for input, // There are some unused input lines that may be used for input,
// but nothing is programmed so far. // but nothing is programmed so far.
//driver->getkey = NULL; //drvthis->getkey = NULL;
return 200; // 200 is arbitrary. (must be 1 or more) return 0;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Frees the frambuffer and exits the driver. // Frees the frambuffer and exits the driver.
// //
void MODULE_EXPORT void
sed1520_close () sed1520_close (Driver *drvthis)
{ {
if (sed1520->framebuf != NULL) if (framebuf != NULL)
free (sed1520->framebuf); free (framebuf);
sed1520->framebuf = NULL; framebuf = NULL;
}
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
sed1520_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
sed1520_height (Driver *drvthis)
{
return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
sed1520_clear () sed1520_clear (Driver *drvthis)
{ {
memset (sed1520->framebuf, 0, 488); memset (framebuf, 0, 488);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// //
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
sed1520_flush () sed1520_flush (Driver *drvthis)
{ {
sed1520->draw_frame (sed1520->framebuf); int i, j;
for (i = 0; i < 4; i++)
{
selectpage (i);
selectcolumn (0, CS2) ;
for (j = 0; j < 61; j++)
writedata (framebuf[j + (i * 122)], CS2);
selectcolumn (0, CS1) ;
for (j = 61; j < 122; j++)
writedata (framebuf[j + (i * 122)], CS1);
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the lc display, at position (x,y). The // Prints a string on the lc display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
sed1520_string (int x, int y, char string[]) sed1520_string (Driver *drvthis, int x, int y, char string[])
{ {
int i; int i;
x--; // Convert 1-based coords to 0-based... x--; // Convert 1-based coords to 0-based...
@@ -308,8 +345,8 @@ sed1520_string (int x, int y, char string[])
// Writes char c at position x,y into the framebuffer. // Writes char c at position x,y into the framebuffer.
// x and y are 1-based textmode coordinates. // x and y are 1-based textmode coordinates.
// //
void MODULE_EXPORT void
sed1520_chr (int x, int y, char c) sed1520_chr (Driver *drvthis, int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -323,8 +360,8 @@ sed1520_chr (int x, int y, char c)
// num=10 a colon is drawn. // num=10 a colon is drawn.
// FIXME: make big numbers use less memory // FIXME: make big numbers use less memory
// //
void MODULE_EXPORT void
sed1520_num (int x, int num) sed1520_num (Driver *drvthis, int x, int num)
{ {
int z, c, i, s; int z, c, i, s;
x--; x--;
@@ -349,7 +386,7 @@ sed1520_num (int x, int num)
if (*(fontbigdp[(z * 8) + i] + c) == '.') if (*(fontbigdp[(z * 8) + i] + c) == '.')
s += 128; s += 128;
} }
sed1520->framebuf[(z * 122) + 122 + (x * 6) + c] = s; framebuf[(z * 122) + 122 + (x * 6) + c] = s;
} }
} }
} }
@@ -367,7 +404,7 @@ sed1520_num (int x, int num)
if (*(fontbignum[num][z * 8 + i] + c) == '.') if (*(fontbignum[num][z * 8 + i] + c) == '.')
s += 128; s += 128;
} }
sed1520->framebuf[(z * 122) + 122 + (x * 6) + c] = s; framebuf[(z * 122) + 122 + (x * 6) + c] = s;
} }
} }
} }
@@ -381,10 +418,10 @@ sed1520_num (int x, int num)
// can be altered. !Important: Characters have to be redraw // can be altered. !Important: Characters have to be redraw
// by drawchar2fb() to show their new shape. Because we use // by drawchar2fb() to show their new shape. Because we use
// a non-standard 6x8 font a *dat not calculated from // a non-standard 6x8 font a *dat not calculated from
// sed1520->width and sed1520->height will fail. // widthth and sed1520->height will fail.
// //
void MODULE_EXPORT void
sed1520_set_char (int n, char *dat) sed1520_set_char (Driver *drvthis, int n, char *dat)
{ {
int row, col, i; int row, col, i;
@@ -409,8 +446,8 @@ sed1520_set_char (int n, char *dat)
// Draws a vertical from the bottom up to the last 3 rows of the // Draws a vertical from the bottom up to the last 3 rows of the
// framebuffer at 1-based position x. len is given in pixels. // framebuffer at 1-based position x. len is given in pixels.
// //
void MODULE_EXPORT void
sed1520_vbar (int x, int len) sed1520_vbar (Driver *drvthis, int x, int len)
{ {
int i, j, k; int i, j, k;
x--; x--;
@@ -426,12 +463,12 @@ sed1520_vbar (int x, int len)
k += 1 << (7 - i); k += 1 << (7 - i);
} }
sed1520->framebuf[((3 - j) * 122) + (x * 6)] = 0; framebuf[((3 - j) * 122) + (x * 6)] = 0;
sed1520->framebuf[((3 - j) * 122) + (x * 6) + 1] = 0; framebuf[((3 - j) * 122) + (x * 6) + 1] = 0;
sed1520->framebuf[((3 - j) * 122) + (x * 6) + 2] = k; framebuf[((3 - j) * 122) + (x * 6) + 2] = k;
sed1520->framebuf[((3 - j) * 122) + (x * 6) + 3] = k; framebuf[((3 - j) * 122) + (x * 6) + 3] = k;
sed1520->framebuf[((3 - j) * 122) + (x * 6) + 4] = k; framebuf[((3 - j) * 122) + (x * 6) + 4] = k;
sed1520->framebuf[((3 - j) * 122) + (x * 6) + 5] = 0; framebuf[((3 - j) * 122) + (x * 6) + 5] = 0;
len -= 8; len -= 8;
} }
@@ -442,8 +479,8 @@ sed1520_vbar (int x, int len)
// Draws a horizontal bar from left to right at 1-based position // Draws a horizontal bar from left to right at 1-based position
// x,y into the framebuffer. len is given in pixels. // x,y into the framebuffer. len is given in pixels.
// //
void MODULE_EXPORT void
sed1520_hbar (int x, int y, int len) sed1520_hbar (Driver *drvthis, int x, int y, int len)
{ {
int i; int i;
x--; x--;
@@ -453,15 +490,15 @@ sed1520_hbar (int x, int y, int len)
return; return;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
sed1520->framebuf[(y * 122) + (x * 6) + i] = 0x3C; framebuf[(y * 122) + (x * 6) + i] = 0x3C;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Reprogrammes character dest to contain an icon given by // Reprogrammes character dest to contain an icon given by
// which. Calls set_char() to do this. // which. Calls set_char() to do this.
// //
void MODULE_EXPORT void
sed1520_icon (int which, char dest) sed1520_icon (Driver *drvthis, int which, char dest)
{ {
char icons[3][6 * 8] = { char icons[3][6 * 8] = {
{ {
@@ -495,42 +532,6 @@ sed1520_icon (int which, char dest)
1, 0, 1, 0, 1, 0,} 1, 0, 1, 0, 1, 0,}
, ,
}; };
sed1520_set_char (dest, &icons[which][0]); sed1520_set_char (drvthis, dest, &icons[which][0]);
} }
/////////////////////////////////////////////////////////////////
// Send a rectangular area from lft,top to rgt,bot to the display
// These coordinates are probably one-based, too. It's so fast to
// flush the whole display that it makes no sense to flush less then
// the whole display. Therefore this function redraws the whole
// display.
// FIXME: Check if this function is worth implementing.
//
void
sed1520_flush_box (int lft, int top, int rgt, int bot)
{
sed1520_flush ();
}
/////////////////////////////////////////////////////////////////
// Outputs the whole framebuffer *dat to the display. This Display
// contains 2 Controllers, each of them controlling one half of the
// screen.
//
void
sed1520_draw_frame (char *dat)
{
int i, j;
if (!dat)
return;
for (i = 0; i < 4; i++)
{
selectpage (i);
selectcolumn (0, CS2) ;
for (j = 0; j < 61; j++)
writedata (dat[j + (i * 122)], CS2);
selectcolumn (0, CS1) ;
for (j = 61; j < 122; j++)
writedata (dat[j + (i * 122)], CS1);
}
}
+16 -14
View File
@@ -1,20 +1,22 @@
#ifndef SED1520_H #ifndef SED1520_H
#define SED1520_H #define SED1520_H
extern lcd_logical_driver *sed1520; #include "lcd.h"
int sed1520_init (struct lcd_logical_driver *driver, char *args); int sed1520_init (Driver *drvthis, char *args);
void sed1520_close (); MODULE_EXPORT void sed1520_close (Driver *drvthis);
void sed1520_clear (); MODULE_EXPORT int sed1520_width (Driver *drvthis);
void sed1520_flush (); MODULE_EXPORT int sed1520_height (Driver *drvthis);
void sed1520_string (int x, int y, char string[]); MODULE_EXPORT void sed1520_clear (Driver *drvthis);
void sed1520_chr (int x, int y, char c); MODULE_EXPORT void sed1520_flush (Driver *drvthis);
void sed1520_vbar (int x, int len); MODULE_EXPORT void sed1520_string (Driver *drvthis, int x, int y, char string[]);
void sed1520_hbar (int x, int y, int len); MODULE_EXPORT void sed1520_chr (Driver *drvthis, int x, int y, char c);
void sed1520_num (int x, int num);
void sed1520_set_char (int n, char *dat); MODULE_EXPORT void sed1520_vbar (Driver *drvthis, int x, int len);
void sed1520_icon (int which, char dest); MODULE_EXPORT void sed1520_hbar (Driver *drvthis, int x, int y, int len);
void sed1520_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT void sed1520_num (Driver *drvthis, int x, int num);
void sed1520_draw_frame (char *dat); MODULE_EXPORT void sed1520_icon (Driver *drvthis, int which, char dest);
MODULE_EXPORT void sed1520_set_char (Driver *drvthis, int n, char *dat);
#endif #endif
+132 -115
View File
@@ -83,6 +83,15 @@
unsigned int stv5730_lptport = LPTPORT; unsigned int stv5730_lptport = LPTPORT;
unsigned int stv5730_charattrib = STV5730_ATTRIB; unsigned int stv5730_charattrib = STV5730_ATTRIB;
unsigned int stv5730_flags = 0; unsigned int stv5730_flags = 0;
char * stv5730_framebuf = NULL;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "stv5730_";
// Translation map ascii->stv5730 charset // Translation map ascii->stv5730 charset
unsigned char stv5730_to_ascii[256] = unsigned char stv5730_to_ascii[256] =
@@ -121,7 +130,6 @@ unsigned char stv5730_to_ascii[256] =
}; };
lcd_logical_driver *stv5730;
//static void stv5730_upause (int delayCalls); //static void stv5730_upause (int delayCalls);
#define stv5730_upause timing_uPause #define stv5730_upause timing_uPause
@@ -263,7 +271,7 @@ stv5730_drawchar2fb (int x, int y, unsigned char z)
if (x < 0 || x >= STV5730_WID || y < 0 || y >= STV5730_HGT) if (x < 0 || x >= STV5730_WID || y < 0 || y >= STV5730_HGT)
return; return;
stv5730->framebuf[(y * STV5730_WID) + x] = stv5730_to_ascii[(unsigned int) z]; stv5730_framebuf[(y * STV5730_WID) + x] = stv5730_to_ascii[(unsigned int) z];
} }
@@ -272,13 +280,11 @@ stv5730_drawchar2fb (int x, int y, unsigned char z)
// a command line argument. // a command line argument.
// //
int int
stv5730_init (struct lcd_logical_driver *driver, char *args) stv5730_init (Driver *drvthis, char *args)
{ {
char *argv[64], *str; char *argv[64], *str;
int argc, i; int argc, i;
stv5730 = driver;
if (args) if (args)
if ((str = (char *) malloc (strlen (args) + 1))) if ((str = (char *) malloc (strlen (args) + 1)))
strcpy (str, args); strcpy (str, args);
@@ -333,9 +339,6 @@ stv5730_init (struct lcd_logical_driver *driver, char *args)
} }
} }
driver->wid = STV5730_WID;
driver->hgt = STV5730_HGT;
if (timing_init() == -1) if (timing_init() == -1)
return -1; return -1;
@@ -426,89 +429,150 @@ stv5730_init (struct lcd_logical_driver *driver, char *args)
stv5730_write16bit (0x10C0); stv5730_write16bit (0x10C0);
} }
// Alocate our own framebuffer
// The Framebuffer LCDproc allocates by default is too small, stv5730_framebuf = malloc (STV5730_WID * STV5730_HGT);
// so we free() it and allocate one of adequate size. if (!stv5730_framebuf)
if (!driver->framebuf)
free (driver->framebuf);
driver->framebuf = malloc (STV5730_WID * STV5730_HGT);
if (!driver->framebuf)
{ {
stv5730_close (); stv5730_close (drvthis);
return -1; return -4;
} }
// clear screen // clear screen
memset (driver->framebuf, 0, STV5730_WID * STV5730_HGT); memset (stv5730_framebuf, 0, STV5730_WID * STV5730_HGT);
driver->cellwid = 4; // Set variables for server
driver->cellhgt = 6; drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = stv5730_clear; // Set the functions the driver supports
driver->string = stv5730_string; drvthis->clear = stv5730_clear;
driver->chr = stv5730_chr; drvthis->string = stv5730_string;
driver->vbar = stv5730_vbar; drvthis->chr = stv5730_chr;
driver->hbar = stv5730_hbar; drvthis->old_vbar = stv5730_vbar;
driver->num = stv5730_num; drvthis->old_hbar = stv5730_hbar;
driver->init = stv5730_init; drvthis->num = stv5730_num;
driver->close = stv5730_close; drvthis->init = stv5730_init;
driver->flush = stv5730_flush; drvthis->close = stv5730_close;
driver->flush_box = stv5730_flush_box; drvthis->width = stv5730_width;
drvthis->height = stv5730_height;
drvthis->cellwidth = stv5730_cellwidth;
drvthis->cellheight = stv5730_cellheight;
drvthis->flush = stv5730_flush;
// We dont't have any programmable chars. // We dont't have any programmable chars.
//driver->set_char = NULL; //drvthis->set_char = NULL;
driver->icon = stv5730_icon; drvthis->old_icon = stv5730_icon;
driver->draw_frame = stv5730_draw_frame;
// We dont't need init for vbar,hbar and friends. // We dont't need init for vbar,hbar and friends.
//driver->init_hbar = NULL; //drvthis->init_hbar = NULL;
//driver->init_vbar = NULL; //drvthis->init_vbar = NULL;
//driver->init_num = NULL; //drvthis->init_num = NULL;
// Neither contrast nor backlight are controllable. // Neither contrast nor backlight are controllable.
//driver->contrast = NULL; //drvthis->contrast = NULL;
//driver->backlight = NULL; //drvthis->backlight = NULL;
// There are some unused input lines that may be used for input, // There are some unused input lines that may be used for input,
// but nothing is programmed so far. // but nothing is programmed so far.
//driver->getkey = NULL; //drvthis->getkey = NULL;
return 200; // 200 is arbitrary. (must be 1 or more) return 0;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Frees the framebuffer and exits the driver. // Frees the framebuffer and exits the driver.
// //
void MODULE_EXPORT void
stv5730_close () stv5730_close (Driver *drvthis)
{ {
if (stv5730->framebuf != NULL) if (stv5730_framebuf != NULL)
free (stv5730->framebuf); free (stv5730_framebuf);
stv5730->framebuf = NULL; stv5730_framebuf = NULL;
} }
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
stv5730_width (Driver *drvthis)
{
return STV5730_WID;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
stv5730_height (Driver *drvthis)
{
return STV5730_HGT;
}
/////////////////////////////////////////////////////////////////
// Returns the number of pixels a character is wide
//
MODULE_EXPORT int
stv5730_cellwidth (Driver *drvthis)
{
return 4;
}
/////////////////////////////////////////////////////////////////
// Returns the number of pixels a character is high
//
MODULE_EXPORT int
stv5730_cellheight (Driver *drvthis)
{
return 6;
}
// cellwidth and cellheight are only needed for old_vbar.
// Therefor these values are now hardcoded into these functions.
// When old_vbar is not used anymore, these two functions can be removed.
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the screen // Clears the screen
// //
void MODULE_EXPORT void
stv5730_clear () stv5730_clear (Driver *drvthis)
{ {
memset (stv5730->framebuf, 0x0B, STV5730_WID * STV5730_HGT); memset (stv5730_framebuf, 0x0B, STV5730_WID * STV5730_HGT);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// //
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
stv5730_flush () stv5730_flush (Driver *drvthis)
{ {
stv5730->draw_frame (stv5730->framebuf); int i, j, atr;
stv5730_locate (0, 0);
for (i = 0; i < STV5730_HGT; i++)
{
if (i == 0)
atr = (STV5730_COL_FLINE << 8);
else
atr = (STV5730_COL_TEXT << 8);
stv5730_write16bit (0x1000 + atr + stv5730_framebuf[i * STV5730_WID] +
stv5730_charattrib);
for (j = 1; j < STV5730_WID; j++)
{
if (stv5730_framebuf[j + (i * STV5730_WID) - 1] !=
stv5730_framebuf[j + (i * STV5730_WID)])
stv5730_write8bit (stv5730_framebuf[j + (i * STV5730_WID)]);
else
stv5730_write0bit ();
};
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the screen, at position (x,y). The // Prints a string on the screen, at position (x,y). The
// upper-left is (1,1), and the lower right should be (28,11). // upper-left is (1,1), and the lower right should be (28,11).
// //
void MODULE_EXPORT void
stv5730_string (int x, int y, char string[]) stv5730_string (Driver *drvthis, int x, int y, char string[])
{ {
int i; int i;
x--; // Convert 1-based coords to 0-based... x--; // Convert 1-based coords to 0-based...
@@ -524,8 +588,8 @@ stv5730_string (int x, int y, char string[])
// Writes char c at position x,y into the framebuffer. // Writes char c at position x,y into the framebuffer.
// x and y are 1-based textmode coordinates. // x and y are 1-based textmode coordinates.
// //
void MODULE_EXPORT void
stv5730_chr (int x, int y, char c) stv5730_chr (Driver *drvthis, int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -536,8 +600,8 @@ stv5730_chr (int x, int y, char c)
// This function draws ugly big numbers. We could use the zoom // This function draws ugly big numbers. We could use the zoom
// feature of the stv5730 if we'd know when big numbers start // feature of the stv5730 if we'd know when big numbers start
// and stop. // and stop.
void MODULE_EXPORT void
stv5730_num (int x, int num) stv5730_num (Driver *drvthis, int x, int num)
{ {
int i, j; int i, j;
@@ -569,8 +633,8 @@ stv5730_num (int x, int num)
// Draws a vertical bar from the bottom up to the last 7 rows of the // Draws a vertical bar from the bottom up to the last 7 rows of the
// framebuffer at 1-based position x. len is given in pixels. // framebuffer at 1-based position x. len is given in pixels.
// //
void MODULE_EXPORT void
stv5730_vbar (int x, int len) stv5730_vbar (Driver *drvthis, int x, int len)
{ {
int i; int i;
@@ -584,11 +648,11 @@ stv5730_vbar (int x, int len)
if (len >= (i + 6)) if (len >= (i + 6))
{ {
stv5730->framebuf[((10 - (i / 6)) * STV5730_WID) + x] = 0x77; stv5730_framebuf[((10 - (i / 6)) * STV5730_WID) + x] = 0x77;
} }
else else
{ {
stv5730->framebuf[((10 - (i / 6)) * STV5730_WID) + x] = stv5730_framebuf[((10 - (i / 6)) * STV5730_WID) + x] =
0x72 + (len % 6); 0x72 + (len % 6);
} }
} }
@@ -601,8 +665,8 @@ stv5730_vbar (int x, int len)
// x,y into the framebuffer. len is given in pixels. // x,y into the framebuffer. len is given in pixels.
// It uses the STV5730 'channel-tuning' chars(0x64-0x68) to do // It uses the STV5730 'channel-tuning' chars(0x64-0x68) to do
// this. // this.
void MODULE_EXPORT void
stv5730_hbar (int x, int y, int len) stv5730_hbar (Driver *drvthis, int x, int y, int len)
{ {
int i; int i;
x--; x--;
@@ -617,11 +681,11 @@ stv5730_hbar (int x, int y, int len)
if (len >= (i + 4)) if (len >= (i + 4))
{ {
stv5730->framebuf[(y * STV5730_WID) + x + (i / 5)] = 0x64; stv5730_framebuf[(y * STV5730_WID) + x + (i / 5)] = 0x64;
} }
else else
{ {
stv5730->framebuf[(y * STV5730_WID) + x + (i / 5)] = stv5730_framebuf[(y * STV5730_WID) + x + (i / 5)] =
0x65 + (len % 5); 0x65 + (len % 5);
} }
} }
@@ -633,8 +697,8 @@ stv5730_hbar (int x, int y, int len)
// The STV5730 has no programmable chars. The charset is very // The STV5730 has no programmable chars. The charset is very
// limited, it doesn't even contain a '%' char. But wait... // limited, it doesn't even contain a '%' char. But wait...
// It contains a heartbeat char ! :-) // It contains a heartbeat char ! :-)
void MODULE_EXPORT void
stv5730_icon (int which, char dest) stv5730_icon (Driver *drvthis, int which, char dest)
{ {
switch (which) switch (which)
{ {
@@ -654,50 +718,3 @@ stv5730_icon (int which, char dest)
} }
} }
/////////////////////////////////////////////////////////////////
// Send a rectangular area from lft,top to rgt,bot to the display
// These coordinates are probably one-based, too. It's so fast to
// flush the whole display that it makes no sense to flush less then
// the whole display. Therefore this function redraws the whole
// display.
// FIXME: Check if this function is worth implementing.
//
void
stv5730_flush_box (int lft, int top, int rgt, int bot)
{
stv5730_flush ();
}
/////////////////////////////////////////////////////////////////
// Outputs the whole framebuffer *dat to the display.
// Attributes are set for every row only.
// The first line has special attributes.
void
stv5730_draw_frame (char *dat)
{
int i, j, atr;
if (!dat)
return;
stv5730_locate (0, 0);
for (i = 0; i < STV5730_HGT; i++)
{
if (i == 0)
atr = (STV5730_COL_FLINE << 8);
else
atr = (STV5730_COL_TEXT << 8);
stv5730_write16bit (0x1000 + atr + dat[i * STV5730_WID] +
stv5730_charattrib);
for (j = 1; j < STV5730_WID; j++)
{
if (dat[j + (i * STV5730_WID) - 1] !=
dat[j + (i * STV5730_WID)])
stv5730_write8bit (dat[j + (i * STV5730_WID)]);
else
stv5730_write0bit ();
};
}
}
+15 -13
View File
@@ -1,19 +1,21 @@
#ifndef STV5730_H #ifndef STV5730_H
#define STV5730_H #define STV5730_H
extern lcd_logical_driver *stv5730; #include "lcd.h"
int stv5730_init (struct lcd_logical_driver *driver, char *args); int stv5730_init (Driver *drvthis, char *args);
void stv5730_close (); MODULE_EXPORT void stv5730_close (Driver *drvthis);
void stv5730_clear (); MODULE_EXPORT int stv5730_width (Driver *drvthis);
void stv5730_flush (); MODULE_EXPORT int stv5730_height (Driver *drvthis);
void stv5730_string (int x, int y, char string[]); MODULE_EXPORT int stv5730_cellwidth (Driver *drvthis);
void stv5730_chr (int x, int y, char c); MODULE_EXPORT int stv5730_cellheight (Driver *drvthis);
void stv5730_vbar (int x, int len); MODULE_EXPORT void stv5730_clear (Driver *drvthis);
void stv5730_hbar (int x, int y, int len); MODULE_EXPORT void stv5730_flush (Driver *drvthis);
void stv5730_num (int x, int num); MODULE_EXPORT void stv5730_string (Driver *drvthis, int x, int y, char string[]);
void stv5730_icon (int which, char dest); MODULE_EXPORT void stv5730_chr (Driver *drvthis, int x, int y, char c);
void stv5730_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT void stv5730_vbar (Driver *drvthis, int x, int len);
void stv5730_draw_frame (char *dat); MODULE_EXPORT void stv5730_hbar (Driver *drvthis, int x, int y, int len);
MODULE_EXPORT void stv5730_num (Driver *drvthis, int x, int num);
MODULE_EXPORT void stv5730_icon (Driver *drvthis, int which, char dest);
#endif #endif
+104 -122
View File
@@ -24,7 +24,6 @@
#include "shared/debug.h" #include "shared/debug.h"
#include "lcd.h" #include "lcd.h"
#include "render.h"
#include "port.h" #include "port.h"
#include "t6963.h" #include "t6963.h"
#include "t6963_font.h" #include "t6963_font.h"
@@ -37,7 +36,6 @@
#define DEBUG4 if(debug_level > 3) printf #define DEBUG4 if(debug_level > 3) printf
extern int debug_level; extern int debug_level;
lcd_logical_driver *t6963;
static u16 t6963_out_port; static u16 t6963_out_port;
static u16 t6963_display_mode; static u16 t6963_display_mode;
@@ -45,8 +43,20 @@ static u8 *t6963_display_buffer1;
static u8 *t6963_display_buffer2; static u8 *t6963_display_buffer2;
static u8 t6963_graph_line[6]; static u8 t6963_graph_line[6];
static char *t6963_framebuf = NULL;
static int width;
static int height;
static int cellwidth;
static int cellheight;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "t6963_";
int int
t6963_init (struct lcd_logical_driver *driver, char *args) t6963_init (Driver *drvthis, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -63,8 +73,6 @@ t6963_init (struct lcd_logical_driver *driver, char *args)
t6963_graph_line[4] = 0x3E; t6963_graph_line[4] = 0x3E;
t6963_graph_line[5] = 0x3F; t6963_graph_line[5] = 0x3F;
t6963 = driver;
DEBUG3 ("Reading arguments...\n"); DEBUG3 ("Reading arguments...\n");
argc = get_args (argv, args, 64); argc = get_args (argv, args, 64);
@@ -101,47 +109,50 @@ t6963_init (struct lcd_logical_driver *driver, char *args)
DEBUG3 (" cool, got 'em!\nSetting width and height\n"); DEBUG3 (" cool, got 'em!\nSetting width and height\n");
DEBUG3 ("done\nAllocating memory: %i x %i bytes = %i...\n", driver->wid, driver->hgt, driver->wid * driver->hgt); DEBUG3 ("done\nAllocating memory: %i x %i bytes = %i...\n", width, height, width * height);
// Set display size // Set display size
t6963->wid = 20; width = 20;
t6963->hgt = 6; height = 6;
t6963->cellwid = 6; cellwidth = 6;
t6963->cellhgt = 8; cellheight = 8;
// You must use driver->framebuf here, but may use lcd.framebuf later. // Allocate framebuf
if (!driver->framebuf) t6963_framebuf = malloc (width * height);
driver->framebuf = malloc (driver->wid * driver->hgt);
if (!driver->framebuf) { if (!t6963_framebuf) {
t6963_close (); t6963_close (drvthis);
return -1; return -1;
} }
// Allocate memory // Allocate memory
t6963_display_buffer1 = malloc (driver->wid * 6); t6963_display_buffer1 = malloc (width * 6);
t6963_display_buffer2 = malloc (driver->wid * 6); t6963_display_buffer2 = malloc (width * 6);
// Clear front and back buffer // Clear front and back buffer
if(t6963_display_buffer1) memset(t6963_display_buffer1, ' ', driver->wid * 6); if(t6963_display_buffer1) memset(t6963_display_buffer1, ' ', width * 6);
if(t6963_display_buffer2) memset(t6963_display_buffer1, ' ', driver->wid * 6); if(t6963_display_buffer2) memset(t6963_display_buffer1, ' ', width * 6);
DEBUG3 ("done\nSetting function pointers...\n"); DEBUG3 ("done\nSetting function pointers...\n");
driver->clear = t6963_clear; // Set variables for server
driver->string = t6963_string; drvthis->stay_in_foreground = &stay_in_foreground;
driver->chr = t6963_chr; drvthis->api_version = api_version;
driver->vbar = t6963_vbar; drvthis->supports_multiple = &supports_multiple;
driver->hbar = t6963_hbar;
driver->num = t6963_num;
driver->init = t6963_init;
driver->close = t6963_close;
driver->flush = t6963_flush;
driver->flush_box = t6963_flush_box;
driver->set_char = t6963_set_char;
driver->icon = t6963_icon;
driver->heartbeat = t6963_heartbeat;
driver->draw_frame = t6963_draw_frame;
driver->getkey = t6963_getkey; // Set the functions the driver supports
drvthis->clear = t6963_clear;
drvthis->string = t6963_string;
drvthis->chr = t6963_chr;
drvthis->old_vbar = t6963_vbar;
drvthis->old_hbar = t6963_hbar;
drvthis->num = t6963_num;
drvthis->init = t6963_init;
drvthis->close = t6963_close;
drvthis->flush = t6963_flush;
drvthis->set_char = t6963_set_char;
drvthis->old_icon = t6963_icon;
drvthis->heartbeat = t6963_heartbeat;
drvthis->getkey = t6963_getkey;
DEBUG3 ("done\nSending init to display...\n"); DEBUG3 ("done\nSending init to display...\n");
DEBUG4 (" make parallel port an output port\n"); DEBUG4 (" make parallel port an output port\n");
@@ -155,25 +166,25 @@ t6963_init (struct lcd_logical_driver *driver, char *args)
DEBUG4(" set graphic/text home adress and area\n"); DEBUG4(" set graphic/text home adress and area\n");
t6963_low_command_word (SET_GRAPHIC_HOME_ADDRESS, ATTRIB_BASE); t6963_low_command_word (SET_GRAPHIC_HOME_ADDRESS, ATTRIB_BASE);
t6963_low_command_word (SET_GRAPHIC_AREA, driver->wid); t6963_low_command_word (SET_GRAPHIC_AREA, width);
t6963_low_command_word (SET_TEXT_HOME_ADDRESS, TEXT_BASE); t6963_low_command_word (SET_TEXT_HOME_ADDRESS, TEXT_BASE);
t6963_low_command_word (SET_TEXT_AREA, driver->wid); t6963_low_command_word (SET_TEXT_AREA, width);
t6963_low_command (SET_MODE | OR_MODE | EXTERNAL_CG); t6963_low_command (SET_MODE | OR_MODE | EXTERNAL_CG);
t6963_low_command_2_bytes (SET_OFFSET_REGISTER, CHARGEN_BASE>>11, 0); t6963_low_command_2_bytes (SET_OFFSET_REGISTER, CHARGEN_BASE>>11, 0);
t6963_low_command (SET_CURSOR_PATTERN | 7); // cursor is 8 lines high t6963_low_command (SET_CURSOR_PATTERN | 7); // cursor is 8 lines high
t6963_low_command_2_bytes (SET_CURSOR_POINTER, 0, 0); t6963_low_command_2_bytes (SET_CURSOR_POINTER, 0, 0);
t6963_set_nchar (0, fontdata_6x8, 256); t6963_set_nchar (drvthis, 0, fontdata_6x8, 256);
t6963_low_enable_mode (TEXT_ON); t6963_low_enable_mode (TEXT_ON);
t6963_low_disable_mode (GRAPHIC_ON); t6963_low_disable_mode (GRAPHIC_ON);
t6963_low_disable_mode (CURSOR_ON); t6963_low_disable_mode (CURSOR_ON);
t6963_low_disable_mode (BLINK_ON); t6963_low_disable_mode (BLINK_ON);
t6963_clear (); t6963_clear (drvthis);
t6963_graphic_clear (0, 0, driver->wid, driver->cellhgt * 6); t6963_graphic_clear (drvthis, 0, 0, width, cellheight * 6);
t6963_flush(); t6963_flush(drvthis);
DEBUG3 ("Initialization done!\n"); DEBUG3 ("Initialization done!\n");
return 0; // 200 is arbitrary. (must be 1 or more) return 0; // 200 is arbitrary. (must be 1 or more)
@@ -183,19 +194,19 @@ t6963_init (struct lcd_logical_driver *driver, char *args)
// lcd.framebuf will be set to the appropriate buffer before calling // lcd.framebuf will be set to the appropriate buffer before calling
// your driver. // your driver.
void MODULE_EXPORT void
t6963_close () t6963_close (Driver *drvthis)
{ {
DEBUG3 ("Shutting down!\n"); DEBUG3 ("Shutting down!\n");
t6963_low_disable_mode (BLINK_ON); t6963_low_disable_mode (BLINK_ON);
ioperm(t6963_out_port, 3, 0); ioperm(t6963_out_port, 3, 0);
if (t6963->framebuf != NULL) if (t6963_framebuf != NULL)
free (t6963->framebuf); free (t6963_framebuf);
if (t6963_display_buffer1 != NULL) free (t6963_display_buffer1); if (t6963_display_buffer1 != NULL) free (t6963_display_buffer1);
if (t6963_display_buffer2 != NULL) free (t6963_display_buffer2); if (t6963_display_buffer2 != NULL) free (t6963_display_buffer2);
t6963->framebuf = NULL; t6963_framebuf = NULL;
t6963_display_buffer1 = NULL; t6963_display_buffer1 = NULL;
t6963_display_buffer2 = NULL; t6963_display_buffer2 = NULL;
} }
@@ -203,20 +214,20 @@ t6963_close ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
t6963_clear () t6963_clear (Driver *drvthis)
{ {
DEBUG4 ("Clearing Display of size %i x %i\n", t6963->wid, 6); DEBUG4 ("Clearing Display of size %i x %i\n", width, 6);
memset (t6963_display_buffer1, ' ', t6963->wid * 6); memset (t6963_display_buffer1, ' ', width * 6);
// for (i=0; i < 6; i++) // for (i=0; i < 6; i++)
// if (t6963_hbar_len[i]==0) t6963_graphic_clear(0, i*t6963->cellhgt, t6963->wid, (i+1)*t6963->cellhgt); // if (t6963_hbar_len[i]==0) t6963_graphic_clear(0, i*cellheight, width, (i+1)*cellheight);
DEBUG4 ("Done\n"); DEBUG4 ("Done\n");
} }
void void
t6963_graphic_clear (int x1, int y1, int x2, int y2) t6963_graphic_clear (Driver *drvthis, int x1, int y1, int x2, int y2)
{ {
int x; int x;
@@ -224,7 +235,7 @@ t6963_graphic_clear (int x1, int y1, int x2, int y2)
for (;y1 < y2; y1++) for (;y1 < y2; y1++)
{ {
t6963_low_command_word(SET_ADDRESS_POINTER, ATTRIB_BASE + y1 * t6963->wid + x1); t6963_low_command_word(SET_ADDRESS_POINTER, ATTRIB_BASE + y1 * width + x1);
for (x = x1; x < x2; x++) for (x = x1; x < x2; x++)
t6963_low_command_byte(DATA_WRITE_INC, 0); t6963_low_command_byte(DATA_WRITE_INC, 0);
} }
@@ -233,13 +244,13 @@ t6963_graphic_clear (int x1, int y1, int x2, int y2)
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void MODULE_EXPORT void
t6963_flush () t6963_flush (Driver *drvthis)
{ {
int i; int i;
DEBUG4 ("Flushing %i x %i\n", t6963->wid, t6963->hgt); DEBUG4 ("Flushing %i x %i\n", width, height);
for (i = 0; i < (t6963->wid * 6); i++) for (i = 0; i < (width * 6); i++)
{ {
DEBUG4 ("%i%i|", t6963_display_buffer1[i], t6963_display_buffer2[i]); DEBUG4 ("%i%i|", t6963_display_buffer1[i], t6963_display_buffer2[i]);
if (t6963_display_buffer1[i] != t6963_display_buffer2[i]) if (t6963_display_buffer1[i] != t6963_display_buffer2[i])
@@ -250,30 +261,15 @@ t6963_flush ()
} }
DEBUG4 ("\n"); DEBUG4 ("\n");
t6963_swap_buffers(); t6963_swap_buffers();
t6963_clear(); t6963_clear(drvthis);
}
//////////////////////////////////////////////////////////////////////
// Send a rectangular area to the display.
//
// I've just called drv_base_flush() because there's not much point yet
// in flushing less than the entire framebuffer.
//
void
t6963_flush_box (int lft, int top, int rgt, int bot)
{
DEBUG4 ("flush_box\n");
t6963_flush();
//drv_base_flush();
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,6). // upper-left is (1,1), and the lower right should be (20,6).
// //
void MODULE_EXPORT void
t6963_string (int x, int y, char string[]) t6963_string (Driver *drvthis, int x, int y, char string[])
{ {
DEBUG4 ("String out\n"); DEBUG4 ("String out\n");
@@ -281,8 +277,8 @@ t6963_string (int x, int y, char string[])
y -= 1; y -= 1;
// t6963_low_command_word(SET_ADDRESS_POINTER,TEXT_BASE+POSITION(x,y)); // t6963_low_command_word(SET_ADDRESS_POINTER,TEXT_BASE+POSITION(x,y));
if(y * t6963->wid + x + strlen(string) <= t6963->wid * 6); if(y * width + x + strlen(string) <= width * 6);
memcpy(&t6963_display_buffer1[y * t6963->wid + x], string, strlen(string)); memcpy(&t6963_display_buffer1[y * width + x], string, strlen(string));
} }
@@ -290,21 +286,21 @@ t6963_string (int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,6). // upper-left is (1,1), and the lower right should be (20,6).
// //
void MODULE_EXPORT void
t6963_chr (int x, int y, char c) t6963_chr (Driver *drvthis, int x, int y, char c)
{ {
DEBUG4 ("Char out\n"); DEBUG4 ("Char out\n");
y--; y--;
x--; x--;
if ((y * t6963->wid) + x <= (t6963->wid * 6)) if ((y * width) + x <= (width * 6))
t6963_display_buffer1[(y * t6963->wid) + x] = c; t6963_display_buffer1[(y * width) + x] = c;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Draws a big (4-row) number. // Draws a big (4-row) number.
// //
void MODULE_EXPORT void
t6963_num (int x, int num) t6963_num (Driver *drvthis, int x, int num)
{ {
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
} }
@@ -313,7 +309,7 @@ t6963_num (int x, int num)
// Changes the font data of character n. // Changes the font data of character n.
// //
void void
t6963_set_nchar (int n, char *dat, int num) t6963_set_nchar (Driver *drvthis, int n, char *dat, int num)
{ {
int row, col; int row, col;
char letter; char letter;
@@ -324,36 +320,36 @@ t6963_set_nchar (int n, char *dat, int num)
return; return;
t6963_low_command_word(SET_ADDRESS_POINTER, CHARGEN_BASE + n*8); t6963_low_command_word(SET_ADDRESS_POINTER, CHARGEN_BASE + n*8);
for (row = 0; row < t6963->cellhgt * num; row++) { for (row = 0; row < cellheight * num; row++) {
letter = 0; letter = 0;
for (col = 0; col < t6963->cellwid; col++) { for (col = 0; col < cellwidth; col++) {
letter <<= 1; letter <<= 1;
letter |= (dat[(row * t6963->cellwid) + col] > 0); letter |= (dat[(row * cellwidth) + col] > 0);
} }
t6963_low_command_byte(DATA_WRITE_INC, letter); t6963_low_command_byte(DATA_WRITE_INC, letter);
} }
} }
void MODULE_EXPORT void
t6963_set_char (int n, char *dat) t6963_set_char (Driver *drvthis, int n, char *dat)
{ {
t6963_set_nchar (n, dat, 1); t6963_set_nchar (drvthis, n, dat, 1);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up. // Draws a vertical bar, from the bottom of the screen up.
// //
void MODULE_EXPORT void
t6963_vbar (int x, int len) t6963_vbar (Driver *drvthis, int x, int len)
{ {
int y; int y;
DEBUG4 ("Drawing vertical bar..."); DEBUG4 ("Drawing vertical bar...");
for (y = 0; y < len/t6963->cellhgt; y++) for (y = 0; y < len/cellheight; y++)
t6963_chr (x, 6-y, 219); t6963_chr (drvthis, x, 6-y, 219);
if (len % t6963->cellhgt) if (len % cellheight)
t6963_chr (x, 6-y, 211 + (len % t6963->cellhgt)); t6963_chr (drvthis, x, 6-y, 211 + (len % cellheight));
DEBUG4 ("Done\n"); DEBUG4 ("Done\n");
} }
@@ -361,16 +357,16 @@ t6963_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void MODULE_EXPORT void
t6963_hbar (int x, int y, int len) t6963_hbar (Driver *drvthis, int x, int y, int len)
{ {
int stop = x + len/t6963->cellwid; int stop = x + len/cellwidth;
DEBUG4 ("Drawing horizontal bar x: %i, y: %i, len:%i, stop: %i...", x, y, len, stop); DEBUG4 ("Drawing horizontal bar x: %i, y: %i, len:%i, stop: %i...", x, y, len, stop);
for (; x < stop; x++) for (; x < stop; x++)
t6963_chr (x, y, 219); t6963_chr (drvthis, x, y, 219);
if (len % t6963->cellwid) if (len % cellwidth)
t6963_chr (x, y, 225 - (len % t6963->cellwid)); t6963_chr (drvthis, x, y, 225 - (len % cellwidth));
DEBUG4 ("Done\n"); DEBUG4 ("Done\n");
} }
@@ -378,8 +374,8 @@ t6963_hbar (int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void MODULE_EXPORT void
t6963_icon (int which, char dest) t6963_icon (Driver *drvthis, int which, char dest)
{ {
// printf("Char %i set to icon %i\n", dest, which); // printf("Char %i set to icon %i\n", dest, which);
DEBUG4 ("Icon %i\n", which); DEBUG4 ("Icon %i\n", which);
@@ -388,8 +384,8 @@ t6963_icon (int which, char dest)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Does the heartbeat // Does the heartbeat
// //
void MODULE_EXPORT void
t6963_heartbeat (int type) t6963_heartbeat (Driver *drvthis, int type)
{ {
static int timer; static int timer;
int whichIcon; int whichIcon;
@@ -402,34 +398,20 @@ t6963_heartbeat (int type)
// Set this to pulsate like a real heartbeat... // Set this to pulsate like a real heartbeat...
whichIcon = (! ((timer + 4) & 5)); whichIcon = (! ((timer + 4) & 5));
// Put character on screen... // Put character on screen...
t6963_chr (t6963->wid, 1, 3+whichIcon); t6963_chr (drvthis, width, 1, 3+whichIcon);
} }
timer++; timer++;
timer &= 0x0f; timer &= 0x0f;
} }
//////////////////////////////////////////////////////////////////////
// Gets a whole screen buffer as argument...
//
void
t6963_draw_frame (char *dat)
{
DEBUG4 ("Drawing frame...");
memcpy (t6963_display_buffer1, dat, t6963->wid * t6963->hgt);
DEBUG4 ("Done");
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device... // Tries to read a character from an input device...
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char MODULE_EXPORT char
t6963_getkey () t6963_getkey (Driver *drvthis)
{ {
DEBUG4 ("Get key"); DEBUG4 ("Get key");
return 0; return 0;
+23 -18
View File
@@ -12,6 +12,8 @@
#ifndef T6963_H #ifndef T6963_H
#define T6963_H #define T6963_H
#include "lcd.h"
#define SM_UP (1) #define SM_UP (1)
#define SM_DOWN (2) #define SM_DOWN (2)
#define CM_ERASE (2) #define CM_ERASE (2)
@@ -105,25 +107,28 @@ typedef unsigned char u8;
// * F U N C T I O N S * // * F U N C T I O N S *
// **************************************************************************************** // ****************************************************************************************
extern lcd_logical_driver *t6963;
int t6963_init (struct lcd_logical_driver *driver, char *args); int t6963_init (Driver *drvthis, char *args);
void t6963_close (); MODULE_EXPORT void t6963_close (Driver *drvthis);
void t6963_clear (); MODULE_EXPORT int t6963_width (Driver *drvthis);
void t6963_graphic_clear (); MODULE_EXPORT int t6963_height (Driver *drvthis);
void t6963_flush (); MODULE_EXPORT void t6963_clear (Driver *drvthis);
void t6963_string (int x, int y, char string[]); MODULE_EXPORT void t6963_flush (Driver *drvthis);
void t6963_chr (int x, int y, char c); MODULE_EXPORT void t6963_string (Driver *drvthis, int x, int y, char string[]);
void t6963_vbar (int x, int len); MODULE_EXPORT void t6963_chr (Driver *drvthis, int x, int y, char c);
void t6963_hbar (int x, int y, int len);
void t6963_num (int x, int num); MODULE_EXPORT void t6963_vbar (Driver *drvthis, int x, int len);
void t6963_set_nchar (int n, char *dat, int num); MODULE_EXPORT void t6963_hbar (Driver *drvthis, int x, int y, int len);
void t6963_set_char (int n, char *dat); MODULE_EXPORT void t6963_num (Driver *drvthis, int x, int num);
void t6963_icon (int which, char dest); MODULE_EXPORT void t6963_icon (Driver *drvthis, int which, char dest);
void t6963_heartbeat (int type); MODULE_EXPORT void t6963_heartbeat (Driver *drvthis, int type);
void t6963_flush_box (int lft, int top, int rgt, int bot);
void t6963_draw_frame (char *dat); MODULE_EXPORT void t6963_set_char (Driver *drvthis, int n, char *dat);
char t6963_getkey ();
MODULE_EXPORT char t6963_getkey (Driver *drvthis);
void t6963_graphic_clear (Driver *drvthis, int x1, int y1, int x2, int y2);
void t6963_set_nchar (Driver *drvthis, int n, char *dat, int num);
void t6963_low_data(u8 byte); void t6963_low_data(u8 byte);
void t6963_low_command (u8 byte); void t6963_low_command (u8 byte);
+146 -136
View File
@@ -6,6 +6,10 @@
* *
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@@ -17,24 +21,7 @@
#include "lcd.h" #include "lcd.h"
#include "text.h" #include "text.h"
#include "drv_base.h" //#include "drv_base.h"
static void text_close ();
static void text_clear ();
static void text_flush ();
static void text_string (int x, int y, char string[]);
static void text_chr (int x, int y, char c);
static int text_contrast (int contrast);
static void text_backlight (int on);
//static void text_init_vbar ();
//static void text_init_hbar ();
//static void text_init_num ();
static void text_vbar (int x, int len);
static void text_hbar (int x, int y, int len);
static void text_num (int x, int num);
//static void text_set_char (int n, char *dat);
//static void text_flush_box (int lft, int top, int rgt, int bot);
static void text_draw_frame (char *dat);
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/ /* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
@@ -79,106 +66,160 @@ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{' ',' ',' '}}}; {' ',' ',' '}}};
/* End of ugly code ;) by Rene Wagner */ /* End of ugly code ;) by Rene Wagner */
lcd_logical_driver *text; // Variables
int width;
int height;
char * framebuf;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "text_";
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Text-Mode Output ////////////////////////////// ////////////////////// For Text-Mode Output //////////////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#define LCD_DEFAULT_WIDTH 20
#define LCD_DEFAULT_HEIGHT 4
// The two value below are fake, we don't support custom char.
#define LCD_DEFAULT_CELL_WIDTH 5
#define LCD_DEFAULT_CELL_HEIGHT 8
// TODO: When using the text driver, ^C fails to interrupt!
// Why? Fix it...
// DONE??? Are you sure, not in my Konsole. David GLAUDE
int int
text_init (lcd_logical_driver * driver, char *args) text_init (Driver *drvthis, char *args)
{ {
text = driver; // Set display sizes
if( drvthis->request_display_width() > 0
&& drvthis->request_display_height() > 0 ) {
// Use size from primary driver
width = drvthis->request_display_width();
height = drvthis->request_display_height();
}
else {
// Use default size
width = LCD_DEFAULT_WIDTH;
height = LCD_DEFAULT_HEIGHT;
}
// Make sure the frame buffer is there... // Allocate the framebuffer
if (!text->framebuf) framebuf = (unsigned char *) malloc (width * height);
text->framebuf = (unsigned char *) memset (framebuf, ' ', width * height);
malloc (text->wid * text->hgt);
memset (text->framebuf, ' ', text->wid * text->hgt);
// Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
// Set the functions the driver supports // Set the functions the driver supports
drvthis->init = text_init;
drvthis->close = text_close;
drvthis->width = text_width;
drvthis->height = text_height;
text->wid = LCD_DEFAULT_WIDTH; drvthis->clear = text_clear;
text->hgt = LCD_DEFAULT_HEIGHT; drvthis->flush = text_flush;
text->cellwid = LCD_DEFAULT_CELL_WIDTH; drvthis->string = text_string;
text->cellhgt = LCD_DEFAULT_CELL_HEIGHT; drvthis->chr = text_chr;
text->clear = text_clear; drvthis->old_vbar = text_vbar;
text->string = text_string; //drvthis->init_vbar = NULL;
text->chr = text_chr; drvthis->old_hbar = text_hbar;
text->vbar = text_vbar; //drvthis->init_hbar = NULL;
//text->init_vbar = NULL; drvthis->num = text_num;
text->hbar = text_hbar; //drvthis->init_num = NULL;
//text->init_hbar = NULL;
text->num = text_num;
//text->init_num = NULL;
text->init = text_init; drvthis->set_contrast = text_set_contrast;
text->close = text_close; drvthis->backlight = text_backlight;
text->flush = text_flush;
//text->flush_box = NULL;
//text->contrast = NULL;
//text->backlight = NULL;
//text->set_char = NULL;
//text->icon = NULL;
text->draw_frame = text_draw_frame;
//text->getkey = NULL; //drvthis->set_char = NULL;
//drvthis->icon = NULL;
return 200; // 200 is arbitrary. (must be 1 or more) //drvthis->getkey = NULL;
return 0;
} }
static void /////////////////////////////////////////////////////////////////
text_close () // Closes the device
//
MODULE_EXPORT void
text_close (Driver *drvthis)
{ {
if (text->framebuf != NULL) if (framebuf != NULL)
free (text->framebuf); free (framebuf);
text->framebuf = NULL; framebuf = NULL;
}
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
text_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
text_height (Driver *drvthis)
{
return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
static void MODULE_EXPORT void
text_clear () text_clear (Driver *drvthis)
{ {
memset (text->framebuf, ' ', text->wid * text->hgt); memset (framebuf, ' ', width * height);
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
static void MODULE_EXPORT void
text_flush () text_flush (Driver *drvthis)
{ {
text_draw_frame (text->framebuf); int i, j;
char out[LCD_MAX_WIDTH];
for (i = 0; i < width; i++) {
out[i] = '-';
}
out[width] = 0;
printf ("+%s+\n", out);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
out[j] = framebuf[j + (i * width)];
}
out[width] = 0;
printf ("|%s|\n", out);
}
for (i = 0; i < width; i++) {
out[i] = '-';
}
out[width] = 0;
printf ("+%s+\n", out);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
static void MODULE_EXPORT void
text_string (int x, int y, char string[]) text_string (Driver *drvthis, int x, int y, char string[])
{ {
int i; int i;
x--; y--; // Convert 1-based coords to 0-based... x--; y--; // Convert 1-based coords to 0-based...
for (i = 0; string[i]; i++) { for (i = 0; string[i]; i++) {
text->framebuf[(y * text->wid) + x + i] = string[i]; framebuf[(y * width) + x + i] = string[i];
} }
} }
@@ -186,24 +227,33 @@ text_string (int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
static void MODULE_EXPORT void
text_chr (int x, int y, char c) text_chr (Driver *drvthis, int x, int y, char c)
{ {
y--; x--; y--; x--;
text->framebuf[(y * text->wid) + x] = c; framebuf[(y * width) + x] = c;
} }
static int /////////////////////////////////////////////////////////////////
text_contrast (int contrast) // Sets the contrast
//
MODULE_EXPORT void
text_set_contrast (Driver *drvthis, int promille)
{ {
// printf("Contrast: %i\n", contrast); /*
return 0; printf("Contrast: %d\n", promille);
*/
} }
static void /////////////////////////////////////////////////////////////////
text_backlight (int on) // Sets the backlight brightness
//
MODULE_EXPORT void
text_backlight (Driver *drvthis, int on)
{ {
//PrivateData * p = (PrivateData*) drvthis->private_data;
/* /*
if(on) if(on)
{ {
@@ -237,14 +287,16 @@ text_backlight (int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. (by Rene Wagner from lcdm001.c) // Writes a big number. (by Rene Wagner from lcdm001.c)
// //
static void text_num (int x, int num) MODULE_EXPORT void text_num (Driver *drvthis, int x, int num)
{ {
//PrivateData * p = (PrivateData*) drvthis->private_data;
int y, dx; int y, dx;
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
for (y = 1; y < 5; y++) for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++) for (dx = 0; dx < 3; dx++)
text_chr (x + dx, y, num_icon[num][y-1][dx]); text_chr (drvthis, x + dx, y, num_icon[num][y-1][dx]);
} }
//void //void
@@ -256,14 +308,14 @@ static void text_num (int x, int num)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
static void MODULE_EXPORT void
text_vbar (int x, int len) text_vbar (Driver *drvthis, int x, int len)
{ {
int y; int y;
for (y = text->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
text_chr (x, y, '|'); text_chr (drvthis, x, y, '|');
len -= text->cellhgt; len -= LCD_DEFAULT_CELLHEIGHT;
} }
} }
@@ -271,56 +323,14 @@ text_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
static void MODULE_EXPORT void
text_hbar (int x, int y, int len) text_hbar (Driver *drvthis, int x, int y, int len)
{ {
for (; x <= text->wid && len > 0; x++) { for (; x <= width && len > 0; x++) {
text_chr (x, y, '-'); text_chr (drvthis, x, y, '-');
len -= text->cellwid; len -= LCD_DEFAULT_CELLWIDTH;
} }
} }
static void
text_flush_box (int lft, int top, int rgt, int bot)
{
text_flush ();
}
static void
text_draw_frame (char *dat)
{
int i, j;
char out[LCD_MAX_WIDTH];
if (!dat)
return;
// printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
for (i = 0; i < text->wid; i++) {
out[i] = '-';
}
out[text->wid] = 0;
printf ("+%s+\n", out);
for (i = 0; i < text->hgt; i++) {
for (j = 0; j < text->wid; j++) {
out[j] = dat[j + (i * text->wid)];
}
out[text->wid] = 0;
printf ("|%s|\n", out);
}
for (i = 0; i < text->wid; i++) {
out[i] = '-';
}
out[text->wid] = 0;
printf ("+%s+\n", out);
}
+19 -2
View File
@@ -1,8 +1,25 @@
#ifndef LCD_TEXT_H #ifndef LCD_TEXT_H
#define LCD_TEXT_H #define LCD_TEXT_H
extern lcd_logical_driver *text; #include "lcd.h"
int text_init (Driver * drvthis, char *args);
MODULE_EXPORT void text_close (Driver *drvthis);
MODULE_EXPORT int text_width (Driver *drvthis);
MODULE_EXPORT int text_height (Driver *drvthis);
MODULE_EXPORT void text_clear (Driver *drvthis);
MODULE_EXPORT void text_flush (Driver *drvthis);
MODULE_EXPORT void text_string (Driver *drvthis, int x, int y, char string[]);
MODULE_EXPORT void text_chr (Driver *drvthis, int x, int y, char c);
MODULE_EXPORT void text_set_contrast (Driver *drvthis, int promille);
MODULE_EXPORT void text_backlight (Driver *drvthis, int on);
//MODULE_EXPORT void text_init_vbar (Driver *drvthis);
//MODULE_EXPORT void text_init_hbar (Driver *drvthis);
//MODULE_EXPORT void text_init_num (Driver *drvthis);
MODULE_EXPORT void text_vbar (Driver *drvthis, int x, int len);
MODULE_EXPORT void text_hbar (Driver *drvthis, int x, int y, int len);
MODULE_EXPORT void text_num (Driver *drvthis, int x, int num);
//MODULE_EXPORT void text_set_char (Driver *drvthis, int n, char *dat);
int text_init (struct lcd_logical_driver *driver, char *args);
#endif #endif
+129 -158
View File
@@ -18,7 +18,7 @@
#include "lcd.h" #include "lcd.h"
#include "wirz-sli.h" #include "wirz-sli.h"
#include "drv_base.h" //#include "drv_base.h"
#include "shared/debug.h" #include "shared/debug.h"
#include "shared/str.h" #include "shared/str.h"
@@ -32,15 +32,22 @@ typedef enum {
} custom_type; } custom_type;
static int fd; static int fd;
static char lastframe[32]; static char *framebuf = NULL;
static int width = 0;
static int height = 0;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "sli_";
lcd_logical_driver *sli;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int int
sli_init (lcd_logical_driver * driver, char *args) sli_init (Driver *drvthis, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -52,8 +59,6 @@ sli_init (lcd_logical_driver * driver, char *args)
char device[256] = "/dev/lcd"; char device[256] = "/dev/lcd";
int speed = B19200; int speed = B19200;
sli = driver;
//debug("sli_init: Args(all): %s\n", args); //debug("sli_init: Args(all): %s\n", args);
argc = get_args (argv, args, 64); argc = get_args (argv, args, 64);
@@ -151,92 +156,109 @@ sli_init (lcd_logical_driver * driver, char *args)
// Set LCD parameters (I use a 16x2 LCD) -- small but still useful // Set LCD parameters (I use a 16x2 LCD) -- small but still useful
// Its also much cheaper than the higher quality Matrix Orbital modules // Its also much cheaper than the higher quality Matrix Orbital modules
// Currently, $30 for interface kit and 16x2 non-backlit LCD... // Currently, $30 for interface kit and 16x2 non-backlit LCD...
driver->wid = 15; width = 15;
driver->hgt = 2; height = 2;
// Set the functions the driver supports... // Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = sli_clear; // Set the functions the driver supports
driver->string = sli_string; drvthis->clear = sli_clear;
driver->chr = sli_chr; drvthis->string = sli_string;
driver->vbar = sli_vbar; drvthis->chr = sli_chr;
driver->init_vbar = sli_init_vbar; drvthis->old_vbar = sli_vbar;
driver->hbar = sli_hbar; drvthis->init_vbar = sli_init_vbar;
driver->init_hbar = sli_init_hbar; drvthis->old_hbar = sli_hbar;
//driver->num = NULL; drvthis->init_hbar = sli_init_hbar;
//driver->init_num = NULL; //drvthis->num = NULL;
//drvthis->init_num = NULL;
driver->init = sli_init; drvthis->init = sli_init;
driver->close = sli_close; drvthis->close = sli_close;
driver->flush = sli_flush; drvthis->flush = sli_flush;
driver->flush_box = sli_flush_box; //drvthis->contrast = NULL;
//driver->contrast = NULL; //drvthis->backlight = NULL;
//driver->backlight = NULL; drvthis->set_char = sli_set_char;
driver->set_char = sli_set_char; drvthis->old_icon = sli_icon;
driver->icon = sli_icon;
driver->draw_frame = sli_draw_frame;
//driver->getkey = NULL; //drvthis->getkey = NULL;
return fd; return fd;
} }
/* Clean-up */ /////////////////////////////////////////////////////////////////
void // Clean up
sli_close () //
MODULE_EXPORT void
sli_close (Driver *drvthis)
{ {
close (fd); close (fd);
if (sli->framebuf) if (framebuf)
free (sli->framebuf); free (framebuf);
sli->framebuf = NULL; framebuf = NULL;
} }
void /////////////////////////////////////////////////////////////////
sli_flush () // Returns the display width
//
MODULE_EXPORT int
sli_width (Driver *drvthis)
{ {
sli_draw_frame (sli->framebuf); return width;
} }
/* no bounds checking is done in MtxOrb.c (which I shamelessly ripped) /////////////////////////////////////////////////////////////////
this is bad imho, so I added it.. may remove later // Returns the display height
speed is not a huge issue though, this isnt a //
device driver or anything ;) */ MODULE_EXPORT int
void sli_height (Driver *drvthis)
sli_flush_box (int lft, int top, int rgt, int bot)
{ {
int y; return height;
char out[2]; /* Why does the matrix driver allocate so much here? */ }
/* simple bounds checking */ /////////////////////////////////////////////////////////////////
if ((top > sli->hgt) | (bot > sli->hgt)) // Flush framebuffer to LCD
return; //
MODULE_EXPORT void
sli_flush (Driver *drvthis)
{
char out[2]; /* Again, why does the Matrix driver allocate so much here? */
if ((lft > sli->wid) | (rgt > sli->wid)) /*
return; out[0]=0x0FE;
out[1]=0x001;
write(fd, out, 2);
*/
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); /* Don't update if we have no new data
this keeps me from getting a migraine
(just like those copyleft penguin mints... mmmmmm) */
/* I like having hex, everywhere and all the time */ // if (!strncmp(dat,lastframe,32)) /* Nothing has changed */
for (y = top; y <= bot; y++) { // return;
if (y == 1)
snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x080 + lft);
if (y == 2)
snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x0C0 + lft);
write (fd, out, 0x002);
write (fd, sli->framebuf + (y * sli->wid) + lft, rgt - lft + 1);
}
/* Do the actual refresh */
out[0] = 0x0FE;
out[1] = 0x080;
write (fd, out, 2);
write (fd, &framebuf[0], 16);
usleep (10);
write (fd, &framebuf[16], 15);
// strncpy(lastframe,dat,32); // Update lastframe...
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void MODULE_EXPORT void
sli_clear () sli_clear (Driver *drvthis)
{ {
memset (sli->framebuf, ' ', sli->wid * sli->hgt); memset (framebuf, ' ', width * height);
} }
@@ -244,8 +266,8 @@ sli_clear ()
// Prints a string on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
sli_string (int x, int y, char string[]) sli_string (Driver *drvthis, int x, int y, char string[])
{ {
int i; int i;
@@ -254,9 +276,9 @@ sli_string (int x, int y, char string[])
for (i = 0; string[i]; i++) { for (i = 0; string[i]; i++) {
// Check for buffer overflows... // Check for buffer overflows...
if ((y * sli->wid) + x + i > (sli->wid * sli->hgt)) if ((y * width) + x + i > (width * height))
break; break;
sli->framebuf[(y * sli->wid) + x + i] = string[i]; framebuf[(y * width) + x + i] = string[i];
} }
} }
@@ -264,26 +286,13 @@ sli_string (int x, int y, char string[])
// Prints a character on the lcd display, at position (x,y). The // 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). // upper-left is (1,1), and the lower right should be (20,4).
// //
void MODULE_EXPORT void
sli_chr (int x, int y, char c) sli_chr (Driver *drvthis, int x, int y, char c)
{ {
y--; y--;
x--; x--;
sli->framebuf[(y * sli->wid) + x] = c; framebuf[(y * width) + x] = c;
}
/////////////////////////////////////////////////////////////////
// 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
sli_chr (int x, int y, char c)
{
y--;
x--;
sli->framebuf[(y * sli->wid) + x] = c;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -299,8 +308,8 @@ sli_chr (int x, int y, char c)
characters, so that you can do both bar types at once.. maybe I characters, so that you can do both bar types at once.. maybe I
will release a new version of the SLI driver that attempts this */ will release a new version of the SLI driver that attempts this */
void MODULE_EXPORT void
sli_init_vbar () sli_init_vbar (Driver *drvthis)
{ {
char a[] = { char a[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -374,13 +383,13 @@ sli_init_vbar ()
}; };
if (custom != vbar) { if (custom != vbar) {
sli_set_char (1, a); sli_set_char (drvthis, 1, a);
sli_set_char (2, b); sli_set_char (drvthis, 2, b);
sli_set_char (3, c); sli_set_char (drvthis, 3, c);
sli_set_char (4, d); sli_set_char (drvthis, 4, d);
sli_set_char (5, e); sli_set_char (drvthis, 5, e);
sli_set_char (6, f); sli_set_char (drvthis, 6, f);
sli_set_char (7, g); sli_set_char (drvthis, 7, g);
custom = vbar; custom = vbar;
} }
} }
@@ -388,8 +397,8 @@ sli_init_vbar ()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void MODULE_EXPORT void
sli_init_hbar () sli_init_hbar (Driver *drvthis)
{ {
char a[] = { char a[] = {
@@ -434,10 +443,10 @@ sli_init_hbar ()
}; };
if (custom != hbar) { if (custom != hbar) {
sli_set_char (1, a); sli_set_char (drvthis, 1, a);
sli_set_char (2, b); sli_set_char (drvthis, 2, b);
sli_set_char (3, c); sli_set_char (drvthis, 3, c);
sli_set_char (4, d); sli_set_char (drvthis, 4, d);
custom = hbar; custom = hbar;
} }
} }
@@ -451,19 +460,19 @@ sli_init_hbar ()
since we only have 2 lines anyway this is rather pointless since we only have 2 lines anyway this is rather pointless
for me to add */ for me to add */
void MODULE_EXPORT void
sli_vbar (int x, int len) sli_vbar (Driver *drvthis, int x, int len)
{ {
char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 }; char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y; int y;
for (y = sli->hgt; y > 0 && len > 0; y--) { for (y = height; y > 0 && len > 0; y--) {
if (len >= sli->cellhgt) if (len >= LCD_DEFAULT_CELLHEIGHT)
sli_chr (x, y, 255); sli_chr (drvthis, x, y, 255);
else else
sli_chr (x, y, map[len]); sli_chr (drvthis, x, y, map[len]);
len -= sli->cellhgt; len -= LCD_DEFAULT_CELLHEIGHT;
} }
} }
@@ -471,18 +480,18 @@ sli_vbar (int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void MODULE_EXPORT void
sli_hbar (int x, int y, int len) sli_hbar (Driver *drvthis, int x, int y, int len)
{ {
char map[6] = { 32, 1, 2, 3, 4, 255 }; char map[6] = { 32, 1, 2, 3, 4, 255 };
for (; x <= sli->wid && len > 0; x++) { for (; x <= width && len > 0; x++) {
if (len >= sli->cellwid) if (len >= LCD_DEFAULT_CELLWIDTH)
sli_chr (x, y, 255); sli_chr (drvthis, x, y, 255);
else else
sli_chr (x, y, map[len]); sli_chr (drvthis, x, y, map[len]);
len -= sli->cellwid; len -= LCD_DEFAULT_CELLWIDTH;
} }
@@ -495,8 +504,8 @@ sli_hbar (int x, int y, int len)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void MODULE_EXPORT void
sli_set_char (int n, char *dat) sli_set_char (Driver *drvthis, int n, char *dat)
{ {
char out[2]; char out[2];
int row, col; int row, col;
@@ -513,11 +522,11 @@ sli_set_char (int n, char *dat)
out[1] = 0x040 + 8 * n; out[1] = 0x040 + 8 * n;
write (fd, out, 2); write (fd, out, 2);
for (row = 0; row < sli->cellhgt; row++) { for (row = 0; row < LCD_DEFAULT_CELLHEIGHT; row++) {
letter = 0; letter = 0;
for (col = 0; col < sli->cellwid; col++) { for (col = 0; col < LCD_DEFAULT_CELLWIDTH; col++) {
letter <<= 1; letter <<= 1;
letter |= (dat[(row * sli->cellwid) + col] > 0); letter |= (dat[(row * LCD_DEFAULT_CELLWIDTH) + col] > 0);
} }
letter |= 0x020; /* SLI can't accept CR, LF, etc in this character! */ letter |= 0x020; /* SLI can't accept CR, LF, etc in this character! */
write (fd, &letter, 1); write (fd, &letter, 1);
@@ -529,8 +538,8 @@ sli_set_char (int n, char *dat)
write (fd, out, 2); write (fd, out, 2);
} }
void MODULE_EXPORT void
sli_icon (int which, char dest) sli_icon (Driver *drvthis, int which, char dest)
{ {
char icons[3][5 * 8] = { char icons[3][5 * 8] = {
{ {
@@ -570,44 +579,6 @@ sli_icon (int which, char dest)
if (custom == bign) if (custom == bign)
custom = beat; custom = beat;
sli_set_char (dest, &icons[which][0]); sli_set_char (drvthis, dest, &icons[which][0]);
} }
/////////////////////////////////////////////////////////////
// Blasts a single frame onscreen, to the lcd...
//
// Input is a character array, sized sli->wid*sli->hgt
//
void
sli_draw_frame (char *dat)
{
char out[2]; /* Again, why does the Matrix driver allocate so much here? */
int y;
if (!dat)
return;
/*
out[0]=0x0FE;
out[1]=0x001;
write(fd, out, 2);
*/
/* Don't update if we have no new data
this keeps me from getting a migraine
(just like those copyleft penguin mints... mmmmmm) */
// if (!strncmp(dat,lastframe,32)) /* Nothing has changed */
// return;
/* Do the actual refresh */
out[0] = 0x0FE;
out[1] = 0x080;
write (fd, out, 2);
write (fd, &dat[0], 16);
usleep (10);
write (fd, &dat[16], 15);
// strncpy(lastframe,dat,32); // Update lastframe...
}
+26 -18
View File
@@ -7,24 +7,32 @@
#ifndef SLI_H #ifndef SLI_H
#define SLI_H #define SLI_H
extern lcd_logical_driver *sli; #include "lcd.h"
int sli_init (lcd_logical_driver * driver, char *device); int sli_init (Driver *drvthis, char *args);
void sli_close (); MODULE_EXPORT void sli_close (Driver *drvthis);
void sli_flush (); MODULE_EXPORT int sli_width (Driver *drvthis);
void sli_flush_box (int lft, int top, int rgt, int bot); MODULE_EXPORT int sli_height (Driver *drvthis);
void sli_chr (int x, int y, char c); MODULE_EXPORT void sli_clear (Driver *drvthis);
int sli_contrast (int contrast); MODULE_EXPORT void sli_flush (Driver *drvthis);
void sli_backlight (int on); MODULE_EXPORT void sli_string (Driver *drvthis, int x, int y, char *string);
void sli_init_vbar (); MODULE_EXPORT void sli_chr (Driver *drvthis, int x, int y, char c);
void sli_init_hbar ();
void sli_vbar (int x, int len); MODULE_EXPORT void sli_vbar (Driver *drvthis, int x, int len);
void sli_hbar (int x, int y, int len); MODULE_EXPORT void sli_hbar (Driver *drvthis, int x, int y, int len);
void sli_init_num (); MODULE_EXPORT void sli_num (Driver *drvthis, int x, int num);
void sli_num (int x, int num); MODULE_EXPORT void sli_icon (Driver *drvthis, int which, char dest);
void sli_set_char (int n, char *dat);
void sli_icon (int which, char dest); MODULE_EXPORT void sli_set_char (Driver *drvthis, int n, char *dat);
void sli_draw_frame (char *dat);
char sli_getkey (); MODULE_EXPORT int sli_get_contrast (Driver *drvthis);
MODULE_EXPORT void sli_set_contrast (Driver *drvthis, int contrast);
MODULE_EXPORT void sli_backlight (Driver *drvthis, int on);
MODULE_EXPORT char sli_getkey (Driver *drvthis);
MODULE_EXPORT void sli_init_vbar (Driver *drvthis);
MODULE_EXPORT void sli_init_hbar (Driver *drvthis);
MODULE_EXPORT void sli_init_num (Driver *drvthis);
#endif #endif
+42 -77
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Handles keypad (and other?) input from the user. * Handles keypad (and other?) input from the user.
@@ -34,44 +33,6 @@
E-Z Ignored E-Z Ignored
*/ */
// These are the keys for a (likely) properly functioning LK202-25...
// #define KEY_UP 'I'
// #define KEY_DOWN 'J'
// #define KEY_LEFT 'O'
// #define KEY_RIGHT 'E'
// #define KEY_F1 'N'
// #define KEY_F2 'M'
// #define KEY_ENTER 'H'
// These are the keys for my (possibly) broken LK202-25...
// #define KEY_UP 'I'
// #define KEY_DOWN 'F'
// #define KEY_LEFT 'K'
// #define KEY_RIGHT 'A'
// #define KEY_F1 'N'
// #define KEY_F2 'M'
// #define KEY_ENTER 'H'
// TODO: Generalize these into each driver...
//
// Really, what this comes down to, is different settings for
// different displays. Unless you want to recompile for all
// the defaults, these key settings must be in the driver.
//
// But then, which driver is active and which screen takes which
// input and... (sigh).
//
// #define PAUSE_KEY KEY_F1
// #define BACK_KEY KEY_LEFT
// #define FORWARD_KEY KEY_RIGHT
// #define MAIN_MENU_KEY KEY_DOWN
// This seems somewhat arbitrary, but it IS the original settings:
//
#define PAUSE_KEY 'A'
#define BACK_KEY 'B'
#define FORWARD_KEY 'C'
#define MAIN_MENU_KEY 'D'
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@@ -80,7 +41,7 @@
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/report.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "client_data.h" #include "client_data.h"
#include "clients.h" #include "clients.h"
@@ -98,70 +59,75 @@
int server_input (int key); int server_input (int key);
// FIXME! The server tends to crash when "E" is pressed.. (?!) /* FIXME! The server tends to crash when "E" is pressed.. (?!)
// (but only when the joystick driver is the last one on the list...) * (but only when the joystick driver is the last one on the list...)
*/
// Checks for keypad input, and dispatches it /* Checks for keypad input, and dispatches it */
int int
handle_input () handle_input ()
{ {
char str[15]; char str[15];
int key; int key;
screen *s; screen *s;
//widget *w; /*widget *w; */
client *c; client *c;
if ((key = lcd_ptr->getkey ()) == 0) report (RPT_INFO, "handle_input()" );
if ((key = drivers_getkey ()) == 0)
return 0; return 0;
//debug (RPT_DEBUG, "handle_input(%c)", (char) key); debug (RPT_INFO, "handle_input got key: '%c'", key);
// Sequence: /* Sequence:
// Does the current screen want the key? * Does the current screen want the key?
// IfTrue: handle and quit * IfTrue: handle and quit
// IfFalse: * IfFalse:
// Let ALL clients handle it if they want * Let ALL clients handle it if they want
// Let Server handle it, too * Let Server handle it, too
// *
// This leads to a unique situation: * This leads to a unique situation:
// First: multiple clients may handle the same key in multiple ways * First: multiple clients may handle the same key in multiple ways
// Second: the server may handle the key differently yet * Second: the server may handle the key differently yet
// *
// Solution: Only the current screen can handle the key press. * Solution: Only the current screen can handle the key press.
// Alternately, only one client can handle the key press. * Alternately, only one client can handle the key press.
*/
// TODO: Interpret and translate keys! /* TODO: Interpret and translate keys! */
// Give current screen a shot at the key first /* Give current screen a shot at the key first */
s = CurrentScreen (); s = CurrentScreen ();
if (KeyWanted(s->keys, key)) { if (KeyWanted(s->keys, key)) {
// This screen wants this key. Tell it we got one /* This screen wants this key. Tell it we got one */
snprintf(str, sizeof(str), "key %c\n", key); snprintf(str, sizeof(str), "key %c\n", key);
sock_send_string(s->parent->sock, str); sock_send_string(s->parent->sock, str);
// Nobody else gets this key /* Nobody else gets this key */
} }
// if the current screen doesn't want it, /* if the current screen doesn't want it,
// let the server have it... * let the server have it...
*/
else { else {
// Give key to clients who want it /* Give key to clients who want it */
c = FirstClient(clients); c = FirstClient(clients);
while (c) { while (c) {
// If the client should have this keypress... /* If the client should have this keypress... */
if(KeyWanted(c->data->client_keys,key)) { if(KeyWanted(c->data->client_keys,key)) {
// Send keypress to client /* Send keypress to client */
snprintf(str, sizeof(str), "key %c\n", key); snprintf(str, sizeof(str), "key %c\n", key);
sock_send_string(c->sock, str); sock_send_string(c->sock, str);
break; // first come, first serve break; /* first come, first serve */
}; };
c = NextClient(clients); c = NextClient(clients);
} // while clients } /* while clients */
// Give server a shot at all keys /* Give server a shot at all keys */
server_input (key); server_input (key);
} }
@@ -171,25 +137,24 @@ handle_input ()
int int
server_input (int key) server_input (int key)
{ {
debug (RPT_INFO, "server_input(%c)", (char) key); report(RPT_INFO, "server_input( key='%c' )", (char) key);
report(RPT_INFO, "key %d pressed on device", key);
switch ((char) key) { switch ((char) key) {
case PAUSE_KEY: case INPUT_PAUSE_KEY:
if (screenlist_action == SCR_HOLD) if (screenlist_action == SCR_HOLD)
screenlist_action = 0; screenlist_action = 0;
else else
screenlist_action = SCR_HOLD; screenlist_action = SCR_HOLD;
break; break;
case BACK_KEY: case INPUT_BACK_KEY:
screenlist_action = SCR_BACK; screenlist_action = SCR_BACK;
screenlist_prev (); screenlist_prev ();
break; break;
case FORWARD_KEY: case INPUT_FORWARD_KEY:
screenlist_action = SCR_SKIP; screenlist_action = SCR_SKIP;
screenlist_next (); screenlist_next ();
break; break;
case MAIN_MENU_KEY: case INPUT_MAIN_MENU_KEY:
debug (RPT_DEBUG, "got the menu key!"); debug (RPT_DEBUG, "got the menu key!");
server_menu (); server_menu ();
break; break;
+12 -2
View File
@@ -6,14 +6,24 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
// Accepts and uses keypad input while displaying screens... /* Accepts and uses keypad input while displaying screens... */
int handle_input (); int handle_input ();
/* These defines should be used by drivers for version 0.4.3 of LCDproc
* as return values for _getkey().
* You should not change these values, as some drivers still return
* A, B, C; D directly without using these defines!
*/
#define INPUT_PAUSE_KEY 'A'
#define INPUT_BACK_KEY 'B'
#define INPUT_FORWARD_KEY 'C'
#define INPUT_MAIN_MENU_KEY 'D'
#endif #endif
+174 -160
View File
@@ -53,7 +53,7 @@ extern int optind, optopt, opterr;
#define MAX_TIMER 0x10000 #define MAX_TIMER 0x10000
//#define DEFAULT_DEBUG_LEVEL 1 /*#define DEFAULT_DEBUG_LEVEL 1*/
#define DEFAULT_LCD_PORT LCDPORT #define DEFAULT_LCD_PORT LCDPORT
#define DEFAULT_BIND_ADDR "127.0.0.1" #define DEFAULT_BIND_ADDR "127.0.0.1"
#define DEFAULT_CONFIGFILE "/etc/LCDd.conf" #define DEFAULT_CONFIGFILE "/etc/LCDd.conf"
@@ -85,13 +85,13 @@ char *build_date = __DATE__;
/**** Configuration variables ****/ /**** Configuration variables ****/
// All variables are set to 'unset' values /* All variables are set to 'unset' values*/
#define UNSET_INT -1 #define UNSET_INT -1
#define UNSET_STR "\01" #define UNSET_STR "\01"
int debug_level; // for compatibility with MtxOrb, lcdm001 and joy drivers. int debug_level; /* for compatibility with MtxOrb and joy drivers.
// I was about to remove the comment in front of this. * I was about to remove the comment in front of this.
// Now how do we become compatible WITHOUT this debug_level ? * Now how do we become compatible WITHOUT this debug_level ?*/
int lcd_port = UNSET_INT; int lcd_port = UNSET_INT;
char bind_addr[64] = UNSET_STR; char bind_addr[64] = UNSET_STR;
@@ -105,33 +105,34 @@ static int reportLevel = UNSET_INT;
static int reportToSyslog = UNSET_INT; static int reportToSyslog = UNSET_INT;
static int serverStarted = 0; static int serverStarted = 0;
// The drivers and their driver parameters /* The drivers and their driver parameters*/
char *drivernames[MAX_DRIVERS]; char *drivernames[MAX_DRIVERS];
char *driverfilenames[MAX_DRIVERS]; char *driverfilenames[MAX_DRIVERS];
char *driverargs[MAX_DRIVERS]; char *driverargs[MAX_DRIVERS];
int num_drivers = 0; int num_drivers = 0;
// The parameter structure and args[] should /* The parameter structure and args[] should
// be removed when getopt(3) is implemented, * be removed when getopt(3) is implemented,
// as there won't be any need for them then. * as there won't be any need for them then.
//typedef struct parameter { * typedef struct parameter {
// char *sh, *lg; // short and long versions * char *sh, *lg; */ /* short and long versions*/
//} parameter; /*} parameter;
+
// This is currently only a list of available arguments, but doesn't * This is currently only a list of available arguments, but doesn't
// really *do* anything. It just helps to figure out which parameters * really *do* anything. It just helps to figure out which parameters
// go to the server, and which ones go to individual drivers... * go to the server, and which ones go to individual drivers...
//static parameter args[] = { *static parameter args[] = {
// {"-h", "--help"}, * {"-h", "--help"},
// {"-d", "--driver"}, * {"-d", "--driver"},
// {"-t", "--type"}, * {"-t", "--type"},
// {"-f", "--foreground"}, * {"-f", "--foreground"},
// {"-b", "--backlight"}, * {"-b", "--backlight"},
// {"-i", "--serverinfo"}, * {"-i", "--serverinfo"},
// {"-w", "--waittime"}, * {"-w", "--waittime"},
// {NULL, NULL}, * {NULL, NULL},
//}; *};
*/
/**** Local functions ****/ /**** Local functions ****/
@@ -155,18 +156,20 @@ void lcd_list_drivers();
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
// FIXME: s is getting clobbered - in MANY places!!! /* FIXME: s is getting clobbered - in MANY places!!!
//screen *s = NULL; *screen *s = NULL;
//char buf[64]; *char buf[64];
*/
signal (SIGINT, exit_program); // Ctrl-C will cause a clean exit... signal (SIGINT, exit_program); /* Ctrl-C will cause a clean exit...*/
signal (SIGTERM, exit_program); // and "kill"... signal (SIGTERM, exit_program); /* and "kill"...*/
signal (SIGHUP, exit_program); // and "kill -HUP" (hangup)... signal (SIGHUP, exit_program); /* and "kill -HUP" (hangup)...*/
signal (SIGKILL, exit_program); // and just in case, "kill -KILL" (which cannot be trapped; but oh well) signal (SIGKILL, exit_program); /* and just in case, "kill -KILL" (which cannot be trapped; but oh well)*/
// If no paramaters given, give the help screen. /* If no paramaters given, give the help screen.
//if (argc == 1) *if (argc == 1)
// HelpScreen (); * HelpScreen ();
*/
/* /*
* Settings in order of preference: * Settings in order of preference:
@@ -188,41 +191,42 @@ main (int argc, char **argv)
* in the variable declaration... * in the variable declaration...
*/ */
// Set the initial reporting parameters /* Set the initial reporting parameters*/
report(RPT_NOTICE, "LCDd version %s starting", version ); report(RPT_NOTICE, "LCDd version %s starting", version );
report(RPT_INFO, "Built on %s, protocol version %s, API version %s", report(RPT_INFO, "Built on %s, protocol version %s, API version %s",
build_date, protocol_version, api_version ); build_date, protocol_version, api_version );
clear_settings(); clear_settings();
// Read command line /* Read command line*/
ESSENTIAL( process_command_line (argc, argv) ); ESSENTIAL( process_command_line (argc, argv) );
// Read config file /* Read config file
// Set configfile to default value first unless changed before * Set configfile to default value first unless changed before
*/
if (strcmp(configfile, UNSET_STR)==0) if (strcmp(configfile, UNSET_STR)==0)
strncpy (configfile, DEFAULT_CONFIGFILE, sizeof(configfile)); strncpy (configfile, DEFAULT_CONFIGFILE, sizeof(configfile));
ESSENTIAL( process_configfile (configfile) ); ESSENTIAL( process_configfile (configfile) );
// Set default values /* Set default values*/
set_default_settings(); set_default_settings();
// Set reporting values /* Set reporting values*/
debug_level = reportLevel; debug_level = reportLevel;
ESSENTIAL( set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) ) ); ESSENTIAL( set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) ) );
report( RPT_NOTICE, "Set report level to %d, output to %s", reportLevel, (reportToSyslog?"syslog":"stderr") ); report( RPT_NOTICE, "Set report level to %d, output to %s", reportLevel, (reportToSyslog?"syslog":"stderr") );
// Startup the server /* Startup the server*/
ESSENTIAL( init_sockets() ); ESSENTIAL( init_sockets() );
ESSENTIAL( init_drivers() ); ESSENTIAL( init_drivers() );
ESSENTIAL( init_screens() ); ESSENTIAL( init_screens() );
ESSENTIAL( drop_privs(user) ); ESSENTIAL( drop_privs(user) );
// Store it for exit_program() /* Store it for exit_program()*/
serverStarted = 1; serverStarted = 1;
#ifndef DEBUG #ifndef DEBUG
// Now, go into daemon mode... /* Now, go into daemon mode...*/
if (daemon_mode) { if (daemon_mode) {
report(RPT_NOTICE, "Server forking to background"); report(RPT_NOTICE, "Server forking to background");
ESSENTIAL( daemonize() ); ESSENTIAL( daemonize() );
@@ -232,7 +236,7 @@ main (int argc, char **argv)
#endif #endif
do_mainloop(); do_mainloop();
// This loop never stops; we'll get out only with a signal... /* This loop never stops; we'll get out only with a signal...*/
return 0; return 0;
} }
@@ -243,7 +247,7 @@ clear_settings ()
{ {
int i; int i;
//report( RPT_INFO, "clear_settings()" ); /*report( RPT_INFO, "clear_settings()" );*/
lcd_port = UNSET_INT; lcd_port = UNSET_INT;
strncpy( bind_addr, UNSET_STR, sizeof(bind_addr) ); strncpy( bind_addr, UNSET_STR, sizeof(bind_addr) );
@@ -275,15 +279,16 @@ process_command_line (int argc, char **argv)
{ {
char c; char c;
//report( RPT_INFO, "process_command_line()" ); /*report( RPT_INFO, "process_command_line()" );*/
// analyze options here.. /* analyze options here..*/
while ((c = getopt(argc, argv, "a:p:d:hfib:w:c:u:sr:")) > 0) { while ((c = getopt(argc, argv, "a:p:d:hfib:w:c:u:sr:")) > 0) {
// FIXME: Setting of c in this loop clobbers s! /* FIXME: Setting of c in this loop clobbers s!
// s is set equivalent to c. * s is set equivalent to c.
*/
switch(c) { switch(c) {
case 'd': case 'd':
// Add to a list of drivers to be initialized later... /* Add to a list of drivers to be initialized later...*/
if (num_drivers < MAX_DRIVERS) { if (num_drivers < MAX_DRIVERS) {
drivernames[num_drivers] = malloc( strlen(optarg)+1 ); drivernames[num_drivers] = malloc( strlen(optarg)+1 );
driverfilenames[num_drivers] = malloc( strlen(optarg)+1 ); driverfilenames[num_drivers] = malloc( strlen(optarg)+1 );
@@ -371,16 +376,17 @@ process_configfile ( char *configfile )
{ {
int i; int i;
char * s; char * s;
//char buf[64]; /*char buf[64];*/
//report( RPT_INFO, "process_configfile()" ); /*report( RPT_INFO, "process_configfile()" );*/
// Read server settings /* Read server settings*/
config_read_file( configfile ); config_read_file( configfile );
// if( debug_level == UNSET_INT ) /* if( debug_level == UNSET_INT )
// debug_level = config_get_int( "server", "debug", 0, UNSET_INT ); * debug_level = config_get_int( "server", "debug", 0, UNSET_INT );
*/
if( lcd_port == UNSET_INT ) if( lcd_port == UNSET_INT )
lcd_port = config_get_int( "server", "port", 0, UNSET_INT ); lcd_port = config_get_int( "server", "port", 0, UNSET_INT );
@@ -430,7 +436,7 @@ process_configfile ( char *configfile )
} }
if( reportToSyslog == UNSET_INT ) { if( reportToSyslog == UNSET_INT ) {
// Is the value set in the config file anyway ? /* Is the value set in the config file anyway ?*/
if( strcmp( config_get_string( "server", "reportToSyslog", 0, "" ), "" ) != 0 ) { if( strcmp( config_get_string( "server", "reportToSyslog", 0, "" ), "" ) != 0 ) {
reportToSyslog = config_get_bool( "server", "reportToSyslog", 0, 0 ); reportToSyslog = config_get_bool( "server", "reportToSyslog", 0, 0 );
} }
@@ -440,12 +446,13 @@ process_configfile ( char *configfile )
} }
// Read drivers /* Read drivers*/
// If drivers have been specified on the command line, then do not /* If drivers have been specified on the command line, then do not
// use the driver list from the config file. * use the driver list from the config file.
*/
if( num_drivers == 0 ) { if( num_drivers == 0 ) {
// read the drivernames /* read the drivernames*/
while( 1 ) { while( 1 ) {
s = config_get_string( "server", "driver", num_drivers, "" ); s = config_get_string( "server", "driver", num_drivers, "" );
@@ -464,8 +471,9 @@ process_configfile ( char *configfile )
} }
} }
// Now read the driver options that the server needs /* Now read the driver options that the server needs
// Drivers can read their own options later... * Drivers can read their own options later...
*/
for( i=0; i<num_drivers; i ++ ) { for( i=0; i<num_drivers; i ++ ) {
s = config_get_string( drivernames[i], "file", 0, "" ); s = config_get_string( drivernames[i], "file", 0, "" );
driverfilenames[i] = realloc( driverfilenames[i], strlen(s)+1 ); driverfilenames[i] = realloc( driverfilenames[i], strlen(s)+1 );
@@ -483,12 +491,13 @@ process_configfile ( char *configfile )
void void
set_default_settings() set_default_settings()
{ {
//report( RPT_INFO, "set_default_settings()" ); /*report( RPT_INFO, "set_default_settings()" );*/
// Set defaults into unfilled variables.... /* Set defaults into unfilled variables....*/
// if (debug_level == UNSET_INT) /* if (debug_level == UNSET_INT)
// debug_level = DEFAULT_DEBUG_LEVEL; * debug_level = DEFAULT_DEBUG_LEVEL;
*/
if (lcd_port == UNSET_INT) if (lcd_port == UNSET_INT)
lcd_port = DEFAULT_LCD_PORT; lcd_port = DEFAULT_LCD_PORT;
if (strcmp( bind_addr, UNSET_STR ) == 0) if (strcmp( bind_addr, UNSET_STR ) == 0)
@@ -512,7 +521,7 @@ set_default_settings()
reportLevel = DEFAULT_REPORTLEVEL; reportLevel = DEFAULT_REPORTLEVEL;
// Use default driver /* Use default driver*/
if( num_drivers == 0 ) { if( num_drivers == 0 ) {
drivernames[0] = malloc(strlen(DEFAULT_DRIVER)+1); drivernames[0] = malloc(strlen(DEFAULT_DRIVER)+1);
driverfilenames[0] = malloc(1); driverfilenames[0] = malloc(1);
@@ -537,20 +546,21 @@ daemonize()
case -1: case -1:
report(RPT_ERR, "Could not fork"); report(RPT_ERR, "Could not fork");
return -1; return -1;
case 0: // We are the child case 0: /* We are the child*/
break; break;
default: // We are the parent default: /* We are the parent*/
usleep (1500000); // Wait for child to initialize usleep (1500000); /* Wait for child to initialize*/
exit (0); /* PARENT EXITS */ exit (0); /* PARENT EXITS */
} }
// This line removed because it eats error messages... /* This line removed because it eats error messages...
//setsid(); /* RELEASE TTY */ * setsid();*/ /* RELEASE TTY */
// /*
// After this point, as a daemon, no error messages should * After this point, as a daemon, no error messages should
// go to the console unless drastic; rather, they should go to syslog * go to the console unless drastic; rather, they should go to syslog
// *
// However, option processing is not yet done, nor is any initialization (!) * However, option processing is not yet done, nor is any initialization (!)
// So we must wait until the main loop. * So we must wait until the main loop.
*/
return 0; return 0;
} }
@@ -565,7 +575,7 @@ init_sockets ()
return -1; return -1;
} }
// Now init a bunch of required stuff... /* Now init a bunch of required stuff...*/
if (client_init () < 0) { if (client_init () < 0) {
report(RPT_ERR, "Error initializing client list"); report(RPT_ERR, "Error initializing client list");
@@ -584,23 +594,19 @@ init_drivers()
report( RPT_INFO, "init_drivers()" ); report( RPT_INFO, "init_drivers()" );
// FIXME: This sets s equal to a value related to i
// (bitshifted left?) FIX FIX FIX ARGH....
//
// Go thru all drivers and initialize all of them
for (i = 0; i < num_drivers; i++) { for (i = 0; i < num_drivers; i++) {
res = load_driver (drivernames[i], driverfilenames[i], driverargs[i]); res = drivers_load_driver (drivernames[i], driverfilenames[i], driverargs[i]);
if (res >= 0) { if (res >= 0) {
// Load went OK /* Load went OK */
switch( res ) { switch( res ) {
case 0: // Driver does input only case 0: /* Driver does input only */
break; break;
case 1: // Driver does output case 1: /* Driver does output */
output_loaded = 1; output_loaded = 1;
break; break;
case 2: // Driver does output in foreground (don't daemonize) case 2: /* Driver does output in foreground (don't daemonize) */
if ( !output_loaded ) { if ( !output_loaded ) {
daemon_mode = 0; daemon_mode = 0;
} }
@@ -612,7 +618,7 @@ init_drivers()
} }
} }
// Do we have a running output driver ? /* Do we have a running output driver ?*/
if ( output_loaded ) { if ( output_loaded ) {
return 0; return 0;
} else { } else {
@@ -652,7 +658,7 @@ init_screens ()
report(RPT_ERR, "Error initializing screen list"); report(RPT_ERR, "Error initializing screen list");
return -1; return -1;
} }
// Make sure the server screen shows up every once in a while.. /* Make sure the server screen shows up every once in a while..*/
if (server_screen_init () < 0) { if (server_screen_init () < 0) {
report(RPT_ERR, "Error initializing server screens"); report(RPT_ERR, "Error initializing server screens");
return -1; return -1;
@@ -671,49 +677,54 @@ do_mainloop ()
report( RPT_INFO, "do_mainloop()" ); report( RPT_INFO, "do_mainloop()" );
//char buf[64]; /*char buf[64];*/
// FIXME: s should still be null from initialization.... what's happening here?! /* FIXME: s should still be null from initialization.... what's happening here?!*/
while (1) { while (1) {
sock_poll_clients (); // poll clients for input sock_poll_clients (); /* poll clients for input*/
parse_all_client_messages (); // analyze input from network clients parse_all_client_messages (); /* analyze input from network clients*/
handle_input (); // handle key input from devices handle_input (); /* handle key input from devices*/
// TODO: Move this code to screenlist.c... /* TODO: Move this code to screenlist.c...
// ... it should just say "handle_screens();" * ... it should just say "handle_screens();"
// Timer gets reset by screenlist_next() * Timer gets reset by screenlist_next()
*/
timer++; timer++;
//if (s == NULL) /*if (s == NULL)
// s = screenlist_current(); * s = screenlist_current();
// this is here because s is getting overwritten... * this is here because s is getting overwritten...
//if (s != screenlist_current()) { *if (s != screenlist_current()) {
// report(RPT_DEBUG, "internal error! s was found overwritten at main.c:637"); * report(RPT_DEBUG, "internal error! s was found overwritten at main.c:637");
// s = screenlist_current(); * s = screenlist_current();
//} *}
// */
//TODO: THIS MUST BE FIXED..... WHY is s getting overwritten?
// s is a local, it is never passed or assigned to anywhere. /*TODO: THIS MUST BE FIXED..... WHY is s getting overwritten?
// So SOMETHING is going haywire and clobbering memory.... * s is a local, it is never passed or assigned to anywhere.
* So SOMETHING is going haywire and clobbering memory....
*/
if (s && (timer >= s->duration)) if (s && (timer >= s->duration))
screenlist_next (); screenlist_next ();
// Just in case it gets out of hand... /* Just in case it gets out of hand...*/
if (timer >= MAX_TIMER) if (timer >= MAX_TIMER)
timer = 0; timer = 0;
// Update server screen with the right number /* Update server screen with the right number
// of clients and screens... * of clients and screens...
// */
// TODO: Move this call to every client connection
// and every screen add... /* TODO: Move this call to every client connection
* and every screen add...
*/
update_server_screen (timer); update_server_screen (timer);
// draw the current scren /* draw the current scren*/
if ((s = screenlist_current ()) != NULL) if ((s = screenlist_current ()) != NULL)
@@ -723,9 +734,10 @@ do_mainloop ()
usleep (TIME_UNIT); usleep (TIME_UNIT);
//Check to see if the screen has a timeout value, if it does /* Check to see if the screen has a timeout value, if it does
//decrese it and then check to see if it has excpired. * decrese it and then check to see if it has excpired.
//Remove if expired. * Remove if expired.
*/
if((message = malloc(256)) == NULL) if((message = malloc(256)) == NULL)
report(RPT_ERR, "Error allocating message string"); report(RPT_ERR, "Error allocating message string");
else { else {
@@ -756,7 +768,7 @@ do_mainloop ()
} }
} }
// Quit! /* Quit! */
exit_program (0); exit_program (0);
} }
@@ -767,8 +779,9 @@ exit_program (int val)
report( RPT_INFO, "exit_program()" ); report( RPT_INFO, "exit_program()" );
// TODO: These things shouldn't be so interdependent. The order /* TODO: These things shouldn't be so interdependent. The order
// things are shut down in shouldn't matter... * things are shut down in shouldn't matter...
*/
strncpy(buf, "Server shutting down on ", sizeof (buf) ); strncpy(buf, "Server shutting down on ", sizeof (buf) );
switch(val) { switch(val) {
@@ -776,26 +789,26 @@ exit_program (int val)
case 2: strcat(buf, "SIGINT"); break; case 2: strcat(buf, "SIGINT"); break;
case 15: strcat(buf, "SIGTERM"); break; case 15: strcat(buf, "SIGTERM"); break;
default: snprintf(buf, sizeof(buf), "Server shutting down on signal %d", val); break; default: snprintf(buf, sizeof(buf), "Server shutting down on signal %d", val); break;
// Other values should not be seen, but just in case.. /* Other values should not be seen, but just in case.. */
} }
report(RPT_NOTICE, buf); // report it report(RPT_NOTICE, buf); /* report it */
// Set emergency reporting and flush all messages if not done already. /* Set emergency reporting and flush all messages if not done already. */
if( reportLevel == UNSET_INT ) if( reportLevel == UNSET_INT )
reportLevel = DEFAULT_REPORTLEVEL; reportLevel = DEFAULT_REPORTLEVEL;
if( reportToSyslog == UNSET_INT ) if( reportToSyslog == UNSET_INT )
reportLevel = DEFAULT_REPORTLEVEL; reportLevel = DEFAULT_REPORTLEVEL;
set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) ); set_reporting( reportLevel, (reportToSyslog?RPT_DEST_SYSLOG:RPT_DEST_STDERR) );
// Shutdown things if server start was complete /* Shutdown things if server start was complete */
if( serverStarted ) { if( serverStarted ) {
goodbye_screen (); // display goodbye screen on LCD display goodbye_screen (); /* display goodbye screen on LCD display */
unload_all_drivers (); // release driver memory and file descriptors drivers_unload_all (); /* release driver memory and file descriptors */
client_shutdown (); // shutdown clients (must come first) client_shutdown (); /* shutdown clients (must come first) */
screenlist_shutdown (); // shutdown screens (must come after client_shutdown) screenlist_shutdown (); /* shutdown screens (must come after client_shutdown) */
sock_close_all (); // close all open sockets (must come after client_shutdown) sock_close_all (); /* close all open sockets (must come after client_shutdown) */
} }
exit (0); exit (0);
@@ -805,39 +818,40 @@ exit_program (int val)
void void
HelpScreen () HelpScreen ()
{ {
// Help screen is printed to stdout on purpose. No reason to have /* Help screen is printed to stdout on purpose. No reason to have
// this in syslog... * this in syslog...
*/
report( RPT_INFO, "HelpScreen()" ); report( RPT_INFO, "HelpScreen()" );
printf ("\nLCDd Server Daemon (part of lcdproc), %s\n", version); fprintf (stdout, "\nLCDd Server Daemon (part of lcdproc), %s\n", version);
printf ("Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n"); fprintf (stdout, "Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n");
printf ("This program is freely redistributable under the terms of the GNU Public License\n\n"); fprintf (stdout, "This program is freely redistributable under the terms of the GNU Public License\n\n");
printf ("Usage: LCDd [ -hfiws ] [ -c <config> ] [ -d <driver> ] [ -a <addr> ] \\\n\t[ -p <port> ] [ -u <user> ] [ -w <time> ] [ -r <level> ]\n\n"); fprintf (stdout, "Usage: LCDd [ -hfiws ] [ -c <config> ] [ -d <driver> ] [ -a <addr> ] \\\n\t[ -p <port> ] [ -u <user> ] [ -w <time> ] [ -r <level> ]\n\n");
printf ("Available options are:\n"); fprintf (stdout, "Available options are:\n");
printf ("\t-h\t\tDisplay this help screen\n"); fprintf (stdout, "\t-h\t\tDisplay this help screen\n");
printf ("\t-c <config>\tUse a configuration file other than %s\n", DEFAULT_CONFIGFILE); fprintf (stdout, "\t-c <config>\tUse a configuration file other than %s\n", DEFAULT_CONFIGFILE);
//printf ("\t-t\t\tSelect an LCD size (20x4, 16x2, etc...)\n"); /*fprintf (stdout, "\t-t\t\tSelect an LCD size (20x4, 16x2, etc...)\n");*/
printf ("\t-d <driver>\tAdd a driver to use (output only to first)\n"); fprintf (stdout, "\t-d <driver>\tAdd a driver to use (output only to first)\n");
//printf ("\t\t\tCFontz, curses, HD44780, irmanin, joy,\n\t\t\tMtxOrb, LB216, text\n"); /*fprintf (stdout, "\t\t\tCFontz, curses, HD44780, irmanin, joy,\n\t\t\tMtxOrb, LB216, text\n");*/
//printf ("\t\t\t(args will be passed to the driver for init)\n"); /*fprintf (stdout, "\t\t\t(args will be passed to the driver for init)\n");*/
printf ("\t-f\t\tRun in the foreground\n"); fprintf (stdout, "\t-f\t\tRun in the foreground\n");
//printf ("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n"); /*fprintf (stdout, "\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n");*/
printf ("\t-i\t\tDisable showing of the main LCDproc server screen\n"); fprintf (stdout, "\t-i\t\tDisable showing of the main LCDproc server screen\n");
printf ("\t-w <waittime>\tTime to pause at each screen (in seconds)\n"); fprintf (stdout, "\t-w <waittime>\tTime to pause at each screen (in seconds)\n");
printf ("\t-a <addr>\tNetwork (IP) address to bind to\n"); fprintf (stdout, "\t-a <addr>\tNetwork (IP) address to bind to\n");
printf ("\t-p <port>\tNetwork port to listen for connections on\n"); fprintf (stdout, "\t-p <port>\tNetwork port to listen for connections on\n");
printf ("\t-u <user>\tUser to run as\n"); fprintf (stdout, "\t-u <user>\tUser to run as\n");
printf ("\t-s\t\tOutput messages to syslog\n"); fprintf (stdout, "\t-s\t\tOutput messages to syslog\n");
printf ("\t-r <level>\tReport level (default=2)\n"); fprintf (stdout, "\t-r <level>\tReport level (default=2)\n");
printf ("\nCurrently available drivers:\n"); fprintf (stdout, "\nCurrently available drivers:\n");
lcd_list_drivers(); lcd_list_drivers();
//printf ("\tHelp on each driver's parameters are obtained upon request:\n\t\t\"LCDd -d driver --help\"\n"); /*fprintf (stdout, "\tHelp on each driver's parameters are obtained upon request:\n\t\t\"LCDd -d driver --help\"\n");*/
//printf ("Example:\n"); /*fprintf (stdout, "Example:\n");*/
//printf ("\tLCDd -d MtxOrb \"--device /dev/lcd --contrast 200\" -d joy\n"); /*fprintf (stdout, "\tLCDd -d MtxOrb \"--device /dev/lcd --contrast 200\" -d joy\n");*/
printf ("\n"); fprintf (stdout, "\n");
exit (0); exit (0);
} }
+3 -3
View File
@@ -30,10 +30,10 @@ extern char *build_date;
void exit_program (int val); void exit_program (int val);
// 1/8th second is a single time unit... /* 1/8th second is a single time unit...*/
#define TIME_UNIT 125000 #define TIME_UNIT 125000
// But I plan to double the framerate soon, or make it variable... /* But I plan to double the framerate soon, or make it variable...*/
//#define TIME_UNIT (125000/2) /*#define TIME_UNIT (125000/2)*/
typedef struct screen_size { typedef struct screen_size {
char *size; char *size;
+72 -66
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Handles server-supplied menus defined by a table. Read menu.h for * Handles server-supplied menus defined by a table. Read menu.h for
@@ -32,10 +31,11 @@
#include "render.h" #include "render.h"
#include "main.h" #include "main.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "menu.h" #include "menu.h"
#include "input.h"
// FIXME: Implement this where it is supposed to be... /* FIXME: Implement this where it is supposed to be...*/
void void
framedelay () framedelay ()
{ {
@@ -51,12 +51,11 @@ draw_heartbeat ()
static int timer = 0; static int timer = 0;
if (heartbeat) { if (heartbeat) {
// Set this to pulsate like a real heart beat... /* Set this to pulsate like a real heart beat... */
// (binary is fun... :) /*drivers_icon (!((timer + 4) & 5), 0); */
lcd_ptr->icon (!((timer + 4) & 5), 0); /*drivers_chr (display_props->width, 1, 0); */
lcd_ptr->chr (lcd_ptr->wid, 1, 0);
} }
lcd_ptr->flush (); drivers_flush ();
timer++; timer++;
timer &= 0x0f; timer &= 0x0f;
@@ -92,28 +91,29 @@ do_menu (Menu menu)
fill_menu_info (menu, &info); fill_menu_info (menu, &info);
while (!done) { while (!done) {
// Keep the cursor off titles... (?) /* Keep the cursor off titles... (?) */
while (menu[info.selected].type == TYPE_TITL) { while (menu[info.selected].type == TYPE_TITL) {
info.selected++; info.selected++;
// If the title is the last thing in the menu... /* If the title is the last thing in the menu... */
if (!menu[info.selected].text) if (!menu[info.selected].text)
info.selected -= 2; info.selected -= 2;
} }
draw_menu (menu, &info); draw_menu (menu, &info);
// FIXME: This should use a better keypress interface, which /* FIXME: This should use a better keypress interface, which */
// FIXME: handles things according to keybindings... /* FIXME: handles things according to keybindings... */
for (key = lcd_ptr->getkey (); key == 0; key = lcd_ptr->getkey ()) { for (key = drivers_getkey (); key == 0; key = drivers_getkey ()) {
// sleep for 1/8th second... /* sleep for 1/8th second... */
framedelay (); framedelay ();
// do the heartbeat... /* do the heartbeat... */
draw_heartbeat (); draw_heartbeat ();
// Check for client input... /* Check for client input... */
} }
printf( "Received key: %c\n", key );
// Handle the key according to the keybindings... /* Handle the key according to the keybindings... */
switch (key) { switch (key) {
case 'D': case 'D':
done = 1; done = 1;
@@ -128,11 +128,11 @@ do_menu (Menu menu)
break; break;
} }
break; break;
case 'C': case INPUT_FORWARD_KEY:
if (menu[info.selected + 1].text) if (menu[info.selected + 1].text)
info.selected++; info.selected++;
break; break;
case 'A': case INPUT_PAUSE_KEY:
switch (menu[info.selected].type) { switch (menu[info.selected].type) {
case TYPE_MENU: case TYPE_MENU:
status = do_menu (menu[info.selected].data); status = do_menu (menu[info.selected].data);
@@ -164,15 +164,17 @@ do_menu (Menu menu)
return MENU_OK; return MENU_OK;
case MENU_QUIT: case MENU_QUIT:
return MENU_QUIT; return MENU_QUIT;
// case MENU_KILL: /* case MENU_KILL:
// return MENU_KILL; * return MENU_KILL;
*/
case MENU_ERROR: case MENU_ERROR:
return MENU_ERROR; return MENU_ERROR;
} }
// status = menu_handle_action(&menu[info.selected]); /* status = menu_handle_action(&menu[info.selected]);*/
// TODO: It should now do special stuff for "mover" widgets, /* TODO: It should now do special stuff for "mover" widgets,
// TODO: and handle the return code appropriately. * TODO: and handle the return code appropriately.
*/
break; break;
default: default:
break; break;
@@ -193,15 +195,15 @@ draw_menu (Menu menu, menu_info * info)
int (*readfunc) (int); int (*readfunc) (int);
// these should maybe be removed: /* these should maybe be removed: */
int wid = lcd_ptr->wid, hgt = lcd_ptr->hgt; int wid = display_props->width, hgt = display_props->height;
if (!menu) if (!menu)
return MENU_ERROR; return MENU_ERROR;
lcd_ptr->clear (); drivers_clear ();
// Scroll down until the selected item is centered, if possible... /* Scroll down until the selected item is centered, if possible...*/
top = info->selected - (hgt / 2); top = info->selected - (hgt / 2);
if (top < 0) if (top < 0)
top = 0; top = 0;
@@ -212,38 +214,38 @@ draw_menu (Menu menu, menu_info * info)
if (top < 0) if (top < 0)
top = 0; top = 0;
// Draw all visible items... /* Draw all visible items...*/
for (i = top; i < bottom; i++, y++) { for (i = top; i < bottom; i++, y++) {
if (i == info->selected) if (i == info->selected)
lcd_ptr->chr (2, y, '>'); drivers_chr (2, y, '>');
switch (menu[i].type) { switch (menu[i].type) {
case TYPE_TITL: case TYPE_TITL:
lcd_ptr->chr (1, y, PAD); drivers_chr (1, y, PAD);
lcd_ptr->chr (2, y, PAD); drivers_chr (2, y, PAD);
lcd_ptr->string (4, y, menu[i].text); drivers_string (4, y, menu[i].text);
for (x = strlen (menu[i].text) + 5; x <= wid; x++) for (x = strlen (menu[i].text) + 5; x <= wid; x++)
lcd_ptr->chr (x, y, PAD); drivers_chr (x, y, PAD);
break; break;
case TYPE_MENU: case TYPE_MENU:
lcd_ptr->string (3, y, menu[i].text); drivers_string (3, y, menu[i].text);
lcd_ptr->chr (wid, y, '>'); drivers_chr (wid, y, '>');
break; break;
case TYPE_FUNC: case TYPE_FUNC:
lcd_ptr->string (3, y, menu[i].text); drivers_string (3, y, menu[i].text);
break; break;
case TYPE_CHEK: case TYPE_CHEK:
if (menu[i].data) { if (menu[i].data) {
readfunc = menu[i].data; readfunc = menu[i].data;
if (readfunc (MENU_READ)) if (readfunc (MENU_READ))
lcd_ptr->chr (wid, y, 'Y'); drivers_chr (wid, y, 'Y');
else else
lcd_ptr->chr (wid, y, 'N'); drivers_chr (wid, y, 'N');
} }
lcd_ptr->string (3, y, menu[i].text); drivers_string (3, y, menu[i].text);
break; break;
case TYPE_SLID: case TYPE_SLID:
lcd_ptr->string (3, y, menu[i].text); drivers_string (3, y, menu[i].text);
break; break;
case TYPE_MOVE: case TYPE_MOVE:
break; break;
@@ -253,12 +255,12 @@ draw_menu (Menu menu, menu_info * info)
} }
if (top != 0) if (top != 0)
lcd_ptr->chr (1, 1, '^'); drivers_chr (1, 1, '^');
if (bottom < info->length) if (bottom < info->length)
lcd_ptr->chr (1, hgt, 'v'); drivers_chr (1, hgt, 'v');
draw_heartbeat (); draw_heartbeat ();
//lcd_ptr->flush(); /*drivers_flush(); */
return 0; return 0;
} }
@@ -270,7 +272,7 @@ fill_menu_info (Menu menu, menu_info * info)
info->selected = 0; info->selected = 0;
// count the entries in the menu /* count the entries in the menu*/
for (i = 0; menu[i].text; i++); for (i = 0; menu[i].text; i++);
info->length = i; info->length = i;
@@ -296,39 +298,43 @@ slid_func (menu_item * item)
readfunc = item->data; readfunc = item->data;
lcd_ptr->init_hbar (); /*drivers_init_hbar (); OBSOLETE */
while (key != 'A' && key != 'D') { while (key != 'A' && key != 'D') {
// Draw the title... /* Draw the title... */
lcd_ptr->clear (); drivers_clear ();
lcd_ptr->chr (1, y, PAD); drivers_chr (1, y, PAD);
lcd_ptr->chr (2, y, PAD); drivers_chr (2, y, PAD);
lcd_ptr->string (4, y, item->text); drivers_string (4, y, item->text);
for (x = strlen (item->text) + 5; x <= lcd_ptr->wid; x++) for (x = strlen (item->text) + 5; x <= display_props->width; x++)
lcd_ptr->chr (x, y, PAD); drivers_chr (x, y, PAD);
// Draw the slider now... /* Draw the slider now...*/
value = readfunc (MENU_READ); value = readfunc (MENU_READ);
if (value < 0 || value >= MENU_CLOSE) if (value < 0 || value >= MENU_CLOSE)
return value; return value;
snprintf (str, sizeof(str), "%i", value); snprintf (str, sizeof(str), "%i", value);
if (lcd_ptr->hgt >= 4) { if (display_props->height >= 4) {
lcd_ptr->string (8, 4, str); int promille;
value = (lcd_ptr->wid * lcd_ptr->cellwid * value / 256); drivers_string (8, 4, str);
lcd_ptr->hbar (1, 3, value); value = (display_props->width * display_props->cellwidth * value / 256);
promille = (long) 100 * value / 256;
drivers_hbar (1, 3, display_props->width, promille, BAR_PATTERN_FILLED);
} else { } else {
lcd_ptr->string (17, 2, str); int promille;
value = ((lcd_ptr->wid - 4) * lcd_ptr->cellwid * value / 256); drivers_string (17, 2, str);
lcd_ptr->hbar (1, 2, value); value = ((display_props->width - 4) * display_props->cellwidth * value / 256);
promille = (long) 100 * value / 256;
drivers_hbar (1, 2, display_props->width, promille, BAR_PATTERN_FILLED);
} }
//lcd_ptr->flush(); /*drivers_flush(); */
for (key = lcd_ptr->getkey (); key == 0; key = lcd_ptr->getkey ()) { for (key = drivers_getkey (); key == 0; key = drivers_getkey ()) {
// do the heartbeat... /* do the heartbeat... */
draw_heartbeat (); draw_heartbeat ();
// sleep for 1/8th second... /* sleep for 1/8th second... */
framedelay (); framedelay ();
// Check for client input... /* Check for client input... */
} }
switch (key) { switch (key) {
+3 -4
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -106,14 +105,14 @@ and sliders should return 0-255.
**************************************************************************/ **************************************************************************/
#endif #endif
// Return codes from selected menu items... /* Return codes from selected menu items...*/
#define MENU_ERROR -0x7FFF0000 #define MENU_ERROR -0x7FFF0000
#define MENU_OK 0 #define MENU_OK 0
#define MENU_CLOSE 0x10000 #define MENU_CLOSE 0x10000
#define MENU_QUIT 0x20000 #define MENU_QUIT 0x20000
#define MENU_KILL 0x20000 #define MENU_KILL 0x20000
// Menu item Types... /* Menu item Types...*/
#define TYPE_TITL 0 #define TYPE_TITL 0
#define TYPE_MENU 1 #define TYPE_MENU 1
#define TYPE_FUNC 2 #define TYPE_FUNC 2
@@ -127,7 +126,7 @@ and sliders should return 0-255.
#define CLIENT_SLID 0x103 #define CLIENT_SLID 0x103
#define CLIENT_MOVE 0x104 #define CLIENT_MOVE 0x104
// User actions, sent to item-handling functions as input. /* User actions, sent to item-handling functions as input.*/
#define MENU_SELECT 1 #define MENU_SELECT 1
#define MENU_CHECK 2 #define MENU_CHECK 2
#define MENU_PLUS 3 #define MENU_PLUS 3
+51 -48
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Defines the default menus the server provides. Also includes the * Defines the default menus the server provides. Also includes the
@@ -24,7 +23,8 @@
#include "shared/report.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "drivers.h"
#include "main.h" #include "main.h"
#include "menus.h" #include "menus.h"
@@ -48,7 +48,7 @@ int Backlight_On_func ();
int Backlight_Open_func (); int Backlight_Open_func ();
menu_item main_menu[] = { menu_item main_menu[] = {
{"LCDproc", 0, 0}, // Title {"LCDproc", 0, 0}, /* Title*/
{"Options", TYPE_MENU, (void *) options_menu}, {"Options", TYPE_MENU, (void *) options_menu},
{"Screens", TYPE_MENU, (void *) screens_menu}, {"Screens", TYPE_MENU, (void *) screens_menu},
{"Shutdown", TYPE_MENU, (void *) shutdown_menu}, {"Shutdown", TYPE_MENU, (void *) shutdown_menu},
@@ -57,29 +57,30 @@ menu_item main_menu[] = {
}; };
menu_item options_menu[] = { menu_item options_menu[] = {
{"OPTIONS", TYPE_TITL, 0}, // Title {"OPTIONS", TYPE_TITL, 0}, /* Title*/
// "24-hour Time", TYPE_CHEK, (void *)Time24_func, /* "24-hour Time", TYPE_CHEK, (void *)Time24_func,*/
{"Contrast...", TYPE_SLID, (void *) Contrast_func}, {"Contrast...", TYPE_SLID, (void *) Contrast_func},
{"Backlight", TYPE_MENU, (void *) Backlight_menu}, {"Backlight", TYPE_MENU, (void *) Backlight_menu},
{"Heartbeat", TYPE_CHEK, (void *) Heartbeat_func}, {"Heartbeat", TYPE_CHEK, (void *) Heartbeat_func},
// { "Backlight...", TYPE_SLID, (void *)Backlight_func}, /* { "Backlight...", TYPE_SLID, (void *)Backlight_func},
// "OK", TYPE_FUNC, (void *)OK_func, * "OK", TYPE_FUNC, (void *)OK_func,
// "Close Menu", TYPE_FUNC, (void *)Close_func, * "Close Menu", TYPE_FUNC, (void *)Close_func,
// "Exit Program", TYPE_FUNC, (void *)Shutdown_func, * "Exit Program", TYPE_FUNC, (void *)Shutdown_func,
// "Another Title",TYPE_TITL, 0, * "Another Title",TYPE_TITL, 0,
// "Main menu?", TYPE_MENU, (void *)main_menu, * "Main menu?", TYPE_MENU, (void *)main_menu,
// "Nothing!", TYPE_FUNC, 0, * "Nothing!", TYPE_FUNC, 0,
*/
{0, 0, 0}, {0, 0, 0},
}; };
menu_item screens_menu[] = { menu_item screens_menu[] = {
{"SCREENS", TYPE_TITL, 0}, // Title {"SCREENS", TYPE_TITL, 0}, /* Title*/
{"Server Scr", TYPE_CHEK, (void *) Server_screen_func}, {"Server Scr", TYPE_CHEK, (void *) Server_screen_func},
{0, 0, 0}, {0, 0, 0},
}; };
menu_item shutdown_menu[] = { menu_item shutdown_menu[] = {
{"Shut Down...", TYPE_TITL, 0}, // Title {"Shut Down...", TYPE_TITL, 0}, /* Title*/
{"Kill LCDproc", TYPE_FUNC, (void *) Shutdown_func}, {"Kill LCDproc", TYPE_FUNC, (void *) Shutdown_func},
{"System halt", TYPE_FUNC, (void *) System_halt_func}, {"System halt", TYPE_FUNC, (void *) System_halt_func},
{"Reboot", TYPE_FUNC, (void *) Reboot_func}, {"Reboot", TYPE_FUNC, (void *) Reboot_func},
@@ -87,21 +88,21 @@ menu_item shutdown_menu[] = {
}; };
menu_item Backlight_menu[] = { menu_item Backlight_menu[] = {
{"BACKLIGHT MENU", TYPE_TITL, 0}, // Title {"BACKLIGHT MENU", TYPE_TITL, 0}, /* Title*/
{"Brightness...", TYPE_SLID, (void *) Backlight_Brightness_func}, {"Brightness...", TYPE_SLID, (void *) Backlight_Brightness_func},
{"\"Off\" Brightness", TYPE_SLID, (void *) Backlight_Off_Brightness_func}, {"\"Off\" Brightness", TYPE_SLID, (void *) Backlight_Off_Brightness_func},
{"Backlight Mode:", TYPE_FUNC, 0}, // Label {"Backlight Mode:", TYPE_FUNC, 0}, /* Label*/
{" - Off", TYPE_FUNC, Backlight_Off_func}, {" - Off", TYPE_FUNC, Backlight_Off_func},
{" - On", TYPE_FUNC, Backlight_On_func}, {" - On", TYPE_FUNC, Backlight_On_func},
{" - Open", TYPE_FUNC, Backlight_Open_func}, {" - Open", TYPE_FUNC, Backlight_Open_func},
{0, 0, 0}, {0, 0, 0},
}; };
/////////////////////////////////////////////////////////////////////// /************************************************************************
// Plug-in functions for menu items * Plug-in functions for menu items
// */
// Exits the program. /* Exits the program.*/
int int
Shutdown_func () Shutdown_func ()
{ {
@@ -110,7 +111,7 @@ Shutdown_func ()
return MENU_KILL; return MENU_KILL;
} }
// Shuts down the system, if possible /* Shuts down the system, if possible*/
int int
System_halt_func () System_halt_func ()
{ {
@@ -126,15 +127,15 @@ System_halt_func ()
if (err == 127) if (err == 127)
return MENU_KILL; return MENU_KILL;
// If we're root, exit /* If we're root, exit*/
if (id == 0) if (id == 0)
exit_program (0); exit_program (0);
// Otherwise, assume shutdown will fail; and show more stats. /* Otherwise, assume shutdown will fail; and show more stats.*/
return MENU_KILL; return MENU_KILL;
} }
// Shuts down the system and restarts it /* Shuts down the system and restarts it*/
int int
Reboot_func () Reboot_func ()
{ {
@@ -150,11 +151,11 @@ Reboot_func ()
if (err == 127) if (err == 127)
return MENU_KILL; return MENU_KILL;
// If we're root, exit /* If we're root, exit*/
if (id == 0) if (id == 0)
exit_program (0); exit_program (0);
// Otherwise, assume shutdown will fail; and show more stats. /* Otherwise, assume shutdown will fail; and show more stats.*/
return MENU_KILL; return MENU_KILL;
} }
@@ -178,14 +179,16 @@ Time24_func (int input)
if (input == MENU_READ) if (input == MENU_READ)
return status; return status;
if (input == MENU_CHECK) if (input == MENU_CHECK)
status ^= 1; // does something. status ^= 1; /* does something.*/
return (status | MENU_OK); return (status | MENU_OK);
// The status is "or"-ed with the MENU value to let do_menu() /* The status is "or"-ed with the MENU value to let do_menu()
// know what to do after selecting the item. (two return * know what to do after selecting the item. (two return
// values in one. :) * values in one. :)
*/
// Also, "MENU_OK" happens to be zero, so it does not matter /* Also, "MENU_OK" happens to be zero, so it does not matter
// unless you want something else (like MENU_CLOSE) * unless you want something else (like MENU_CLOSE)
*/
} }
int int
@@ -254,7 +257,7 @@ Backlight_func (int input)
else backlight = BACKLIGHT_OPEN; else backlight = BACKLIGHT_OPEN;
} }
*/ */
lcd_ptr->backlight (backlight_state & BACKLIGHT_ON); drivers_backlight (backlight_state & BACKLIGHT_ON);
return (status | MENU_OK); return (status | MENU_OK);
} }
@@ -277,22 +280,22 @@ Server_screen_func (int input)
int int
Contrast_func (int input) Contrast_func (int input)
{ {
int status; static int status = 500;
status = lcd_ptr->contrast (-1); status = drivers_get_contrast ();
if (input == MENU_READ) if (input == MENU_READ)
return status; return status;
if (input == MENU_PLUS) if (input == MENU_PLUS)
status += 5; // does something. status += 5; /* does something.*/
if (input == MENU_MINUS) if (input == MENU_MINUS)
status -= 5; // does something. status -= 5; /* does something.*/
if (status < 0) if (status < 0)
status = 0; status = 0;
if (status > 255) if (status > 1000)
status = 255; status = 1000;
lcd_ptr->contrast (status); drivers_set_contrast (status);
return (status | MENU_OK); return (status | MENU_OK);
} }
@@ -314,15 +317,15 @@ Backlight_Brightness_func (int input)
if (input == MENU_READ) if (input == MENU_READ)
return status; return status;
if (input == MENU_PLUS) if (input == MENU_PLUS)
status += 5; // does something. status += 5; /* does something.*/
if (input == MENU_MINUS) if (input == MENU_MINUS)
status -= 5; // does something. status -= 5; /* does something.*/
if (status < 0) if (status < 0)
status = 0; status = 0;
if (status > 255) if (status > 255)
status = 255; status = 255;
lcd_ptr->backlight (status); drivers_backlight (status);
backlight_brightness = status; backlight_brightness = status;
@@ -337,15 +340,15 @@ Backlight_Off_Brightness_func (int input)
if (input == MENU_READ) if (input == MENU_READ)
return status; return status;
if (input == MENU_PLUS) if (input == MENU_PLUS)
status += 5; // does something. status += 5; /* does something.*/
if (input == MENU_MINUS) if (input == MENU_MINUS)
status -= 5; // does something. status -= 5; /* does something.*/
if (status < 0) if (status < 0)
status = 0; status = 0;
if (status > 255) if (status > 255)
status = 255; status = 255;
lcd_ptr->backlight (status); drivers_backlight (status);
backlight_off_brightness = status; backlight_off_brightness = status;
@@ -357,7 +360,7 @@ Backlight_Off_func ()
{ {
backlight_state = BACKLIGHT_OFF; backlight_state = BACKLIGHT_OFF;
backlight = BACKLIGHT_OFF; backlight = BACKLIGHT_OFF;
lcd_ptr->backlight (backlight_off_brightness); drivers_backlight (backlight_off_brightness);
return MENU_OK; return MENU_OK;
} }
@@ -366,7 +369,7 @@ Backlight_On_func ()
{ {
backlight_state = BACKLIGHT_ON; backlight_state = BACKLIGHT_ON;
backlight = BACKLIGHT_ON; backlight = BACKLIGHT_ON;
lcd_ptr->backlight (backlight_brightness * (backlight_state & BACKLIGHT_ON)); drivers_backlight (backlight_brightness * (backlight_state & BACKLIGHT_ON));
return MENU_OK; return MENU_OK;
} }
+2 -3
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -15,14 +14,14 @@
#include "menu.h" #include "menu.h"
// These probably don't need to be defined here... /* These probably don't need to be defined here... */
extern menu_item main_menu[]; extern menu_item main_menu[];
extern menu_item options_menu[]; extern menu_item options_menu[];
extern menu_item screens_menu[]; extern menu_item screens_menu[];
extern menu_item shutdown_menu[]; extern menu_item shutdown_menu[];
extern menu_item Backlight_menu[]; extern menu_item Backlight_menu[];
// Brings up the main menu... /* Brings up the main menu... */
void server_menu (); void server_menu ();
#endif #endif
+53 -49
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Handles input commands from clients, by splitting strings into tokens * Handles input commands from clients, by splitting strings into tokens
@@ -28,22 +27,23 @@
#include "client_functions.h" #include "client_functions.h"
#include "parse.h" #include "parse.h"
// This is a big function... TOO big. How to trim.... /* This is a big function... TOO big. How to trim....
// TODO: Simplify... simplify... * TODO: Simplify... simplify...
*/
#define MAX_ARGUMENTS 256 #define MAX_ARGUMENTS 256
int int
parse_all_client_messages () parse_all_client_messages ()
{ {
int i; // int j, len; int i; /* int j, len;*/
//int newtoken, inquote; /*int newtoken, inquote;*/
client *c; client *c;
char *str, *p, *q, *s; char *str, *p, *q, *s;
// char *tok; /* char *tok;*/
int argc; int argc;
char *argv[MAX_ARGUMENTS]; char *argv[MAX_ARGUMENTS];
//char delimiters[] = " "; /*char delimiters[] = " ";*/
char leftquote[] = "\"'`([{"; char leftquote[] = "\"'`([{";
char rightquote[] = "\"'`)]}"; char rightquote[] = "\"'`)]}";
char errmsg[256]; char errmsg[256];
@@ -60,114 +60,118 @@ parse_all_client_messages ()
#define LINE_TERM_CHAR '\0' #define LINE_TERM_CHAR '\0'
#define COMMENT_CHAR '#' #define COMMENT_CHAR '#'
//debug("parse: Rewinding list..."); /*debug("parse: Rewinding list...");*/
LL_Rewind (clients); LL_Rewind (clients);
do { do {
// Get the next client... /* Get the next client...*/
//debug("parse: Getting client..."); /*debug("parse: Getting client...");*/
c = LL_Get (clients); c = LL_Get (clients);
if (c) { if (c) {
// And parse all its messages... /* And parse all its messages...*/
//debug(RPT_DEBUG, "parse: Getting messages..."); /*debug(RPT_DEBUG, "parse: Getting messages...");*/
for (str = client_get_message (c); str; str = client_get_message (c)) { for (str = client_get_message (c); str; str = client_get_message (c)) {
debug (RPT_DEBUG, "parse: ...%s", str); debug (RPT_DEBUG, "parse: ...%s", str);
// Now, split up the string... /* Now, split up the string...*/
argc = 0; argc = 0;
i = 0; i = 0;
q = p = str; q = p = str;
if (*p == COMMENT_CHAR) { if (*p == COMMENT_CHAR) {
continue; // found a comment line - skip it... continue; /* found a comment line - skip it...*/
} }
debug (RPT_DEBUG, "starting string scan..."); debug (RPT_DEBUG, "starting string scan...");
do { do {
// bypass initial white space... /* bypass initial white space...*/
while ((*p == SEPARATOR_CHAR) && (*p)) { while ((*p == SEPARATOR_CHAR) && (*p)) {
p++; p++;
q++; q++;
} }
// If (*p) is null here, we reached the end of /* If (*p) is null here, we reached the end of
// an empty parameter... so one of two things * an empty parameter... so one of two things
// is true: * is true:
// *
// 1. There is nothing but white space on this line (odd..) * 1. There is nothing but white space on this line (odd..)
// 2. This is trailing white space (odd... but allowable) * 2. This is trailing white space (odd... but allowable)
*/
if (*p == LINE_TERM_CHAR) { if (*p == LINE_TERM_CHAR) {
break; break;
// if there are no arguments, argc == 0 and will fail /* if there are no arguments, argc == 0 and will fail
// appropriately... * appropriately...
// *
// if this is trailing white space, ignore the argc++ at the * if this is trailing white space, ignore the argc++ at the
// end and claim this as the end... * end and claim this as the end...
*/
} }
// Handle quoted strings... /* Handle quoted strings...*/
if ((s = strchr(leftquote, *p)) != NULL) { if ((s = strchr(leftquote, *p)) != NULL) {
quoteindex = s - leftquote; quoteindex = s - leftquote;
//debug(RPT_DEBUG, "found <%c> at index [%d] = <%c>", *p, quoteindex, leftquote[quoteindex]); /*debug(RPT_DEBUG, "found <%c> at index [%d] = <%c>", *p, quoteindex, leftquote[quoteindex]);*/
q = ++p; // past open quote... q = ++p; /* past open quote...*/
while ((rightquote[quoteindex] != *p) && (*p != LINE_TERM_CHAR)) { while ((rightquote[quoteindex] != *p) && (*p != LINE_TERM_CHAR)) {
p++; p++;
} }
if (*p == LINE_TERM_CHAR) { if (*p == LINE_TERM_CHAR) {
// We just sucked up the rest of the command line: ERROR!! /* We just sucked up the rest of the command line: ERROR!!*/
snprintf (errmsg, sizeof(errmsg), "huh? unterminated string! missing ending %c\n", snprintf (errmsg, sizeof(errmsg), "huh? unterminated string! missing ending %c\n",
rightquote[quoteindex]); rightquote[quoteindex]);
sock_send_string (c->sock, errmsg); sock_send_string (c->sock, errmsg);
continue; continue;
} else { } else {
*p = LINE_TERM_CHAR; // terminate string *p = LINE_TERM_CHAR; /* terminate string*/
p++; // bypass to next character p++; /* bypass to next character*/
// Note that next character could be a EndOfLine (null) /* Note that next character could be a EndOfLine (null)
// if the string was last on the line, or it could be * if the string was last on the line, or it could be
// something else... is it a blank? * something else... is it a blank?
*/
if (*p != SEPARATOR_CHAR && *p != LINE_TERM_CHAR) { if (*p != SEPARATOR_CHAR && *p != LINE_TERM_CHAR) {
sock_send_string (c->sock, "huh? improperly terminated string! (missing whitespace)\n"); sock_send_string (c->sock, "huh? improperly terminated string! (missing whitespace)\n");
continue; continue;
} }
} }
// Otherwise, normal string... /* Otherwise, normal string...*/
} else { } else {
while (*p != SEPARATOR_CHAR && *p != LINE_TERM_CHAR) while (*p != SEPARATOR_CHAR && *p != LINE_TERM_CHAR)
p++; p++;
} }
// Not end of line? /* Not end of line?*/
if (*p) { if (*p) {
*p = LINE_TERM_CHAR; *p = LINE_TERM_CHAR;
//debug(RPT_DEBUG, "found new token: %s", q); /*debug(RPT_DEBUG, "found new token: %s", q);*/
argv[i++] = q; argv[i++] = q;
q = ++p; q = ++p;
} else { } else {
//debug(RPT_DEBUG, "found new token: %s", q); /*debug(RPT_DEBUG, "found new token: %s", q);*/
argv[i++] = q; argv[i++] = q;
} }
// At the end of this statement, /* At the end of this statement,
// *p will be '\0' if end of input reached; * *p will be '\0' if end of input reached;
// otherwise, it is the first character of the * otherwise, it is the first character of the
// next part of the string. * next part of the string.
*/
argc++; argc++;
} while (*p); } while (*p);
//debug(RPT_DEBUG, "exiting string scan..."); /*debug(RPT_DEBUG, "exiting string scan...");*/
argv[argc] = NULL; argv[argc] = NULL;
if (argc < 1) if (argc < 1)
continue; continue;
// Now find and call the appropriate function... /* Now find and call the appropriate function...*/
invalid = 1; invalid = 1;
for (i = 0; commands[i].keyword; i++) { for (i = 0; commands[i].keyword; i++) {
if (0 == strcmp (argv[0], commands[i].keyword)) { if (0 == strcmp (argv[0], commands[i].keyword)) {
invalid = commands[i].function (c, argc, argv); invalid = commands[i].function (c, argc, argv);
break; // found our function - don't continue on... break; /* found our function - don't continue on...*/
} }
} }
@@ -176,9 +180,9 @@ parse_all_client_messages ()
sock_send_string (c->sock, errmsg); sock_send_string (c->sock, errmsg);
} }
free (str); // fixed memory leak? free (str); /* fixed memory leak?*/
} // end for(str...) } /* end for(str...)*/
} // end if (c) } /* end if (c)*/
} while (LL_Next (clients) == 0); } while (LL_Next (clients) == 0);
return 0; return 0;
-1
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
+153 -133
View File
@@ -6,7 +6,7 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn * 2001, Joris Robijn
* *
* *
* Draws screens on the LCD. * Draws screens on the LCD.
@@ -31,7 +31,8 @@
#include "shared/report.h" #include "shared/report.h"
#include "shared/LL.h" #include "shared/LL.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "drivers.h"
#include "screen.h" #include "screen.h"
#include "screenlist.h" #include "screenlist.h"
@@ -57,13 +58,10 @@ draw_screen (screen * s, int timer)
static screen *old_s = NULL; static screen *old_s = NULL;
int tmp = 0, tmp_state = 0; int tmp = 0, tmp_state = 0;
//debug(RPT_DEBUG, "Render..."); report(RPT_INFO, "draw_screen( screen=\"%.40s\", timer=%d ) ==== START RENDERING ====", s->name, timer );
//return 0;
reset = 1; reset = 1;
//debug(RPT_DEBUG, "draw_screen: %8x, %i", (int)s, timer);
if (!s) if (!s)
return -1; return -1;
@@ -71,123 +69,129 @@ draw_screen (screen * s, int timer)
reset = 0; reset = 0;
old_s = s; old_s = s;
// Clear the LCD screen... /* Clear the LCD screen... */
lcd_ptr->clear (); drivers_clear ();
// FIXME lcd_ptr->backlight -- /* FIXME drivers_backlight --
// *
// This should be in a separate function altogether. * This should be in a separate function altogether.
// Perhaps several: lcd_ptr->backlight_off, lcd_ptr->backlight_on, * Perhaps several: drivers_backlight_off, drivers_backlight_on,
// lcd_ptr->backlight_brightness, lcd_ptr->backlight_flash ... * drivers_backlight_brightness, drivers_backlight_flash ...
*
// If the screen's backlight_state isn't set (default) then we * If the screen's backlight_state isn't set (default) then we
// inherit the backlight state from the parent client. This allows * inherit the backlight state from the parent client. This allows
// the client to override it's childrens settings. * the client to override it's childrens settings.
*/
if (s->backlight_state == BACKLIGHT_NOTSET) { if (s->backlight_state == BACKLIGHT_NOTSET) {
if (s->parent) tmp_state = s->parent->backlight_state; if (s->parent) tmp_state = s->parent->backlight_state;
} else { } else {
tmp_state = s->backlight_state; tmp_state = s->backlight_state;
} }
// Set up backlight to the correct state... /* Set up backlight to the correct state... */
// NOTE: dirty stripping of other options... /* NOTE: dirty stripping of other options... */
switch (tmp_state & 1) { switch (tmp_state & 1) {
case BACKLIGHT_OFF: case BACKLIGHT_OFF:
lcd_ptr->backlight (BACKLIGHT_OFF); drivers_backlight (BACKLIGHT_OFF);
break; break;
// Backlight on (easy) /* Backlight on (easy) */
case BACKLIGHT_ON: case BACKLIGHT_ON:
lcd_ptr->backlight (BACKLIGHT_ON); drivers_backlight (BACKLIGHT_ON);
break; break;
default: default:
// Backlight flash: check timer and flip backlight as appropriate /* Backlight flash: check timer and flip backlight as appropriate */
if (tmp_state & BACKLIGHT_FLASH) { if (tmp_state & BACKLIGHT_FLASH) {
tmp = (!((timer & 7) == 7)); tmp = (!((timer & 7) == 7));
if (tmp_state & 1) if (tmp_state & 1)
lcd_ptr->backlight (tmp ? backlight_brightness : backlight_off_brightness); drivers_backlight (tmp ? backlight_brightness : backlight_off_brightness);
//lcd_ptr->backlight(backlight_brightness * (!((timer&7) == 7))); /*drivers_backlight(backlight_brightness * (!((timer&7) == 7))); */
else else
lcd_ptr->backlight (!tmp ? backlight_brightness : backlight_off_brightness); drivers_backlight (!tmp ? backlight_brightness : backlight_off_brightness);
//lcd_ptr->backlight(backlight_brightness * ((timer&7) == 7)); /*drivers_backlight(backlight_brightness * ((timer&7) == 7)); */
// Backlight blink: check timer and flip backlight as appropriate /* Backlight blink: check timer and flip backlight as appropriate */
} else if (tmp_state & BACKLIGHT_BLINK) { } else if (tmp_state & BACKLIGHT_BLINK) {
tmp = (!((timer & 14) == 14)); tmp = (!((timer & 14) == 14));
if (tmp_state & 1) if (tmp_state & 1)
lcd_ptr->backlight (tmp ? backlight_brightness : backlight_off_brightness); drivers_backlight (tmp ? backlight_brightness : backlight_off_brightness);
//lcd_ptr->backlight(backlight_brightness * (!((timer&14) == 14))); /*drivers_backlight(backlight_brightness * (!((timer&14) == 14))); */
else else
lcd_ptr->backlight (!tmp ? backlight_brightness : backlight_off_brightness); drivers_backlight (!tmp ? backlight_brightness : backlight_off_brightness);
//lcd_ptr->backlight(backlight_brightness * ((timer&14) == 14)); /*drivers_backlight(backlight_brightness * ((timer&14) == 14)); */
} }
break; break;
} }
// Output ports from LCD - outputs depend on the current screen /* Output ports from LCD - outputs depend on the current screen */
lcd_ptr->output (output_state); drivers_output (output_state);
// Draw a frame... /* Draw a frame... */
draw_frame (s->widgets, 'v', 0, 0, lcd_ptr->wid, lcd_ptr->hgt, s->wid, s->hgt, (((s->duration / s->hgt) < 1) ? 1 : (s->duration / s->hgt)), timer); draw_frame (s->widgets, 'v', 0, 0, display_props->width, display_props->height, s->wid, s->hgt, (((s->duration / s->hgt) < 1) ? 1 : (s->duration / s->hgt)), timer);
//debug(RPT_DEBUG, "draw_screen done"); /*debug(RPT_DEBUG, "draw_screen done"); */
if (heartbeat) { if (heartbeat) {
lcd_ptr->heartbeat(s->heartbeat); drivers_heartbeat(s->heartbeat);
//if ((s->heartbeat == HEART_ON) || heartbeat == HEART_ON) { /*if ((s->heartbeat == HEART_ON) || heartbeat == HEART_ON) { */
// Set this to pulsate like a real heart beat... /* Set this to pulsate like a real heart beat... */
// (binary is fun... :) /* (binary is fun... :) */
// lcd_ptr->heartbeat (); /* drivers_heartbeat (); */
//lcd_ptr->icon (!((timer + 4) & 5), 0); /*drivers_icon (!((timer + 4) & 5), 0); */
//lcd_ptr->chr (lcd_ptr->wid, 1, 0); /*drivers_chr (display_props->width, 1, 0); */
//} /*} */
// else /* else */
// This seems unnecessary... heartbeat is nicer... /* This seems unnecessary... heartbeat is nicer... */
// if ((s->heartbeat == HEART_OPEN) && heartbeat != HEART_OFF) { /* if ((s->heartbeat == HEART_OPEN) && heartbeat != HEART_OFF) { */
// char *phases = "-\\|/"; /* char *phases = "-\\|/"; */
// lcd_ptr->chr (lcd_ptr->wid, 1, phases[timer & 3]); /* drivers_chr (ldisplay_props->width, 1, phases[timer & 3]); */
// } /* } */
} }
// flush display out, frame and all... /* flush display out, frame and all... */
lcd_ptr->flush (); drivers_flush ();
//debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer); /*debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer); */
report(RPT_INFO, "==== END RENDERING ====" );
return 0; return 0;
} }
// The following function is positively ghastly (as was mentioned above!) /* The following function is positively ghastly (as was mentioned above!) */
// Best thing to do is to remove support for frames... but anyway... /* Best thing to do is to remove support for frames... but anyway... */
// /* */
static int static int
draw_frame (LinkedList * list, draw_frame (LinkedList * list,
char fscroll, // direction of scrolling char fscroll, /* direction of scrolling */
int left, // left edge of frame int left, /* left edge of frame */
int top, // top edge of frame int top, /* top edge of frame */
int right, // right edge of frame int right, /* right edge of frame */
int bottom, // bottom edge of frame int bottom, /* bottom edge of frame */
int fwid, // frame width? int fwid, /* frame width? */
int fhgt, // frame height? int fhgt, /* frame height? */
int fspeed, // speed of scrolling... int fspeed, /* speed of scrolling... */
int timer) // ? int timer) /* ? */
{ {
#define VerticalScrolling (fscroll == 'v') #define VerticalScrolling (fscroll == 'v')
#define HorizontalScrolling (fscroll == 'h') #define HorizontalScrolling (fscroll == 'h')
char str[BUFSIZE]; // scratch buffer char str[BUFSIZE]; /* scratch buffer */
widget *w; widget *w;
int wid, hgt; // Width and height of visible frame area int wid, hgt; /* Width and height of visible frame area */
int x, y; int x, y;
int fx, fy; // Scrolling offset for the frame... int fx, fy; /* Scrolling offset for the frame... */
int length, speed; int length, speed;
//int lines; /*int lines; */
int reset = 1; int reset = 1;
wid = right - left; // This is the size of the visible frame area report( RPT_INFO, "draw_frame( list=%p, fscroll='%c', left=%d, top=%d, "
"right=%d, bottom=%d, fwid=%d, fhgt=%d, fspeed=%d, timer=%d )",
list, fscroll, left,top, right, bottom, fwid, fhgt, fspeed, timer );
wid = right - left; /* This is the size of the visible frame area */
hgt = bottom - top; hgt = bottom - top;
fx = 0; fx = 0;
@@ -201,15 +205,16 @@ draw_frame (LinkedList * list,
if (fy < 0) if (fy < 0)
fy = 0; fy = 0;
// Make sure the whole frame gets displayed, at least... /* Make sure the whole frame gets displayed, at least...
// ...by setting the action to RENDER_HOLD if no other action * ...by setting the action to RENDER_HOLD if no other action
// is currently defined... * is currently defined...
*/
if (!screenlist_action) if (!screenlist_action)
screenlist_action = RENDER_HOLD; screenlist_action = RENDER_HOLD;
if ((fy) > fhgt - 1) { if ((fy) > fhgt - 1) {
// Release hold after it has been displayed /* Release hold after it has been displayed */
if (!screenlist_action || screenlist_action == RENDER_HOLD) if (!screenlist_action || screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
@@ -219,14 +224,13 @@ draw_frame (LinkedList * list,
fy = fhgt - hgt; fy = fhgt - hgt;
} else if (HorizontalScrolling) { } else if (HorizontalScrolling) {
// TODO: Frames don't scroll horizontally yet! /* TODO: Frames don't scroll horizontally yet! */
} }
//debug(RPT_DEBUG, "draw_screen: %8x, %i", s, timer);
if (!list) if (!list)
return -1; return -1;
//debug(RPT_DEBUG, "draw_frame: %8x, %i", frame, timer); /*debug(RPT_DEBUG, "draw_frame: %8x, %i", frame, timer); */
#define PositiveX(a) ((a)->x > 0) #define PositiveX(a) ((a)->x > 0)
#define PositiveY(a) ((a)->y > 0) #define PositiveY(a) ((a)->y > 0)
@@ -239,7 +243,7 @@ draw_frame (LinkedList * list,
if (!w) if (!w)
return -1; return -1;
// TODO: Make this cleaner and more flexible! /* TODO: Make this cleaner and more flexible!*/
switch (w->type) { switch (w->type) {
case WID_STRING: case WID_STRING:
if (ValidPoint(w) && TextPresent(w)) { if (ValidPoint(w) && TextPresent(w)) {
@@ -247,50 +251,64 @@ draw_frame (LinkedList * list,
if (w->x > wid) w->x=wid; if (w->x > wid) w->x=wid;
strncpy (str, w->text, wid - w->x + 1); strncpy (str, w->text, wid - w->x + 1);
str[wid - w->x + 1] = 0; str[wid - w->x + 1] = 0;
lcd_ptr->string (w->x + left, w->y + top - fy, str); drivers_string (w->x + left, w->y + top - fy, str);
} }
} }
break; break;
case WID_HBAR: case WID_HBAR:
if (reset) { if (reset) {
lcd_ptr->init_hbar (); drivers_init_hbar ();
reset = 0; reset = 0;
} }
if ((w->x > 0) && (w->y > 0)) { if ((w->x > 0) && (w->y > 0)) {
if ((w->y <= hgt + fy) && (w->y > fy)) { if ((w->y <= hgt + fy) && (w->y > fy)) {
if (w->length > 0) { if (w->length > 0) {
if ((w->length / lcd_ptr->cellwid) < wid - w->x + 1) if ((w->length / display_props->cellwidth) < wid - w->x + 1) {
lcd_ptr->hbar (w->x + left, w->y + top - fy, w->length); /*was: drivers_hbar (w->x + left, w->y + top - fy, w->length); */
else /* improvised len and promille */
lcd_ptr->hbar (w->x + left, w->y + top - fy, wid * lcd_ptr->cellwid); int full_len = display_props->width - w->x + left;
int promille = (long) 1000 * w->length / ( display_props->cellwidth * full_len );
drivers_hbar (w->x + left, w->y + top - fy, full_len, promille, BAR_PATTERN_FILLED);
}
else {
/*was: drivers_hbar (w->x + left, w->y + top - fy, wid * display_props->cellwidth); */
/* Improvised len and promille while we have the old widget language */
int full_len = ( display_props->width - w->x + left);
drivers_hbar (w->x + left, w->y + top - fy, full_len, 1000, BAR_PATTERN_FILLED);
}
} else if (w->length < 0) { } else if (w->length < 0) {
// TODO: Rearrange stuff to get left-extending /* TODO: Rearrange stuff to get left-extending
// hbars to draw correctly... * hbars to draw correctly...
// .. er, this'll require driver modifications, * .. er, this'll require driver modifications,
// so I'll leave it out for now. * so I'll leave it out for now.
*/
} }
} }
} }
break; break;
case WID_VBAR: // FIXME: Vbars don't work in frames! case WID_VBAR: /* FIXME: Vbars don't work in frames!*/
if (reset) { if (reset) {
lcd_ptr->init_vbar (); drivers_init_vbar ();
reset = 0; reset = 0;
} }
if ((w->x > 0) && (w->y > 0)) { if ((w->x > 0) && (w->y > 0)) {
if (w->length > 0) { if (w->length > 0) {
lcd_ptr->vbar (w->x, w->length); /* Improvised len and promille while we have the old widget language */
int full_len = - display_props->height; /* Yeah negative length because the bar grows in the */
int promille = (long) 1000 * w->length / display_props->cellheight / -full_len;
drivers_vbar (w->x, display_props->height, full_len, promille, BAR_PATTERN_FILLED);
} else if (w->length < 0) { } else if (w->length < 0) {
// TODO: Rearrange stuff to get down-extending /* TODO: Rearrange stuff to get down-extending
// vbars to draw correctly... * vbars to draw correctly...
// .. er, this'll require driver modifications, * .. er, this'll require driver modifications,
// so I'll leave it out for now. * so I'll leave it out for now.
*/
} }
} }
break; break;
case WID_ICON: // FIXME: Not implemented case WID_ICON: /* FIXME: Not implemented*/
break; break;
case WID_TITLE: // FIXME: Doesn't work quite right in frames... case WID_TITLE: /* FIXME: Doesn't work quite right in frames...*/
if (!w->text) if (!w->text)
break; break;
if (wid < 8) if (wid < 8)
@@ -302,17 +320,17 @@ draw_frame (LinkedList * list,
if (length <= wid - 6) { if (length <= wid - 6) {
memcpy (str + 3, w->text, length); memcpy (str + 3, w->text, length);
str[length + 3] = ' '; str[length + 3] = ' ';
} else // Scroll the title, if it doesn't fit... } else /* Scroll the title, if it doesn't fit...*/
{ {
speed = 1; speed = 1;
x = timer / speed; x = timer / speed;
y = x / length; y = x / length;
// Make sure the whole title gets displayed, at least... /* Make sure the whole title gets displayed, at least...*/
if (!screenlist_action) if (!screenlist_action)
screenlist_action = RENDER_HOLD; screenlist_action = RENDER_HOLD;
if (x > length - 6) { if (x > length - 6) {
// Release hold after it has been displayed /* Release hold after it has been displayed*/
if (!screenlist_action || screenlist_action == RENDER_HOLD) if (!screenlist_action || screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
@@ -323,7 +341,7 @@ draw_frame (LinkedList * list,
if (x > length - (wid - 6)) if (x > length - (wid - 6))
x = length - (wid - 6); x = length - (wid - 6);
if (y & 1) // Scrolling backwards... if (y & 1) /* Scrolling backwards...*/
{ {
x = (length - (wid - 6)) - x; x = (length - (wid - 6)) - x;
} }
@@ -332,9 +350,9 @@ draw_frame (LinkedList * list,
} }
str[wid] = 0; str[wid] = 0;
lcd_ptr->string (1 + left, 1 + top, str); drivers_string (1 + left, 1 + top, str);
break; break;
case WID_SCROLLER: // FIXME: doesn't work in frames... case WID_SCROLLER: /* FIXME: doesn't work in frames...*/
{ {
int offset; int offset;
int screen_width; int screen_width;
@@ -342,16 +360,17 @@ draw_frame (LinkedList * list,
break; break;
if (w->right < w->left) if (w->right < w->left)
break; break;
//printf(RPT_DEBUG, "rendering: %s %d",w->text,timer); /*debug(RPT_DEBUG, "rendering: %s %d",w->text,timer);*/
screen_width = w->right - w->left + 1; screen_width = w->right - w->left + 1;
switch (w->length) { // actually, direction... switch (w->length) { /* actually, direction...*/
// FIXED: Horz scrollers don't show the /* FIXED: Horz scrollers don't show the
// last letter in the string... (1-off error?) * last letter in the string... (1-off error?)
*/
case 'h': case 'h':
length = strlen (w->text) + 1; length = strlen (w->text) + 1;
if (length <= screen_width) { if (length <= screen_width) {
/* it fits within the box, just render it */ /* it fits within the box, just render it */
lcd_ptr->string (w->left, w->top, w->text); drivers_string (w->left, w->top, w->text);
} else { } else {
int effLength = length - screen_width; int effLength = length - screen_width;
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
@@ -360,11 +379,11 @@ draw_frame (LinkedList * list,
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLength * w->speed; necessaryTimeUnits = effLength * w->speed;
if (((timer / (effLength * w->speed)) % 2) == 0) { if (((timer / (effLength * w->speed)) % 2) == 0) {
//wiggle one way /*wiggle one way*/
offset = (timer % (effLength * w->speed)) offset = (timer % (effLength * w->speed))
/ w->speed; / w->speed;
} else { } else {
//wiggle the other /*wiggle the other*/
offset = (((timer % (effLength * w->speed)) offset = (((timer % (effLength * w->speed))
- (effLength * w->speed) + 1) - (effLength * w->speed) + 1)
/ w->speed) * -1; / w->speed) * -1;
@@ -390,33 +409,33 @@ draw_frame (LinkedList * list,
if (offset <= length) { if (offset <= length) {
strncpy (str, &((w->text)[offset]), screen_width); strncpy (str, &((w->text)[offset]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//debug(RPT_DEBUG, "scroller %s : %d", str, length-offset); /*debug(RPT_DEBUG, "scroller %s : %d", str, length-offset); */
} else { } else {
str[0] = '\0'; str[0] = '\0';
} }
lcd_ptr->string (w->left, w->top, str); drivers_string (w->left, w->top, str);
} }
break; break;
// FIXME: Vert scrollers don't always seem to scroll /* FIXME: Vert scrollers don't always seem to scroll */
// back up after hitting the bottom. They jump back to /* back up after hitting the bottom. They jump back to */
// the top instead... (nevermind?) /* the top instead... (nevermind?) */
case 'v': case 'v':
{ {
int i = 0; int i = 0;
length = strlen (w->text); length = strlen (w->text);
if (length <= screen_width) { if (length <= screen_width) {
/* no scrolling required... */ /* no scrolling required... */
lcd_ptr->string (w->left, w->top, w->text); drivers_string (w->left, w->top, w->text);
} else { } else {
int lines_required = (length / screen_width) int lines_required = (length / screen_width)
+ (length % screen_width ? 1 : 0); + (length % screen_width ? 1 : 0);
int available_lines = (w->bottom - w->top + 1); int available_lines = (w->bottom - w->top + 1);
if (lines_required <= available_lines) { if (lines_required <= available_lines) {
// easy... /* easy...*/
for (i = 0; i < lines_required; i++) { for (i = 0; i < lines_required; i++) {
strncpy (str, &((w->text)[i * screen_width]), screen_width); strncpy (str, &((w->text)[i * screen_width]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
lcd_ptr->string (w->left, w->top + i, str); drivers_string (w->left, w->top + i, str);
} }
} else { } else {
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
@@ -424,15 +443,15 @@ draw_frame (LinkedList * list,
int begin = 0; int begin = 0;
if (!screenlist_action) if (!screenlist_action)
screenlist_action = RENDER_HOLD; screenlist_action = RENDER_HOLD;
//debug(RPT_DEBUG, "length: %d sw: %d lines req: %d avail lines: %d effLines: %d ",length,screen_width,lines_required,available_lines,effLines); /*debug(RPT_DEBUG, "length: %d sw: %d lines req: %d avail lines: %d effLines: %d ",length,screen_width,lines_required,available_lines,effLines);*/
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLines * w->speed; necessaryTimeUnits = effLines * w->speed;
if (((timer / (effLines * w->speed)) % 2) == 0) { if (((timer / (effLines * w->speed)) % 2) == 0) {
//debug(RPT_DEBUG, "up "); /*debug(RPT_DEBUG, "up ");*/
begin = (timer % (effLines * w->speed)) begin = (timer % (effLines * w->speed))
/ w->speed; / w->speed;
} else { } else {
//debug(RPT_DEBUG, "down "); /*debug(RPT_DEBUG, "down ");*/
begin = (((timer % (effLines * w->speed)) begin = (((timer % (effLines * w->speed))
- (effLines * w->speed) + 1) / w->speed) - (effLines * w->speed) + 1) / w->speed)
* -1; * -1;
@@ -450,13 +469,13 @@ draw_frame (LinkedList * list,
} else { } else {
begin = 0; begin = 0;
} }
//debug(RPT_DEBUG, "rendering begin: %d timer: %d effLines: %d",begin,timer,effLines); /*debug(RPT_DEBUG, "rendering begin: %d timer: %d effLines: %d",begin,timer,effLines); */
for (i = begin; i < begin + available_lines; i++) { for (i = begin; i < begin + available_lines; i++) {
strncpy (str, &((w->text)[i * (screen_width)]), screen_width); strncpy (str, &((w->text)[i * (screen_width)]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//debug(RPT_DEBUG, "rendering: '%s' of %s", /*debug(RPT_DEBUG, "rendering: '%s' of %s", */
//str,w->text); /*str,w->text); */
lcd_ptr->string (w->left, w->top + (i - begin), str); drivers_string (w->left, w->top + (i - begin), str);
} }
if (timer > necessaryTimeUnits) { if (timer > necessaryTimeUnits) {
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
@@ -471,8 +490,9 @@ draw_frame (LinkedList * list,
} }
case WID_FRAME: case WID_FRAME:
{ {
// FIXME: doesn't handle nested frames quite right! /* FIXME: doesn't handle nested frames quite right!
// doesn't handle scrolling in nested frames at all... * doesn't handle scrolling in nested frames at all...
*/
int new_left, new_top, new_right, new_bottom; int new_left, new_top, new_right, new_bottom;
new_left = left + w->left - 1; new_left = left + w->left - 1;
new_top = top + w->top - 1; new_top = top + w->top - 1;
@@ -482,20 +502,20 @@ draw_frame (LinkedList * list,
new_right = right; new_right = right;
if (new_bottom > bottom) if (new_bottom > bottom)
new_bottom = bottom; new_bottom = bottom;
if (new_left >= right || new_top >= bottom) { // Do nothing if it's invisible... if (new_left >= right || new_top >= bottom) { /* Do nothing if it's invisible...*/
} else { } else {
draw_frame (w->kids, w->length, new_left, new_top, new_right, new_bottom, w->wid, w->hgt, w->speed, timer); draw_frame (w->kids, w->length, new_left, new_top, new_right, new_bottom, w->wid, w->hgt, w->speed, timer);
} }
} }
break; break;
case WID_NUM: // FIXME: doesn't work in frames... case WID_NUM: /* FIXME: doesn't work in frames...*/
// NOTE: y=10 means COLON (:) /* NOTE: y=10 means COLON (:)*/
if ((w->x > 0) && (w->y >= 0) && (w->y <= 10)) { if ((w->x > 0) && (w->y >= 0) && (w->y <= 10)) {
if (reset) { if (reset) {
lcd_ptr->init_num (); drivers_init_num ();
reset = 0; reset = 0;
} }
lcd_ptr->num (w->x + left, w->y); drivers_num (w->x + left, w->y);
} }
break; break;
case WID_NONE: case WID_NONE:
-1
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
+15 -16
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Does screen management * Does screen management
@@ -19,7 +18,7 @@
#include "shared/report.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "clients.h" #include "clients.h"
#include "client_data.h" #include "client_data.h"
@@ -48,14 +47,14 @@ screen_create ()
s->priority = DEFAULT_SCREEN_PRIORITY; s->priority = DEFAULT_SCREEN_PRIORITY;
s->duration = default_duration; s->duration = default_duration;
s->heartbeat = DEFAULT_HEARTBEAT; s->heartbeat = DEFAULT_HEARTBEAT;
s->wid = lcd_ptr->wid; s->wid = display_props->width;
s->hgt = lcd_ptr->hgt; s->hgt = display_props->height;
s->keys = NULL; s->keys = NULL;
s->parent = NULL; s->parent = NULL;
s->widgets = NULL; s->widgets = NULL;
s->timeout = default_timeout; //ignored unless greater than 0. s->timeout = default_timeout; /*ignored unless greater than 0.*/
s->backlight_state = BACKLIGHT_NOTSET; //Lets the screen do it's own s->backlight_state = BACKLIGHT_NOTSET; /*Lets the screen do it's own*/
//or do what the client says. /*or do what the client says.*/
s->widgets = LL_new (); s->widgets = LL_new ();
if (!s->widgets) { if (!s->widgets) {
@@ -76,7 +75,7 @@ screen_destroy (screen * s)
LL_Rewind (s->widgets); LL_Rewind (s->widgets);
do { do {
// Free a widget... /* Free a widget...*/
w = LL_Get (s->widgets); w = LL_Get (s->widgets);
widget_destroy (w); widget_destroy (w);
} while (LL_Next (s->widgets) == 0); } while (LL_Next (s->widgets) == 0);
@@ -128,7 +127,7 @@ screen_add (client * c, char *id)
if (!id) if (!id)
return -1; return -1;
// Make sure this screen doesn't already exist... /* Make sure this screen doesn't already exist...*/
s = screen_find (c, id); s = screen_find (c, id);
if (s) { if (s) {
return 1; return 1;
@@ -147,10 +146,10 @@ screen_add (client * c, char *id)
report (RPT_ERR, "screen_add: Error allocating name"); report (RPT_ERR, "screen_add: Error allocating name");
return -1; return -1;
} }
// TODO: Check for errors here? /* TODO: Check for errors here?*/
LL_Push (c->data->screenlist, (void *) s); LL_Push (c->data->screenlist, (void *) s);
// Now, add it to the screenlist... /* Now, add it to the screenlist...*/
if (screenlist_add (s) < 0) { if (screenlist_add (s) < 0) {
report (RPT_ERR, "screen_add: Error queueing new screen"); report (RPT_ERR, "screen_add: Error queueing new screen");
return -1; return -1;
@@ -169,23 +168,23 @@ screen_remove (client * c, char *id)
if (!id) if (!id)
return -1; return -1;
// Make sure this screen *does* exist... /* Make sure this screen *does* exist...*/
s = screen_find (c, id); s = screen_find (c, id);
if (!s) { if (!s) {
report (RPT_ERR, "screen_remove: Error finding screen %s", id); report (RPT_ERR, "screen_remove: Error finding screen %s", id);
return 1; return 1;
} }
// TODO: Check for errors here? /* TODO: Check for errors here?*/
LL_Remove (c->data->screenlist, (void *) s); LL_Remove (c->data->screenlist, (void *) s);
// Now, remove it from the screenlist... /* Now, remove it from the screenlist...*/
if (screenlist_remove_all (s) < 0) { if (screenlist_remove_all (s) < 0) {
// Not a serious error.. /* Not a serious error..*/
report (RPT_ERR, "screen_remove: Error dequeueing screen"); report (RPT_ERR, "screen_remove: Error dequeueing screen");
return 0; return 0;
} }
// TODO: Check for errors here too? /* TODO: Check for errors here too?*/
screen_destroy (s); screen_destroy (s);
return 0; return 0;
-1
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
+38 -39
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* All actions that can be performed on the list of screens * All actions that can be performed on the list of screens
@@ -108,43 +107,43 @@ screenlist_current ()
debug( RPT_INFO, "screenlist_current:"); debug( RPT_INFO, "screenlist_current:");
//LL_dprint(screenlist); /*LL_dprint(screenlist);*/
s = (screen *) LL_GetFirst (screenlist); s = (screen *) LL_GetFirst (screenlist);
// FIXME: Make sure the screen/client exists! /* FIXME: Make sure the screen/client exists!*/
if (s != old_s) { if (s != old_s) {
//debug (RPT_DEBUG, "screenlist_current: new screen"); /*debug (RPT_DEBUG, "screenlist_current: new screen");*/
timer = 0; timer = 0;
// Tell the client we're done with the current screen /* Tell the client we're done with the current screen*/
if (old_s) { if (old_s) {
//debug(RPT_DEBUG, "screenlist_current: ignoring old screen"); /*debug(RPT_DEBUG, "screenlist_current: ignoring old screen");*/
LL_Rewind (screenlist); LL_Rewind (screenlist);
if (old_s != LL_Find (screenlist, compare_addresses, old_s)) { if (old_s != LL_Find (screenlist, compare_addresses, old_s)) {
report (RPT_WARNING, "screenlist: Didn't find screen 0x%8x!", (int) old_s); report (RPT_WARNING, "screenlist: Didn't find screen 0x%8x! Client crashed?", (int) old_s);
} else { } else {
//debug(RPT_DEBUG, "screenlist_current: ... sending ignore"); /*debug(RPT_DEBUG, "screenlist_current: ... sending ignore");*/
c = old_s->parent; c = old_s->parent;
if (c) // Tell the client we're not listening any more... if (c) /* Tell the client we're not listening any more...*/
{ {
snprintf (str, sizeof(str), "ignore %s\n", old_s->id); snprintf (str, sizeof(str), "ignore %s\n", old_s->id);
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
} else // The server has the display, so do nothing } else /* The server has the display, so do nothing*/
{ {
; ;
} }
//debug(RPT_DEBUG, "screenlist_current: ... sent ignore"); /*debug(RPT_DEBUG, "screenlist_current: ... sent ignore");*/
} }
} }
if (s) { if (s) {
//debug(RPT_DEBUG, "screenlist_current: listening to new screen"); /*debug(RPT_DEBUG, "screenlist_current: listening to new screen");*/
c = s->parent; c = s->parent;
if (c) // Tell the client we're paying attention... if (c) /* Tell the client we're paying attention...*/
{ {
snprintf (str, sizeof(str), "listen %s\n", s->id); snprintf (str, sizeof(str), "listen %s\n", s->id);
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
} else // The server has the display, so do nothing } else /* The server has the display, so do nothing*/
{ {
; ;
} }
@@ -153,7 +152,7 @@ screenlist_current ()
old_s = s; old_s = s;
//debug(RPT_DEBUG, "screenlist_current: return %8x", s); /*debug(RPT_DEBUG, "screenlist_current: return %8x", s);*/
return s; return s;
} }
@@ -161,7 +160,7 @@ screenlist_current ()
int int
screenlist_add (screen * s) screenlist_add (screen * s)
{ {
// TODO: Different queueing modes... /* TODO: Different queueing modes...*/
return screenlist_add_end (s); return screenlist_add_end (s);
} }
@@ -170,27 +169,27 @@ screenlist_next ()
{ {
screen *s; screen *s;
//debug(RPT_DEBUG, "Screenlist_next()"); /*debug(RPT_DEBUG, "Screenlist_next()");*/
s = screenlist_current (); s = screenlist_current ();
// If we're on hold, don't advance! /* If we're on hold, don't advance!*/
if (screenlist_action == SCR_HOLD) if (screenlist_action == SCR_HOLD)
return s; return s;
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
return s; return s;
// Otherwise, reset it to regular operation /* Otherwise, reset it to regular operation*/
screenlist_action = 0; screenlist_action = 0;
//debug(RPT_DEBUG, "Screenlist_next: calling handler..."); /*debug(RPT_DEBUG, "Screenlist_next: calling handler...");*/
// Call the selected queuing function... /* Call the selected queuing function...*/
// TODO: Different queueing modes... /* TODO: Different queueing modes...*/
s = screenlist_next_priority (); s = screenlist_next_priority ();
//s = screenlist_next_roll(); /*s = screenlist_next_roll();*/
//debug(RPT_DEBUG, "Screenlist_next() done"); /*debug(RPT_DEBUG, "Screenlist_next() done");*/
return s; return s;
} }
@@ -202,23 +201,23 @@ screenlist_prev ()
s = screenlist_current (); s = screenlist_current ();
// If we're on hold, don't advance! /* If we're on hold, don't advance!*/
if (screenlist_action == SCR_HOLD) if (screenlist_action == SCR_HOLD)
return s; return s;
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
return s; return s;
// Otherwise, reset it no regular operation /* Otherwise, reset it no regular operation*/
screenlist_action = 0; screenlist_action = 0;
// Call the selected queuing function... /* Call the selected queuing function...*/
// TODO: Different queueing modes... /* TODO: Different queueing modes...*/
s = screenlist_prev_roll (); s = screenlist_prev_roll ();
return s; return s;
} }
// Adds new screens to the end of the screenlist... /* Adds new screens to the end of the screenlist...*/
int int
screenlist_add_end (screen * screen) screenlist_add_end (screen * screen)
{ {
@@ -227,11 +226,11 @@ screenlist_add_end (screen * screen)
return LL_Push (screenlist, (void *) screen); return LL_Push (screenlist, (void *) screen);
} }
// Simple round-robin approach to screen cycling... /* Simple round-robin approach to screen cycling...*/
screen * screen *
screenlist_next_roll () screenlist_next_roll ()
{ {
//debug(RPT_DEBUG, "screenlist_next_roll()"); /*debug(RPT_DEBUG, "screenlist_next_roll()");*/
if (LL_UnRoll (screenlist) != 0) if (LL_UnRoll (screenlist) != 0)
return NULL; return NULL;
@@ -239,12 +238,12 @@ screenlist_next_roll ()
return screenlist_current (); return screenlist_current ();
} }
// Strict priority queue approach... /* Strict priority queue approach...*/
screen * screen *
screenlist_next_priority () screenlist_next_priority ()
{ {
//screen *s, *t; /*screen *s, *t;*/
//debug(RPT_DEBUG, "screenlist_next_priority"); /*debug(RPT_DEBUG, "screenlist_next_priority");*/
if (LL_UnRoll (screenlist) != 0) if (LL_UnRoll (screenlist) != 0)
return NULL; return NULL;
@@ -254,11 +253,11 @@ screenlist_next_priority ()
return screenlist_current (); return screenlist_current ();
} }
// Simple round-robin approach to screen cycling... /* Simple round-robin approach to screen cycling...*/
screen * screen *
screenlist_prev_roll () screenlist_prev_roll ()
{ {
//debug(RPT_DEBUG, "screenlist_prev_roll()"); /*debug(RPT_DEBUG, "screenlist_prev_roll()");*/
if (LL_Roll (screenlist) != 0) if (LL_Roll (screenlist) != 0)
return NULL; return NULL;
@@ -271,7 +270,7 @@ compare_priority (void *one, void *two)
{ {
screen *a, *b; screen *a, *b;
//debug(RPT_DEBUG, "compare_priority: %8x %8x", one, two); /*debug(RPT_DEBUG, "compare_priority: %8x %8x", one, two);*/
if (!one) if (!one)
return 0; return 0;
@@ -281,7 +280,7 @@ compare_priority (void *one, void *two)
a = (screen *) one; a = (screen *) one;
b = (screen *) two; b = (screen *) two;
//debug(RPT_DEBUG, "compare_priority: done?"); /*debug(RPT_DEBUG, "compare_priority: done?");*/
return (a->priority - b->priority); return (a->priority - b->priority);
} }
@@ -289,6 +288,6 @@ compare_priority (void *one, void *two)
int int
compare_addresses (void *one, void *two) compare_addresses (void *one, void *two)
{ {
//printf(RPT_DEBUG, "compare_addresses: %p == %p ???", one, two); /*debug(RPT_DEBUG, "compare_addresses: %p == %p ???", one, two);*/
return (one != two); return (one != two);
} }
-1
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
+39 -41
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Implements the serverscreens * Implements the serverscreens
@@ -23,7 +22,7 @@
#include "shared/report.h" #include "shared/report.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "clients.h" #include "clients.h"
#include "screen.h" #include "screen.h"
@@ -62,7 +61,7 @@ server_screen_init ()
server_screen->id = id; server_screen->id = id;
server_screen->name = name; server_screen->name = name;
server_screen->duration = 8; // 1 second, instead of 4... server_screen->duration = 8; /* 1 second, instead of 4...*/
if (widget_add (server_screen, "title", "title", NULL, 1) != 0) { if (widget_add (server_screen, "title", "title", NULL, 1) != 0) {
report (RPT_ERR, "server_screen_init: internal error: could not add title widget"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
@@ -77,7 +76,7 @@ server_screen_init ()
report (RPT_ERR, "server_screen_init: internal error: could not add title widget"); report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
} }
// Now, initialize all the widgets... /* Now, initialize all the widgets...*/
if ((w = widget_find (server_screen, "title")) != NULL) { if ((w = widget_find (server_screen, "title")) != NULL) {
WidgetText(w,title); WidgetText(w,title);
} else } else
@@ -98,7 +97,7 @@ server_screen_init ()
else else
report (RPT_ERR, "server_screen_init: Can't find widget three"); report (RPT_ERR, "server_screen_init: Can't find widget three");
// And enqueue the screen /* And enqueue the screen*/
screenlist_add (server_screen); screenlist_add (server_screen);
debug (RPT_DEBUG, "server_screen_init done"); debug (RPT_DEBUG, "server_screen_init done");
@@ -125,13 +124,13 @@ update_server_screen (int timer)
{ {
client *c; client *c;
int num_clients; int num_clients;
//screen *s; /*screen *s;*/
int num_screens; int num_screens;
// Draw a title... /* Draw a title...*/
//strcpy(title, "LCDproc Server"); /*strcpy(title, "LCDproc Server");*/
// Now get info on the number of connected clients... /* Now get info on the number of connected clients...*/
num_clients = 0; num_clients = 0;
num_screens = 0; num_screens = 0;
LL_Rewind (clients); LL_Rewind (clients);
@@ -140,27 +139,26 @@ update_server_screen (int timer)
if (c) { if (c) {
num_clients++; num_clients++;
num_screens += screen_count(c); num_screens += screen_count(c);
// LL_Rewind (c->data->screenlist); /* LL_Rewind (c->data->screenlist); */
// do { /* do { */
// s = LL_Get (c->data->screenlist); /* s = LL_Get (c->data->screenlist); */
// if (s) { /* if (s) { */
// num_screens++; /* num_screens++; */
// } /* } */
// } while (LL_Next (c->data->screenlist) == 0); /* } while (LL_Next (c->data->screenlist) == 0); */
} }
} while (LL_Next (clients) == 0); } while (LL_Next (clients) == 0);
// Format strings for the appropriate size display... /* Format strings for the appropriate size display... */
// if (display_props->height >= 3) {
if (lcd_ptr->hgt >= 3) {
snprintf (one, sizeof(one), "Clients: %i", num_clients); snprintf (one, sizeof(one), "Clients: %i", num_clients);
snprintf (two, sizeof(two), "Screens: %i", num_screens); snprintf (two, sizeof(two), "Screens: %i", num_screens);
} else { } else {
if (lcd_ptr->wid >= 20) if (display_props->width >= 20)
snprintf (one, sizeof(one), "%i Client%s, %i Screen%s", num_clients, snprintf (one, sizeof(one), "%i Client%s, %i Screen%s", num_clients,
(num_clients == 1) ? "" : "s", num_screens, (num_clients == 1) ? "" : "s", num_screens,
(num_screens == 1) ? "" : "s"); (num_screens == 1) ? "" : "s");
else // 16x2 size else /* 16x2 size*/
snprintf (one, sizeof(one), "%i Cli%s, %i Scr%s", num_clients, snprintf (one, sizeof(one), "%i Cli%s, %i Scr%s", num_clients,
(num_clients == 1) ? "" : "s", num_screens, (num_clients == 1) ? "" : "s", num_screens,
(num_screens == 1) ? "" : "s"); (num_screens == 1) ? "" : "s");
@@ -173,9 +171,9 @@ int
no_screen_screen (int timer) no_screen_screen (int timer)
{ {
lcd_ptr->clear (); drivers_clear ();
lcd_ptr->string (1, 1, "Error: No screen!"); drivers_string (1, 1, "Error: No screen!");
lcd_ptr->flush (); drivers_flush ();
return 0; return 0;
} }
@@ -199,31 +197,31 @@ goodbye_screen ()
char *l16 = " LCDproc! "; char *l16 = " LCDproc! ";
#endif #endif
lcd_ptr->clear (); drivers_clear ();
if (lcd_ptr->hgt >= 4) { if (display_props->height >= 4) {
if (lcd_ptr->wid >= 20) { if (display_props->width >= 20) {
lcd_ptr->string (1, 1, b20); drivers_string (1, 1, b20);
lcd_ptr->string (1, 2, t20); drivers_string (1, 2, t20);
lcd_ptr->string (1, 3, l20); drivers_string (1, 3, l20);
lcd_ptr->string (1, 4, b20); drivers_string (1, 4, b20);
} else { } else {
lcd_ptr->string (1, 1, b16); drivers_string (1, 1, b16);
lcd_ptr->string (1, 2, t16); drivers_string (1, 2, t16);
lcd_ptr->string (1, 3, l16); drivers_string (1, 3, l16);
lcd_ptr->string (1, 4, b16); drivers_string (1, 4, b16);
} }
} else { } else {
if (lcd_ptr->wid >= 20) { if (display_props->width >= 20) {
lcd_ptr->string (1, 1, t20); drivers_string (1, 1, t20);
lcd_ptr->string (1, 2, l20); drivers_string (1, 2, l20);
} else { } else {
lcd_ptr->string (1, 1, t16); drivers_string (1, 1, t16);
lcd_ptr->string (1, 2, l16); drivers_string (1, 2, l16);
} }
} }
lcd_ptr->flush (); drivers_flush ();
return 0; return 0;
} }
-1
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
+30 -29
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* LCDproc sockets code... * LCDproc sockets code...
@@ -44,12 +43,12 @@ extern int lcd_port;
fd_set active_fd_set, read_fd_set; fd_set active_fd_set, read_fd_set;
int orig_sock; int orig_sock;
// Length of longest transmission allowed at once... /* Length of longest transmission allowed at once...*/
#define MAXMSG 8192 #define MAXMSG 8192
int read_from_client (int filedes); int read_from_client (int filedes);
// Creates a socket in internet space /* Creates a socket in internet space*/
int int
sock_create_inet_socket (char * addr, unsigned int port) sock_create_inet_socket (char * addr, unsigned int port)
{ {
@@ -59,7 +58,7 @@ sock_create_inet_socket (char * addr, unsigned int port)
report (RPT_INFO, "sock_create_inet_socket(%i)", port); report (RPT_INFO, "sock_create_inet_socket(%i)", port);
/* Create the socket. */ /* Create the socket. */
//debug(RPT_DEBUG, "Creating Inet Socket"); /*debug(RPT_DEBUG, "Creating Inet Socket");*/
sock = socket (PF_INET, SOCK_STREAM, 0); sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
report(RPT_ERR, "Could not create socket"); report(RPT_ERR, "Could not create socket");
@@ -72,7 +71,7 @@ sock_create_inet_socket (char * addr, unsigned int port)
} }
/* Give the socket a name. */ /* Give the socket a name. */
//debug(RPT_DEBUG, "Binding Inet Socket"); /*debug(RPT_DEBUG, "Binding Inet Socket");*/
memset (&name, 0, sizeof (name)); memset (&name, 0, sizeof (name));
name.sin_family = AF_INET; name.sin_family = AF_INET;
name.sin_port = htons (port); name.sin_port = htons (port);
@@ -89,7 +88,7 @@ sock_create_inet_socket (char * addr, unsigned int port)
} }
//int StartSocketServer() /*int StartSocketServer()*/
int int
sock_create_server (char *bind_addr, int lcd_port) sock_create_server (char *bind_addr, int lcd_port)
{ {
@@ -133,7 +132,7 @@ sock_create_server (char *bind_addr, int lcd_port)
return sock; return sock;
} }
// Service all clients with input pending... /* Service all clients with input pending...*/
int int
sock_poll_clients () sock_poll_clients ()
@@ -176,7 +175,7 @@ sock_poll_clients ()
fcntl (new, F_SETFL, O_NONBLOCK); fcntl (new, F_SETFL, O_NONBLOCK);
// TODO: Create new "client" here... (done?) /* TODO: Create new "client" here... (done?)*/
if (client_create (new) == NULL) { if (client_create (new) == NULL) {
report( RPT_ERR, "sock_poll_clients: error creating client %i", i); report( RPT_ERR, "sock_poll_clients: error creating client %i", i);
return -1; return -1;
@@ -189,10 +188,10 @@ sock_poll_clients ()
err = read_from_client (i); err = read_from_client (i);
debug (RPT_DEBUG, "sock_poll_clients: ...done"); debug (RPT_DEBUG, "sock_poll_clients: ...done");
if (err < 0) { if (err < 0) {
// TODO: Destroy a "client" here... (done?) /* TODO: Destroy a "client" here... (done?)*/
c = client_find_sock (i); c = client_find_sock (i);
if (c) { if (c) {
//sock_send_string(i, "bye\n"); /*sock_send_string(i, "bye\n");*/
client_destroy (c); client_destroy (c);
close (i); close (i);
FD_CLR (i, &active_fd_set); FD_CLR (i, &active_fd_set);
@@ -217,31 +216,31 @@ read_from_client (int filedes)
report(RPT_DEBUG, "read_from_client()" ); report(RPT_DEBUG, "read_from_client()" );
//nbytes = read (filedes, buffer, MAXMSG); /*nbytes = read (filedes, buffer, MAXMSG);*/
//debug(RPT_DEBUG, "read_from_client(%i): reading...", filedes); /*debug(RPT_DEBUG, "read_from_client(%i): reading...", filedes);*/
//nbytes = sock_recv (filedes, buffer, MAXMSG); /*nbytes = sock_recv (filedes, buffer, MAXMSG);*/
//debug(RPT_DEBUG, "read_from_client(%i): ...done", filedes); /*debug(RPT_DEBUG, "read_from_client(%i): ...done", filedes);*/
//debug (RPT_DEBUG, "read_from_client(%i): %i bytes", filedes, nbytes); /*debug (RPT_DEBUG, "read_from_client(%i): %i bytes", filedes, nbytes);*/
errno = 0; errno = 0;
if ((nbytes = sock_recv (filedes, buffer, MAXMSG)) < 0) { if ((nbytes = sock_recv (filedes, buffer, MAXMSG)) < 0) {
if (errno != EAGAIN) if (errno != EAGAIN)
report (RPT_DEBUG, "read_from_client: (fd %d) %s", filedes, strerror(errno)); report (RPT_DEBUG, "read_from_client: (fd %d) %s", filedes, strerror(errno));
return 0; return 0;
} else if (nbytes == 0) // EOF } else if (nbytes == 0) /* EOF*/
return -1; return -1;
else if (nbytes > (MAXMSG - (MAXMSG / 8))) // Very noisy client... else if (nbytes > (MAXMSG - (MAXMSG / 8))) /* Very noisy client...*/
{ {
sock_send_string (filedes, "huh? Too much data received... quiet down!\n"); sock_send_string (filedes, "huh? Too much data received... quiet down!\n");
return -1; return -1;
} else // Data Read } else /* Data Read*/
{ {
buffer[nbytes] = 0; buffer[nbytes] = 0;
// Now, replace zeros with linefeeds... /* Now, replace zeros with linefeeds...*/
for (i = 0; i < nbytes; i++) for (i = 0; i < nbytes; i++)
if (buffer[i] == 0) if (buffer[i] == 0)
buffer[i] = '\n'; buffer[i] = '\n';
// Enqueue a "client message" here... /* Enqueue a "client message" here...*/
c = client_find_sock (filedes); c = client_find_sock (filedes);
if (c) { if (c) {
client_add_message (c, buffer); client_add_message (c, buffer);
@@ -254,9 +253,10 @@ read_from_client (int filedes)
return nbytes; return nbytes;
} }
// FIXME: This talks to all open files, including /* FIXME: This talks to all open files, including
// stdin, stdout, stderr, the LCD, etc... * stdin, stdout, stderr, the LCD, etc...
// BUT it should only talk to sockets! * BUT it should only talk to sockets!
*/
int int
sock_close_all () sock_close_all ()
{ {
@@ -265,19 +265,20 @@ sock_close_all ()
report (RPT_INFO, "sock_close_all()"); report (RPT_INFO, "sock_close_all()");
for (fd = 0; fd < FD_SETSIZE; fd++) { for (fd = 0; fd < FD_SETSIZE; fd++) {
// TODO: Destroy a "client" here...? Nope. /* TODO: Destroy a "client" here...? Nope.*/
// Instead of using STDIN_FILENO, STDOUT_FILENO, /* Instead of using STDIN_FILENO, STDOUT_FILENO,
// and STDERR_FILENO, one could use "fd = 4" in the * and STDERR_FILENO, one could use "fd = 4" in the
// for() call - but this would probably not be good * for() call - but this would probably not be good
// practice... * practice...
*/
if ( fd == STDIN_FILENO || if ( fd == STDIN_FILENO ||
fd == STDOUT_FILENO || fd == STDOUT_FILENO ||
fd == STDERR_FILENO) fd == STDERR_FILENO)
continue; continue;
else { else {
//sock_send_string (fd, "bye\n"); /*sock_send_string (fd, "bye\n");*/
close (fd); close (fd);
FD_CLR (fd, &active_fd_set); FD_CLR (fd, &active_fd_set);
debug (RPT_DEBUG, "sock_close_all: Closed connection %i", fd); debug (RPT_DEBUG, "sock_close_all: Closed connection %i", fd);
+1 -2
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -17,7 +16,7 @@
typedef struct sockaddr_in sockaddr_in; typedef struct sockaddr_in sockaddr_in;
// Server functions... /* Server functions...*/
int sock_create_server (); int sock_create_server ();
int sock_create_inet_socket (unsigned short int port); int sock_create_inet_socket (unsigned short int port);
int sock_poll_clients (); int sock_poll_clients ();
+41 -40
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
* *
* Does widget management * Does widget management
@@ -33,7 +32,7 @@ char *types[] = { "none",
"scroller", "scroller",
"frame", "frame",
"num", "num",
//"", /*"",*/
NULL, NULL,
}; };
@@ -84,12 +83,12 @@ widget_destroy (widget * w)
if (w->id) if (w->id)
free (w->id); free (w->id);
//debug(RPT_DEBUG, "widget_destroy: id..."); /*debug(RPT_DEBUG, "widget_destroy: id...");*/
if (w->text) if (w->text)
free (w->text); free (w->text);
//debug(RPT_DEBUG, "widget_destroy: text..."); /*debug(RPT_DEBUG, "widget_destroy: text...");*/
// TODO: Free kids! /* TODO: Free kids!*/
if (w->kids) { if (w->kids) {
list = w->kids; list = w->kids;
LL_Rewind (list); LL_Rewind (list);
@@ -104,7 +103,7 @@ widget_destroy (widget * w)
} }
free (w); free (w);
//debug(RPT_DEBUG, "widget_destroy: widget..."); /*debug(RPT_DEBUG, "widget_destroy: widget...");*/
return 0; return 0;
} }
@@ -112,7 +111,7 @@ widget_destroy (widget * w)
widget * widget *
widget_find (screen * s, char *id) widget_find (screen * s, char *id)
{ {
//widget *w, *err; /*widget *w, *err;*/
if (!s) if (!s)
return NULL; return NULL;
@@ -138,22 +137,22 @@ widget_finder (LinkedList * list, char *id)
LL_Rewind (list); LL_Rewind (list);
do { do {
//debug(RPT_DEBUG, "widget_finder: Iteration"); /*debug(RPT_DEBUG, "widget_finder: Iteration");*/
w = LL_Get (list); w = LL_Get (list);
if (w) { if (w) {
//debug(RPT_DEBUG, "widget_finder: ..."); /*debug(RPT_DEBUG, "widget_finder: ...");*/
if (0 == strcmp (w->id, id)) { if (0 == strcmp (w->id, id)) {
debug (RPT_DEBUG, "widget_finder: Found %s", id); debug (RPT_DEBUG, "widget_finder: Found %s", id);
return w; return w;
} }
// Search kids recursively /* Search kids recursively*/
//debug(RPT_DEBUG, "widget_finder: ..."); /*debug(RPT_DEBUG, "widget_finder: ...");*/
if (w->type == WID_FRAME) { if (w->type == WID_FRAME) {
err = widget_finder (w->kids, id); err = widget_finder (w->kids, id);
if (err) if (err)
return err; return err;
} }
//debug(RPT_DEBUG, "widget_finder: ..."); /*debug(RPT_DEBUG, "widget_finder: ...");*/
} }
} while (LL_Next (list) == 0); } while (LL_Next (list) == 0);
@@ -180,22 +179,22 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
list = s->widgets; list = s->widgets;
if (0 == strcmp (id, "heartbeat")) { if (0 == strcmp (id, "heartbeat")) {
s->heartbeat = HEARTBEAT_ON; // was 1 s->heartbeat = HEARTBEAT_ON; /* was 1*/
return 0; return 0;
} }
// Make sure this screen doesn't already exist... /* Make sure this screen doesn't already exist...*/
w = widget_find (s, id); w = widget_find (s, id);
if (w) { if (w) {
// already exists /* already exists*/
sock_send_string (sock, "huh? You already have a widget with that id#\n"); sock_send_string (sock, "huh? You already have a widget with that id#\n");
return 1; return 1;
} }
// Make sure the container, if any, is real /* Make sure the container, if any, is real*/
if (in) { if (in) {
parent = widget_find (s, in); parent = widget_find (s, in);
if (!parent) { if (!parent) {
// no frame to use as parent /* no frame to use as parent*/
sock_send_string (sock, "huh? Frame doesn't exist\n"); sock_send_string (sock, "huh? Frame doesn't exist\n");
return 3; return 3;
} else { } else {
@@ -204,31 +203,31 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
if (!list) if (!list)
report (RPT_DEBUG, "widget_add: Parent has no kids"); report (RPT_DEBUG, "widget_add: Parent has no kids");
} else { } else {
// no frame to use as parent /* no frame to use as parent*/
sock_send_string (sock, "huh? Not a frame\n"); sock_send_string (sock, "huh? Not a frame\n");
return 4; return 4;
} }
} }
} }
// Make sure it's a valid widget type /* Make sure it's a valid widget type*/
for (i = 1; types[i]; i++) { for (i = 1; types[i]; i++) {
if (0 == strcmp (types[i], type)) { if (0 == strcmp (types[i], type)) {
valid = 1; valid = 1;
wid_type = i; wid_type = i;
break; // it's valid: skip out... break; /* it's valid: skip out...*/
} }
} }
if (!valid) { if (!valid) {
// invalid widget type /* invalid widget type*/
sock_send_string (sock, "huh? Invalid widget type\n"); sock_send_string (sock, "huh? Invalid widget type\n");
return 2; return 2;
} }
debug (RPT_DEBUG, "widget_add: making widget"); debug (RPT_DEBUG, "widget_add: making widget");
// Now, make it... /* Now, make it...*/
w = widget_create (); w = widget_create ();
if (!w) { if (!w) {
report (RPT_ERR, "widget_add: Error creating widget"); report (RPT_ERR, "widget_add: Error creating widget");
@@ -243,7 +242,7 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
w->type = wid_type; w->type = wid_type;
// Set up the container's widget list... /* Set up the container's widget list...*/
if (w->type == WID_FRAME) { if (w->type == WID_FRAME) {
if (!w->kids) { if (!w->kids) {
w->kids = LL_new (); w->kids = LL_new ();
@@ -254,7 +253,7 @@ widget_add (screen * s, char *id, char *type, char *in, int sock)
} }
} }
// TODO: Check for errors here? /* TODO: Check for errors here?*/
LL_Push (list, (void *) w); LL_Push (list, (void *) w);
return 0; return 0;
@@ -276,10 +275,10 @@ widget_remove (screen * s, char *id, int sock)
list = s->widgets; list = s->widgets;
if (0 == strcmp (id, "heartbeat")) { if (0 == strcmp (id, "heartbeat")) {
s->heartbeat = HEARTBEAT_OFF; // was 0 s->heartbeat = HEARTBEAT_OFF; /* was 0*/
return 0; return 0;
} }
// Make sure this screen *does* exist... /* Make sure this screen *does* exist...*/
w = widget_find (s, id); w = widget_find (s, id);
if (!w) { if (!w) {
sock_send_string (sock, "huh? You don't have a widget with that id#\n"); sock_send_string (sock, "huh? You don't have a widget with that id#\n");
@@ -287,17 +286,19 @@ widget_remove (screen * s, char *id, int sock)
return 1; return 1;
} }
// TODO: Check for errors here? /* TODO: Check for errors here?
// TODO: Make this work with frames... * TODO: Make this work with frames...
// LL_Remove(list, (void *)w); * LL_Remove(list, (void *)w);
*/
// TODO: Check for errors here? /* TODO: Check for errors here?
// widget_destroy(w); * widget_destroy(w);
*/
return widget_remover (list, w); return widget_remover (list, w);
// return 0; /* return 0;*/
} }
int int
@@ -313,19 +314,19 @@ widget_remover (LinkedList * list, widget * w)
if (!w) if (!w)
return 0; return 0;
// Search through the list... /* Search through the list...*/
LL_Rewind (list); LL_Rewind (list);
do { do {
// Test each item /* Test each item*/
foo = LL_Get (list); foo = LL_Get (list);
if (foo) { if (foo) {
// Frames require recursion to search and/or destroy /* Frames require recursion to search and/or destroy*/
if (foo->type == WID_FRAME) { if (foo->type == WID_FRAME) {
// If removing a frame, kill all its kids, too... /* If removing a frame, kill all its kids, too...*/
if (foo == w) { if (foo == w) {
if (!foo->kids) { if (!foo->kids) {
debug (RPT_DEBUG, "widget_remover: frame has no kids"); debug (RPT_DEBUG, "widget_remover: frame has no kids");
} else // Kill the kids... } else /* Kill the kids...*/
{ {
LL_Rewind (foo->kids); LL_Rewind (foo->kids);
do { do {
@@ -333,12 +334,12 @@ widget_remover (LinkedList * list, widget * w)
err = widget_remover (foo->kids, bar); err = widget_remover (foo->kids, bar);
} while (0 == LL_Next (foo->kids)); } while (0 == LL_Next (foo->kids));
// Then kill the parent... /* Then kill the parent...*/
LL_Remove (list, (void *) w); LL_Remove (list, (void *) w);
widget_destroy (w); widget_destroy (w);
} }
} else // Otherwise, search the frame recursively... } else /* Otherwise, search the frame recursively...*/
{ {
if (!foo->kids) { if (!foo->kids) {
debug (RPT_DEBUG, "widget_remover: frame has no kids"); debug (RPT_DEBUG, "widget_remover: frame has no kids");
@@ -346,7 +347,7 @@ widget_remover (LinkedList * list, widget * w)
err = widget_remover (foo->kids, w); err = widget_remover (foo->kids, w);
} }
} else // If not a frame, remove it if it matches... } else /* If not a frame, remove it if it matches...*/
{ {
if (foo == w) { if (foo == w) {
LL_Remove (list, (void *) w); LL_Remove (list, (void *) w);
+9 -10
View File
@@ -6,7 +6,6 @@
* COPYING file distributed with this package. * COPYING file distributed with this package.
* *
* Copyright (c) 1999, William Ferrell, Scott Scriven * Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
* *
*/ */
@@ -18,17 +17,17 @@
typedef struct widget { typedef struct widget {
char *id; char *id;
int type; int type;
// some sort of data here... /* some sort of data here...*/
int x, y; // Position int x, y; /* Position*/
int wid, hgt; // Size int wid, hgt; /* Size*/
int left, top, right, bottom; // bounding rectangle int left, top, right, bottom; /* bounding rectangle*/
int length; // size or direction int length; /* size or direction*/
int speed; // For scroller... int speed; /* For scroller...*/
char *text; // text or binary data char *text; /* text or binary data*/
LinkedList *kids; // Frames can contain more widgets... LinkedList *kids; /* Frames can contain more widgets...*/
} widget; } widget;
// These correspond to the index into the "types" array... /* These correspond to the index into the "types" array...*/
#define WID_NONE 0 #define WID_NONE 0
#define WID_STRING 1 #define WID_STRING 1
#define WID_HBAR 2 #define WID_HBAR 2
+11 -1
View File
@@ -1,5 +1,15 @@
/* /*
* REPORTING FUNCTIONS * report.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
*
*
* Contains reporting functions
* *
*/ */
+59 -42
View File
@@ -1,46 +1,65 @@
#ifndef DEBUG_H /*
#define DEBUG_H * report.h
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
* 2001, Joris Robijn
*
*/
/* DEBUGGING #ifndef REPORT_H
To enable the debug() function on all of the software, just type: #define REPORT_H
./configure --enable-debug
and recompile with 'make'
To enable the debug() function only in specific files: /* DEBUGGING / REPORTING
1) Configure without enabling debug (that is without --enable-debug) *
2) Edit the source file that you want to debug and put this: * To enable the debug() function on all of the software, just type:
#define DEBUG * ./configure --enable-debug
#include "shared/debug.h" * and recompile with 'make'
#undef DEBUG *
Then recompile with 'make' * To enable the debug() function only in specific files:
This way, the global DEBUG macro is off but is locally enabled in * 1) Configure without enabling debug (that is without --enable-debug)
certains parts of the software. * 2) Edit the source file that you want to debug and put the following
* line at the top, before the #include "report.h" line:
The debug levels use the following * #define DEBUG
* 3) Then recompile with 'make'
0 RPT_CRIT Critical conditions: the program stops right after this. * This way, the global DEBUG macro is off but is locally enabled in
Only use this if the program is exited from the current * certains parts of the software.
function. *
1 RPT_ERR Error conditions: serious problem, program continues. * The reporting levels have the following meaning:
Use just before you return -1 from a function. *
2 RPT_WARNING Warning conditions: request user to fix this problem. * 0 RPT_CRIT Critical conditions: the program stops right after
Ex: What a queer port did you select. * this. Only use this if the program is exited from
3 RPT_NOTICE Normal but significant condition: * the current function.
Ex: What options have been set. * 1 RPT_ERR Error conditions: serious problem, program continues.
4 RPT_INFO Informational * Use just before you return -1 from a function.
Ex: What functions have been called. * 2 RPT_WARNING Warning conditions: request user to fix this problem.
5 RPT_DEBUG Debug-level messages: further debug messages * Ex: What a queer port did you select.
Ex: what are we going to do in the next few lines of code. * 3 RPT_NOTICE Normal but significant condition:
* Ex: What options have been set, version number.
Levels 4 and 5 should be reported using the debug function. The code * 4 RPT_INFO Informational
that this function generates will not be in the executable when compiled * Ex: What functions have been called.
without debugging. This way memory and CPU cycles are saved. * 5 RPT_DEBUG Debug-level messages: further debug messages
*/ * Ex: what are we going to do in the next few lines of
* code.
*
* Levels 4 (maybe) and 5 (certainly) should be reported using the debug
* function.
* The code that this function generates will not be in the executable when
* compiled without debugging. This way memory and CPU cycles are saved.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
// Reporting levels // Reporting levels
#define RPT_CRIT 0 #define RPT_CRIT 0
#define RPT_ERR 1 #define RPT_ERR 1
@@ -48,16 +67,14 @@ without debugging. This way memory and CPU cycles are saved.
#define RPT_NOTICE 3 #define RPT_NOTICE 3
#define RPT_INFO 4 #define RPT_INFO 4
#define RPT_DEBUG 5 #define RPT_DEBUG 5
// Don't just modify these numbers, they're related to syslog.
// Reporting destinations
#define RPT_DEST_STDERR 0 #define RPT_DEST_STDERR 0
#define RPT_DEST_SYSLOG 1 #define RPT_DEST_SYSLOG 1
#define RPT_DEST_STORE 2 #define RPT_DEST_STORE 2
// Don't just modify these numbers, they're related to syslog.
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
// For compatibility, to be removed ?
extern int report_level; extern int report_level;
extern int report_dest; extern int report_dest;