harmonize coding style and messages

This commit is contained in:
marschap
2006-04-08 16:44:24 +00:00
parent cbf92bba92
commit 23fbf7717c
+58 -78
View File
@@ -272,7 +272,7 @@ serialVFD_init (Driver *drvthis)
/* Which device should be used */ /* Which device should be used */
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device)); strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
p->device[sizeof(p->device)-1] = '\0'; p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO,"%s: Device (in config) is: '%s'", __FUNCTION__, p->device); report(RPT_INFO, "%s: using Device %s", drvthis->name, p->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));
@@ -280,8 +280,8 @@ serialVFD_init (Driver *drvthis)
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, "%s: Cannot parse size: %s. Using default %s.\n", report(RPT_WARNING, "%s: cannot parse Size: %s; using default %s",
__FUNCTION__, size, DEFAULT_SIZE); drvthis->name, size, DEFAULT_SIZE);
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h); sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
} }
p->width = w; p->width = w;
@@ -290,8 +290,8 @@ serialVFD_init (Driver *drvthis)
/* Which backlight brightness */ /* Which backlight brightness */
tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: Brightness must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_BRIGHTNESS); drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
brightness = tmp; brightness = tmp;
@@ -303,8 +303,8 @@ serialVFD_init (Driver *drvthis)
/* Which displaytype */ /* Which displaytype */
tmp = drvthis->config_get_int(drvthis->name, "Type", 0, DEFAULT_DISPLAYTYPE); tmp = drvthis->config_get_int(drvthis->name, "Type", 0, DEFAULT_DISPLAYTYPE);
if ((tmp < 0) || (tmp > 3)) { if ((tmp < 0) || (tmp > 3)) {
report (RPT_WARNING, "%s: Displaytype must be between 0 and 3. Using default %d.\n", report(RPT_WARNING, "%s: Type must be between 0 and 3; using default %d",
__FUNCTION__, DEFAULT_DISPLAYTYPE); drvthis->name, DEFAULT_DISPLAYTYPE);
tmp = DEFAULT_DISPLAYTYPE; tmp = DEFAULT_DISPLAYTYPE;
} }
p->display_type = tmp; p->display_type = tmp;
@@ -313,8 +313,8 @@ serialVFD_init (Driver *drvthis)
/* 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);
if ((tmp != 1200) && (tmp != 2400) && (tmp != 9600) && (tmp != 19200) && (tmp != 115200)) { if ((tmp != 1200) && (tmp != 2400) && (tmp != 9600) && (tmp != 19200) && (tmp != 115200)) {
report (RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200. Using default %d.\n", report(RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200; using default %d",
__FUNCTION__, DEFAULT_SPEED); drvthis->name, DEFAULT_SPEED);
tmp = DEFAULT_SPEED; tmp = DEFAULT_SPEED;
} }
if (tmp == 1200) p->speed = B1200; if (tmp == 1200) p->speed = B1200;
@@ -328,9 +328,8 @@ serialVFD_init (Driver *drvthis)
/* Set up io port correctly, and open it...*/ /* Set up io port correctly, and open it...*/
debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device); debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device);
p->fd = open(p->device, O_RDWR | O_NOCTTY | O_NDELAY); p->fd = open(p->device, O_RDWR | O_NOCTTY | O_NDELAY);
if (p->fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "%s: open() of %s failed (%s)\n", __FUNCTION__, p->device, strerror (errno)); report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, p->device, strerror(errno));
return -1; return -1;
} }
@@ -360,7 +359,7 @@ serialVFD_init (Driver *drvthis)
/* make sure the frame buffer is there... */ /* make sure the frame buffer is there... */
p->framebuf = (unsigned char *) malloc(p->width * p->height); p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (p->framebuf == NULL) { if (p->framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1; return -1;
} }
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
@@ -368,14 +367,13 @@ serialVFD_init (Driver *drvthis)
/* make sure the framebuffer backing store is there... */ /* make sure the framebuffer backing store is there... */
p->backingstore = (unsigned char *) malloc(p->width * p->height); p->backingstore = (unsigned char *) malloc(p->width * p->height);
if (p->backingstore == NULL) { if (p->backingstore == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer backing store.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer backing store", drvthis->name);
return -1; return -1;
} }
memset(p->backingstore, ' ', p->width * p->height); memset(p->backingstore, ' ', p->width * p->height);
//setup displayspecific data //setup displayspecific data
switch (p->display_type) switch (p->display_type) {
{
//nec_fipc //nec_fipc
case 0: //nec_fipc case 0: //nec_fipc
p->need_refresh = 0; // 1 if displays need refresh after changing custonchars p->need_refresh = 0; // 1 if displays need refresh after changing custonchars
@@ -397,8 +395,8 @@ serialVFD_init (Driver *drvthis)
{2 ,0x14, 0x11}, // init {2 ,0x14, 0x11}, // init
{1 ,0x1A}, // set user char {1 ,0x1A}, // set user char
{1 ,0x09}}; // tab {1 ,0x09}}; // tab
for (tmp=0;tmp < (10) ;tmp++) for (tmp = 0; tmp < 10; tmp++)
for (w=0;w < (4) ;w++) for (w = 0; w < 4 ;w++)
p->hw_cmd[tmp][w] = hw_cmd_0[tmp][w]; p->hw_cmd[tmp][w] = hw_cmd_0[tmp][w];
// Translates ISO 8859-1 to display charset. // Translates ISO 8859-1 to display charset.
@@ -468,8 +466,8 @@ serialVFD_init (Driver *drvthis)
{2 ,0x14, 0x11}, // init {2 ,0x14, 0x11}, // init
{1 ,0x1A}, // set user char {1 ,0x1A}, // set user char
{1 ,0x09}}; // tab {1 ,0x09}}; // tab
for (tmp=0;tmp < (10) ;tmp++) for (tmp = 0; tmp < 10; tmp++)
for (w=0;w < (4) ;w++) for (w = 0; w < 4; w++)
p->hw_cmd[tmp][w] = hw_cmd_1[tmp][w]; p->hw_cmd[tmp][w] = hw_cmd_1[tmp][w];
const unsigned char charmap_1[] = { const unsigned char charmap_1[] = {
@@ -539,8 +537,8 @@ serialVFD_init (Driver *drvthis)
{2 ,0x14, 0x11}, // init {2 ,0x14, 0x11}, // init
{2 ,0x1B, 0x43}, // set user char {2 ,0x1B, 0x43}, // set user char
{1 ,0x09}}; // tab {1 ,0x09}}; // tab
for (tmp=0;tmp < (10) ;tmp++) for (tmp = 0; tmp < 10; tmp++)
for (w=0;w < (4) ;w++) for (w = 0; w < 4; w++)
p->hw_cmd[tmp][w] = hw_cmd_2[tmp][w]; p->hw_cmd[tmp][w] = hw_cmd_2[tmp][w];
// no charmap needed // no charmap needed
@@ -616,7 +614,6 @@ serialVFD_init (Driver *drvthis)
for (tmp = 0; tmp < 128; tmp++) for (tmp = 0; tmp < 128; tmp++)
p->charmap[tmp] = charmap_3[tmp]; p->charmap[tmp] = charmap_3[tmp];
//{bytes to send, icon bit mapped to bit 0, icon bit mapped to bit 1, ...} //{bytes to send, icon bit mapped to bit 0, icon bit mapped to bit 1, ...}
const int usr_chr_dot_assignment_3[57]={5, 8, 7, 6, 5, 4, 3, 2, 1, const int usr_chr_dot_assignment_3[57]={5, 8, 7, 6, 5, 4, 3, 2, 1,
16,15,14,13,12,11,10, 9, 16,15,14,13,12,11,10, 9,
@@ -641,8 +638,8 @@ serialVFD_init (Driver *drvthis)
write(p->fd, &p->hw_cmd[init_cmds][1],p->hw_cmd[init_cmds][0]); write(p->fd, &p->hw_cmd[init_cmds][1],p->hw_cmd[init_cmds][0]);
serialVFD_set_brightness(drvthis, 1, brightness); serialVFD_set_brightness(drvthis, 1, brightness);
report(RPT_DEBUG, "%s: init() done", drvthis->name);
report (RPT_DEBUG, "%s: done\n", __FUNCTION__);
return 0; return 0;
} }
@@ -656,13 +653,10 @@ serialVFD_set_brightness (Driver *drvthis, int state, int brightness)
{ // set p->brightness { // set p->brightness
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
if (brightness > 0) {
if (brightness > 0)
{
if (brightness > 255) if (brightness > 255)
brightness = 255; brightness = 255;
if (p->brightness != brightness) if (p->brightness != brightness) {
{
p->brightness = brightness; p->brightness = brightness;
serialVFD_put_brightness(drvthis); serialVFD_put_brightness(drvthis);
} }
@@ -674,8 +668,8 @@ serialVFD_put_brightness (Driver *drvthis)
{ // set hardware brightness { // set hardware brightness
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int realbrightness = (int) (p->brightness / 64); int realbrightness = (int) (p->brightness / 64);
//(4 steps 0-64, 65-128, 129-192, 193-1000)
//(4 steps 0-64, 65-128, 129-192, 193-1000)
write(p->fd, &p->hw_cmd[realbrightness][1],\ write(p->fd, &p->hw_cmd[realbrightness][1],\
p->hw_cmd[realbrightness][0]); p->hw_cmd[realbrightness][0]);
} }
@@ -719,24 +713,21 @@ MODULE_EXPORT void
serialVFD_set_char (Driver *drvthis, int n, char *dat) serialVFD_set_char (Driver *drvthis, int n, char *dat)
{ //set char in p->custom_char { //set char in p->custom_char
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int letter=0;
unsigned int byte, bit; unsigned int byte, bit;
if (n < 0 || n > p->customchars-1) if ((n < 0) || (n > p->customchars-1))
return; return;
if (!dat) if (!dat)
return; return;
for (byte = 0; byte < p->usr_chr_dot_assignment[0]; byte++) {
int letter = 0;
for (byte = 0;byte < p->usr_chr_dot_assignment[0]; byte++) for (bit = 0; bit < 8; bit++) {
{
for (bit = 0;bit < 8; bit++)
{
if ((int) p->usr_chr_dot_assignment[bit+8*byte+1] != 0) if ((int) p->usr_chr_dot_assignment[bit+8*byte+1] != 0)
letter |= (dat[(int)p->usr_chr_dot_assignment[bit+8*byte+1]-1] << bit); letter |= (dat[(int)p->usr_chr_dot_assignment[bit+8*byte+1]-1] << bit);
} }
p->custom_char[n][byte] = letter; p->custom_char[n][byte] = letter;
letter = 0;
} }
if (p->display_type != 1) //not KD Rev 2.1 if (p->display_type != 1) //not KD Rev 2.1
@@ -750,7 +741,8 @@ void
serialVFD_put_char (Driver *drvthis, int n) serialVFD_put_char (Driver *drvthis, int n)
{ // put char in display { // put char in display
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
write (p->fd, &p->hw_cmd[set_user_char][1],\
write(p->fd, &p->hw_cmd[set_user_char][1],
p->hw_cmd[set_user_char][0]);// substitute and select Character to overwrite p->hw_cmd[set_user_char][0]);// substitute and select Character to overwrite
write(p->fd, &p->usr_chr_mapping[n], 1); write(p->fd, &p->usr_chr_mapping[n], 1);
write(p->fd, &p->custom_char[n][0], p->usr_chr_dot_assignment[0]);// overwrite selected Character write(p->fd, &p->custom_char[n][0], p->usr_chr_dot_assignment[0]);// overwrite selected Character
@@ -771,17 +763,15 @@ serialVFD_draw_frame (Driver *drvthis, char *dat)
if (!dat) if (!dat)
return; return;
if (p->refresh_timer > 500) // Do a full refresh every 500 refreshs. if (p->refresh_timer > 500) { // Do a full refresh every 500 refreshs.
// With this it is possible to switch display on and off while lcdproc is running // With this it is possible to switch display on and off while lcdproc is running
{
write(p->fd, &p->hw_cmd[init_cmds][1],p->hw_cmd[init_cmds][0]); write(p->fd, &p->hw_cmd[init_cmds][1],p->hw_cmd[init_cmds][0]);
serialVFD_put_brightness(drvthis); // restore brightness serialVFD_put_brightness(drvthis); // restore brightness
for (i = 0; i < (p->height * p->width); i++) for (i = 0; i < (p->height * p->width); i++)
p->backingstore[i]=0; // clear Backing-store p->backingstore[i] = '\0'; // clear Backing-store
if (p->display_type != 1) //not KD Rev 2.1 if (p->display_type != 1) {//not KD Rev 2.1
{
for (i = 0; i < p->customchars; i++) // refresh all customcharacters for (i = 0; i < p->customchars; i++) // refresh all customcharacters
serialVFD_put_char(drvthis, i); serialVFD_put_char(drvthis, i);
/* { /* {
@@ -795,52 +785,40 @@ serialVFD_draw_frame (Driver *drvthis, char *dat)
} }
p->refresh_timer++; p->refresh_timer++;
for (i = 0; i < (p->height * p->width); i++) {
for (i = 0; i < (p->height * p->width); i++)
{
/* Backing-store implementation. If it's already /* Backing-store implementation. If it's already
* on the screen, don't put it there again * on the screen, don't put it there again
*/ */
if (dat[i] != p->backingstore[i] || (dat[i] <=30 && p->custom_char_changed[(int)dat[i]])) if (dat[i] != p->backingstore[i] || (dat[i] <=30 && p->custom_char_changed[(int)dat[i]]))
{ {
if (last_chr < i-1) // if not last char written cursor has to be moved. if (last_chr < i-1) { // if not last char written cursor has to be moved.
{ if (last_chr < i-2-p->hw_cmd[mv_cursor][0]) {
if(last_chr < i-2-p->hw_cmd[mv_cursor][0]) write(p->fd, &p->hw_cmd[mv_cursor][1],
{
write (p->fd, &p->hw_cmd[mv_cursor][1],\
p->hw_cmd[mv_cursor][0]); p->hw_cmd[mv_cursor][0]);
write(p->fd, &i, 1); write(p->fd, &i, 1);
} }
else else {
{ for (j = last_chr; j < (i-1); j++) {
for (j = last_chr; j < (i-1); j++)
{
write(p->fd, &p->hw_cmd[hor_tab][1], p->hw_cmd[hor_tab][0]); write(p->fd, &p->hw_cmd[hor_tab][1], p->hw_cmd[hor_tab][0]);
} }
} }
} }
if(dat[i] >= 0 && dat[i] <= 30) // custom character if (dat[i] >= 0 && dat[i] <= 30) {// custom character
{ if (p->display_type == 1) {// KD Rev 2.1 only
if (p->display_type == 1) // KD Rev 2.1 only
{
write(p->fd, "\x1A\xDB", 2); // substitute and select character to overwrite(237) write(p->fd, "\x1A\xDB", 2); // substitute and select character to overwrite(237)
write(p->fd, &p->custom_char[(int)dat[i]][0], 7);// overwrite selected character write(p->fd, &p->custom_char[(int)dat[i]][0], 7);// overwrite selected character
write(p->fd, "\xDB", 1); // write character write(p->fd, "\xDB", 1); // write character
} }
else // all other displays else { // all other displays
{
write(p->fd, &p->usr_chr_mapping[(int)dat[i]], 1); write(p->fd, &p->usr_chr_mapping[(int)dat[i]], 1);
} }
} }
else if(dat[i] < 0 && (p->ISO_8859_1 != 0)) // ISO_8859_1 translation for 129 ... 255 else if (dat[i] < 0 && (p->ISO_8859_1 != 0)) { // ISO_8859_1 translation for 129 ... 255
{
write(p->fd, &p->charmap[dat[i] + 128], 1); write(p->fd, &p->charmap[dat[i] + 128], 1);
} }
else else {
{
write(p->fd, &dat[i], 1); write(p->fd, &dat[i], 1);
} }
@@ -848,27 +826,24 @@ serialVFD_draw_frame (Driver *drvthis, char *dat)
} }
} }
if (last_chr != -10) // update backingstore if something changed if (last_chr != -10) { // update backingstore if something changed
{
memcpy(p->backingstore, dat, p->height * p->width);
int i; int i;
memcpy(p->backingstore, dat, p->height * p->width);
for (i = 0; i < p->customchars; i++) for (i = 0; i < p->customchars; i++)
p->custom_char_changed[i]=0; p->custom_char_changed[i] = '\0';
} }
} }
MODULE_EXPORT void MODULE_EXPORT void
serialVFD_num( Driver * drvthis, int x, int num ) serialVFD_num( Driver * drvthis, int x, int num )
{ {
int do_init=0;
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int do_init = 0;
if (p->ccmode != CCMODE_BIGNUM) { // Are the customcharacters set up correctly? If not:
if (p->ccmode != CCMODE_BIGNUM) // Are the customcharacters set up correctly? If not:
{
do_init = 1; // Lib_adv_bignum has to set the customcharacters. do_init = 1; // Lib_adv_bignum has to set the customcharacters.
p->ccmode = CCMODE_BIGNUM; // Switch customcharactermode to bignum. p->ccmode = CCMODE_BIGNUM; // Switch customcharactermode to bignum.
} }
@@ -1079,10 +1054,11 @@ MODULE_EXPORT void
serialVFD_string (Driver *drvthis, int x, int y, char string[]) serialVFD_string (Driver *drvthis, int x, int y, char string[])
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int i;
x--; x--;
y--; y--;
int i; for (i = 0; string[i] != '\0'; i++) {
for (i = 0; string[i]; i++) {
// Check for buffer overflows... // Check for buffer overflows...
if ((y * p->width) + x + i > (p->width * p->height)) if ((y * p->width) + x + i > (p->width * p->height))
break; break;
@@ -1097,6 +1073,7 @@ MODULE_EXPORT void
serialVFD_close (Driver *drvthis) serialVFD_close (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
if (p != NULL) { if (p != NULL) {
close(p->fd); close(p->fd);
@@ -1141,6 +1118,7 @@ MODULE_EXPORT int
serialVFD_get_free_chars (Driver *drvthis) serialVFD_get_free_chars (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
return p->customchars; return p->customchars;
} }
/* /*
@@ -1171,6 +1149,7 @@ MODULE_EXPORT void
serialVFD_flush (Driver *drvthis) serialVFD_flush (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
serialVFD_draw_frame(drvthis, p->framebuf); serialVFD_draw_frame(drvthis, p->framebuf);
} }
@@ -1184,9 +1163,9 @@ MODULE_EXPORT void
serialVFD_chr (Driver *drvthis, int x, int y, char c) serialVFD_chr (Driver *drvthis, int x, int y, char c)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
y--; y--;
x--; x--;
p->framebuf[(y * p->width) + x ] = c; p->framebuf[(y * p->width) + x ] = c;
} }
@@ -1209,6 +1188,7 @@ MODULE_EXPORT char *
serialVFD_get_info (Driver *drvthis) serialVFD_get_info (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
strcpy(p->info, "Driver for many serialVFDs from NEC(all FIPC based), Noritake, Futaba and the \"KD Rev2.1\"VFD."); strcpy(p->info, "Driver for many serialVFDs from NEC(all FIPC based), Noritake, Futaba and the \"KD Rev2.1\"VFD.");
return p->info; return p->info;
} }