Implement power cycling the GPS directly
authorEnrico Zini <enrico@enricozini.org>
Sun, 6 Sep 2009 19:51:18 +0000 (20:51 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 6 Sep 2009 19:51:18 +0000 (20:51 +0100)
src/app_gps.vala
src/gps.vala

index e1b8f842c61761f4ed72368d9ba7441551de80dc..88d41f9eca67f5966320ea9f3b7a7f175fe34dad 100644 (file)
@@ -174,17 +174,12 @@ public class GPSStuck : Gtk.Button
 
        public void on_clicked()
        {
 
        public void on_clicked()
        {
-               if (!happened)
-               {
-                       zavai.app.run_script(zavai.config.homedir + "/reset_gps");
+               zavai.gps.gps.power_cycle(happened);
+               happened = !happened;
+               if (happened)
                        label = "The GPS is stuck AGAIN";
                        label = "The GPS is stuck AGAIN";
-               }
                else
                else
-               {
-                       zavai.app.run_script(zavai.config.homedir + "/reset_gps again");
                        label = "The GPS is stuck";
                        label = "The GPS is stuck";
-               }
-               happened = !happened;
        }
 }
 
        }
 }
 
index 478f681e68db3871109e7fcfbad8d29d49b63ce2..0e5e30eb1916e811142e3b75193a36527c457a69 100644 (file)
@@ -45,6 +45,17 @@ public class GPS: zavai.Service
                        "org.freedesktop.Gypsy.Device");
        }
 
                        "org.freedesktop.Gypsy.Device");
        }
 
+    public void power_cycle(bool aggressive)
+    {
+        usage.SetResourcePolicy("GPS", "disabled");
+        if (aggressive)
+            // Sometimes the GPS crashes because its state contains something
+            // that makes it crash, so we need to remove the saved state or it
+            // crashes again quite soon
+            FileUtils.unlink("/var/lib/freesmartphone/ogpsd.pickle");
+        usage.SetResourcePolicy("GPS", "auto");
+    }
+
        /// Request GPS resource
        public override void start()
        {
        /// Request GPS resource
        public override void start()
        {