Added feature: GPS on/off and checks if at least 4 satellites is in use.
authorToni Jussila <toni.jussila@fudeco.com>
Thu, 18 Mar 2010 10:30:23 +0000 (12:30 +0200)
committerToni Jussila <toni.jussila@fudeco.com>
Thu, 18 Mar 2010 10:30:23 +0000 (12:30 +0200)
Client/carmainwindow.cpp
Client/carmainwindow.h
Client/carmainwindow.ui
Client/gpsdata.cpp
Client/gpsdata.h
Client/maemo5location.cpp
Client/maemo5location.h
Client/maemo5locationprivate.cpp
Client/maemo5locationprivate.h

index 1e3b7c7..c5c39ab 100644 (file)
@@ -36,6 +36,11 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     connect(myLogin,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
     myRoute = new RouteDialog( this);
 
+    //GPS
+    location = new Maemo5Location(this);
+    gpsData = new GPSData(location);
+    connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
+
     time = 0;
     speed = 0;
     timer = new QTimer();
@@ -58,16 +63,22 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
 }
 
 /**
-  *Destructor of this class. Should be used to release all allocated resources.
+  *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
   */
 CarMainWindow::~CarMainWindow()
 {
     delete ui;
+    ui = NULL;
     //delete result;
     //delete measure;
     delete categorylist;
+    categorylist = NULL;
     delete welcomeDialog;
+    welcomeDialog = NULL;
     delete myRoute;
+    myRoute = NULL;
+    delete gpsData;
+    gpsData = NULL;
 }
 
 /**
@@ -434,3 +445,40 @@ void CarMainWindow::userLogin()
 {
     myHttpClient->checkLogin();
 }
+
+/**
+  *This slot function is called when GPS on checkbox state changed.  Route-tab view.
+  *@param int GPSState
+  */
+void CarMainWindow::on_gpsOnCheckBox_stateChanged(int GPSState)
+{
+    if (GPSState == 0)
+    {
+        ui->labelRouteTabGPSStatus->setText("GPS off");//testing
+        location->stopPollingGPS();
+    }
+    else
+    {
+        ui->labelRouteTabGPSStatus->setText("GPS on");//testing
+        location->startPollingGPS();
+    }
+}
+
+/**
+  *This slot function is called when GPS status changed.  Route-tab view.
+  */
+void CarMainWindow::gpsStatus()
+{
+    if (ui->gpsOnCheckBox->isChecked())
+    {
+        if (location->getSatellitesInUse() >= 4)
+        {
+            ui->labelRouteTabGPSStatus->setText("GPS ready");
+        }
+
+        else
+        {
+            ui->labelRouteTabGPSStatus->setText("Waiting for GPS");
+        }
+    }
+}
index a65818f..8366c46 100644 (file)
@@ -39,6 +39,8 @@
 #include "categorylist.h"
 #include "httpclient.h"
 #include "routedialog.h"
