Simple desktop monitor backlight adjustment slider for unwilling monitors

This post is a complete rewrite of something that I posted earlier on ubuntu-mate.community

Using my desktop-computer I have the brightness (=backlight) of my monitor turned up full (it is a reasonably sunny room and a reasonably old monitor)
In the evening i turn the brightness down to almost minimum.

Since the values of my monitor settings are set through a menu with ‘up’ and ‘down’ entries i thought that setting it could be accomplished in a less ‘labour intensive’ way.

The goal is to crate a slider to adjust the backlight of my monitor
and in MATE it is easy to make a launcher for a script so let’s make that script.

Now the trouble is that my monitor is a bit old and the firmware is therefore either not fully compliant to the standard control protocols or the firmware is just plain buggy.

 Mfg id:               SAM - Samsung Electric Company
 Model:                SA300/SA350
 Product code:         1941  (0x0795)
 Manufacture year:     2011,  Week: 37

Anyway, I decided to use ddcutil to do the switching but since my monitor not always seem to understand the commands and sometimes replies a bit confused (1 out of 3 on average) I decided to go bruteforce and keep on repeating the command until the monitor does what it is told to do.

I also have to do the same for retreiving the current value from the monitor to set the slider to the right ‘startvalue’.

Anyway, this is the script. The only thing you have to do yourself is saving it, making it executable and creating a launcher for it.

Dependencies: ddcutil and yad

#!/bin/bash

# Force brightness change onto an unwilling monitor with questionable firmware

# 1) keep querying the monitor until it gives its stored value without error
# 2) use this value as initial value as for setting the actuator
# 3) while actuated value is unequal to the stored value:
# 	a) keep writing the actuated value to the monitor until it complies without error
# 	b) keep querying the monitor until it gives the written value back without error

#### comment out to debug
exec 2>/dev/null

#### kill all other still running instances of this script if there are any
kill -SIGKILL $( pgrep "${0##*/}" | grep -v "$$" )

declare -i get_value set_value

GetValueByForce()
{
	while ! ddcutil getvcp '10'
	do sleep 0.1
	done |tr ":," "\n\n" |grep 'current' |cut -d= -f2
}
NewValue()
{
	yad --title='Monitor Backlight' --width=500 --scale --value="$1" || kill -SIGTERM "$$"
}
SetValueByForce()
{
	while ! ddcutil setvcp '10' "$1" --sleep-multiplier 2.0 --disable-dynamic-sleep
	do sleep 0.1
	done
}
#### main
get_value=$( GetValueByForce )
set_value=$( NewValue "$get_value" )
while [ "$get_value" -ne "$set_value" ]
do
	SetValueByForce "$set_value" >/dev/null
	get_value=$( GetValueByForce )
done
  1. Keep in mind that adjusting the monitor brightness (=backlight) with this scripts could potentially take up to several seconds due to buggy monitor firmware.
    The time it takes depends on how buggy the monitor firmware is.

  2. Brightness will change after you click OK because of the process involved. I tried to let it change immediately upon moving the slider but that turned out to be a very bad idea. :roll_eyes:

4 Likes