b9a2c25efa2506dc2e894d63da87957e07859e8f
[gregoa/zavai.git] / lindi / om-device
1 #!/bin/sh
2 . $HOME/.sysfsrc
3
4 mode="$1"
5 if [ "$mode" = "" ]; then
6     mode="list"
7 fi
8 case "$mode" in
9      stop)
10         dev="$2"
11         case "$dev" in
12             bt)
13                 sudo sh -c "echo 1 > $sys_pm_bt/reset"
14                 sudo sh -c "echo 0 > $sys_pm_bt_power"
15                 ;;
16             gsm)
17                 sudo sh -c "echo 0 > $sys_pm_gsm_power"
18                 ;;
19             gps)
20                 sudo sh -c "echo 0 > $sys_pm_gps_power"
21                 if [ `cat $sys_pm_gps_power` = 1 ]; then
22                     echo "error, retrying"
23                     sudo sh -c "echo 1 > $sys_pm_gps_power"
24                     sudo sh -c "echo 0 > $sys_pm_gps_power"
25                 fi
26                 ;;
27             wifi)
28                 sudo sh -c "echo s3c2440-sdi > $sys_wlan_driver/unbind"
29                 ;;
30             *)
31                 echo "unknown device $dev"
32                 exit 1
33                 ;;
34             esac
35         ;;
36     start)
37         dev="$2"
38         case "$dev" in
39             bt)
40                 sudo sh -c "echo 1 > $sys_pm_bt_power"
41                 sudo sh -c "echo 0 > $sys_pm_bt/reset"
42                 ;;
43             gsm)
44                 sudo sh -c "echo 0 > $sys_pm_gsm/power_on"
45                 sudo sh -c "echo 1 > $sys_pm_gsm/power_on"
46                 sudo sh -c "echo 1 > $sys_pm_gsm/reset"
47                 ;;
48             gps)
49                 sudo sh -c "echo 1 > $sys_pm_gps_power"
50                 ;;
51             wifi)
52                 sudo sh -c "echo s3c2440-sdi > $sys_wlan_driver/unbind" 2> /dev/null
53                 sudo sh -c "echo s3c2440-sdi > $sys_wlan_driver/bind"
54                 ;;
55             *)
56                 echo "unknown device $dev"
57                 exit 1
58                 ;;
59             esac
60         ;;
61         
62      list)
63         echo "bt `cat $sys_pm_bt_power`"
64         echo "gsm `cat $sys_pm_gsm_power`"
65         echo "gps `cat $sys_pm_gps_power`"
66         #echo "wifi ?"
67         wifi 2> /dev/null
68         ;;
69     measure-consumption)
70         echo turning $2 on
71         $0 start $2
72         for i in `seq 1 30`; do
73             echo $i `cat $sys_battery/current_now`
74             sleep 1
75         done
76         start=`cat $sys_battery/current_now`
77         echo turning $2 off
78         $0 stop $2
79         for i in `seq 1 40`; do
80             echo $i `cat $sys_battery/current_now`
81             sleep 1
82         done
83         end=`cat $sys_battery/current_now`
84         diff=`expr $start - $end`
85         echo difference $diff
86         ;;
87     *)
88         echo "unknown operation $mode"
89         exit 1
90         ;;
91 esac