Zarro warnings.
[speedometer] / util.c
diff --git a/util.c b/util.c
index 63d644a..0b246f5 100644 (file)
--- a/util.c
+++ b/util.c
 #include "appdata.h"
 #include "callbacks.h"
 
-void start_gps(AppData* appdata) {
+static LocationGPSDevice *device = NULL;
+static LocationGPSDControl *control = NULL;
 
+void start_gps(AppData* appdata) {
 #ifdef __arm__
-       // gps device
-       LocationGPSDevice *device;
-       device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
-       g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
-
-       LocationGPSDControl *control;
-
+       if(!device) {
+               device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+               g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
+       }
        control = location_gpsd_control_get_default();
-       location_gpsd_control_start(control);
+       location_gpsd_control_request_status(control);
+       if(control->can_control) {
+               location_gpsd_control_start(control);
+               }
 #endif // __arm__
-
 }
 
 void stop_gps(AppData* appdata) {
-
+#ifdef __arm__
+       control = location_gpsd_control_get_default();
+       location_gpsd_control_request_status(control);
+       if(control->can_control) {
+               location_gpsd_control_stop(control);
+       }
+#endif // __arm__
 }