Skip to content

Instantly share code, notes, and snippets.

@lansing

lansing/bright.py

Created May 17, 2019
Embed
What would you like to do?
#!/usr/bin/env python3
import subprocess
import sys
import re
from subprocess import Popen, PIPE, STDOUT
FILENAME = "/tmp/last_bright"
INC_ABS = 6
if len(sys.argv) < 2:
print("usage: bright.py -u/-d")
exit(-1)
if sys.argv[1] == "-u":
inc = INC_ABS
elif sys.argv[1] == "-d":
inc = -INC_ABS
else:
print("usage: bright.py -u/-d")
exit(-1)
try:
with open(FILENAME, "r") as f:
current_lvl = int(f.read())
except:
current_lvl_str = subprocess.check_output(['ddcutil', '-d', '1', 'getvcp', '10']).decode()
current_lvl = int(re.search(r'current value =\W+(\d+)', current_lvl_str).group(1))
next_lvl = current_lvl + inc
if next_lvl < 0:
next_lvl = 0
Popen(['ddcutil', '-d', '1', 'setvcp', '10', str(next_lvl)], stdin=None, stdout=None, stderr=None, close_fds=True, shell=False)
with open(FILENAME, 'w') as f:
f.write(str(next_lvl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.