Alexander Clausen wrote:
On So, Jan 18, 2004 at 01:23:26 +0100, Andreas Jaggi wrote:
I've got coded a quick'n'dirty daemon for changing keyboard backlight,
based on lmu.c.
Its at http://waterwave.ch/weblog/stuff/lmud-0.01.tar.gz
Try it an turn of the light in your room :-)
Hey, nice thingy ;)
If it doesnt work, change #define ADAPTER_NUMBER in lmud.c
I enhanced it a bit:
- function definitions in lmu.h, my lmu code in lmu.c
- quick'n'dirty auto-detection, till i figured out how to do it
properly with sysfs..
You can grab it at
http://alex.homelinux.net/~alex/lmud-0.02.tar.gz
Please tell me if it detects the i2c port properly!
Yes it detected the i2c port and works on my powerbook 15"!
I slightly modified lmud.c to "fade" to the new backlight level when the
sensor-values change. I think (if I remember correctly) this is how it
works on OSX. I attached the patch if someone want to test it.
Regards,
Jonas
PS
I use this line to start the program from some init.d script:
/sbin/start-stop-daemon --start --background --user root \
--pidfile /var/run/lmud.pid --exec /usr/local/sbin/lmud
DS
--
Jonas Borgström | Edgewall research and development
[EMAIL PROTECTED] | http://www.edgewall.com/
--- lmud.c.vanilla 2004-01-18 20:16:06.911888456 +0100
+++ lmud.c 2004-01-18 20:14:47.610944032 +0100
@@ -19,13 +19,12 @@
#include <stdio.h>
#include <stdlib.h>
-#define LIGHTON_PERIOD 1 // time in seconds between checks if light is off
-#define LIGHTOFF_PERIOD 1 // time in seconds between checks if light is on
-
-#define LIGHT_LIMIT 600
+#define UPDATE_PERIOD 20 // time in ms between checks if light is off
+#define LIGHT_THRESHOLD 600
int main ( ) {
int left = 0, right = 0, dev;
+ int level = 0, new;
dev = open_bus( );
if (dev == -1) {
@@ -36,22 +35,20 @@
printf("access denied\n");
exit ( EXIT_FAILURE );
}
-
while(1) {
if ( get_env_light_level ( dev, &left, &right ) == -1 ) {
printf ( "read failed\n" );
exit ( EXIT_FAILURE );
}
-
- if( (right+left) < 2*LIGHT_LIMIT && (right+left) > 0) {
- set_level( dev, (-15*(right+left))/(2*LIGHT_LIMIT) + 15 );
- usleep( LIGHTON_PERIOD * 1000000L );
- } else {
- set_level ( dev, 0 );
- usleep( LIGHTOFF_PERIOD * 1000000L );
+ new = (-15*(right+left))/(2*LIGHT_THRESHOLD) + 15;
+ if ((left + right) > 2 * LIGHT_THRESHOLD)
+ new = 0;
+ if (new != level) {
+ level += new > level ? 1 : -1;
+ set_level( dev, level);
}
+ usleep(UPDATE_PERIOD * 10000L);
}
-
return 0;
}