Subversion Repositories oBacklight

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 soulskater 1
#!/bin/bash
2
 
3
#####################################################################
4
# Simple script to catch the changes to backlight events on sony    #
5
# in combination with nvidiabl.                                     #
6
#                                                                   #
7
# Tested with a Sony Vaio VPCCW1S1E Laptop.                         #
8
#                                                                   #
9
# This has been tested on openSUSE 11.2, 11.3 & 11.4 and            #
10
# Ubuntu 11.10 but should work on any distributions.                #
11
#                                                                   #
12
# Released under the BSDL Licens                                    #
13
#                                                                   #
14
# Developer: oSource Development                                    #
15
# DevTeam: Marcus Uddenhed                                          #
16
# Version: 0.3.9                                                    #
17
#                                                                   #
3 soulskater 18
# Web: http://www.osource.se/                                       #
2 soulskater 19
#                                                                   #
3 soulskater 20
# Last Updated:	2014-05-18 18:43                                    #
2 soulskater 21
#                                                                   #
22
#####################################################################
23
 
24
### BEGIN INIT INFO
25
# Provides:          oBacklight
26
# Required-Start:    $acpid
27
# Required-Stop:
28
# Default-Start:     5
29
# Default-Stop:      0 1 2 3 6
30
# Short-Description: Provides a backlight event handler for nvidiabl
31
# Description:       Captures all backlight events from ACPI Events and feeds them to nvidiabl.
32
### END INIT INFO
33
 
34
init() {
35
## Default parameters
36
BMT="1"			# Set Brightness Mode Types.
37
			# Available types: 1, 2, 3, 4
38
 
39
ACPIS="1"		# Set correct System ACPI codes.
40
			# Available settings: 1, 2, 3
41
 
42
## Various brightness modes
43
# Mode 1 (Default)
44
if [ "$BMT" == "1" ]
45
then
46
  BBL="2"		# Default brightness level when on battery.
47
  DID="1"		# The amount of steps to increase/decrease with on backlight changes.
48
  MBV="7"		# Max brightness value possible on your system.
49
fi
50
# Mode 2
51
if [ "$BMT" == "2" ]
52
then
53
  BBL="40"
54
  DID="10"
55
  MBV="127"
56
fi
57
# Mode 3
58
if [ "$BMT" == "3" ]
59
then
60
  BBL="4"
61
  DID="1"
62
  MBV="32"
63
fi
64
# Mode 4
65
# Tested on a VPCCW15FL, thanks to Esteban
66
if [ "$BMT" == "4" ]
67
then
68
  BBL="40"
69
  DID="17"
70
  MBV="120"
71
fi
72
 
73
## ACPI Codes for various systems.
74
 
75
# ACPIS 1(Default)
76
# Works on some Sony Vaio VPCCW1S1E
77
if [ "$ACPIS" == "1" ]
78
then
79
  ACBU="00000001 00000011"	# ACPI brightness up event
80
  ACBD="00000001 00000010"	# ACPI brightness down event
81
  ACOB="00000081 00000000"	# ACPI brightness on battery event
82
fi
83
# ACPIS 2
84
# Works on some Sony Vaio VPCCW1S1E
85
if [ "$ACPIS" == "2" ]
86
then
87
  ACBU="00000086 00000000"
88
  ACBD="00000087 00000000"
89
  ACOB="00000081 00000000"
90
fi
91
# ACPIS 3
92
# Works on Dell Vostro 3700
93
if [ "$ACPIS" == "3" ]
94
then
95
  ACBU="00000086 00000000"
96
  ACBD="00000087 00000000"
97
  ACOB="00000080 00000000"
98
fi
99
 
100
# Set correct values in configuration files on startup
101
echo "$MBV" > /sys/class/backlight/nvidia_backlight/brightness
102
echo "$MBV" > /root/oBacklight.def
103
 
104
# Check if oBacklight.def exists
105
if [ ! -e "/root/oBacklight.def" ]
106
 then
107
  echo "$MBV" > /root/oBacklight.def
108
fi
109
}
110
 
111
start() {
112
 
113
/etc/init.d/oBacklight run &
114
 
115
}
116
 
117
stop() {
118
 
119
echo $(cat /sys/class/backlight/nvidia_backlight/brightness) > /root/oBacklight.def
120
killall -r oBacklight
121
 
122
}
123
 
124
run() {
125
while [ exit != 130 ]
126
do
127
 
128
GVAR=$(cat /sys/class/backlight/nvidia_backlight/brightness)
129
 
130
CMD=$(acpi_listen -c 1 | egrep -o " [0-9].+" | egrep -o "[0-9].+")
131
 
132
# Brightness down acpi event
133
if [ "$CMD" == "$ACBD" ]
134
 then
135
 
136
  if [ "$GVAR" -ge "$DID" ] # Thanks to damdim @ nvnews forum for this fix.
137
   then
138
    SVAR=$(($GVAR - $DID))
139
    echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
140
    echo $SVAR > /root/oBacklight.def
141
   else
142
    SVAR="0"
143
    echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
144
    echo $SVAR > /root/oBacklight.def
145
  fi
146
 
147
fi
148
 
149
# Brightness up acpi event
150
if [ "$CMD" == "$ACBU" ]
151
 then
152
  if [ "$GVAR" -le $(($MBV-$DID)) ] # Thanks to damdim @ nvnews forum for this fix.
153
   then
154
    SVAR=$(($GVAR + $DID))
155
    echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
156
    echo $SVAR > /root/oBacklight.def
157
   else
158
    SVAR=$MBV
159
    echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
160
    echo $SVAR > /root/oBacklight.def
161
  fi
162
fi
163
 
164
# AC to battery change
165
if [ "$CMD" == "$ACOB" ]
166
 then
167
  if [ "$GVAR" > "$BBL" ]
168
   then
169
    echo $BBL > /sys/class/backlight/nvidia_backlight/brightness
170
    echo $BBL > /root/oBacklight.def
171
  fi
172
fi
173
 
174
done
175
}
176
 
177
case $1 in
178
start)
179
start
180
;;
181
stop)
182
stop
183
;;
184
run)
185
init
186
run
187
;;
188
*)
189
echo "start|stop|run"
190
;;
191
esac