-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromeos_kbd
57 lines (46 loc) · 1.48 KB
/
chromeos_kbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
set -e
# determine chromeos driver and set as [file] variable
file=/sys/class/leds/chromeos\:\:kbd_backlight/brightness
# read current brightness and set as [cur]
read -r cur < "$file"
# declare [step] and set value
step=$2
: ${step:=10}
# Ansi color code variables
highlight="\e[0;36m"
reset="\e[0m"
# take input and modify [val] as instructed
case "$1" in
-h|--help) ((val = step));
echo -e "${highlight}Chromeos_kbd LED backlight v0.0.1a "
echo -e "(c)Nebletech Industries 2022${reset}"
echo "Increase or decrease keyboard LED brighness."
echo "Usage: ${0##*/} --increase num | --decrease num | --set num"
echo "(--set -s can not currently be used to turn off the backlight)"
echo "Accepted values for input 1-99"
exit 0;;
-i|--increase) ((val = +step));;
-d|--decrease) ((val = -step));;
-s|--set) ((val = $2));
if ((val < 0)); then ((val = 0)); fi
if ((val > 100)); then ((val = 100)); fi
printf '%d' "$val" > "$file"
echo -e "Brightness set to ${highlight}$val%${reset}"
exit 0;;
esac
# show help screen if no value
if !((val)); then
echo "Increase or decrease keyboard LED brighness."
echo "Usage: ${0##*/} --increase num | --decrease num | --set num"
exit 0
fi
#set [val] to [cur]+[val]
((val = cur + val))
# prevent value going beyond limits
if ((val < 0)); then ((val = 0)); fi
if ((val > 100)); then ((val = 100)); fi
#print value to driver
printf '%d' "$val" > "$file"
echo -e "Brightness set to ${highlight}$val%${reset}"
exit 0