better checks for some necessary arrays,

alternative implementation for CF633_flush (hidden behind #ifdef)
more space between functions
This commit is contained in:
marschap
2005-05-16 17:12:36 +00:00
parent 6de90bf3a5
commit 634b86d63e
+66 -30
View File
@@ -77,8 +77,8 @@ typedef enum {
} custom_type;
static int fd;
static char *framebuf = NULL;
static char *old = NULL;
static unsigned char *framebuf = NULL;
static unsigned char *old = NULL;
static int width = 0;
static int height = 0;
static int cellwidth = DEFAULT_CELL_WIDTH;
@@ -129,12 +129,12 @@ CFontz633_init (Driver * drvthis, char *args)
/* Read config file */
/* Which serial device should be used */
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,"CFontz633: Using device: %s", device);
/* Which 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
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) {
@@ -146,21 +146,24 @@ CFontz633_init (Driver * drvthis, char *args)
}
/* 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) {
if (0<=drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) &&
drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) <= 1000) {
contrast = drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST);
} else {
report (RPT_WARNING, "CFontz633_init: Contrast must be between 0 and 1000. Using default value.\n");
}
/* 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) <= 100) {
if (0<=drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) &&
drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) <= 100) {
brightness = drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS);
} else {
report (RPT_WARNING, "CFontz633_init: Brightness must be between 0 and 100. Using default value.\n");
}
/* 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) <= 100) {
if (0<=drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) &&
drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) <= 100) {
offbrightness = drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS);
} else {
report (RPT_WARNING, "CFontz633_init: OffBrightness must be between 0 and 100. Using default value.\n");
@@ -198,11 +201,7 @@ CFontz633_init (Driver * drvthis, char *args)
/* Set up io port correctly, and open it... */
debug( RPT_DEBUG, "CFontz633: Opening serial device: %s", device);
if ( usb ) {
fd = open (device, O_RDWR | O_NOCTTY);
} else {
fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY);
}
fd = open (device, (usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
if (fd == -1) {
report (RPT_ERR, "CFontz633_init: failed (%s)\n", strerror (errno));
return -1;
@@ -245,8 +244,20 @@ CFontz633_init (Driver * drvthis, char *args)
/* Make sure the frame buffer is there... */
framebuf = (unsigned char *) malloc (width * height);
if (framebuf == NULL) {
report(RPT_ERR, "CFontz633_init: unable to create framebuffer.\n");
return -1;
}
memset (framebuf, ' ', width * height);
/* make sure the framebuffer backing store is there... */
old = (unsigned char *) malloc (width * height);
if (old == NULL) {
report(RPT_ERR, "CFontz633_init: unable to create framebuffer backing store.\n");
return -1;
}
memset (old, ' ', width * height);
/* Set display-specific stuff.. */
if (reboot) {
CFontz633_reboot ();
@@ -257,12 +268,14 @@ CFontz633_init (Driver * drvthis, char *args)
CFontz633_set_contrast (drvthis, contrast);
CFontz633_no_live_report ();
CFontz633_hardware_clear (drvthis);
report (RPT_DEBUG, "CFontz633_init: done\n");
return 0;
}
/*
* Clean-up
*/
@@ -278,6 +291,7 @@ CFontz633_close (Driver * drvthis)
old = NULL;
}
/*
* Returns the display width
*/
@@ -291,6 +305,7 @@ CFontz633_width (Driver *drvthis)
return width;
}
/*
* Returns the display height
*/
@@ -300,6 +315,7 @@ CFontz633_height (Driver *drvthis)
return height;
}
/*
* Flushes all output to the lcd...
*/
@@ -307,19 +323,28 @@ MODULE_EXPORT void
CFontz633_flush (Driver * drvthis)
{
int i;
char *xp, *xq;
#if defined(CF635_FLUSH)
int len = width * height;
char out[4];
for (i = 0; i < len; i++) {
if (framebuf[i] != old[i]) {
out[1] = i / width; // line
out[0] = i - (out[1] * width); // column
out[2] = framebuf[i]; // character
out[2] = '\0';
send_bytes_message(fd, 3, CF633_Send_Data_to_LCD, out);
old[i] = framebuf[i];
}
}
#else
/*
* We don't use delta update yet.
* It is possible but not easy, we can only update a line, full or begining.
*/
if (old==NULL) {
old = (unsigned char *) malloc (width * height);
memset (old, ' ', width * height);
CFontz633_hardware_clear (drvthis);
}
xp = framebuf;
xq = old;
unsigned char *xp = framebuf;
unsigned char *xq = old;
for (i = 0; i < width; i++) {
if (*xp != *xq) {
@@ -341,9 +366,10 @@ memcpy(&old[width], &framebuf[width], width);
}
xp++; xq++;
}
#endif /* defined(CF635_FLUSH) */
}
/*
* Return one char from the KeyRing
*/
@@ -394,6 +420,7 @@ CFontz633_chr (Driver * drvthis, int x, int y, char c)
framebuf[(y * width) + x] = c;
}
/*
* Returns current contrast
* This is only the locally stored contrast, the contrast value
@@ -406,6 +433,7 @@ CFontz633_get_contrast (Driver * drvthis)
return contrast;
}
/*
* Changes screen contrast (valid hardware value: 0-50)
* Value 0 to 1000.
@@ -427,6 +455,7 @@ CFontz633_set_contrast (Driver * drvthis, int promille)
send_onebyte_message(fd, CF633_Set_LCD_Contrast, hardware_contrast);
}
/*
* Sets the backlight on or off.
* The hardware support any value between 0 and 100.
@@ -435,15 +464,12 @@ CFontz633_set_contrast (Driver * drvthis, int promille)
MODULE_EXPORT void
CFontz633_backlight (Driver * drvthis, int on)
{
if (on) {
/* Next line is to be checked $$$ */
send_onebyte_message(fd, CF633_Set_LCD_And_Keypad_Backlight, brightness);
} else {
/* Next line is to be checked $$$ */
send_onebyte_message(fd, CF633_Set_LCD_And_Keypad_Backlight, offbrightness);
}
send_onebyte_message(fd, CF633_Set_LCD_And_Keypad_Backlight,
(on) ? brightness : offbrightness);
}
/*
* Get rid of the blinking curson
*/
@@ -466,6 +492,7 @@ CFontz633_no_live_report ()
send_bytes_message(fd, 2, CF633_Set_Up_Live_Fan_or_Temperature_Display , out);
}
/*
* Stop the reporting of any fan.
*/
@@ -475,6 +502,7 @@ CFontz633_no_fan_report ()
send_onebyte_message(fd, CF633_Set_Up_Fan_Reporting, 0);
}
/*
* Stop the reporting of any temperature.
*/
@@ -482,9 +510,11 @@ static void
CFontz633_no_temp_report ()
{
char out[4]= {0, 0, 0, 0};
send_bytes_message(fd, 4, CF633_Set_Up_Temperature_Reporting, out);
}
/*
* Reset the display bios
*/
@@ -492,9 +522,11 @@ static void
CFontz633_reboot ()
{
char out[3]= {8, 18, 99};
send_bytes_message(fd, 3, CF633_Reboot, out);
}
/*
* Sets up for vertical bars.
*/
@@ -585,13 +617,13 @@ CFontz633_init_vbar (Driver * drvthis)
}
}
/*
* Inits horizontal bars...
*/
static void
CFontz633_init_hbar (Driver * drvthis)
{
char a[] = {
1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
@@ -717,6 +749,7 @@ CFontz633_num (Driver * drvthis, int x, int num)
*/
}
/*
* Sets a custom character from 0-7...
*
@@ -757,6 +790,7 @@ CFontz633_set_char (Driver * drvthis, int n, char *dat)
send_bytes_message(fd, 9, CF633_Set_LCD_Special_Character_Data , out);
}
/*
* Places an icon on screen
*/
@@ -904,9 +938,9 @@ CFontz633_icon (Driver * drvthis, int x, int y, int icon)
return -1; /* Let the core do other icons */
}
return 0;
}
/*
* Clears the LCD screen
*/
@@ -916,6 +950,7 @@ CFontz633_clear (Driver * drvthis)
memset (framebuf, ' ', width * height);
}
/*
* Hardware clears the LCD screen
*/
@@ -925,6 +960,7 @@ CFontz633_hardware_clear (Driver * drvthis)
send_zerobyte_message(fd, CF633_Clear_LCD_Screen);
}
/*
* Prints a string on the lcd display, at position (x,y). The
* upper-left is (1,1), and the lower right should be (16,2).