pandora-scripts: unhardcode some sysfs paths
[openpandora.oe.git] / recipes / pandora-system / pandora-state / rc.pandora-state
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          pandora-lcd-state
5 # Required-Start:    #adjust
6 # Required-Stop:     #adjust
7 # Default-Start:     S
8 # Default-Stop:      0 1 6
9 ### END INIT INFO
10  
11 DESC="OpenPandora Save and Restore LCD Settings"
12 NAME="pandora-state"
13
14 . /usr/pandora/scripts/op_paths.sh
15
16 d_stop() {
17         echo "Saving Pandora specific settings"
18         bright=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
19         if [ $bright != "0" ]; then
20             echo $bright > /etc/pandora/conf/brightness.state
21         fi
22         touch /etc/pandora/shutdown
23         cat $SYSFS_GAMMA > /etc/pandora/conf/gamma.state
24         cat -v /proc/pandora/nub0/mode | sed -n '1p' > /etc/pandora/conf/nubs.state
25         cat -v /proc/pandora/nub0/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
26         cat -v /proc/pandora/nub0/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
27         cat -v /proc/pandora/nub0/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
28         cat -v /proc/pandora/nub0/scroll_rate| sed -n '1p' >> /etc/pandora/conf/nubs.state
29         cat -v /proc/pandora/nub0/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
30         cat -v /proc/pandora/nub1/mode | sed -n '1p' >> /etc/pandora/conf/nubs.state
31         cat -v /proc/pandora/nub1/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
32         cat -v /proc/pandora/nub1/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
33         cat -v /proc/pandora/nub1/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
34         cat -v /proc/pandora/nub1/scroll_rate | sed -n '1p' >> /etc/pandora/conf/nubs.state
35         cat -v /proc/pandora/nub1/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
36 }
37
38 d_start() {
39         echo "Restoring Pandora specific settings"
40         bright=$(cat /etc/pandora/conf/brightness.state)
41         if [ "$bright" -gt "0" ]; then
42                 echo $bright > $SYSFS_BACKLIGHT_BRIGHTNESS
43         fi
44         cat /etc/pandora/conf/dirty_expire_centisecs >  /proc/sys/vm/dirty_expire_centisecs
45         cat /etc/pandora/conf/gamma.state > $SYSFS_GAMMA
46         if [ -f /etc/pandora/conf/filter.state ]; then
47                 filter=$(cat /etc/pandora/conf/filter.state)
48                 /usr/pandora/scripts/op_videofir.sh $filter 
49         fi
50         cpuspeed="$(cat /etc/pandora/conf/cpu.conf | grep default | awk -F\: '{print $2}')"
51         oppmax="$(cat /etc/pandora/conf/cpu.conf | grep opp | awk -F\: '{print $2}')"
52         echo $oppmax > /proc/pandora/cpu_opp_max
53         if [ -f /etc/pandora/shutdown ]; then
54               rm /etc/pandora/shutdown
55               sync
56               echo $cpuspeed > /proc/pandora/cpu_mhz_max
57         else
58               echo "No clean shutdown - will not set CPU speed"
59               touch /tmp/nocleanwarn
60         fi
61         sed -n '1p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mode
62         sed -n '2p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mouse_sensitivity
63         sed -n '3p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrollx_sensitivity
64         sed -n '4p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrolly_sensitivity
65         sed -n '5p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scroll_rate
66         sed -n '6p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_threshold
67         sed -n '7p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mode
68         sed -n '8p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mouse_sensitivity
69         sed -n '9p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrollx_sensitivity
70         sed -n '10p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrolly_sensitivity
71         sed -n '11p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scroll_rate
72         sed -n '12p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_threshold
73 }
74
75 case "$1" in
76   start)
77         echo -n "Starting $DESC: $NAME - "
78         d_start
79         echo "."
80         ;;
81   stop)
82         echo -n "Stopping $DESC: $NAME - "
83         d_stop
84         echo "."
85         ;;
86   reload)
87         echo -n "Reloading $DESC: $NAME - "
88         d_start
89         echo "."
90         ;;      
91   restart|force-reload)
92         echo -n "Restarting $DESC: $NAME - "
93         d_stop
94         sleep 1
95         d_start
96         echo "."
97         ;;
98   *)
99         echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
100         exit 1
101         ;;
102 esac
103
104 exit 0