+#include "gpsdata.h"
+#include <maemo5location.h>
 
 namespace Ui {
     class CarMainWindow;
@@ -69,6 +71,8 @@ private:
     HttpClient *myHttpClient;
     LoginWindow *myLogin;
     RouteDialog *myRoute;
+    GPSData *gpsData;
+    Maemo5Location *location;
     //void initCategoryCompoBox();
     void initComboBoxStartTabUnits();                   //Start-tab view
     void initListViewStartTabAccelerationCategories();  //Start-tab view
@@ -90,6 +94,8 @@ signals:
     void userNameChanged();
 
 private slots:
+    void on_gpsOnCheckBox_stateChanged(int GPSState);   //Route-tab view
+    void gpsStatus();                                   //Route-tab view
     void on_drawRoutePushButton_clicked();
     void on_pushButtonSendResult_clicked();
     void on_pushButtonMeasureTabAbort_clicked();
index f619f55..e5f7a8a 100644 (file)
        <string>Draw route</string>
       </property>
      </widget>
+     <widget class="QWidget" name="">
+      <property name="geometry">
+       <rect>
+        <x>310</x>
+        <y>16</y>
+        <width>221</width>
+        <height>211</height>
+       </rect>
+      </property>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QLabel" name="labelRouteTabGPSStatus">
+         <property name="text">
+          <string>Label GPS Status</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="labelRouteTabLatitude">
+         <property name="text">
+          <string>Label Latitude</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="labelRouteTabLongitude">
+         <property name="text">
+          <string>Label Longitude</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </widget>
    <widget class="QPushButton" name="registratePushButton">
index 4dd783e..aa0b436 100644 (file)
@@ -11,9 +11,9 @@
 /**
   *Default constructor of this class.
   */
-GPSData::GPSData()
+GPSData::GPSData(Maemo5Location *maemo5location)
 {
-    location = new Maemo5Location(this);
+    location = maemo5location;
 
     connect(location,SIGNAL(agnss()),this,SLOT(agnss()));
     connect(location,SIGNAL(awcp()),this,SLOT(awcp()));
@@ -39,6 +39,7 @@ void GPSData::agnss()
     QString satellitesInUse = QString::number(location->getSatellitesInUse());  //Returns number of satellites in use.
     QString satellitesInView = QString::number(location->getSatellitesInView());//Returns number of satellites in view.
     QString signalStrength = QString::number(location->getSignalStrength());    //Returns average signal strength of satellites which are in use.
+    QString gpsOnline = QString::number(location->getGpsOnline());              //Returns gsp online
     QString latitude = QString::number(location->getLatitude());                //Returns latitude.
     QString longitude = QString::number(location->getLongitude());              //Returns longitude.
     QString time = QString::number(location->getTime());                        //Returns timestamp of the update in seconds.
index b51a929..51ee130 100644 (file)
@@ -14,8 +14,9 @@
 
 class GPSData : public QObject
 {
+    Q_OBJECT
 public:
-    GPSData();
+    GPSData(Maemo5Location *maemo5location);
     ~GPSData();
 
 private:
index b294c53..d869419 100755 (executable)
@@ -18,16 +18,14 @@ Maemo5Location::Maemo5Location(QObject* parent):QObject(parent)
 {
     ptr = new Maemo5LocationPrivate(this);
 
-    connect(ptr,SIGNAL(agnss()),this,SIGNAL(agnss()));
-    connect(ptr,SIGNAL(awcp()),this,SIGNAL(awcp()));
-    connect(ptr,SIGNAL(locationUpdated()),this,SIGNAL(locationUpdated()));
+    connect(ptr, SIGNAL(agnss()), this, SIGNAL(agnss()));
+    connect(ptr, SIGNAL(awcp()), this, SIGNAL(awcp()));
+    connect(ptr, SIGNAL(locationUpdated()), this, SIGNAL(locationUpdated()));
     connect(ptr, SIGNAL(gps_connected()), this, SIGNAL(gps_connected()));
     connect(ptr, SIGNAL(gps_disconnected()), this, SIGNAL(gps_disconnected()));
     connect(ptr, SIGNAL(gps_err(int)), this, SIGNAL(gps_error(int)));
     connect(ptr, SIGNAL(gpsd_running()), this, SIGNAL(gpsd_running()));
-    connect(ptr, SIGNAL(gpsd_stopped()), this, SIGNAL(gpsd_stopped()));
-
-    ptr->get_agnss();
+    connect(ptr, SIGNAL(gpsd_stopped()), this, SIGNAL(gpsd_stopped())); 
 }
 
 /**
@@ -39,19 +37,19 @@ Maemo5Location::~Maemo5Location()
 }
 
 /**
-  *Returns latitude.
+  *Start polling gps.
   */
-double Maemo5Location::getLatitude()
+void Maemo5Location::startPollingGPS()
 {
-    return ptr->get_lat();
+    ptr->get_agnss();
 }
 
 /**
-  *Returns longitude.
+  *Stop polling gps.
   */
-double Maemo5Location::getLongitude()
+void Maemo5Location::stopPollingGPS()
 {
-    return ptr->get_lon();
+    ptr->stop();
 }
 
 /**
@@ -79,6 +77,30 @@ int Maemo5Location::getSignalStrength()
 }
 
 /**
+  *Returns gps online.
+  */
+bool Maemo5Location::getGpsOnline()
+{
+    return ptr->get_gps_online();
+}
+
+/**
+  *Returns latitude.
+  */
+double Maemo5Location::getLatitude()
+{
+    return ptr->get_lat();
+}
+
+/**
+  *Returns longitude.
+  */
+double Maemo5Location::getLongitude()
+{
+    return ptr->get_lon();
+}
+
+/**
   *Returns timestamp of the update in seconds.
   */
 double Maemo5Location::getTime()
index c16decb..2e69b75 100755 (executable)
@@ -20,9 +20,12 @@ public:
     Maemo5Location(QObject* parent = 0);
     ~Maemo5Location();
 
+    void startPollingGPS();
+    void stopPollingGPS();
     int getSatellitesInUse();
     int getSatellitesInView();
     int getSignalStrength();
+    bool getGpsOnline();
     double getLatitude();
     double getLongitude();
     double getTime();
index 5e4374a..5bde883 100755 (executable)
@@ -62,7 +62,7 @@ void Maemo5LocationPrivate::get_agnss()
 }
 
 /**
-  *Stop pollling
+  *Stop polling gps
   */
 void Maemo5LocationPrivate::stop()
 {
@@ -180,7 +180,7 @@ void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
             gps->satellites_in_use = gps->device->satellites_in_use;
             gps->satellites_in_view = gps->device->satellites_in_view;
 
-            if(gps->device->fix->fields &       LOCATION_GPS_DEVICE_TIME_SET)
+            if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET)
             {
                 gps->time = gps->device->fix->time;
                 gps->ept = gps->device->fix->ept;
@@ -217,7 +217,7 @@ void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
             {
                 for(int i=0 ; i < gps->satellites_in_use ; i++)
                 {
-                    LocationGPSDeviceSatellite * view = (LocationGPSDeviceSatellite*) g_ptr_array_index (gps->device->satellites, i);
+                    LocationGPSDeviceSatellite *view = (LocationGPSDeviceSatellite*) g_ptr_array_index (gps->device->satellites, i);
                     temp = temp + view->signal_strength;
                 }
                 gps->signal_strength = (temp / gps->satellites_in_use);
index 14b3bba..9d35b27 100755 (executable)
@@ -58,6 +58,7 @@ public:
     double get_climb() { return climb; }
     double get_epc() { return epc; }
     double distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f);
+    void stop();
 
 signals:
     void awcp();
@@ -71,7 +72,7 @@ signals:
 
 private:
     void resetAll();
-    void stop();
+    //void stop();
     void restart();
 
     int satellites_in_view;