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:40:40 +0000 (12:40 +0200)
committerToni Jussila <toni.jussila@fudeco.com>
Thu, 18 Mar 2010 10:40:40 +0000 (12:40 +0200)
Merge branch 'development/GPS'

Conflicts:
Client/carmainwindow.cpp
Client/carmainwindow.h

1  2 
Client/carmainwindow.cpp
Client/carmainwindow.h
Client/carmainwindow.ui

@@@ -576,151 -447,38 +587,188 @@@ void CarMainWindow::userLogin(
  }
  
  /**
 +  * Resets Accelerometer measurement variables
 +  */
 +void CarMainWindow::resetAccelerometerMeasurements()
 +{
 +    currentAcceleration = 0;
 +    currentAccelerationString = "";
 +    currentSpeed = "";
 +    currentTime = 0;
 +    distanceTraveled = "";
 +    firstAcceleration = 0;
 +    //horsepower = null;
 +    isNewRun = true;
 +    //lastScreenUpdateInSeconds = 0;
 +    previousTime = 0;
 +    reverseAccelerationFlag = false;
 +    stopWatch.setHMS(0, 0, 0, 0);
 +    //accelerometer->stop();
 +    totalTime = "";
 +    vehicleStartedMoving = false;
 +    calculate->reset();
 +}
 +
 +/**
 +  * This function is called to handle checkpoints
 +  *@param totalTime total time elapsed since starting measurements
 +  *@param currentSpeed current speed of the device
 +  */
 +void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
 +{
 +    // TODO
 +    //totalTime;
 +    //currentSpeed;
 +    return;
 +}
 +
 +/**
 +  *This function is called to read (and process) data from the accelerometer
 +  */
 +void CarMainWindow::readAccelerometerData()
 +{
 +    QString s;
 +    double changeInAcceleration = 0;
 +    qreal x, y, z;
 +
 +    accelerometer->getAcceleration(x, y, z);
 +    accelerometer->smoothData(x, y, z);
 +
 +    // Apply calibration
 +    x -= accelerometer->getCalibrationX();
 +    y -= accelerometer->getCalibrationY();
 +    z -= accelerometer->getCalibrationZ();
 +
 +    QString str = QString("acc x: " + QString::number(x) + "\n" +
 +                          "acc y: " + QString::number(y) + "\n" +
 +                          "acc z: " + QString::number(z) + "\n");
 +
 +    if (!vehicleStartedMoving)
 +    {
 +        if (isNewRun)
 +        {
 +            firstAcceleration = sqrt(x*x + y*y + z*z);
 +            //firstAcceleration = y; // first read
 +            isNewRun = false;
 +        }
 +    }
 +
 +    currentAcceleration = sqrt(x*x + y*y + z*z);
 +    changeInAcceleration = (currentAcceleration - firstAcceleration); // firstAcceleration only gets set once
 +
 +    if (((abs(changeInAcceleration) <= accelerationStartThreshold)
 +                && !vehicleStartedMoving))
 +    {
 +        return;
 +    }
 +
 +    if (reverseAccelerationFlag)
 +    {
 +        // will be false until after 1st calculation
 +        if ((changeInAcceleration <= 0))
 +        {
 +            // actually increasing here...
 +            changeInAcceleration = abs(changeInAcceleration);
 +        }
 +        else
 +        {
 +            // actually decreasing here...
 +            changeInAcceleration = (changeInAcceleration * -1);
 +        }
 +    }
 +    if (!vehicleStartedMoving)
 +    {
 +        if ((changeInAcceleration < 0))
 +        {
 +            // we started to move backwards first time through
 +            reverseAccelerationFlag = true;
 +            changeInAcceleration = abs(changeInAcceleration);
 +        }
 +        vehicleStartedMoving = true;
 +
 +        stopWatch.setHMS(0, 0, 0, 0);
 +        stopWatch.start();
 +    }
 +    //  keep the following line as close to the SetKinematicsProperties method as possible
 +    currentTime = stopWatch.elapsed();
 +    calculate->calculateParameters(changeInAcceleration, (currentTime - previousTime)/1000);
 +    previousTime = currentTime;
 +
 +    s.sprintf("%.2f", changeInAcceleration);
 +    currentAccelerationString = s;
 +
 +    double speed = 0.0;
 +    speed = calculate->getCurrentSpeed();
 +    speed = ((speed*1000)/kSecondsInHour);
 +    s.sprintf("%.2f", speed);
 +    currentSpeed = s;
 +
 +    s.sprintf("%.2f", calculate->getDistanceTraveled());
 +    distanceTraveled = s;
 +
 +    // TODO
 +    //distanceTraveled;
 +    //horsepower;
 +    //totalTime;
 +
 +    s.sprintf("%.2f", calculate->getTotalTime());
 +    totalTime = s;
 +
 +    str.append("ca: " + currentAccelerationString + " G\n" );
 +    str.append("cspeed: " + currentSpeed + " km/h \n" );
 +    str.append("dist: " + distanceTraveled + " m \n" );
 +    str.append("time: " + totalTime + " s \n" );
 +
 +    if ((stopTime > 0) && (previousTime >= stopTime))
 +    {
 +        // we want to end at a stopping point that the user chose
 +        // output results
 +        resetAccelerometerMeasurements();
 +    }
 +}
 +
 +/**
 +  *This function is used to calibrate accelerometer
 +  */
 +void CarMainWindow::calibrateAccelerometer()
 +{
 +    resetAccelerometerMeasurements();
 +    accelerometer->calibrate();
 +}
++
++/**
+   *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");
+         }
+     }
+ }
@@@ -41,7 -39,8 +41,9 @@@
  #include "categorylist.h"
  #include "httpclient.h"
  #include "routedialog.h"
 +#include "calculate.h"
+ #include "gpsdata.h"
+ #include <maemo5location.h>
  
  namespace Ui {
      class CarMainWindow;
@@@ -121,7 -94,8 +125,9 @@@ signals
      void userNameChanged();
  
  private slots:
 +    void on_pushButtonShowResultDialog_clicked();
+     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();
Simple merge