2001-09-24 16:30:31 +00:00
/*
* CrystalFontz driver
*
* http://www.crystalfontz.com
*
*/
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
2001-09-25 14:34:40 +00:00
#include <syslog.h>
2001-05-25 03:14:27 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
1999-12-09 23:15:14 +00:00
#include "lcd.h"
#include "CFontz.h"
#include "drv_base.h"
2001-05-25 03:14:27 +00:00
#include "render.h"
#include "shared/debug.h"
#include "shared/str.h"
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
#define DEFAULT_CELL_WIDTH 6
#define DEFAULT_CELL_HEIGHT 8
#define DEFAULT_CONTRAST 140
#define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_SPEED B9600
2000-03-30 20:20:41 +00:00
static int custom = 0 ;
1999-12-09 23:15:14 +00:00
typedef enum {
2000-04-03 22:13:57 +00:00
hbar = 1 ,
vbar = 2 ,
bign = 4 ,
beat = 8
2000-03-30 20:20:41 +00:00
} custom_type ;
1999-12-09 23:15:14 +00:00
static int fd ;
2000-03-30 20:20:41 +00:00
static void CFontz_linewrap ( int on );
static void CFontz_autoscroll ( int on );
static void CFontz_hidecursor ();
static void CFontz_reboot ();
1999-12-09 23:15:14 +00:00
// TODO: Get rid of this variable?
lcd_logical_driver * CFontz ;
// TODO: Get the frame buffers working right
/////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly...
//
2000-03-30 20:20:41 +00:00
int
CFontz_init ( lcd_logical_driver * driver , char * args )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char * argv [ 64 ];
int argc ;
struct termios portset ;
int i ;
int tmp ;
int reboot = 0 ;
2000-03-30 20:20:41 +00:00
2001-09-25 14:34:40 +00:00
int contrast = DEFAULT_CONTRAST ;
char device [ 256 ] = DEFAULT_DEVICE ;
int speed = DEFAULT_SPEED ;
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
CFontz = driver ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
//debug("CFontz_init: Args(all): %s\n", args);
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
argc = get_args ( argv , args , 64 );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
/*
for(i=0; i<argc; i++)
{
printf("Arg(%i): %s\n", i, argv[i]);
}
*/
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
for ( i = 0 ; i < argc ; i ++ ) {
//printf("Arg(%i): %s\n", i, argv[i]);
if ( 0 == strcmp ( argv [ i ], "-d" ) || 0 == strcmp ( argv [ i ], "--device" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "CFontz_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
strcpy ( device , argv [ ++ i ]);
} else if ( 0 == strcmp ( argv [ i ], "-c" ) || 0 == strcmp ( argv [ i ], "--contrast" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "CFontz_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
tmp = atoi ( argv [ ++ i ]);
if (( tmp < 0 ) || ( tmp > 255 )) {
fprintf ( stderr , "CFontz_init: %s argument must between 0 and 255. Using default value. \n " , argv [ i ]);
} else
contrast = tmp ;
} else if ( 0 == strcmp ( argv [ i ], "-b" ) || 0 == strcmp ( argv [ i ], "--brightness" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "CFontz_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
tmp = atoi ( argv [ ++ i ]);
if (( tmp < 0 ) || ( tmp > 255 )) {
fprintf ( stderr , "CFontz_init: %s argument must between 0 and 255. Using default value. \n " , argv [ i ]);
} else
backlight_brightness = tmp ;
} else if ( 0 == strcmp ( argv [ i ], "-o" ) || 0 == strcmp ( argv [ i ], "--off-bright" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "CFontz_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
tmp = atoi ( argv [ ++ i ]);
if (( tmp < 0 ) || ( tmp > 255 )) {
fprintf ( stderr , "CFontz_init: %s argument must between 0 and 255. Using default value. \n " , argv [ i ]);
} else
backlight_off_brightness = tmp ;
} else if ( 0 == strcmp ( argv [ i ], "-s" ) || 0 == strcmp ( argv [ i ], "--speed" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "CFontz_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
tmp = atoi ( argv [ ++ i ]);
if ( tmp == 1200 )
speed = B1200 ;
else if ( tmp == 2400 )
speed = B2400 ;
else if ( tmp == 9600 )
speed = B9600 ;
else {
fprintf ( stderr , "CFontz_init: %s argument must be 1200, 2400, or 9600. Using default value. \n " , argv [ i ]);
}
} else if ( 0 == strcmp ( argv [ i ], "-h" ) || 0 == strcmp ( argv [ i ], "--help" )) {
printf ( "LCDproc CrystalFontz LCD driver \n " " \t -d \t --device \t Select the output device to use [/dev/lcd] \n " " \t -t \t --type \t\t Select the LCD type (size) [20x4] \n " " \t -c \t --contrast \t Set the initial contrast [140] \n " " \t -b \t --brightness \t Set the initial brightness [255] \n " " \t -o \t --off-bright \t Set the initial brightness [0] \n " " \t -s \t --speed \t\t Set the communication speed [9600] \n " " \t -r \t --reboot \t Reinitialize the LCD's BIOS \n " " \t -h \t --help \t\t Show this help information \n " );
return - 1 ;
} else if ( 0 == strcmp ( argv [ i ], "-r" ) || 0 == strcmp ( argv [ i ], "--reboot" )) {
printf ( "LCDd: rebooting CrystalFontz LCD... \n " );
reboot = 1 ;
} else {
printf ( "Invalid parameter: %s \n " , argv [ i ]);
}
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
}
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
// Set up io port correctly, and open it...
fd = open ( device , O_RDWR | O_NOCTTY | O_NDELAY );
if ( fd == - 1 ) {
fprintf ( stderr , "CFontz_init: failed (%s) \n " , strerror ( errno ));
return - 1 ;
}
//else fprintf(stderr, "CFontz_init: opened device %s\n", device);
tcgetattr ( fd , & portset );
2001-07-18 22:30:12 +00:00
// We use RAW mode
#ifdef HAVE_CFMAKERAW
// The easy way
cfmakeraw ( & portset );
#else
// The hard way
portset . c_iflag &= ~ ( IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON );
portset . c_oflag &= ~ OPOST ;
portset . c_lflag &= ~ ( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
portset . c_cflag &= ~ ( CSIZE | PARENB | CRTSCTS );
portset . c_cflag |= CS8 | CREAD | CLOCAL ;
1999-12-09 23:15:14 +00:00
#endif
2001-07-18 22:30:12 +00:00
// Set port speed
2000-04-03 22:13:57 +00:00
cfsetospeed ( & portset , speed );
2001-07-18 22:30:12 +00:00
cfsetispeed ( & portset , B0 );
// Do it...
2000-04-03 22:13:57 +00:00
tcsetattr ( fd , TCSANOW , & portset );
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
// Set display-specific stuff..
if ( reboot ) {
CFontz_reboot ();
sleep ( 4 );
reboot = 0 ;
}
sleep ( 1 );
CFontz_hidecursor ();
CFontz_linewrap ( 1 );
CFontz_autoscroll ( 0 );
CFontz_backlight ( backlight_brightness );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( ! driver -> framebuf ) {
2001-09-25 14:34:40 +00:00
syslog ( LOG_ERR , "cfontz_init: no frame buffer!" );
CFontz_close ();
2000-04-03 22:13:57 +00:00
return - 1 ;
}
// Set the functions the driver supports...
1999-12-09 23:15:14 +00:00
2001-09-25 00:13:57 +00:00
driver -> clear = CFontz_clear ;
driver -> string = CFontz_string ;
2000-04-03 22:13:57 +00:00
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_num = CFontz_init_num ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
driver -> init = CFontz_init ;
driver -> close = CFontz_close ;
driver -> flush = CFontz_flush ;
driver -> flush_box = CFontz_flush_box ;
driver -> contrast = CFontz_contrast ;
driver -> backlight = CFontz_backlight ;
driver -> set_char = CFontz_set_char ;
driver -> icon = CFontz_icon ;
driver -> draw_frame = CFontz_draw_frame ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
CFontz_contrast ( contrast );
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
driver -> cellwid = DEFAULT_CELL_WIDTH ;
driver -> cellhgt = DEFAULT_CELL_HEIGHT ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
debug ( "CFontz: foo! \n " );
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
return fd ;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clean-up
//
2000-03-30 20:20:41 +00:00
void
CFontz_close ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
close ( fd );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( CFontz -> framebuf )
free ( CFontz -> framebuf );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
CFontz -> framebuf = NULL ;
1999-12-09 23:15:14 +00:00
}
2000-03-30 20:20:41 +00:00
void
CFontz_flush ()
1999-12-09 23:15:14 +00:00
{
2001-09-25 14:34:40 +00:00
CFontz_draw_frame ( CFontz -> framebuf );
1999-12-09 23:15:14 +00:00
}
2000-03-30 20:20:41 +00:00
void
CFontz_flush_box ( int lft , int top , int rgt , int bot )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int y ;
char out [ LCD_MAX_WIDTH ];
2000-03-30 20:20:41 +00:00
1999-12-09 23:15:14 +00:00
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot);
2000-04-03 22:13:57 +00:00
for ( y = top ; y <= bot ; y ++ ) {
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c%c" , 17 , lft , y );
2000-04-03 22:13:57 +00:00
write ( fd , out , 4 );
2001-09-25 14:34:40 +00:00
write ( fd , CFontz -> framebuf + ( y * CFontz -> wid ) + lft , rgt - lft + 1 );
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
}
2000-03-30 20:20:41 +00:00
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// 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).
//
2000-03-30 20:20:41 +00:00
void
CFontz_chr ( int x , int y , char c )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
y -- ;
x -- ;
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
if ( c < 32 && c >= 0 )
c += 128 ;
2001-09-25 14:34:40 +00:00
CFontz -> framebuf [( y * CFontz -> wid ) + x ] = c ;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good)
//
2000-03-30 20:20:41 +00:00
int
CFontz_contrast ( int contrast )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int realcontrast ;
char out [ 4 ];
static int status = 140 ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( contrast > 0 ) {
status = contrast ;
realcontrast = ((( int ) ( status )) * 100 ) / 255 ;
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c" , 15 , realcontrast );
2000-04-03 22:13:57 +00:00
write ( fd , out , 3 );
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return status ;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets the backlight on or off -- can be done quickly for
// an intermediate brightness...
//
2000-03-30 20:20:41 +00:00
void
CFontz_backlight ( int on )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
if ( on ) {
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c" , 14 , ( unsigned char ) ( on * 100 / 255 ));
2001-09-25 15:02:33 +00:00
//snprintf(out, sizeof(out), "%c%c", 14, 100);
2000-04-03 22:13:57 +00:00
} else {
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c" , 14 , 0 );
2000-04-03 22:13:57 +00:00
}
write ( fd , out , 3 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Toggle the built-in linewrapping feature
//
2000-03-30 20:20:41 +00:00
static void
CFontz_linewrap ( int on )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
if ( on )
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 23 );
2000-04-03 22:13:57 +00:00
else
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 24 );
2000-04-03 22:13:57 +00:00
write ( fd , out , 1 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Toggle the built-in automatic scrolling feature
//
2000-03-30 20:20:41 +00:00
static void
CFontz_autoscroll ( int on )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
if ( on )
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 19 );
2000-04-03 22:13:57 +00:00
else
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 20 );
2000-04-03 22:13:57 +00:00
write ( fd , out , 1 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Get rid of the blinking curson
//
2000-03-30 20:20:41 +00:00
static void
CFontz_hidecursor ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 4 );
2000-04-03 22:13:57 +00:00
write ( fd , out , 1 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Reset the display bios
//
2000-03-30 20:20:41 +00:00
static void
CFontz_reboot ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c" , 26 );
2000-04-03 22:13:57 +00:00
write ( fd , out , 1 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
2001-09-25 14:34:40 +00:00
// Sets up for vertical bars. Call before CFontz->vbar()
1999-12-09 23:15:14 +00:00
//
2000-03-30 20:20:41 +00:00
void
CFontz_init_vbar ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char a [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char b [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char c [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char d [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char e [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char f [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
char g [] = {
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
0 , 1 , 1 , 1 , 1 , 1 ,
};
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( custom != vbar ) {
CFontz_set_char ( 1 , a );
CFontz_set_char ( 2 , b );
CFontz_set_char ( 3 , c );
CFontz_set_char ( 4 , d );
CFontz_set_char ( 5 , e );
CFontz_set_char ( 6 , f );
CFontz_set_char ( 7 , g );
custom = vbar ;
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Inits horizontal bars...
//
2000-03-30 20:20:41 +00:00
void
CFontz_init_hbar ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char a [] = {
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 0 , 0 , 0 , 0 ,
};
char b [] = {
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
1 , 1 , 0 , 0 , 0 , 0 ,
};
char c [] = {
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
1 , 1 , 1 , 0 , 0 , 0 ,
};
char d [] = {
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
1 , 1 , 1 , 1 , 0 , 0 ,
};
char e [] = {
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
1 , 1 , 1 , 1 , 1 , 0 ,
};
char f [] = {
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
};
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( custom != hbar ) {
CFontz_set_char ( 1 , a );
CFontz_set_char ( 2 , b );
CFontz_set_char ( 3 , c );
CFontz_set_char ( 4 , d );
CFontz_set_char ( 5 , e );
CFontz_set_char ( 6 , f );
custom = hbar ;
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar...
//
2000-03-30 20:20:41 +00:00
void
CFontz_vbar ( int x , int len )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char map [ 9 ] = { 32 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 255 };
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
int y ;
2001-09-25 14:34:40 +00:00
for ( y = CFontz -> hgt ; y > 0 && len > 0 ; y -- ) {
if ( len >= CFontz -> cellhgt )
2000-04-03 22:13:57 +00:00
CFontz_chr ( x , y , 255 );
else
CFontz_chr ( x , y , map [ len ]);
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
len -= CFontz -> cellhgt ;
2000-04-03 22:13:57 +00:00
}
2000-03-30 20:20:41 +00:00
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
2000-03-30 20:20:41 +00:00
void
CFontz_hbar ( int x , int y , int len )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char map [ 7 ] = { 32 , 1 , 2 , 3 , 4 , 5 , 6 };
2000-03-30 20:20:41 +00:00
2001-09-25 14:34:40 +00:00
for (; x <= CFontz -> wid && len > 0 ; x ++ ) {
if ( len >= CFontz -> cellwid )
2000-04-03 22:13:57 +00:00
CFontz_chr ( x , y , map [ 6 ]);
else
CFontz_chr ( x , y , map [ len ]);
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
len -= CFontz -> cellwid ;
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets up for big numbers.
//
2000-03-30 20:20:41 +00:00
void
CFontz_init_num ()
1999-12-09 23:15:14 +00:00
{
}
/////////////////////////////////////////////////////////////////
// Writes a big number.
//
2000-03-30 20:20:41 +00:00
void
CFontz_num ( int x , int num )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 5 ];
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c%c" , 28 , x , num );
2000-04-03 22:13:57 +00:00
write ( fd , out , 3 );
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets a custom character from 0-7...
//
// For input, values > 0 mean "on" and values <= 0 are "off".
//
// The input is just an array of characters...
//
2000-03-30 20:20:41 +00:00
void
CFontz_set_char ( int n , char * dat )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ 4 ];
int row , col ;
int letter ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( n < 0 || n > 7 )
return ;
if ( ! dat )
return ;
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
snprintf ( out , sizeof ( out ), "%c%c" , 25 , n );
2000-04-03 22:13:57 +00:00
write ( fd , out , 2 );
1999-12-09 23:15:14 +00:00
2001-09-25 14:34:40 +00:00
for ( row = 0 ; row < CFontz -> cellhgt ; row ++ ) {
2000-04-03 22:13:57 +00:00
letter = 0 ;
2001-09-25 14:34:40 +00:00
for ( col = 0 ; col < CFontz -> cellwid ; col ++ ) {
2000-04-03 22:13:57 +00:00
letter <<= 1 ;
2001-09-25 14:34:40 +00:00
letter |= ( dat [( row * CFontz -> cellwid ) + col ] > 0 );
2000-04-03 22:13:57 +00:00
}
write ( fd , & letter , 1 );
}
1999-12-09 23:15:14 +00:00
}
2000-03-30 20:20:41 +00:00
void
CFontz_icon ( int which , char dest )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char icons [ 3 ][ 6 * 8 ] = {
{
1 , 1 , 1 , 1 , 1 , 1 , // Empty Heart
1 , 0 , 1 , 0 , 1 , 1 ,
0 , 0 , 0 , 0 , 0 , 1 ,
0 , 0 , 0 , 0 , 0 , 1 ,
0 , 0 , 0 , 0 , 0 , 1 ,
1 , 0 , 0 , 0 , 1 , 1 ,
1 , 1 , 0 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
},
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
{
1 , 1 , 1 , 1 , 1 , 1 , // Filled Heart
1 , 0 , 1 , 0 , 1 , 1 ,
0 , 1 , 0 , 1 , 0 , 1 ,
0 , 1 , 1 , 1 , 0 , 1 ,
0 , 1 , 1 , 1 , 0 , 1 ,
1 , 0 , 1 , 0 , 1 , 1 ,
1 , 1 , 0 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 ,
},
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
{
0 , 0 , 0 , 0 , 0 , 0 , // Ellipsis
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
1 , 0 , 1 , 0 , 1 , 0 ,
},
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
};
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
if ( custom == bign )
custom = beat ;
CFontz_set_char ( dest , & icons [ which ][ 0 ]);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////
// Blasts a single frame onscreen, to the lcd...
//
2001-09-25 14:34:40 +00:00
// Input is a character array, sized CFontz->wid*CFontz->hgt
1999-12-09 23:15:14 +00:00
//
2000-03-30 20:20:41 +00:00
void
CFontz_draw_frame ( char * dat )
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char out [ LCD_MAX_WIDTH * LCD_MAX_HEIGHT ];
int i ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( ! dat )
return ;
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
// Custom characters start at 128, not at 0.
/*
2001-09-25 14:34:40 +00:00
for(i=0; i<CFontz->wid*CFontz->hgt; i++)
2000-04-03 22:13:57 +00:00
{
if(dat[i] < 32 && dat[i] >= 0) dat[i] += 128;
}
*/
2000-03-30 20:20:41 +00:00
2001-09-25 14:34:40 +00:00
for ( i = 0 ; i < CFontz -> hgt ; i ++ ) {
snprintf ( out , sizeof ( out ), "%c%c%c" , 17 , 0 , i );
2000-04-03 22:13:57 +00:00
write ( fd , out , 3 );
2001-09-25 14:34:40 +00:00
write ( fd , dat + ( CFontz -> wid * i ), CFontz -> wid );
2000-04-03 22:13:57 +00:00
}
/*
2001-09-25 15:02:33 +00:00
snprintf(out, sizeof(out), "%c", 1);
2000-04-03 22:13:57 +00:00
write(fd, out, 1);
2001-09-25 14:34:40 +00:00
write(fd, dat, CFontz->wid*CFontz->hgt);
2000-04-03 22:13:57 +00:00
*/
1999-12-09 23:15:14 +00:00
}
2001-09-25 00:13:57 +00:00
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
void
CFontz_clear ()
{
2001-09-25 14:34:40 +00:00
memset ( CFontz -> framebuf , ' ' , CFontz -> wid * CFontz -> hgt );
2001-09-25 00:13:57 +00:00
}
/////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4).
//
void
CFontz_string ( int x , int y , char string [])
{
int i ;
x -= 1 ; // Convert 1-based coords to 0-based...
y -= 1 ;
for ( i = 0 ; string [ i ]; i ++ ) {
// Check for buffer overflows...
2001-09-25 14:34:40 +00:00
if (( y * CFontz -> wid ) + x + i > ( CFontz -> wid * CFontz -> hgt ))
2001-09-25 00:13:57 +00:00
break ;
2001-09-25 14:34:40 +00:00
CFontz -> framebuf [( y * CFontz -> wid ) + x + i ] = string [ i ];
2001-09-25 00:13:57 +00:00
}
}