convert CFontz633 driver to use bignum library

This commit is contained in:
marschap
2006-04-26 10:00:20 +00:00
parent 3c8146daed
commit 3827d1ce50
3 changed files with 211 additions and 305 deletions
+204 -299
View File
@@ -61,6 +61,7 @@
#include "CFontz633io.h" #include "CFontz633io.h"
#include "report.h" #include "report.h"
#include "lcd_lib.h" #include "lcd_lib.h"
#include "adv_bignum.h"
#define CF633_KEY_UP 1 #define CF633_KEY_UP 1
#define CF633_KEY_DOWN 2 #define CF633_KEY_DOWN 2
@@ -650,191 +651,6 @@ CFontz633_reboot (Driver *drvthis)
} }
/*
* Sets up for vertical bars.
*/
static void
CFontz633_init_vbar (Driver *drvthis)
{
PrivateData *p = drvthis->private_data;
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,
};
if (p->ccmode != vbar) {
//if (p->ccmode != standard) {
// /* Not supported(yet) */
// report(RPT_WARNING, "%s: init_vbar: cannot combine two modes using user defined characters"
// drvthis->name);
// return;
//}
p->ccmode = vbar;
CFontz633_set_char(drvthis, 1, a);
CFontz633_set_char(drvthis, 2, b);
CFontz633_set_char(drvthis, 3, c);
CFontz633_set_char(drvthis, 4, d);
CFontz633_set_char(drvthis, 5, e);
CFontz633_set_char(drvthis, 6, f);
CFontz633_set_char(drvthis, 7, g);
}
}
/*
* Inits horizontal bars...
*/
static void
CFontz633_init_hbar (Driver *drvthis)
{
PrivateData *p = drvthis->private_data;
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,
};
if (p->ccmode != hbar) {
//if (p->ccmode != standard) {
// /* Not supported(yet) */
// report(RPT_WARNING, "%s: init_hbar: Cannot combine two modes using user defined characters",
// drvthis->name);
// return;
//}
p->ccmode = hbar;
CFontz633_set_char(drvthis, 1, a);
CFontz633_set_char(drvthis, 2, b);
CFontz633_set_char(drvthis, 3, c);
CFontz633_set_char(drvthis, 4, d);
CFontz633_set_char(drvthis, 5, e);
CFontz633_set_char(drvthis, 6, f);
}
}
/* /*
* Draws a vertical bar... * Draws a vertical bar...
*/ */
@@ -849,7 +665,27 @@ CFontz633_vbar (Driver *drvthis, int x, int y, int len, int promille, int option
*/ */
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
CFontz633_init_vbar(drvthis); if (p->ccmode != vbar) {
unsigned char vBar[p->cellheight];
int i;
if (p->ccmode != standard) {
/* Not supported(yet) */
report(RPT_WARNING, "%s: vbar: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
p->ccmode = vbar;
memset(vBar, 0x00, sizeof(vBar));
for (i = 1; i < p->cellheight; i++) {
// add pixel line per pixel line ...
vBar[p->cellheight - i] = 0xFF;
CFontz633_set_char(drvthis, i, vBar);
}
}
lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0); lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
} }
@@ -868,28 +704,70 @@ CFontz633_hbar (Driver *drvthis, int x, int y, int len, int promille, int option
*/ */
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
CFontz633_init_hbar(drvthis); if (p->ccmode != hbar) {
unsigned char hBar[p->cellheight];
int i;
if (p->ccmode != standard) {
/* Not supported(yet) */
report(RPT_WARNING, "%s: hbar: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
p->ccmode = hbar;
memset(hBar, 0x00, sizeof(hBar));
for (i = 1; i <= p->cellwidth; i++) {
// fill pixel columns from left to right.
memset(hBar, 0xFF & ~((1 << (p->cellwidth - i)) - 1), sizeof(hBar)-1);
CFontz633_set_char(drvthis, i, hBar);
}
}
lib_hbar_static(drvthis, x, y, len, promille, options, p->cellwidth, 0); lib_hbar_static(drvthis, x, y, len, promille, options, p->cellwidth, 0);
} }
/* /*
* Writes a big number. * Writes a big number.
* This is not supported on 633 because we only have 2 lines...
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_num(Driver *drvthis, int x, int num) CFontz633_num(Driver *drvthis, int x, int num)
{ {
/*
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
unsigned char out[5]; int do_init = 0;
if ((x <= 0) || (x > p->width)) if ((num < 0) || (num > 10))
return; return;
snprintf(out, sizeof(out), "%c%c%c", 28, x, num); if (p->ccmode != bignum) {
write(p->fd, out, 3); if (p->ccmode != standard) {
/* Not supported (yet) */
report(RPT_WARNING, "%s: num: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
p->ccmode = bignum;
do_init = 1;
}
// Lib_adv_bignum does everything needed to show the bignumbers.
lib_adv_bignum(drvthis, x, num, do_init, NUM_CCs);
}
/*
* Gets number of custom chars (always NUM_CCs)
*/ */
MODULE_EXPORT int
CFontz633_get_free_chars (Driver *drvthis)
{
//PrivateData *p = drvthis->private_data;
return NUM_CCs;
} }
@@ -901,11 +779,12 @@ CFontz633_num (Driver *drvthis, int x, int num)
* The input is just an array of characters... * The input is just an array of characters...
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_set_char (Driver *drvthis, int n, char *dat) CFontz633_set_char (Driver *drvthis, int n, unsigned char *dat)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
unsigned char out[9]; unsigned char out[9];
int row, col; unsigned char mask = (1 << p->cellwidth) - 1;
int row;
if ((n < 0) || (n >= NUM_CCs)) if ((n < 0) || (n >= NUM_CCs))
return; return;
@@ -915,13 +794,7 @@ CFontz633_set_char (Driver *drvthis, int n, char *dat)
out[0] = n; /* Custom char to define. xxx */ out[0] = n; /* Custom char to define. xxx */
for (row = 0; row < p->cellheight; row++) { for (row = 0; row < p->cellheight; row++) {
int letter = 0; out[row+1] = dat[row] & mask;
for (col = 0; col < p->cellwidth; col++) {
letter <<= 1;
letter |= (dat[(row * p->cellwidth) + col] > 0);
}
out[row+1] = letter;
} }
send_bytes_message(p->fd, CF633_Set_LCD_Special_Character_Data, 9, out); send_bytes_message(p->fd, CF633_Set_LCD_Special_Character_Data, 9, out);
} }
@@ -934,96 +807,128 @@ MODULE_EXPORT int
CFontz633_icon (Driver *drvthis, int x, int y, int icon) CFontz633_icon (Driver *drvthis, int x, int y, int icon)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char icons[8][6 * 8] = {
/* Empty Heart */ static unsigned char heart_open[] =
{ { b__XXXXX,
1, 1, 1, 1, 1, 1, b__X_X_X,
1, 1, 0, 1, 0, 1, b_______,
1, 0, 0, 0, 0, 0, b_______,
1, 0, 0, 0, 0, 0, b_______,
1, 0, 0, 0, 0, 0, b__X___X,
1, 1, 0, 0, 0, 1, b__XX_XX,
1, 1, 1, 0, 1, 1, b__XXXXX };
1, 1, 1, 1, 1, 1, static unsigned char heart_filled[] =
}, { b__XXXXX,
/* Filled Heart */ b__X_X_X,
{ b___X_X_,
1, 1, 1, 1, 1, 1, b___XXX_,
1, 1, 0, 1, 0, 1, b___XXX_,
1, 0, 1, 0, 1, 0, b__X_X_X,
1, 0, 1, 1, 1, 0, b__XX_XX,
1, 0, 1, 1, 1, 0, b__XXXXX };
1, 1, 0, 1, 0, 1, static unsigned char arrow_up[] =
1, 1, 1, 0, 1, 1, { b____X__,
1, 1, 1, 1, 1, 1, b___XXX_,
}, b__X_X_X,
/* arrow_up */ b____X__,
{ b____X__,
0, 0, 0, 1, 0, 0, b____X__,
0, 0, 1, 1, 1, 0, b____X__,
0, 1, 0, 1, 0, 1, b_______ };
0, 0, 0, 1, 0, 0, static unsigned char arrow_down[] =
0, 0, 0, 1, 0, 0, { b____X__,
0, 0, 0, 1, 0, 0, b____X__,
0, 0, 0, 1, 0, 0, b____X__,
0, 0, 0, 0, 0, 0, b____X__,
}, b__X_X_X,
/* arrow_down */ b___XXX_,
{ b____X__,
0, 0, 0, 1, 0, 0, b_______ };
0, 0, 0, 1, 0, 0, /*
0, 0, 0, 1, 0, 0, static unsigned char arrow_left[] =
0, 0, 0, 1, 0, 0, { b_______,
0, 1, 0, 1, 0, 1, b____X__,
0, 0, 1, 1, 1, 0, b___X___,
0, 0, 0, 1, 0, 0, b__XXXXX,
0, 0, 0, 0, 0, 0, b___X___,
}, b____X__,
/* checkbox_off */ b_______,
{ b_______ };
0, 0, 0, 0, 0, 0, static unsigned char arrow_right[] =
0, 0, 0, 0, 0, 0, { b_______,
0, 1, 1, 1, 1, 1, b____X__,
0, 1, 0, 0, 0, 1, b_____X_,
0, 1, 0, 0, 0, 1, b__XXXXX,
0, 1, 0, 0, 0, 1, b_____X_,
0, 1, 1, 1, 1, 1, b____X__,
0, 0, 0, 0, 0, 0, b_______,
}, b_______ };
/* checkbox_on */ */
{ static unsigned char checkbox_off[] =
0, 0, 0, 1, 0, 0, { b_______,
0, 0, 0, 1, 0, 0, b_______,
0, 1, 1, 1, 0, 1, b__XXXXX,
0, 1, 0, 1, 1, 0, b__X___X,
0, 1, 0, 1, 0, 1, b__X___X,
0, 1, 0, 0, 0, 1, b__X___X,
0, 1, 1, 1, 1, 1, b__XXXXX,
0, 0, 0, 0, 0, 0, b_______ };
}, static unsigned char checkbox_on[] =
/* checkbox_gray */ { b____X__,
{ b____X__,
0, 0, 0, 0, 0, 0, b__XXX_X,
0, 0, 0, 0, 0, 0, b__X_XX_,
0, 1, 1, 1, 1, 1, b__X_X_X,
0, 1, 0, 1, 0, 1, b__X___X,
0, 1, 1, 0, 1, 1, b__XXXXX,
0, 1, 0, 1, 0, 1, b_______ };
0, 1, 1, 1, 1, 1, static unsigned char checkbox_gray[] =
0, 0, 0, 0, 0, 0, { b_______,
}, b_______,
/* Ellipsis */ b__XXXXX,
{ b__X_X_X,
0, 0, 0, 0, 0, 0, b__XX_XX,
0, 0, 0, 0, 0, 0, b__X_X_X,
0, 0, 0, 0, 0, 0, b__XXXXX,
0, 0, 0, 0, 0, 0, b_______ };
0, 0, 0, 0, 0, 0, /*
0, 0, 0, 0, 0, 0, static unsigned char selector_left[] =
0, 0, 0, 0, 0, 0, { b___X___,
1, 0, 1, 0, 1, 0, b___XX__,
}, b___XXX_,
}; b___XXXX,
b___XXX_,
b___XX__,
b___X___,
b_______ };
static unsigned char selector_right[] =
{ b_____X_,
b____XX_,
b___XXX_,
b__XXXX_,
b___XXX_,
b____XX_,
b_____X_,
b_______ };
static unsigned char ellipsis[] =
{ b_______,
b_______,
b_______,
b_______,
b_______,
b_______,
b__X_X_X,
b_______ };
static unsigned char block_filled[] =
{ b__XXXXX,
b__XXXXX,
b__XXXXX,
b__XXXXX,
b__XXXXX,
b__XXXXX,
b__XXXXX,
b__XXXXX };
*/
/* Yes we know, this is a VERY BAD implementation :-) */ /* Yes we know, this is a VERY BAD implementation :-) */
switch (icon) { switch (icon) {
@@ -1032,22 +937,22 @@ CFontz633_icon (Driver *drvthis, int x, int y, int icon)
break; break;
case ICON_HEART_FILLED: case ICON_HEART_FILLED:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 0, icons[1]); CFontz633_set_char(drvthis, 0, heart_filled);
CFontz633_chr(drvthis, x, y, 0); CFontz633_chr(drvthis, x, y, 0);
break; break;
case ICON_HEART_OPEN: case ICON_HEART_OPEN:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 0, icons[0]); CFontz633_set_char(drvthis, 0, heart_open);
CFontz633_chr(drvthis, x, y, 0); CFontz633_chr(drvthis, x, y, 0);
break; break;
case ICON_ARROW_UP: case ICON_ARROW_UP:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 1, icons[2]); CFontz633_set_char(drvthis, 1, arrow_up);
CFontz633_chr(drvthis, x, y, 1); CFontz633_chr(drvthis, x, y, 1);
break; break;
case ICON_ARROW_DOWN: case ICON_ARROW_DOWN:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 2, icons[3]); CFontz633_set_char(drvthis, 2, arrow_down);
CFontz633_chr(drvthis, x, y, 2); CFontz633_chr(drvthis, x, y, 2);
break; break;
case ICON_ARROW_LEFT: case ICON_ARROW_LEFT:
@@ -1058,17 +963,17 @@ CFontz633_icon (Driver *drvthis, int x, int y, int icon)
break; break;
case ICON_CHECKBOX_OFF: case ICON_CHECKBOX_OFF:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 3, icons[4]); CFontz633_set_char(drvthis, 3, checkbox_off);
CFontz633_chr(drvthis, x, y, 3); CFontz633_chr(drvthis, x, y, 3);
break; break;
case ICON_CHECKBOX_ON: case ICON_CHECKBOX_ON:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 4, icons[5]); CFontz633_set_char(drvthis, 4, checkbox_on);
CFontz633_chr(drvthis, x, y, 4); CFontz633_chr(drvthis, x, y, 4);
break; break;
case ICON_CHECKBOX_GRAY: case ICON_CHECKBOX_GRAY:
p->ccmode = custom; p->ccmode = custom;
CFontz633_set_char(drvthis, 5, icons[6]); CFontz633_set_char(drvthis, 5, checkbox_gray);
CFontz633_chr(drvthis, x, y, 5); CFontz633_chr(drvthis, x, y, 5);
break; break;
default: default:
+2 -1
View File
@@ -36,7 +36,8 @@ MODULE_EXPORT void CFontz633_hbar (Driver *drvthis, int x, int y, int len, int p
MODULE_EXPORT void CFontz633_num (Driver *drvthis, int x, int num); MODULE_EXPORT void CFontz633_num (Driver *drvthis, int x, int num);
MODULE_EXPORT int CFontz633_icon(Driver *drvthis, int x, int y, int icon); MODULE_EXPORT int CFontz633_icon(Driver *drvthis, int x, int y, int icon);
MODULE_EXPORT void CFontz633_set_char (Driver *drvthis, int n, char *dat); MODULE_EXPORT int CFontz633_iget_free_chars (Driver *drvthis);
MODULE_EXPORT void CFontz633_set_char (Driver *drvthis, int n, unsigned char *dat);
MODULE_EXPORT int CFontz633_get_contrast (Driver *drvthis); MODULE_EXPORT int CFontz633_get_contrast (Driver *drvthis);
MODULE_EXPORT void CFontz633_set_contrast (Driver *drvthis, int promille); MODULE_EXPORT void CFontz633_set_contrast (Driver *drvthis, int promille);
+2 -2
View File
@@ -26,7 +26,7 @@ IOWarrior_CFLAGS = @libusb_cflags@ $(AM_CFLAGS)
hd44780_CFLAGS = @libusb_cflags@ $(AM_CFLAGS) hd44780_CFLAGS = @libusb_cflags@ $(AM_CFLAGS)
CFontz_LDADD = libLCD.a CFontz_LDADD = libLCD.a
CFontz633_LDADD = libLCD.a CFontz633_LDADD = libLCD.a libbignum.a
CFontzPacket_LDADD = libLCD.a libbignum.a CFontzPacket_LDADD = libLCD.a libbignum.a
curses_LDADD = @LIBCURSES@ curses_LDADD = @LIBCURSES@
CwLnx_LDADD = libLCD.a CwLnx_LDADD = libLCD.a
@@ -55,7 +55,7 @@ libbignum_a_SOURCES = adv_bignum.h adv_bignum.c
bayrad_SOURCES = lcd.h lcd_lib.h bayrad.h bayrad.c report.h bayrad_SOURCES = lcd.h lcd_lib.h bayrad.h bayrad.c report.h
CFontz_SOURCES = lcd.h lcd_lib.h CFontz.c CFontz.h CFontz-charmap.h report.h CFontz_SOURCES = lcd.h lcd_lib.h CFontz.c CFontz.h CFontz-charmap.h report.h
CFontz633_SOURCES = lcd.h lcd_lib.h CFontz633.c CFontz633.h CFontz-charmap.h CFontz633io.c CFontz633io.h report.h CFontz633_SOURCES = lcd.h lcd_lib.h CFontz633.c CFontz633.h CFontz-charmap.h CFontz633io.c CFontz633io.h report.h adv_bignum.h
CFontzPacket_SOURCES = lcd.h lcd_lib.h CFontzPacket.c CFontzPacket.h CFontz-charmap.h CFontz633io.c CFontz633io.h report.h adv_bignum.h CFontzPacket_SOURCES = lcd.h lcd_lib.h CFontzPacket.c CFontzPacket.h CFontz-charmap.h CFontz633io.c CFontz633io.h report.h adv_bignum.h
curses_SOURCES = lcd.h curses_drv.h curses_drv.c report.h curses_SOURCES = lcd.h curses_drv.h curses_drv.c report.h
CwLnx_SOURCES = lcd.h lcd_lib.h CwLnx.c CwLnx.h report.h CwLnx_SOURCES = lcd.h lcd_lib.h CwLnx.c CwLnx.h report.h