Diff of /trunk/src/gps.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 117 by harbaum, Fri Mar 6 13:41:08 2009 UTC revision 118 by harbaum, Mon Mar 9 14:28:35 2009 UTC
# Line 23  Line 23 
23    
24  #include "appdata.h"  #include "appdata.h"
25    
26    #ifdef ENABLE_LIBLOCATION
27    
28    #include <location/location-gps-device.h>
29    
30    pos_t *gps_get_pos(appdata_t *appdata) {
31      gps_state_t *gps_state = appdata->gps_state;
32      static pos_t retval;
33    
34      if(!gps_state->fix)
35        return NULL;
36    
37      retval.lat = gps_state->latitude;
38      retval.lon = gps_state->longitude;
39    
40      return &retval;
41    }
42    
43    static void
44    location_changed(LocationGPSDevice *device, gps_state_t *gps_state) {
45    
46      gps_state->fix =
47        (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET);
48    
49      if(gps_state->fix) {
50        gps_state->latitude = device->fix->latitude;
51        gps_state->longitude = device->fix->longitude;
52      }
53    }
54    
55    void gps_init(appdata_t *appdata) {
56      gps_state_t *gps_state = appdata->gps_state = g_new0(gps_state_t, 1);
57    
58      printf("GPS init: Using liblocation\n");
59    
60      gps_state->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
61      if(!gps_state->device) {
62        printf("Unable to connect to liblocation\n");
63        return;
64      }
65    
66      gps_state->idd_changed =
67        g_signal_connect(gps_state->device, "changed",
68                         G_CALLBACK(location_changed), gps_state);
69    
70      gps_state->control = location_gpsd_control_get_default();
71      if(gps_state->control->can_control) {
72        printf("Having control over GPSD, starting it\n");
73        location_gpsd_control_start(gps_state->control);
74      }
75    }
76    
77    void gps_release(appdata_t *appdata) {
78      gps_state_t *gps_state = appdata->gps_state;
79    
80      if(!gps_state->device) return;
81    
82      /* Disconnect signal */
83      if(gps_state->control->can_control) {
84        printf("Having control over GPSD, stopping it\n");
85        location_gpsd_control_stop(gps_state->control);
86      }
87    
88      g_signal_handler_disconnect(gps_state->device, gps_state->idd_changed);
89    
90      g_free(appdata->gps_state);
91      appdata->gps_state = NULL;
92    }
93    
94    #else  // ENABLE_LIBLOCATION
95    
96  #ifdef ENABLE_GPSBT  #ifdef ENABLE_GPSBT
97  #include <gpsbt.h>  #include <gpsbt.h>
98  #include <gpsmgr.h>  #include <gpsmgr.h>
# Line 245  gpointer gps_thread(gpointer data) { Line 315  gpointer gps_thread(gpointer data) {
315  void gps_init(appdata_t *appdata) {  void gps_init(appdata_t *appdata) {
316    appdata->gps_state = g_new0(gps_state_t, 1);    appdata->gps_state = g_new0(gps_state_t, 1);
317    
318      printf("GPS init: Using gpsd\n");
319    
320    /* start a new thread to listen to gpsd */    /* start a new thread to listen to gpsd */
321    appdata->gps_state->mutex = g_mutex_new();    appdata->gps_state->mutex = g_mutex_new();
322    appdata->gps_state->thread_p =    appdata->gps_state->thread_p =
# Line 256  void gps_release(appdata_t *appdata) { Line 328  void gps_release(appdata_t *appdata) {
328    gpsbt_stop(&appdata->gps_state->context);    gpsbt_stop(&appdata->gps_state->context);
329  #endif  #endif
330    g_free(appdata->gps_state);    g_free(appdata->gps_state);
331      appdata->gps_state = NULL;
332  }  }
333    
334    #endif // ENABLE_LIBLOCATION

Legend:
Removed from v.117  
changed lines
  Added in v.118