add get_brightness() & set_brightness() functions to CFontz{633,Packet}.c

and normalize the brightness to range [0, 1000] to support changing the
brightness online
This commit is contained in:
marschap
2005-06-12 16:25:50 +00:00
parent 285db95e4d
commit fbd81f910e
4 changed files with 130 additions and 51 deletions
+7 -4
View File
@@ -161,13 +161,13 @@ Reboot=no
# Select the output device to use [default: /dev/lcd] # Select the output device to use [default: /dev/lcd]
Device=/dev/ttyS0 Device=/dev/ttyS0
# Select the LCD type (size) [default: 20x4] # Select the LCD type (size) [default: 16x2]
Size=16x2 Size=16x2
# Set the initial contrast [default: 140; legal: 0 - 1000] # Set the initial contrast [default: 140; legal: 0 - 1000]
Contrast=140 Contrast=140
# Set the initial brightness [default: 100; legal: 0 - 255] # Set the initial brightness [default: 1000; legal: 0 - 1000]
Brightness=100 Brightness=1000
# Set the initial off-brightness [default: 0; legal: 0 - 255] # Set the initial off-brightness [default: 0; legal: 0 - 1000]
# This value is used when the display is normally # This value is used when the display is normally
# switched off in case LCDd is inactive # switched off in case LCDd is inactive
OffBrightness=50 OffBrightness=50
@@ -271,6 +271,9 @@ ConnectionType=4bit
# You may also need to configure the keypad layout further on in this file. # You may also need to configure the keypad layout further on in this file.
Keypad=no Keypad=no
# set the initial contrast (for bwctusb only) [default: 0; legal: 0 - 1000]
Contrast=0
# If you have a switchable backlight. # If you have a switchable backlight.
Backlight=no Backlight=no
+52 -16
View File
@@ -191,16 +191,16 @@ CFontz633_init (Driver *drvthis, char *args)
/* 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 > 100)) { if ((tmp < 0) || (tmp > 1000)) {
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 1000. Using default value.\n");
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp; p->brightness = tmp;
/* Which backlight-off "brightness" */ /* Which backlight-off "brightness" */
tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS); tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
if ((tmp < 0) || (tmp > 100)) { if ((tmp < 0) || (tmp > 1000)) {
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 1000. Using default value.\n");
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp; p->offbrightness = tmp;
@@ -486,10 +486,9 @@ CFontz633_chr (Driver *drvthis, int x, int y, char c)
/* /*
* Returns current contrast * Returns current contrast (in promille)
* This is only the locally stored contrast, the contrast value * This is only the locally stored contrast, the contrast value
* cannot be retrieved from the LCD. * cannot be retrieved from the LCD.
* Value 0 to 1000.
*/ */
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_get_contrast (Driver *drvthis) CFontz633_get_contrast (Driver *drvthis)
@@ -501,8 +500,7 @@ CFontz633_get_contrast (Driver *drvthis)
/* /*
* Changes screen contrast (valid hardware value: 0-50) * Changes screen contrast (in promille)
* Value 0 to 1000.
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_set_contrast (Driver *drvthis, int promille) CFontz633_set_contrast (Driver *drvthis, int promille)
@@ -514,33 +512,71 @@ CFontz633_set_contrast (Driver *drvthis, int promille)
if (promille < 0 || promille > 1000) if (promille < 0 || promille > 1000)
return; return;
/* Store the software value since there is not get. */ /* store the software value since there is not get */
p->contrast = promille; p->contrast = promille;
hardware_contrast = p->contrast/20; /* map range [0, 1000] -> [0, 50] that the hardware understands */
/* Next line is to be checked $$$ */ hardware_contrast = p->contrast / 20;
send_onebyte_message(p->fd, CF633_Set_LCD_Contrast, hardware_contrast); send_onebyte_message(p->fd, CF633_Set_LCD_Contrast, hardware_contrast);
} }
/*
* Retrieves brightness (in promille)
*/
MODULE_EXPORT int
CFontz633_get_brightness(Driver *drvthis, int state)
{
PrivateData *p = drvthis->private_data;
return (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
}
/*
* Sets on/off brightness (in promille)
*/
MODULE_EXPORT void
CFontz633_set_brightness(Driver *drvthis, int state, int promille)
{
PrivateData *p = drvthis->private_data;
/* Check it */
if (promille < 0 || promille > 1000)
return;
/* store the software value since there is not get */
if (state == BACKLIGHT_ON) {
p->brightness = promille;
//CFontz633_backlight(drvthis, BACKLIGHT_ON);
}
else {
p->offbrightness = promille;
//CFontz633_backlight(drvthis, BACKLIGHT_OFF);
}
}
/* /*
* 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.
* Need to find out if we have support for intermediate value.
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_backlight (Driver *drvthis, int on) CFontz633_backlight (Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int hardware_value = (on == BACKLIGHT_ON)
? p->brightness
: p->offbrightness;
/* Next line is to be checked $$$ */ /* map range [0, 1000] -> [0, 100] that the hardware understands */
send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight, hardware_value /= 10;
(on) ? p->brightness : p->offbrightness); send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight, hardware_value);
} }
/* /*
* Get rid of the blinking curson * Get rid of the blinking cursor
*/ */
static void static void
CFontz633_hidecursor (Driver *drvthis) CFontz633_hidecursor (Driver *drvthis)
+4 -2
View File
@@ -8,7 +8,7 @@
#define DEFAULT_CONTRAST 560 #define DEFAULT_CONTRAST 560
#define DEFAULT_DEVICE "/dev/lcd" #define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_SPEED B19200 #define DEFAULT_SPEED B19200
#define DEFAULT_BRIGHTNESS 100 #define DEFAULT_BRIGHTNESS 1000
#define DEFAULT_OFFBRIGHTNESS 0 #define DEFAULT_OFFBRIGHTNESS 0
#define DEFAULT_SIZE "16x2" #define DEFAULT_SIZE "16x2"
#define DEFAULT_SIZE_CF635 "20x4" #define DEFAULT_SIZE_CF635 "20x4"
@@ -35,7 +35,9 @@ 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 void CFontz633_set_char (Driver *drvthis, int n, 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 contrast); MODULE_EXPORT void CFontz633_set_contrast (Driver *drvthis, int promille);
MODULE_EXPORT int CFontz633_get_brightness (Driver *drvthis, int state);
MODULE_EXPORT void CFontz633_set_brightness (Driver *drvthis, int state, int promille);
MODULE_EXPORT void CFontz633_backlight (Driver *drvthis, int on); MODULE_EXPORT void CFontz633_backlight (Driver *drvthis, int on);
#endif /* CFONTZ633_H */ #endif /* CFONTZ633_H */
+54 -16
View File
@@ -8,7 +8,7 @@
*/ */
/* /*
* This is the LCDproc driver for CrystalFontz LCD using Packet protocol. * This is the LCDproc driver for CrystalFontz LCD using Packet protocol.
* It support the CrystalFontz 633 USB/Serial, the 631 USB and the 635USB * It support the CrystalFontz 633 USB/Serial, the 631 USB and the 635 USB
* (get yours from http://crystalfontz.com) * (get yours from http://crystalfontz.com)
* *
* Applicable Data Sheets * Applicable Data Sheets
@@ -57,7 +57,7 @@
* *
* THINGS TO DO: * THINGS TO DO:
* + Make the caching at least for heartbeat icon * + Make the caching at least for heartbeat icon
* + Create and use the library (for custom char handeling) * + Create and use the library (for custom char handling)
* *
*/ */
@@ -251,8 +251,8 @@ CFontz633_init (Driver *drvthis, char *args)
/* 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);
debug (RPT_INFO,"CFontzPacket_init: Brightness (in config) is '%d'", tmp); debug (RPT_INFO,"CFontzPacket_init: Brightness (in config) is '%d'", tmp);
if ((tmp < 0) || (tmp > 100)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "CFontzPacket_init: Brightness must be between 0 and 100. Using default value.\n"); report (RPT_WARNING, "CFontzPacket_init: Brightness must be between 0 and 1000. Using default value.\n");
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp; p->brightness = tmp;
@@ -260,8 +260,8 @@ CFontz633_init (Driver *drvthis, char *args)
/* Which backlight-off "brightness" */ /* Which backlight-off "brightness" */
tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS); tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
debug (RPT_INFO,"CFontzPacket_init: OffBrightness (in config) is '%d'", tmp); debug (RPT_INFO,"CFontzPacket_init: OffBrightness (in config) is '%d'", tmp);
if ((tmp < 0) || (tmp > 100)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "CFontzPacket_init: OffBrightness must be between 0 and 100. Using default value.\n"); report (RPT_WARNING, "CFontzPacket_init: OffBrightness must be between 0 and 1000. Using default value.\n");
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp; p->offbrightness = tmp;
@@ -623,10 +623,9 @@ CFontz633_raw_chr (Driver *drvthis, int x, int y, unsigned char c)
/* /*
* Returns current contrast * Returns current contrast (in promille)
* This is only the locally stored contrast, the contrast value * This is only the locally stored contrast, the contrast value
* cannot be retrieved from the LCD. * cannot be retrieved from the LCD.
* Value 0 to 1000.
*/ */
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_get_contrast (Driver *drvthis) CFontz633_get_contrast (Driver *drvthis)
@@ -638,8 +637,7 @@ CFontz633_get_contrast (Driver *drvthis)
/* /*
* Changes screen contrast (valid hardware value: 0-50) * Changes screen contrast (in promille)
* Value 0 to 1000.
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_set_contrast (Driver *drvthis, int promille) CFontz633_set_contrast (Driver *drvthis, int promille)
@@ -651,10 +649,11 @@ CFontz633_set_contrast (Driver *drvthis, int promille)
if (promille < 0 || promille > 1000) if (promille < 0 || promille > 1000)
return; return;
/* Store the software value since there is not get. */ /* store the software value since there is not get */
p->contrast = promille; p->contrast = promille;
// on CF633: 0 - 50, on CF631, CF635: 0 - 255 /* map range [0, 1000] to a range that the hardware understands */
/* on CF633: [0, 50], on CF631 & CF635: [0, 255] */
hardware_contrast = (p->model == 633) hardware_contrast = (p->model == 633)
? (p->contrast / 20) ? (p->contrast / 20)
: ((p->contrast * 255) / 1000); : ((p->contrast * 255) / 1000);
@@ -663,23 +662,62 @@ CFontz633_set_contrast (Driver *drvthis, int promille)
} }
/*
* Retrieves brightness (in promille)
*/
MODULE_EXPORT int
CFontz633_get_brightness(Driver *drvthis, int state)
{
PrivateData *p = drvthis->private_data;
return (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
}
/*
* Sets on/off brightness (in promille)
*/
MODULE_EXPORT void
CFontz633_set_brightness(Driver *drvthis, int state, int promille)
{
PrivateData *p = drvthis->private_data;
/* Check it */
if (promille < 0 || promille > 1000)
return;
/* store the software value since there is not get */
if (state == BACKLIGHT_ON) {
p->brightness = promille;
//CFontz633_backlight(drvthis, BACKLIGHT_ON);
}
else {
p->offbrightness = promille;
//CFontz633_backlight(drvthis, BACKLIGHT_OFF);
}
}
/* /*
* 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.
* Need to find out if we have support for intermediate value.
*/ */
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_backlight (Driver *drvthis, int on) CFontz633_backlight (Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int hardware_value = (on == BACKLIGHT_ON)
? p->brightness
: p->offbrightness;
send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight, /* map range [0, 1000] -> [0, 100] that the hardware understands */
(on) ? p->brightness : p->offbrightness); hardware_value /= 10;
send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight, hardware_value);
} }
/* /*
* Get rid of the blinking curson * Get rid of the blinking cursor
*/ */
static void static void
CFontz633_hidecursor (Driver *drvthis) CFontz633_hidecursor (Driver *drvthis)