Use custom script to start/stop gps
authorEnrico Zini <enrico@enricozini.org>
Wed, 2 Dec 2009 08:09:28 +0000 (09:09 +0100)
committerEnrico Zini <enrico@enricozini.org>
Wed, 2 Dec 2009 08:10:13 +0000 (09:10 +0100)
README
hooks/gps [new file with mode: 0755]
src/config.vala
src/gps.vala

diff --git a/README b/README
index 3340817501893fdc84c776a42914d9727cf8622a..6c520c069741f1ffbc95bae595723a233d6c3ce9 100644 (file)
--- a/README
+++ b/README
@@ -121,6 +121,9 @@ Features / guide
 
  Patches welcome.
 
+ Details: the alarms are scheduled with at(1). Please see omhacks for simple
+ suspend hooks that will wake up the phone to run scheduled at jobs.
+
  * Calendar
 
  You can reach the calendar from the menu or by clicking on the date in the
@@ -166,9 +169,9 @@ TODO list / wish list
       that they can be reinstated if zavai is restarted
     - show active alarms and allow to delete them
  - work without ogpsd
+    + power on/off the gps and start/stop gpsd
+    + set to keep the GPS on during suspend
     - use the gpsd protocol
-    - power on/off the gps and start/stop gpsd
-    - set to keep the GPS on during suspend
     - suspend/resume hooks to put the GPS into low power mode
  - next30: don't update if not shown currently on the notebook
  - gtk_calendar_set_detail_func
diff --git a/hooks/gps b/hooks/gps
new file mode 100755 (executable)
index 0000000..4102487
--- /dev/null
+++ b/hooks/gps
@@ -0,0 +1,39 @@
+#!/bin/sh
+case "$1" in
+       # At the start of zavai
+       status)
+               if [ `om gps power` = 1 ]
+               then
+                       if [ `pgrep -c gpsd` != 0 ]
+                       then
+                               echo on
+                       else
+                               echo off
+                       fi
+               else
+                       echo off
+               fi
+       ;;
+       # When starting the gps
+       start)
+               old=`om gps --swap power 1`
+               if [ $old = 0 ]
+               then
+                       om gpt keep_on_during_suspend 1
+                       /etc/init.d/gpsd stop
+                       # TODO: configure to UBX mode
+                       /etc/init.d/gpsd start
+               fi
+       ;;
+       # When stopping the gps
+       stop)
+               /etc/init.d/gpsd stop
+               om gps power 0
+       ;;
+       *)
+               echo "Usage: $0 {start|stop|status}." >&2
+               exit 1
+       ;;
+esac
+
+exit 0
index dec3b202c22844eb124256c8a7086d3e1569a123..ded93e9b56a4db30f4586a83554b978f6bf418f1 100644 (file)
@@ -29,7 +29,11 @@ public class Config
     public string gprs_apn { get; set; }
     public string gprs_user { get; set; }
     public string gprs_pass { get; set; }
-    public string argv0 { get; set; }
+    private string _argv0;
+    public string argv0 {
+           get { return _argv0; }
+           set { _argv0 = value; }
+    }
 
     public Config()
     {
index 6b37d80e012ab636a93e4494efaaf956e3d83137..0cf1b089b51f4bcf52adc539745d8958cb233f3d 100644 (file)
@@ -70,18 +70,39 @@ public class GPS: zavai.Service
        public override void start()
        {
                if (started) return;
+               bool done = false;
                try {
+                       // First try with FSO
                        usage.RequestResource("GPS");
-                       zavai.log.info("Acquired GPS");
-                       base.start();
+                       done = true;
                } catch (GLib.Error e) {
-                       zavai.log.error(e.message);
+                       zavai.log.error("Requesting resource GPS: " + e.message);
+               }
+               if (!done)
+               {
                        try {
+                               // Then make it work for fil
+                               // TODO: switch fil to om
                                zavai.app.run_script("om-device start gps");
+                               done = true;
                        } catch (Error e) {
-                               zavai.log.error("Running device start gps: " + e.message);
+                               zavai.log.error("Running om-device start gps: " + e.message);
                        }
                }
+               if (!done)
+               {
+                       try {
+                               // Then run our own script
+                               zavai.app.run_script(zavai.config.homedir + "/gps start");
+                               done = true;
+                       } catch (Error e) {
+                               zavai.log.error("Running " + zavai.config.homedir + "/gps on: " + e.message);
+                       }
+               }
+               if (done)
+                       zavai.log.info("GPS turned on");
+               else
+                       zavai.log.error("Could not turn on GPS");
                base.start();
        }
 
@@ -89,18 +110,35 @@ public class GPS: zavai.Service
        public override void stop()
        {
                if (!started) return;
+               bool done = false;
                try {
                        usage.ReleaseResource("GPS");
-                       zavai.log.info("Released GPS");
-                       base.stop();
+                       done = true;
                } catch (GLib.Error e) {
-                       zavai.log.error(e.message);
+                       zavai.log.error("Releasing resource GPS: " + e.message);
+               }
+               if (!done)
+               {
                        try {
                                zavai.app.run_script("om-device stop gps");
+                               done = true;
+                       } catch (Error e) {
+                               zavai.log.error("Running device stop gps: " + e.message);
+                       }
+               }
+               if (!done)
+               {
+                       try {
+                               zavai.app.run_script(zavai.config.homedir + "/gps stop");
+                               done = true;
                        } catch (Error e) {
                                zavai.log.error("Running device stop gps: " + e.message);
                        }
                }
+               if (done)
+                       zavai.log.info("GPS turned off");
+               else
+                       zavai.log.error("Could not turn off GPS");
                base.stop();
        }
 }