Added a limited 'base_drv'-like implementation of the extended

driver functions.
Removed some of this functionality from the curses and text driver.
This commit is contained in:
robijn
2002-05-13 22:25:04 +00:00
parent 40706764dd
commit 31641610d1
5 changed files with 205 additions and 238 deletions
+172 -1
View File
@@ -18,11 +18,14 @@
#include <string.h>
#include <sys/errno.h>
#include <dlfcn.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "screenlist.h" /* for timer */
#include "shared/report.h"
#include "configfile.h"
@@ -295,7 +298,6 @@ request_display_width()
return display_props->width;
}
static int
request_display_height()
{
@@ -303,3 +305,172 @@ request_display_height()
return 0;
return display_props->height;
}
void
driver_alt_vbar( Driver * drv, int x, int y, int len, int promille, int pattern )
{
int pos;
if (!drv->chr)
return;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
drv->chr (drv, x, y-pos, '|');
} else {
; /* print nothing */
}
}
}
void
driver_alt_hbar( Driver * drv, int x, int y, int len, int promille, int pattern )
{
int pos;
if (!drv->chr)
return;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
drv->chr (drv, x+pos, y, '-');
} else {
; /* print nothing */
}
}
}
void
driver_alt_num( Driver * drv, int x, int num )
{
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
/* Moved to driver.c by Joris Robijn */
static char num_map [10][4][3] = {
{
{' ','_',' '}, /*0*/
{'|',' ','|'},
{'|','_','|'},
{' ',' ',' '}},
{
{' ',' ',' '},/*1*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*2*/
{' ','_','|'},
{'|','_',' '},
{' ',' ',' '}},
{
{' ','_',' '},/*3*/
{' ','_','|'},
{' ','_','|'},
{' ',' ',' '}},
{
{' ',' ',' '},/*4*/
{'|','_','|'},
{' ',' ','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*5*/
{'|','_',' '},
{' ','_','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*6*/
{'|','_',' '},
{'|','_','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*7*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*8*/
{'|','_','|'},
{'|','_','|'},
{' ',' ',' '}},
{
{' ','_',' '},/*9*/
{'|','_','|'},
{' ','_','|'},
{' ',' ',' '}}
};
/* End of ugly code ;) by Rene Wagner */
/* I like this code ! Joris */
int y, dx;
if (!drv->chr)
return;
for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++)
drv->chr (drv, x + dx, y, num_map[num][y-1][dx]);
}
void
driver_alt_heartbeat( Driver * drv, int state )
{
int icon;
if (state == HEARTBEAT_OFF)
return;
/* Don't display anything */
if (!drv->width)
return;
/* Hmm, is this a good method ?
* Or should we use clock() ? Or ftime ? Or gettimeofday ?
*/
icon = (timer & 5) ? ICON_HEART_FILLED : ICON_HEART_OPEN;
if (drv->icon)
drv->icon( drv, drv->width(drv), 1, icon);
else
driver_alt_icon( drv, drv->width(drv), 1, icon);
}
void
driver_alt_icon( Driver * drv, int x, int y, int icon )
{
char ch;
if (!drv->chr)
return;
switch (icon) {
case ICON_HEART_OPEN:
ch = '-';
break;
case ICON_HEART_FILLED:
ch = '#';
break;
case ICON_BLOCK_FILLED:
ch = '#';
break;
default:
ch = '?';
}
drv->chr( drv, x, y, ch);
}
void driver_alt_cursor( Driver * drv, int x, int y, int state )
{
/* Same question about timer in this function... */
switch( state ) {
case CURSOR_BLOCK:
case CURSOR_DEFAULT_ON:
if (timer & 2)
driver_alt_icon( drv, x, y, ICON_BLOCK_FILLED );
break;
case CURSOR_UNDER:
if (timer & 2 && drv->chr)
drv->chr( drv, x, y, '_');
break;
}
}
+15
View File
@@ -41,4 +41,19 @@ driver_support_multiple( Driver * driver );
bool
driver_stay_in_foreground( Driver * driver );
/* Alternative functions for all extended functions */
void driver_alt_vbar( Driver * drv, int x, int y, int len, int promille, int pattern );
void driver_alt_hbar( Driver * drv, int x, int y, int len, int promille, int pattern );
void driver_alt_num( Driver * drv, int x, int num );
void driver_alt_heartbeat( Driver * drv, int state );
void driver_alt_icon( Driver * drv, int x, int y, int icon );
void driver_alt_cursor( Driver * drv, int x, int y, int state );
#endif
+18 -44
View File
@@ -233,9 +233,10 @@ drivers_vbar( int x, int y, int len, int promille, int pattern )
ForAllDrivers(drv) {
if( drv->vbar ) {
if( drv->vbar )
drv->vbar( drv, x, y, len, promille, pattern );
}
else
driver_alt_vbar( drv, x, y, len, promille, pattern );
}
}
@@ -248,9 +249,10 @@ drivers_hbar( int x, int y, int len, int promille, int pattern )
report( RPT_INFO, "drivers_hbar( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", x, y, len, promille, pattern );
ForAllDrivers(drv) {
if( drv->hbar ) {
if( drv->hbar )
drv->hbar( drv, x, y, len, promille, pattern );
}
else
driver_alt_hbar( drv, x, y, len, promille, pattern );
}
}
@@ -265,6 +267,8 @@ drivers_num( int x, int num )
ForAllDrivers(drv) {
if( drv->num )
drv->num( drv, x, num );
else
driver_alt_num( drv, x, num );
}
}
@@ -279,6 +283,8 @@ drivers_heartbeat( int state )
ForAllDrivers(drv) {
if( drv->heartbeat )
drv->heartbeat( drv, state );
else
driver_alt_heartbeat( drv, state );
}
}
@@ -293,58 +299,26 @@ drivers_icon( int x, int y, int icon )
ForAllDrivers(drv) {
if( drv->icon )
drv->icon( drv, x, y, icon );
else
driver_alt_icon( drv, x, y, icon );
}
}
void
drivers_set_char( char ch, char *dat )
drivers_cursor( int x, int y, int state )
{
Driver *drv;
report( RPT_INFO, "drivers_set_char( ch=%d, dat=%p )", ch, dat );
report( RPT_INFO, "drivers_cursor( x=%d, y=%d, state=%d )", x, y, state );
ForAllDrivers(drv) {
if( drv->set_char )
drv->set_char( drv, ch, dat );
if( drv->cursor )
drv->cursor( drv, x, y, state );
else
driver_alt_cursor( drv, x, y, state );
}
}
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 )
{
-95
View File
@@ -112,49 +112,6 @@ void curses_drv_restore_screen (Driver *drvthis);
static char icon_char = '@';
static WINDOW *lcd_win;
/*this is really ugly ;) but works ;)*/
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{'|',' ','|'},
{'|','_','|'},
{' ',' ',' '}},
{{' ',' ',' '},/*1*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*2*/
{' ','_','|'},
{'|','_',' '},
{' ',' ',' '}},
{{' ','_',' '},/*3*/
{' ','_','|'},
{' ','_','|'},
{' ',' ',' '}},
{{' ',' ',' '},/*4*/
{'|','_','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*5*/
{'|','_',' '},
{' ','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*6*/
{'|','_',' '},
{'|','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*7*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*8*/
{'|','_','|'},
{'|','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*9*/
{'|','_','|'},
{' ','_','|'},
{' ',' ',' '}}};
/*end of ugly code ;) Rene Wagner*/
chtype get_color (char *colorstr) {
if (strcasecmp(colorstr, "red") == 0)
return COLOR_RED;
@@ -499,29 +456,6 @@ curses_drv_chr (Driver *drvthis, int x, int y, char c)
mvwaddch (lcd_win, y, x, c);
}
/////////////////////////////////////////////////////////////////
// Sets up for big numbers.
//
MODULE_EXPORT void
curses_drv_init_num (Driver *drvthis)
{
;
}
/////////////////////////////////////////////////////////////////
// Writes a big number.
//
MODULE_EXPORT void
curses_drv_num (Driver *drvthis, int x, int num)
{
int y, dx;
for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++)
curses_drv_chr (drvthis, x + dx, y, num_icon[num][y-1][dx]);
// printf("%1d",num);
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen.
//
@@ -625,35 +559,6 @@ curses_drv_icon (Driver *drvthis, int x, int y, int icon)
*/
}
/////////////////////////////////////////////////////////////
// Does the heartbeat...
//
MODULE_EXPORT void
curses_drv_heartbeat (Driver *drvthis, int type)
{
static int timer = 0;
int whichIcon;
static int saved_type = HEARTBEAT_ON;
if (type)
saved_type = type;
if (type == HEARTBEAT_ON) {
// Set this to pulsate like a real heart beat...
if ( (timer + 4) & 5 ) {
whichIcon = ICON_HEART_OPEN;
}
else {
whichIcon = ICON_HEART_FILLED;
}
// Place the icon on screen
curses_drv_icon (drvthis, width, 1, whichIcon);
}
timer++;
timer &= 0x0f;
}
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
-98
View File
@@ -23,48 +23,6 @@
#include "text.h"
//#include "drv_base.h"
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
{'|',' ','|'},
{'|','_','|'},
{' ',' ',' '}},
{{' ',' ',' '},/*1*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*2*/
{' ','_','|'},
{'|','_',' '},
{' ',' ',' '}},
{{' ','_',' '},/*3*/
{' ','_','|'},
{' ','_','|'},
{' ',' ',' '}},
{{' ',' ',' '},/*4*/
{'|','_','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*5*/
{'|','_',' '},
{' ','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*6*/
{'|','_',' '},
{'|','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*7*/
{' ',' ','|'},
{' ',' ','|'},
{' ',' ',' '}},
{{' ','_',' '},/*8*/
{'|','_','|'},
{'|','_','|'},
{' ',' ',' '}},
{{' ','_',' '},/*9*/
{'|','_','|'},
{' ','_','|'},
{' ',' ',' '}}};
/* End of ugly code ;) by Rene Wagner */
// Variables
int width;
@@ -235,59 +193,3 @@ text_backlight (Driver *drvthis, int on)
*/
}
/////////////////////////////////////////////////////////////////
// Writes a big number. (by Rene Wagner from lcdm001.c)
//
MODULE_EXPORT void
text_num (Driver *drvthis, int x, int num)
{
//PrivateData * p = (PrivateData*) drvthis->private_data;
int y, dx;
// printf("BigNum(%i, %i)\n", x, num);
for (y = 1; y < 5; y++)
for (dx = 0; dx < 3; dx++)
text_chr (drvthis, x + dx, y, num_icon[num][y-1][dx]);
}
//void
//text_set_char (int n, char *dat)
//{
//// printf("Set Character %i\n", n);
//}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen.
//
MODULE_EXPORT void
text_vbar (Driver *drvthis, int x, int y, int len, int promille, int options)
{
int pos;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
text_chr (drvthis, x, y-pos, '|');
} else {
; /* print nothing */
}
}
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
MODULE_EXPORT void
text_hbar (Driver *drvthis, int x, int y, int len, int promille, int options)
{
int pos;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
text_chr (drvthis, x+pos, y, '-');
} else {
; /* print nothing */
}
}
}