Skip to content

Commit c156986

Browse files
committed
Add support for center, right and extra region in backlight bash script
1 parent dd887c6 commit c156986

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

src/DEBIAN/control

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Source: tuxedo-backlight-control
22
Package: tuxedo-backlight-control
3-
Version: 0.1
3+
Version: 0.2
44
Maintainer: Kevin Van Lierde
55
Architecture: all
66
Description: Tuxedo Backlight Control
@@ -9,4 +9,4 @@ Description: Tuxedo Backlight Control
99
Section: utils/contrib
1010
Priority: optional
1111
Recommends: python3, python3-tk
12-
Installed-Size: 50
12+
Installed-Size: 52

src/usr/share/tuxedo-backlight-control/bin/backlight

+56-15
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
package='Tuxedo Backlight Control <tuxedo-backlight-control>'
44
version='0.1'
5-
date='2019-03-05'
5+
date='2019-04-25'
66
author='Kevin Van Lierde <[email protected]>'
77
conf_path='/etc/modprobe.d/tuxedo_keyboard.conf'
8-
9-
opt="$1"
10-
color="$2"
8+
module_path='/sys/module/tuxedo_keyboard'
119

1210
# see https://github.com/tuxedocomputers/tuxedo-keyboard
11+
1312
declare -A opts
1413
opts['breathe']='mode=1'
1514
opts['cycle']='mode=2'
@@ -22,8 +21,8 @@ opts['off']='state=0'
2221
opts['color']='mode=0'
2322

2423
# see https://www.cssportal.com/html-colors/orig-16-colors.php
25-
declare -A colors
2624

25+
declare -A colors
2726
colors['white']='FFFFFF'
2827
colors['yellow']='FFFF00'
2928
colors['fuchsia']='FF00FF'
@@ -45,14 +44,20 @@ colors['pink']='FFC0CB'
4544
colors['turquoise']='40E0D0'
4645

4746

48-
if [ ! -f $conf_path ]
47+
if [ ! -e $conf_path ]
4948
then
5049
echo "Cannot start tuxedo-backlight-control:"
5150
echo "tuxedo_keyboard conf not found at $conf_path."
5251
exit
5352
fi
5453

55-
if [ $opt == '--help' ] || [ $opt == '-h' ]
54+
opt="$1"
55+
color_left="$2"
56+
color_center="$color_left"
57+
color_right="$color_left"
58+
color_extra="$color_left"
59+
60+
if [ "$opt" == '--help' ] || [ "$opt" == '-h' ]
5661
then
5762
echo -ne '\n'
5863
echo "$package - v$version - $date"
@@ -73,6 +78,7 @@ if [ $opt == '--help' ] || [ $opt == '-h' ]
7378
echo ' fuchsia, purple, rose, cyan, turquoise, teal, blue, navy,'
7479
echo ' olive, lime, green'
7580
echo -ne '\n'
81+
echo 'Report bugs at https://github.com/webketje/tuxedo-backlight-control/issues'
7682
echo 'For info on the tuxedo_keyboard kernel module, see https://github.com/tuxedocomputers/tuxedo-keyboard'
7783
echo -ne '\n'
7884
exit
@@ -98,22 +104,57 @@ if [ "$opt" == 'ui' ]
98104
exit
99105
fi
100106

101-
if [ "$opt" == 'color' ] && ([ ! "$color" ] || [ ! ${colors[${color}]} ])
107+
if [ ! "$opt" ] || [ ! ${opts[${opt}]} ]
102108
then
103-
echo 'No or invalid color provided for keyboard backlight'
109+
echo 'backlight: No or invalid option provided for keyboard backlight'
104110
exit
105-
elif [ ! "$opt" ] || [ ! ${opts[${opt}]} ]
111+
elif [ "$opt" == 'color' ]
106112
then
107-
echo 'No or invalid option provided for keyboard backlight'
108-
exit
109-
fi
113+
if [ ! "$color_left" ] || [ ! ${colors[${color_left}]} ]
114+
then
115+
echo 'backlight: No or invalid color provided for keyboard backlight'
116+
exit
117+
elif [ "$3" ] && [ ! "$4" ]
118+
then
119+
echo 'backlight: Please provide a single or 3 colors (left, center, right)'
120+
exit
121+
elif [ "$3" ] && [ "$4" ]
122+
then
123+
if [ ! ${colors[${3}]} ]
124+
then
125+
echo "backlight: '$3' is not a supported color"
126+
exit
127+
elif [ ! ${colors[${4}]} ]
128+
then
129+
echo "backlight: '$4' is not a supported color"
130+
exit
131+
else
132+
color_center="$3"
133+
color_right="$4"
134+
fi
110135

136+
if [ "$5" ]
137+
then
138+
if [ ! ${colors[${5}]} ]
139+
then
140+
echo "backlight: '$4' is not a supported color"
141+
exit
142+
else
143+
color_extra="$5"
144+
fi
145+
fi
111146

112-
eval 'sudo rmmod tuxedo_keyboard'
147+
fi
148+
fi
149+
150+
if [ -e $module_path ]
151+
then
152+
eval 'sudo rmmod tuxedo_keyboard'
153+
fi
113154

114155
if [ "$opt" == 'color' ]
115156
then
116-
eval "echo \"options tuxedo_keyboard ${opts[${opt}]} color_left=0x${colors[${color}]} color_center=0x${colors[${color}]} color_right=0x${colors[${color}]}\" > /etc/modprobe.d/tuxedo_keyboard.conf"
157+
eval "echo \"options tuxedo_keyboard ${opts[${opt}]} color_left=0x${colors[${color_left}]} color_center=0x${colors[${color_center}]} color_right=0x${colors[${color_right}]} color_extra=0x${colors[${color_extra}]}\" > /etc/modprobe.d/tuxedo_keyboard.conf"
117158
else
118159
eval "echo \"options tuxedo_keyboard ${opts[${opt}]}\" > /etc/modprobe.d/tuxedo_keyboard.conf"
119160
fi

0 commit comments

Comments
 (0)