make {Off,}Brightness run-time configurable in range [0, 1000]

This commit is contained in:
marschap
2006-11-26 20:08:56 +00:00
parent 220dd0a783
commit 1d4d4443e8
5 changed files with 60 additions and 13 deletions
+1
View File
@@ -21,6 +21,7 @@ v.0.5dev (ongoing development)
* allow compiling with LDFLAG "--as-needed" (Robert Buchholz) * allow compiling with LDFLAG "--as-needed" (Robert Buchholz)
* optimize MtxOrb flush() * optimize MtxOrb flush()
* make MtxOrb use Brightness and OffBrightness like CFontzPacket * make MtxOrb use Brightness and OffBrightness like CFontzPacket
* make Brightness & OffBrightness run-time configurable in CFontz & MtxOrb
v.0.5.1 v.0.5.1
+ config file support in lcdproc client (Andrew Foss) + config file support in lcdproc client (Andrew Foss)
+3 -3
View File
@@ -142,9 +142,9 @@ Device=/dev/ttyS0
Size=20x4 Size=20x4
# Set the initial contrast [default: 560; legal: 0 - 1000] # Set the initial contrast [default: 560; legal: 0 - 1000]
Contrast=350 Contrast=350
# Set the initial brightness [default: 255; legal: 0 - 255] # Set the initial brightness [default: 1000; legal: 0 - 1000]
Brightness=255 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=0 OffBrightness=0
+3 -3
View File
@@ -61,8 +61,8 @@ CFontz chipset.
<listitem><para> <listitem><para>
Set the initial brightness. Set the initial brightness.
Legal values for <replaceable>BRIGHTNESS</replaceable> range from Legal values for <replaceable>BRIGHTNESS</replaceable> range from
<literal>0</literal> to <literal>255</literal>. <literal>0</literal> to <literal>1000</literal>.
If not given, it defaults to <literal>255</literal>. If not given, it defaults to <literal>1000</literal>.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
@@ -76,7 +76,7 @@ CFontz chipset.
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.
Legal values <replaceable>BRIGHTNESS</replaceable> are in the range Legal values <replaceable>BRIGHTNESS</replaceable> are in the range
from <literal>0</literal> to <literal>255</literal>. from <literal>0</literal> to <literal>1000</literal>.
The default is <literal>0</literal>. The default is <literal>0</literal>.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
+50 -6
View File
@@ -161,8 +161,8 @@ CFontz_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 > 255)) { if ((tmp < 0) || (tmp > 1000)) {
report(RPT_WARNING, "%s: Brightness must be between 0 and 255; using default %d", report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
drvthis->name, DEFAULT_BRIGHTNESS); drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
@@ -170,8 +170,8 @@ CFontz_init(Driver *drvthis)
/* 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 > 255)) { if ((tmp < 0) || (tmp > 1000)) {
report(RPT_WARNING, "%s: OffBrightness must be between 0 and 255; using default %d", report(RPT_WARNING, "%s: OffBrightness must be between 0 and 1000; using default %d",
drvthis->name, DEFAULT_OFFBRIGHTNESS); drvthis->name, DEFAULT_OFFBRIGHTNESS);
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
@@ -490,6 +490,48 @@ CFontz_set_contrast(Driver *drvthis, int promille)
} }
/**
* Retrieve brightness.
* \param drvthis Pointer to driver structure.
* \param state Brightness state (on/off) for which we want the value.
* \return Stored brightness in promille.
*/
MODULE_EXPORT int
CFontz_get_brightness(Driver *drvthis, int state)
{
PrivateData *p = drvthis->private_data;
return (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
}
/**
* Set on/off brightness.
* \param drvthis Pointer to driver structure.
* \param state Brightness state (on/off) for which we want to store the value.
* \param promille New brightness in promille.
*/
MODULE_EXPORT void
CFontz_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;
//CFontz_backlight(drvthis, BACKLIGHT_ON);
}
else {
p->offbrightness = promille;
//CFontz_backlight(drvthis, BACKLIGHT_OFF);
}
}
/** /**
* Turn the LCD backlight on or off. * Turn the LCD backlight on or off.
* \param drvthis Pointer to driver structure. * \param drvthis Pointer to driver structure.
@@ -499,9 +541,11 @@ MODULE_EXPORT void
CFontz_backlight(Driver *drvthis, int on) CFontz_backlight(Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4] = { CFONTZ_Backlight_Control, 0 }; unsigned char out[4] = { CFONTZ_Backlight_Control, 0 };
int promille = (on == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
out[1] = (on) ? p->brightness : p->offbrightness; /* map range [0, 1000] -> [0, 255] that the hardware understands */
out[1] = (unsigned char) ((long) promille * 255 / 1000);
write(p->fd, out, 2); write(p->fd, out, 2);
} }
+3 -1
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 B9600 #define DEFAULT_SPEED B9600
#define DEFAULT_BRIGHTNESS 60 #define DEFAULT_BRIGHTNESS 1000
#define DEFAULT_OFFBRIGHTNESS 0 #define DEFAULT_OFFBRIGHTNESS 0
#define DEFAULT_SIZE "20x4" #define DEFAULT_SIZE "20x4"
@@ -65,6 +65,8 @@ MODULE_EXPORT void CFontz_set_char(Driver *drvthis, int n, unsigned char *dat);
MODULE_EXPORT int CFontz_get_contrast(Driver *drvthis); MODULE_EXPORT int CFontz_get_contrast(Driver *drvthis);
MODULE_EXPORT void CFontz_set_contrast(Driver *drvthis, int contrast); MODULE_EXPORT void CFontz_set_contrast(Driver *drvthis, int contrast);
MODULE_EXPORT int CFontz_get_brightness(Driver *drvthis, int state);
MODULE_EXPORT void CFontz_set_brightness(Driver *drvthis, int state, int promille);
MODULE_EXPORT void CFontz_backlight(Driver *drvthis, int on); MODULE_EXPORT void CFontz_backlight(Driver *drvthis, int on);
#endif #endif