diff --git a/ChangeLog b/ChangeLog
index fdab36c..0614e85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,7 @@ v.0.5dev (ongoing development)
* allow compiling with LDFLAG "--as-needed" (Robert Buchholz)
* optimize MtxOrb flush()
* make MtxOrb use Brightness and OffBrightness like CFontzPacket
+ * make Brightness & OffBrightness run-time configurable in CFontz & MtxOrb
v.0.5.1
+ config file support in lcdproc client (Andrew Foss)
diff --git a/LCDd.conf b/LCDd.conf
index 9cd3b10..304dba6 100644
--- a/LCDd.conf
+++ b/LCDd.conf
@@ -142,9 +142,9 @@ Device=/dev/ttyS0
Size=20x4
# Set the initial contrast [default: 560; legal: 0 - 1000]
Contrast=350
-# Set the initial brightness [default: 255; legal: 0 - 255]
-Brightness=255
-# Set the initial off-brightness [default: 0; legal: 0 - 255]
+# Set the initial brightness [default: 1000; legal: 0 - 1000]
+Brightness=1000
+# Set the initial off-brightness [default: 0; legal: 0 - 1000]
# This value is used when the display is normally
# switched off in case LCDd is inactive
OffBrightness=0
diff --git a/docs/lcdproc-user/drivers/CFontz.docbook b/docs/lcdproc-user/drivers/CFontz.docbook
index 609c44f..8fd17a2 100644
--- a/docs/lcdproc-user/drivers/CFontz.docbook
+++ b/docs/lcdproc-user/drivers/CFontz.docbook
@@ -61,8 +61,8 @@ CFontz chipset.
Set the initial brightness.
Legal values for BRIGHTNESS range from
- 0 to 255.
- If not given, it defaults to 255.
+ 0 to 1000.
+ If not given, it defaults to 1000.
@@ -76,7 +76,7 @@ CFontz chipset.
This value is used when the display is normally
switched off in case LCDd is inactive.
Legal values BRIGHTNESS are in the range
- from 0 to 255.
+ from 0 to 1000.
The default is 0.
diff --git a/server/drivers/CFontz.c b/server/drivers/CFontz.c
index ece990e..e66e9e6 100644
--- a/server/drivers/CFontz.c
+++ b/server/drivers/CFontz.c
@@ -161,8 +161,8 @@ CFontz_init(Driver *drvthis)
/* Which backlight brightness */
tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
- if ((tmp < 0) || (tmp > 255)) {
- report(RPT_WARNING, "%s: Brightness must be between 0 and 255; using default %d",
+ if ((tmp < 0) || (tmp > 1000)) {
+ report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS;
}
@@ -170,8 +170,8 @@ CFontz_init(Driver *drvthis)
/* Which backlight-off "brightness" */
tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
- if ((tmp < 0) || (tmp > 255)) {
- report(RPT_WARNING, "%s: OffBrightness must be between 0 and 255; using default %d",
+ if ((tmp < 0) || (tmp > 1000)) {
+ report(RPT_WARNING, "%s: OffBrightness must be between 0 and 1000; using default %d",
drvthis->name, 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.
* \param drvthis Pointer to driver structure.
@@ -499,9 +541,11 @@ MODULE_EXPORT void
CFontz_backlight(Driver *drvthis, int on)
{
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);
}
diff --git a/server/drivers/CFontz.h b/server/drivers/CFontz.h
index 8d801fd..8883d65 100644
--- a/server/drivers/CFontz.h
+++ b/server/drivers/CFontz.h
@@ -8,7 +8,7 @@
#define DEFAULT_CONTRAST 560
#define DEFAULT_DEVICE "/dev/lcd"
#define DEFAULT_SPEED B9600
-#define DEFAULT_BRIGHTNESS 60
+#define DEFAULT_BRIGHTNESS 1000
#define DEFAULT_OFFBRIGHTNESS 0
#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 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);
#endif