Files
lcdproc/server/drivers/CFontz.c
T

806 lines
19 KiB
C
Raw Normal View History

/* This is the LCDproc driver for CrystalFontz devices (http://crystalfontz.com)
Copyright (C) 2001 ????
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */
/*configfile support added by Rene Wagner (c) 2001*/
/*backlight support modified by Rene Wagner (c) 2001*/
/*block patch by Eddie Sheldrake (c) 2001 inserted by Rene Wagner*/
/*big num patch by Luis Llorente (c) 2002*/
/*adaptions to other CFontz* dirvers Peter Marschall (c) 2005*/
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>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
1999-12-09 23:15:14 +00:00
#include "lcd.h"
#include "CFontz.h"
2001-12-30 00:15:25 +00:00
#include "report.h"
2002-02-08 00:14:10 +00:00
#include "lcd_lib.h"
2001-12-30 00:15:25 +00:00
2001-09-25 14:34:40 +00:00
2005-06-12 20:32:27 +00:00
/* Constants for userdefchar_mode */
#define NUM_CCs 8 /* max. number of custom characters */
1999-12-09 23:15:14 +00:00
typedef enum {
2005-06-12 20:32:27 +00:00
standard, /* only char 0 is used for heartbeat */
vbar, /* vertical bars */
hbar, /* horizontal bars */
custom, /* custom settings */
bignum, /* big numbers */
bigchar /* big characters */
} CGmode;
typedef struct cgram_cache {
char cache[DEFAULT_CELL_HEIGHT];
int clean;
} CGram;
typedef struct driver_private_data {
char device[200];
int fd;
int model;
int newfirmware;
/* dimensions */
int width, height;
int cellwidth, cellheight;
/* framebuffer and buffer for old LCD contents */
unsigned char *framebuf;
unsigned char *backingstore;
/* defineable characters */
CGram cc[NUM_CCs];
CGmode ccmode;
int contrast;
int brightness;
int offbrightness;
} PrivateData;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
// 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_";
2002-02-21 22:50:12 +00:00
2001-12-30 00:15:25 +00:00
// Internal functions
2005-06-12 20:32:27 +00:00
static void CFontz_linewrap (Driver *drvthis, int on);
static void CFontz_autoscroll (Driver *drvthis, int on);
static void CFontz_hidecursor (Driver *drvthis);
static void CFontz_reboot (Driver *drvthis);
static void CFontz_init_vbar (Driver *drvthis);
static void CFontz_init_hbar (Driver *drvthis);
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
1999-12-09 23:15:14 +00:00
// TODO: Get the frame buffers working right
/////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly...
//
2002-02-21 22:50:12 +00:00
MODULE_EXPORT int
CFontz_init (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
struct termios portset;
int tmp, w, h;
2000-04-03 22:13:57 +00:00
int reboot = 0;
2003-02-12 03:08:27 +00:00
int usb = 0;
2001-09-25 14:34:40 +00:00
int speed = DEFAULT_SPEED;
2001-12-26 16:25:41 +00:00
char size[200] = DEFAULT_SIZE;
2005-06-12 20:32:27 +00:00
PrivateData *p;
/* Allocate and store private data */
p = (PrivateData *) calloc(1, sizeof(PrivateData));
if (p == NULL)
return -1;
if (drvthis->store_private_ptr(drvthis, p))
return -1;
/* Initialize the PrivateData structure */
p->cellwidth = DEFAULT_CELL_WIDTH;
p->cellheight = DEFAULT_CELL_HEIGHT;
p->ccmode = standard;
debug(RPT_INFO, "CFontz: init(%p)", drvthis );
/* Read config file */
2005-06-12 20:32:27 +00:00
/* Which device should be used */
strncpy(p->device, drvthis->config_get_string (drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO,"CFontz: Using device: %s", p->device);
/* Which size */
strncpy(size, drvthis->config_get_string (drvthis->name, "Size", 0, DEFAULT_SIZE), sizeof(size));
size[sizeof(size)-1] = '\0';
if ((sscanf(size, "%dx%d", &w, &h) != 2)
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) {
report (RPT_WARNING, "CFontz_init: Cannot read size: %s. Using default value.\n", size);
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
}
2005-06-12 20:32:27 +00:00
p->width = w;
p->height = h;
/* Which contrast */
tmp = drvthis->config_get_int (drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
if ((tmp < 0) || (tmp > 1000)) {
2005-01-29 18:49:29 +00:00
report (RPT_WARNING, "CFontz_init: Contrast must be between 0 and 1000. Using default value.\n");
tmp = DEFAULT_CONTRAST;
}
2005-06-12 20:32:27 +00:00
p->contrast = tmp;
2005-06-12 20:32:27 +00:00
/* Which backlight brightness */
tmp = drvthis->config_get_int (drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
if ((tmp < 0) || (tmp > 255)) {
2005-01-29 18:49:29 +00:00
report (RPT_WARNING, "CFontz_init: Brightness must be between 0 and 255. Using default value.\n");
tmp = DEFAULT_BRIGHTNESS;
}
2005-06-12 20:32:27 +00:00
p->brightness = tmp;
/* Which backlight-off "brightness" */
tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
if ((tmp < 0) || (tmp > 255)) {
2005-01-29 18:49:29 +00:00
report (RPT_WARNING, "CFontz_init: OffBrightness must be between 0 and 255. Using default value.\n");
tmp = DEFAULT_OFFBRIGHTNESS;
}
2005-06-12 20:32:27 +00:00
p->offbrightness = tmp;
/* Which speed */
tmp = drvthis->config_get_int (drvthis->name, "Speed", 0, DEFAULT_SPEED);
if (tmp == 1200) speed = B1200;
else if (tmp == 2400) speed = B2400;
else if (tmp == 9600) speed = B9600;
2003-02-12 03:08:27 +00:00
else if (tmp == 19200) speed = B19200;
else if (tmp == 115200) speed = B115200;
else {
report (RPT_WARNING, "CFontz_init: Speed must be 1200, 2400, 9600, 19200 or 115200. Using default value.\n");
speed = DEFAULT_SPEED;
}
/* New firmware version? */
2005-06-12 20:32:27 +00:00
p->newfirmware = drvthis->config_get_bool(drvthis->name, "NewFirmware", 0, 0);
/* Reboot display? */
reboot = drvthis->config_get_bool(drvthis->name, "Reboot", 0, 0);
/* Am I USB or not? */
usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0);
2003-02-12 03:08:27 +00:00
/* Set up io port correctly, and open it... */
2005-06-12 20:32:27 +00:00
debug( RPT_DEBUG, "CFontz: Opening device: %s", p->device);
p->fd = open(p->device, (usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
if (p->fd == -1) {
report (RPT_ERR, "CFontz_init: failed (%s)\n", strerror (errno));
2000-04-03 22:13:57 +00:00
return -1;
}
2005-06-12 20:32:27 +00:00
tcgetattr (p->fd, &portset);
/* We use RAW mode */
if (usb) {
/* The USB 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 ;
portset.c_cc[VMIN] = 1;
portset.c_cc[VTIME] = 3;
} else {
#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
}
/* Set port speed */
2000-04-03 22:13:57 +00:00
cfsetospeed (&portset, speed);
cfsetispeed (&portset, B0);
2005-06-12 20:32:27 +00:00
/* Do it... */
tcsetattr (p->fd, TCSANOW, &portset);
2005-06-12 20:32:27 +00:00
/* make sure the frame buffer is there... */
p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (p->framebuf == NULL) {
report(RPT_ERR, "CFontz_init: unable to create p->framebuffer.\n");
return -1;
}
2005-06-12 20:32:27 +00:00
memset(p->framebuf, ' ', p->width * p->height);
2001-11-23 15:15:05 +00:00
2000-04-03 22:13:57 +00:00
// Set display-specific stuff..
if (reboot) {
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n");
2005-06-12 20:32:27 +00:00
CFontz_reboot (drvthis);
2000-04-03 22:13:57 +00:00
}
sleep (1);
2005-06-12 20:32:27 +00:00
CFontz_hidecursor (drvthis);
CFontz_linewrap (drvthis, 1);
CFontz_autoscroll (drvthis, 0);
2001-12-30 00:15:25 +00:00
//CFontz_backlight (drvthis, backlight_brightness); // render.c variables should not be used in drivers !
1999-12-09 23:15:14 +00:00
2005-06-12 20:32:27 +00:00
CFontz_set_contrast (drvthis, p->contrast);
1999-12-09 23:15:14 +00:00
report (RPT_DEBUG, "CFontz_init: done\n");
2001-12-30 00:15:25 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clean-up
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_close (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
1999-12-09 23:15:14 +00:00
2005-06-12 20:32:27 +00:00
if (p != NULL) {
close(p->fd);
if (p->framebuf)
free(p->framebuf);
p->framebuf = NULL;
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
2005-06-12 20:32:27 +00:00
// Returns the display p->width
2001-12-30 00:15:25 +00:00
//
MODULE_EXPORT int
CFontz_width (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
return p->width;
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
2005-06-12 20:32:27 +00:00
// Returns the display p->height
2001-12-30 00:15:25 +00:00
//
MODULE_EXPORT int
CFontz_height (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
return p->height;
2001-12-30 00:15:25 +00:00
}
2001-12-30 00:15:25 +00:00
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_flush (Driver *drvthis)
2001-12-30 00:15:25 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2001-12-30 00:15:25 +00:00
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
// Custom characters start at 128, not at 0.
2005-06-12 20:32:27 +00:00
for (i = 0; i < p->width * p->height; i++) {
if (p->framebuf[i] < 32)
p->framebuf[i] += 128;
}
2005-06-12 20:32:27 +00:00
for (i = 0; i < p->height; i++) {
2001-12-30 00:15:25 +00:00
snprintf (out, sizeof(out), "%c%c%c", 17, 0, i);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 3);
write (p->fd, p->framebuf + (p->width * i), p->width);
2000-04-03 22:13:57 +00:00
}
2001-12-30 00:15:25 +00:00
/*
snprintf(out, sizeof(out), "%c", 1);
2005-06-12 20:32:27 +00:00
write(p->fd, out, 1);
write(p->fd, p->framebuf, p->width*p->height);
2001-12-30 00:15:25 +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).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_chr (Driver *drvthis, int x, int y, unsigned char c)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
y--;
x--;
2005-06-12 20:32:27 +00:00
if (c < 32)
2000-04-03 22:13:57 +00:00
c += 128;
// For V2 of the firmware to get the block to display right
2005-06-12 20:32:27 +00:00
if (p->newfirmware && c == 255) {
c = 214;
}
2005-06-12 20:32:27 +00:00
p->framebuf[(y * p->width) + x] = c;
2001-12-30 00:15:25 +00:00
}
/////////////////////////////////////////////////////////////////
2005-06-12 20:32:27 +00:00
// Returns current p->contrast
// This is only the locally stored p->contrast, the p->contrast value
2001-12-30 00:15:25 +00:00
// cannot be retrieved from the LCD.
// Value 0 to 1000.
//
MODULE_EXPORT int
2005-06-12 20:32:27 +00:00
CFontz_get_contrast (Driver *drvthis)
2001-12-30 00:15:25 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
return p->contrast;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
2005-06-12 20:32:27 +00:00
// Changes screen p->contrast (0-1000; 400 seems good)
2001-12-30 00:15:25 +00:00
// Value 0 to 100.
1999-12-09 23:15:14 +00:00
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_set_contrast (Driver *drvthis, int promille)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char out[4];
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
// Check it
if (promille < 0 || promille > 1000)
2001-12-30 00:15:25 +00:00
return;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
// Store it
2005-06-12 20:32:27 +00:00
p->contrast = promille;
2001-12-30 00:15:25 +00:00
// And do it
snprintf (out, sizeof(out), "%c%c", 15, (unsigned char) (promille / 10) ); // converted to be 0 to 100
2005-06-12 20:32:27 +00:00
write (p->fd, out, 3);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets the backlight on or off -- can be done quickly for
2005-06-12 20:32:27 +00:00
// an intermediate p->brightness...
1999-12-09 23:15:14 +00:00
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_backlight (Driver *drvthis, int on)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char out[4];
if (on) {
2005-06-12 20:32:27 +00:00
snprintf (out, sizeof(out), "%c%c", 14, p->brightness);
2000-04-03 22:13:57 +00:00
} else {
2005-06-12 20:32:27 +00:00
snprintf (out, sizeof(out), "%c%c", 14, p->offbrightness);
2000-04-03 22:13:57 +00:00
}
2005-06-12 20:32:27 +00:00
write (p->fd, out, 3);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Toggle the built-in linewrapping feature
//
static void
2005-06-12 20:32:27 +00:00
CFontz_linewrap (Driver *drvthis, int on)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char out[4];
snprintf (out, sizeof(out), "%c", (on) ? 23 : 24);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 1);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Toggle the built-in automatic scrolling feature
//
static void
2005-06-12 20:32:27 +00:00
CFontz_autoscroll (Driver *drvthis, int on)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char out[4];
snprintf (out, sizeof(out), "%c", (on) ? 19 : 20);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 1);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Get rid of the blinking cursor
1999-12-09 23:15:14 +00:00
//
static void
2005-06-12 20:32:27 +00:00
CFontz_hidecursor (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
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);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 1);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Reset the display bios
//
static void
2005-06-12 20:32:27 +00:00
CFontz_reboot (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
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);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 1);
sleep(4);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
2002-02-08 00:14:10 +00:00
// Sets up for vertical bars.
1999-12-09 23:15:14 +00:00
//
2002-02-08 00:14:10 +00:00
static void
2005-06-12 20:32:27 +00:00
CFontz_init_vbar (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
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
2005-06-12 20:32:27 +00:00
if (p->ccmode != vbar) {
2001-12-30 00:15:25 +00:00
CFontz_set_char (drvthis, 1, a);
CFontz_set_char (drvthis, 2, b);
CFontz_set_char (drvthis, 3, c);
CFontz_set_char (drvthis, 4, d);
CFontz_set_char (drvthis, 5, e);
CFontz_set_char (drvthis, 6, f);
CFontz_set_char (drvthis, 7, g);
2005-06-12 20:32:27 +00:00
p->ccmode = vbar;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Inits horizontal bars...
//
2002-02-08 00:14:10 +00:00
static void
2005-06-12 20:32:27 +00:00
CFontz_init_hbar (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
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
2005-06-12 20:32:27 +00:00
if (p->ccmode != hbar) {
2001-12-30 00:15:25 +00:00
CFontz_set_char (drvthis, 1, a);
CFontz_set_char (drvthis, 2, b);
CFontz_set_char (drvthis, 3, c);
CFontz_set_char (drvthis, 4, d);
CFontz_set_char (drvthis, 5, e);
CFontz_set_char (drvthis, 6, f);
2005-06-12 20:32:27 +00:00
p->ccmode = hbar;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar...
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_vbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2002-02-08 00:14:10 +00:00
/* x and y are the start position of the bar.
* The bar by default grows in the 'up' direction
* (other direction not yet implemented).
* len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled.
*/
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
1999-12-09 23:15:14 +00:00
2002-02-08 00:14:10 +00:00
CFontz_init_vbar(drvthis);
2005-06-12 20:32:27 +00:00
lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_hbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2002-02-08 00:14:10 +00:00
/* x and y are the start position of the bar.
* The bar by default grows in the 'right' direction
* (other direction not yet implemented).
* len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled.
*/
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2002-02-08 00:14:10 +00:00
CFontz_init_hbar(drvthis);
2005-06-12 20:32:27 +00:00
lib_hbar_static(drvthis, x, y, len, promille, options, p->cellwidth, 0);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
2005-06-12 20:32:27 +00:00
// Sets a custom character from 0 - (NUM_CCs-1)...
1999-12-09 23:15:14 +00:00
//
// For input, values > 0 mean "on" and values <= 0 are "off".
//
// The input is just an array of characters...
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_set_char (Driver *drvthis, int n, char *dat)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char out[4];
int row, col;
int letter;
1999-12-09 23:15:14 +00:00
2005-06-12 20:32:27 +00:00
if ((n < 0) || (n >= NUM_CCs))
2000-04-03 22:13:57 +00:00
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);
2005-06-12 20:32:27 +00:00
write (p->fd, out, 2);
1999-12-09 23:15:14 +00:00
2005-06-12 20:32:27 +00:00
for (row = 0; row < p->cellheight; row++) {
2000-04-03 22:13:57 +00:00
letter = 0;
2005-06-12 20:32:27 +00:00
for (col = 0; col < p->cellwidth; col++) {
2000-04-03 22:13:57 +00:00
letter <<= 1;
2005-06-12 20:32:27 +00:00
letter |= (dat[(row * p->cellheight) + col] > 0);
2000-04-03 22:13:57 +00:00
}
2005-06-12 20:32:27 +00:00
write (p->fd, &letter, 1);
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
2002-02-08 00:14:10 +00:00
/////////////////////////////////////////////////////////////////
// Places an icon on screen
//
2002-05-23 18:03:36 +00:00
MODULE_EXPORT int
2005-06-12 20:32:27 +00:00
CFontz_icon (Driver *drvthis, int x, int y, int icon)
1999-12-09 23:15:14 +00:00
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
char icons[3][6 * 8] = {
// Empty Heart
2000-04-03 22:13:57 +00:00
{
1, 1, 1, 1, 1, 1,
2005-06-12 20:32:27 +00:00
1, 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,
2000-04-03 22:13:57 +00:00
1, 1, 1, 1, 1, 1,
},
// Filled Heart
2000-04-03 22:13:57 +00:00
{
1, 1, 1, 1, 1, 1,
2005-06-12 20:32:27 +00:00
1, 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,
2000-04-03 22:13:57 +00:00
1, 1, 1, 1, 1, 1,
},
// Ellipsis
2000-04-03 22:13:57 +00:00
{
0, 0, 0, 0, 0, 0,
2000-04-03 22:13:57 +00:00
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-04-03 22:13:57 +00:00
};
2005-06-12 20:32:27 +00:00
if (p->ccmode == bignum)
p->ccmode = standard;
2002-02-08 00:14:10 +00:00
switch( icon ) {
case ICON_BLOCK_FILLED:
CFontz_chr(drvthis, x, y, 255 );
2002-02-08 00:14:10 +00:00
break;
case ICON_HEART_FILLED:
CFontz_set_char(drvthis, 0, icons[1] );
CFontz_chr(drvthis, x, y, 0 );
2002-02-08 00:14:10 +00:00
break;
case ICON_HEART_OPEN:
CFontz_set_char(drvthis, 0, icons[0] );
CFontz_chr(drvthis, x, y, 0 );
2002-02-08 00:14:10 +00:00
break;
default:
2002-05-23 18:03:36 +00:00
return -1;
2002-02-08 00:14:10 +00:00
}
2002-05-23 18:03:36 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_clear (Driver *drvthis)
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
memset (p->framebuf, ' ', p->width * p->height);
}
/////////////////////////////////////////////////////////////////
// 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).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2005-06-12 20:32:27 +00:00
CFontz_string (Driver *drvthis, int x, int y, unsigned char string[])
{
2005-06-12 20:32:27 +00:00
PrivateData *p = drvthis->private_data;
int i;
// Convert 1-based coords to 0-based...
x--;
y--;
2001-12-26 16:25:41 +00:00
for (i = 0; string[i] != '\0'; i++) {
2001-12-30 00:15:25 +00:00
2001-12-26 16:25:41 +00:00
// For V2 of the firmware to get the block to display right
2005-06-12 20:32:27 +00:00
if (p->newfirmware && string[i] == 255) {
string[i] = 214;
2001-12-26 16:25:41 +00:00
}
// Check for buffer overflows...
2005-06-12 20:32:27 +00:00
if ((y * p->width) + x + i > (p->width * p->height))
break;
2005-06-12 20:32:27 +00:00
p->framebuf[(y * p->width) + x + i] = string[i];
}
}