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