Skip to content

Instantly share code, notes, and snippets.

@whompyjaw
Forked from meseznik/brightness_control.sh
Created September 25, 2021 17:13
Show Gist options
  • Save whompyjaw/f9ef035805c0a9bd5505990267173bf6 to your computer and use it in GitHub Desktop.
Save whompyjaw/f9ef035805c0a9bd5505990267173bf6 to your computer and use it in GitHub Desktop.
bash script to control brightness/contrast
#!/bin/bash
# brightness_control --contrast --up 10
# brightness_control --brightness --down 5
# for the script to work without sudo, do this:
# https://frdmtoplay.com/using-ddccontrol-as-a-non-root-user/
# https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux
if [ "$1" = "--brightness" ]
then
type=10
elif [ "$1" = "--contrast" ]
then
type=12
fi
get_cmd=$(ddcutil getvcp --bus 4 "${type}")
regex="([0-9]{1,3}),"
if [[ $get_cmd =~ $regex ]]
then
current_amount="${BASH_REMATCH[1]}"
else
echo "$get_cmd doesn't match" >&2
fi
if [ "$2" = "--up" ]
then
amount=$(($current_amount+$3))
elif [ "$2" = "--down" ]
then
amount=$(($current_amount-$3))
fi
if [ "$amount" -ge 0 -a "$amount" -le 100 ]
then
ddcutil setvcp --bus 4 "${type}" "${amount}"
else
echo "amount $amount is beyond range (>0,<100)" >&2
fi
# ddcutil setvcp --bus 4 10 10
# sudo ddcutil -d 1 getvcp 0x10
# /dev/i2c-4
# CP code 0x02 (New control value ): One or more new control values have been saved (0x02)
# VCP code 0x0b (Color temperature increment ): 100 degree(s) Kelvin
# VCP code 0x0c (Color temperature request ): 3000 + 100 * (feature 0B color temp increment) degree(s) Kelvin
# VCP code 0x10 (Brightness ): current value = 30, max value = 100
# VCP code 0x12 (Contrast ): current value = 0, max value = 100
# VCP code 0x14 (Select color preset ): Setting: User 1 (0x0b)
# VCP code 0x16 (Video gain: Red ): current value = 0, max value = 100
# VCP code 0x18 (Video gain: Green ): current value = 0, max value = 100
# VCP code 0x1a (Video gain: Blue ): current value = 0, max value = 100
# VCP code 0x1e (Auto setup ): Auto setup not active (sl=0x00)
# VCP code 0x20 (Horizontal Position (Phase) ): current value = 50, max value = 100
# VCP code 0x30 (Vertical Position (Phase) ): current value = 35, max value = 100
# VCP code 0x52 (Active control ): Value: 0x00
# VCP code 0x60 (Input Source ): DisplayPort-1 (sl=0x0f)
# VCP code 0x62 (Audio speaker volume ): current value = 50, max value = 100
# VCP code 0x6c (Video black level: Red ): current value = 50, max value = 100
# VCP code 0x6e (Video black level: Green ): current value = 50, max value = 100
# VCP code 0x70 (Video black level: Blue ): current value = 50, max value = 100
# VCP code 0x72 (Gamma ): SL: 0x00 , SH: 0x00
# VCP code 0x73 (LUT Size ): Maximum retries exceeded
# VCP code 0x74 (Single point LUT operation ): Maximum retries exceeded
# VCP code 0x75 (Block LUT operation ): Maximum retries exceeded
# VCP code 0x78 (Display Identification Operation): Maximum retries exceeded
# VCP code 0x86 (Display Scaling ): Max image, no aspect ration distortion (sl=0x02)
# VCP code 0x8d (Audio mute/Screen blank ): Unmute the audio (sl=0x02), Invalid value (sh=0x00)
# VCP code 0xa4 (Window mask control ): Maximum retries exceeded
# VCP code 0xaa (Screen Orientation ): 0 degrees (sl=0x01)
# VCP code 0xac (Horizontal frequency ): 26828 hz
# VCP code 0xae (Vertical frequency ): 143.81 hz
# VCP code 0xb4 (Source Timing Mode ): Maximum retries exceeded
# VCP code 0xb6 (Display technology type ): LCD (active matrix) (sl=0x03)
# VCP code 0xc0 (Display usage time ): Usage time (hours) = 498 (0x0001f2) mh=0xff, ml=0xff, sh=0x01, sl=0xf2
# VCP code 0xc3 (Transmit display descriptor ): Maximum retries exceeded
# VCP code 0xc6 (Application enable key ): 0x0040
# VCP code 0xc8 (Display controller type ): Mfg: Mstar (sl=0x05), controller number: mh=0xff, ml=0x16, sh=0x00
# VCP code 0xc9 (Display firmware level ): 0.5
# VCP code 0xca (OSD/Button Control ): SL: 0x02 , SH: 0x00
# VCP code 0xcc (OSD Language ): English (sl=0x02)
# VCP code 0xd2 (Asset Tag ): Maximum retries exceeded
# VCP code 0xd6 (Power mode ): DPM: On, DPMS: Off (sl=0x01)
# VCP code 0xda (Scan mode ): Normal operation (sl=0x00)
# VCP code 0xdc (Display Mode ): Invalid value (sl=0x10)
# VCP code 0xdf (VCP Version ): 2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment