Sunspot Home. . . . . . Joggler menu

Change screen brightness on mouse activity


Have the screen LED backlight dim after a period of mouse inactivity
- then have it brighten when the screen is touched or the mouse moved

I found a small python script that could detect mouse activity by observing /dev/input/mice
I made it write "mouse_moved" to a file mouse_moved.txt in /var/www/ramdisk

#! /usr/bin/python

fh = file('/dev/input/mice')
while True:
§§fileHandle = open ( '/var/www/ramdisk/mouse_moved.txt', 'w' )
§§fileHandle.write ( 'mouse_moved' )

I have a Blassic basic "watchdog" program that loops continuously and monitors files in the ramdisk and then takes action as needed.
I made it watch the file /var/www/ramdisk/mouse_moved.txt
On mouse activity it brightens the screen then starts a count that counts down as the watchdog loops.
At the end of the count the screen is dimmed to minimum brightness.

#! /usr/sbin/blassic
' /home/graham/blassic/act_on_code.bas

' startup values
SHELL "echo -n 0 >/var/www/ramdisk/command.txt"
SHELL "echo 1 > /var/www/ramdisk/mouse_moved.txt"
loop_delay = 1000
SHELL "play /home/graham/sounds/online.wav"
back_light_count = 0


IF (back_light_count = 0) THEN GOTO IgnoreBacklight
back_light_count = back_light_count - 1
IF back_light_count = 1 THEN GOSUB DimBackLight
LABEL IgnoreBacklight

OPEN "/var/www/ramdisk/mouse_moved.txt" FOR INPUT AS #1 : INPUT #1,mouse$ : CLOSE #1
PRINT back_light_count
IF mouse$ = "mouse_moved" THEN GOSUB BrightBackLight
SHELL "echo 1 > /var/www/ramdisk/mouse_moved.txt"
PAUSE loop_delay

OPEN "/var/www/ramdisk/command.txt" FOR INPUT AS #1 : INPUT #1,command$ : CLOSE #1
If command$ = "0" THEN GOSUB Command_wait_loop ' return to watching and waiting
If command$ = "7" THEN GOSUB Command_Stephen ' Stephen has left a message
If command$ = "8" THEN GOSUB Command_David ' David has left a message

GOTO DoItAgain

LABEL Command_wait_loop ' just loop and wait for a command
'PAUSE 1000

LABEL Command_David
message$ = "David"+CHR$(20)+"has"+CHR$(20)+"left"+CHR$(20)+"a"+CHR$(20)+"messidge."
PRINT message$
SHELL "flite -t "+message$

LABEL Command_Stephen
message$ = "Steven"+CHR$(20)+"has"+CHR$(20)+"left"+CHR$(20)+"a"+CHR$(20)+"messidge."
PRINT message$
SHELL "flite -t "+message$

LABEL BrightBackLight
back_light_count = 100
SHELL "echo -n 32 > /sys/class/backlight/openframe-bl/brightness"
PRINT "Screen brightness is now 32"

LABEL DimBackLight
SHELL "echo -n 0 > /sys/class/backlight/openframe-bl/brightness"
PRINT "Screen brightness is now 0"



You can set the screen to black after a chosen delay as below - but this does not actually turn off the LED backlight
- it just blacks the LCD screen.

turn screen "off"

Thanks to - - - this post

Change this

# Following lines disable screen blanking
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"

in /etc/X11/xorg.conf

to this:-

# Following lines enable screen blanking
Option "BlankTime" "2"
Option "StandbyTime" "2"
Option "SuspendTime" "0"
Option "OffTime" "0"

(Change 2 to the time in minutes you want it to be idle before the display sleeps). Much better for the bedroom!

 You can turn the LED back light off completely
(not just blank the LCD)

do this
apt-get install xutils

as a new line

To turn the backlight off
xset dpms force off

(DPMS is display power management)

If you touch the screen/move the mouse it comes on again

turn it on by script
xset dpms force on

turn off after 100 seconds
xset dpms 100 101
(100 seconds to standby, 101 to all display power off - standby turns the LEDs off on this display)

Type xset alone to see the other options

Sunspot Home . . . . . . . Joggler menu

Comments? email me