cell/gps only on maemo5
[googlelatitude] / src / gps.cpp
1 #include "gps.h"
2
3 #ifdef Q_WS_MAEMO_5
4
5 GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
6     latitude = 0;
7     longitude = 0;
8     accuracy = 0;
9     usegps = -1;
10
11     control = location_gpsd_control_get_default();
12     device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
13     g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
14 }
15
16 void GpsMaemo5::get_acwp() {
17     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
18     usegps = 0;
19     restart();
20 }
21
22 void GpsMaemo5::get_agnss() {
23     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
24     usegps = 1;
25     restart();
26 }
27
28 void GpsMaemo5::stop() {
29     location_gpsd_control_stop(control);
30 }
31
32 void GpsMaemo5::restart() {
33     location_gpsd_control_stop(control);
34     location_gpsd_control_start(control);
35 }
36
37 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
38     if (gps->device->fix) {
39         if (gps->device->fix->fields) {
40             g_print("lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
41             gps->latitude = gps->device->fix->latitude;
42             gps->longitude = gps->device->fix->longitude;
43             gps->accuracy = gps->device->fix->eph/100.;
44
45             if ( gps->usegps == 0) {
46                 emit gps->getOK_acwp();
47                 // if ( gps->accuracy < 100*1000 ) gps->stop();
48                 if ( gps->accuracy < 640*1000 ) gps->stop();
49             } else if ( gps->usegps == 1 ) {
50                 emit gps->getOK_agnss();
51                 // if ( device->satellites_in_use > 0 ) gps->stop();
52                 if ( gps->device->fix->mode == LOCATION_GPS_DEVICE_MODE_3D ) gps->stop();
53             } else {
54                 emit gps->getOK();
55             }
56         }
57     }
58 }
59
60 #endif