1st round of adapting it to new driver model
This commit is contained in:
+60
-69
@@ -20,6 +20,7 @@
|
|||||||
/*backlight support modified by Rene Wagner (c) 2001*/
|
/*backlight support modified by Rene Wagner (c) 2001*/
|
||||||
/*block patch by Eddie Sheldrake (c) 2001 inserted by Rene Wagner*/
|
/*block patch by Eddie Sheldrake (c) 2001 inserted by Rene Wagner*/
|
||||||
/*big num patch by Luis Llorente (c) 2002*/
|
/*big num patch by Luis Llorente (c) 2002*/
|
||||||
|
/*adaptions to other CFontz* dirvers Peter Marschall (c) 2005*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -103,43 +104,44 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
|
|
||||||
/* Which serial device should be used */
|
/* Which serial device should be used */
|
||||||
strncpy(device, drvthis->config_get_string (drvthis->name, "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, drvthis->config_get_string (drvthis->name, "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;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
}
|
|
||||||
|
|
||||||
/* Which contrast */
|
/* Which contrast */
|
||||||
if (0<=drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) && drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) <= 1000) {
|
tmp = drvthis->config_get_int (drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
|
||||||
contrast = drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST);
|
if ((tmp < 0) || (tmp > 1000)) {
|
||||||
} else {
|
|
||||||
report (RPT_WARNING, "CFontz_init: Contrast must be between 0 and 1000. Using default value.\n");
|
report (RPT_WARNING, "CFontz_init: Contrast must be between 0 and 1000. Using default value.\n");
|
||||||
|
tmp = DEFAULT_CONTRAST;
|
||||||
}
|
}
|
||||||
|
contrast = tmp;
|
||||||
|
|
||||||
/*Which backlight brightness*/
|
/*Which backlight brightness*/
|
||||||
if (0<=drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) && drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) <= 255) {
|
tmp = drvthis->config_get_int (drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
|
||||||
brightness = drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS);
|
if ((tmp < 0) || (tmp > 255)) {
|
||||||
} else {
|
|
||||||
report (RPT_WARNING, "CFontz_init: Brightness must be between 0 and 255. Using default value.\n");
|
report (RPT_WARNING, "CFontz_init: Brightness must be between 0 and 255. Using default value.\n");
|
||||||
|
tmp = DEFAULT_BRIGHTNESS;
|
||||||
}
|
}
|
||||||
|
brightness = tmp;
|
||||||
|
|
||||||
/* Which backlight-off "brightness" */
|
/* Which backlight-off "brightness" */
|
||||||
if (0<=drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) && drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) <= 255) {
|
tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
|
||||||
offbrightness = drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS);
|
if ((tmp < 0) || (tmp > 255)) {
|
||||||
} else {
|
|
||||||
report (RPT_WARNING, "CFontz_init: OffBrightness must be between 0 and 255. Using default value.\n");
|
report (RPT_WARNING, "CFontz_init: OffBrightness must be between 0 and 255. Using default value.\n");
|
||||||
|
tmp = DEFAULT_OFFBRIGHTNESS;
|
||||||
}
|
}
|
||||||
|
offbrightness = tmp;
|
||||||
|
|
||||||
/* Which speed */
|
/* Which speed */
|
||||||
tmp = drvthis->config_get_int (drvthis->name, "Speed", 0, DEFAULT_SPEED);
|
tmp = drvthis->config_get_int (drvthis->name, "Speed", 0, DEFAULT_SPEED);
|
||||||
@@ -147,32 +149,24 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
else if (tmp == 2400) speed = B2400;
|
else if (tmp == 2400) speed = B2400;
|
||||||
else if (tmp == 9600) speed = B9600;
|
else if (tmp == 9600) speed = B9600;
|
||||||
else if (tmp == 19200) speed = B19200;
|
else if (tmp == 19200) speed = B19200;
|
||||||
else { report (RPT_WARNING, "CFontz_init: Speed must be 1200, 2400, 9600 or 19200. Using default value.\n", speed);
|
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? */
|
/* New firmware version? */
|
||||||
if(drvthis->config_get_bool( drvthis->name , "NewFirmware" , 0 , 0)) {
|
newfirmware = drvthis->config_get_bool(drvthis->name, "NewFirmware", 0, 0);
|
||||||
newfirmware = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reboot display? */
|
/* Reboot display? */
|
||||||
if (drvthis->config_get_bool( drvthis->name , "Reboot" , 0 , 0)) {
|
reboot = drvthis->config_get_bool(drvthis->name, "Reboot", 0, 0);
|
||||||
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n");
|
|
||||||
reboot = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Am I USB or not? */
|
/* Am I USB or not? */
|
||||||
if(drvthis->config_get_bool( drvthis->name , "USB" , 0 , 0)) {
|
usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0);
|
||||||
usb = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up io port correctly, and open it...
|
/* Set up io port correctly, and open it... */
|
||||||
debug( RPT_DEBUG, "CFontz: Opening serial device: %s", device);
|
debug( RPT_DEBUG, "CFontz: Opening device: %s", device);
|
||||||
if ( usb ) {
|
fd = open (device, (usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
|
||||||
fd = open (device, O_RDWR | O_NOCTTY);
|
|
||||||
} else {
|
|
||||||
fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY);
|
|
||||||
}
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
report (RPT_ERR, "CFontz_init: failed (%s)\n", strerror (errno));
|
report (RPT_ERR, "CFontz_init: failed (%s)\n", strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -180,9 +174,9 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
|
|
||||||
tcgetattr (fd, &portset);
|
tcgetattr (fd, &portset);
|
||||||
|
|
||||||
// We use RAW mode
|
/* We use RAW mode */
|
||||||
if (usb) {
|
if (usb) {
|
||||||
// The USB way
|
/* The USB 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;
|
||||||
@@ -193,10 +187,10 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
portset.c_cc[VTIME] = 3;
|
portset.c_cc[VTIME] = 3;
|
||||||
} else {
|
} else {
|
||||||
#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;
|
||||||
@@ -206,22 +200,25 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set port speed
|
/* Set port speed */
|
||||||
cfsetospeed (&portset, speed);
|
cfsetospeed (&portset, speed);
|
||||||
cfsetispeed (&portset, B0);
|
cfsetispeed (&portset, B0);
|
||||||
|
|
||||||
// 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... */
|
||||||
framebuf = (unsigned char *) malloc (width * height);
|
framebuf = (unsigned char *) malloc (width * height);
|
||||||
|
if (framebuf == NULL) {
|
||||||
|
report(RPT_ERR, "CFontz_init: unable to create framebuffer.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
memset (framebuf, ' ', width * height);
|
memset (framebuf, ' ', width * height);
|
||||||
|
|
||||||
// Set display-specific stuff..
|
// Set display-specific stuff..
|
||||||
if (reboot) {
|
if (reboot) {
|
||||||
|
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n");
|
||||||
CFontz_reboot ();
|
CFontz_reboot ();
|
||||||
sleep (4);
|
|
||||||
reboot = 0;
|
|
||||||
}
|
}
|
||||||
sleep (1);
|
sleep (1);
|
||||||
CFontz_hidecursor ();
|
CFontz_hidecursor ();
|
||||||
@@ -231,7 +228,6 @@ CFontz_init (Driver * drvthis, char *args)
|
|||||||
|
|
||||||
CFontz_set_contrast (drvthis, contrast);
|
CFontz_set_contrast (drvthis, contrast);
|
||||||
|
|
||||||
|
|
||||||
report (RPT_DEBUG, "CFontz_init: done\n");
|
report (RPT_DEBUG, "CFontz_init: done\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -245,7 +241,8 @@ CFontz_close (Driver * drvthis)
|
|||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
if(framebuf) free (framebuf);
|
if (framebuf)
|
||||||
|
free (framebuf);
|
||||||
framebuf = NULL;
|
framebuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +274,9 @@ CFontz_flush (Driver * drvthis)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Custom characters start at 128, not at 0.
|
// Custom characters start at 128, not at 0.
|
||||||
for(i=0; i<width*height; i++)
|
for (i = 0; i < width * height; i++) {
|
||||||
{
|
if (framebuf[i] < 32 && framebuf[i] >= 0)
|
||||||
if(framebuf[i] < 32 && framebuf[i] >= 0) framebuf[i] += 128;
|
framebuf[i] += 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < height; i++) {
|
for (i = 0; i < height; i++) {
|
||||||
@@ -371,10 +368,8 @@ static void
|
|||||||
CFontz_linewrap (int on)
|
CFontz_linewrap (int on)
|
||||||
{
|
{
|
||||||
char out[4];
|
char out[4];
|
||||||
if (on)
|
|
||||||
snprintf (out, sizeof(out), "%c", 23);
|
snprintf (out, sizeof(out), "%c", (on) ? 23 : 24);
|
||||||
else
|
|
||||||
snprintf (out, sizeof(out), "%c", 24);
|
|
||||||
write (fd, out, 1);
|
write (fd, out, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,15 +380,12 @@ static void
|
|||||||
CFontz_autoscroll (int on)
|
CFontz_autoscroll (int on)
|
||||||
{
|
{
|
||||||
char out[4];
|
char out[4];
|
||||||
if (on)
|
snprintf (out, sizeof(out), "%c", (on) ? 19 : 20);
|
||||||
snprintf (out, sizeof(out), "%c", 19);
|
|
||||||
else
|
|
||||||
snprintf (out, sizeof(out), "%c", 20);
|
|
||||||
write (fd, out, 1);
|
write (fd, out, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// Get rid of the blinking curson
|
// Get rid of the blinking cursor
|
||||||
//
|
//
|
||||||
static void
|
static void
|
||||||
CFontz_hidecursor ()
|
CFontz_hidecursor ()
|
||||||
@@ -412,6 +404,7 @@ CFontz_reboot ()
|
|||||||
char out[4];
|
char out[4];
|
||||||
snprintf (out, sizeof(out), "%c", 26);
|
snprintf (out, sizeof(out), "%c", 26);
|
||||||
write (fd, out, 1);
|
write (fd, out, 1);
|
||||||
|
sleep(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
@@ -596,7 +589,6 @@ CFontz_vbar (Driver * drvthis, int x, int y, int len, int promille, int options)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CFontz_init_vbar(drvthis);
|
CFontz_init_vbar(drvthis);
|
||||||
|
|
||||||
lib_vbar_static(drvthis, x, y, len, promille, options, cellheight, 0);
|
lib_vbar_static(drvthis, x, y, len, promille, options, cellheight, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +606,6 @@ CFontz_hbar (Driver * drvthis, int x, int y, int len, int promille, int options)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CFontz_init_hbar(drvthis);
|
CFontz_init_hbar(drvthis);
|
||||||
|
|
||||||
lib_hbar_static(drvthis, x, y, len, promille, options, cellwidth, 0);
|
lib_hbar_static(drvthis, x, y, len, promille, options, cellwidth, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,7 +624,7 @@ CFontz_set_char (Driver * drvthis, int n, char *dat)
|
|||||||
int row, col;
|
int row, col;
|
||||||
int letter;
|
int letter;
|
||||||
|
|
||||||
if (n < 0 || n > 7)
|
if ((n < 0) || (n > 7))
|
||||||
return;
|
return;
|
||||||
if (!dat)
|
if (!dat)
|
||||||
return;
|
return;
|
||||||
@@ -658,8 +649,9 @@ MODULE_EXPORT int
|
|||||||
CFontz_icon (Driver * drvthis, int x, int y, int icon)
|
CFontz_icon (Driver * drvthis, int x, int y, int icon)
|
||||||
{
|
{
|
||||||
char icons[3][6 * 8] = {
|
char icons[3][6 * 8] = {
|
||||||
|
// Empty Heart
|
||||||
{
|
{
|
||||||
1, 1, 1, 1, 1, 1, // Empty Heart
|
1, 1, 1, 1, 1, 1,
|
||||||
1, 0, 1, 0, 1, 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,
|
0, 0, 0, 0, 0, 1,
|
||||||
@@ -668,9 +660,9 @@ CFontz_icon (Driver * drvthis, int x, int y, int icon)
|
|||||||
1, 1, 0, 1, 1, 1,
|
1, 1, 0, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1,
|
||||||
},
|
},
|
||||||
|
// Filled Heart
|
||||||
{
|
{
|
||||||
1, 1, 1, 1, 1, 1, // Filled Heart
|
1, 1, 1, 1, 1, 1,
|
||||||
1, 0, 1, 0, 1, 1,
|
1, 0, 1, 0, 1, 1,
|
||||||
0, 1, 0, 1, 0, 1,
|
0, 1, 0, 1, 0, 1,
|
||||||
0, 1, 1, 1, 0, 1,
|
0, 1, 1, 1, 0, 1,
|
||||||
@@ -679,9 +671,9 @@ CFontz_icon (Driver * drvthis, int x, int y, int icon)
|
|||||||
1, 1, 0, 1, 1, 1,
|
1, 1, 0, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1,
|
||||||
},
|
},
|
||||||
|
// Ellipsis
|
||||||
{
|
{
|
||||||
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,
|
0, 0, 0, 0, 0, 0,
|
||||||
@@ -721,7 +713,6 @@ MODULE_EXPORT void
|
|||||||
CFontz_clear (Driver * drvthis)
|
CFontz_clear (Driver * drvthis)
|
||||||
{
|
{
|
||||||
memset (framebuf, ' ', width * height);
|
memset (framebuf, ' ', width * height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
@@ -733,21 +724,21 @@ CFontz_string (Driver * drvthis, int x, int y, char string[])
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
x -= 1; // Convert 1-based coords to 0-based...
|
// Convert 1-based coords to 0-based...
|
||||||
y -= 1;
|
x--;
|
||||||
|
y--;
|
||||||
for (i = 0; string[i]; i++) {
|
|
||||||
|
|
||||||
|
for (i = 0; string[i] != '\0'; i++) {
|
||||||
|
|
||||||
// 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 && string[i] == -1) {
|
if (newfirmware && string[i] == -1) {
|
||||||
string[i] = 214;
|
string[i] = 214;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check for buffer overflows...
|
// Check for buffer overflows...
|
||||||
if ((y * width) + x + i > (width * height))
|
if ((y * width) + x + i > (width * height))
|
||||||
break;
|
break;
|
||||||
framebuf[(y * width) + x + i] = string[i];
|
framebuf[(y * width) + x + i] = string[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user