Merge branch 'fixing/MeasuresClass'
authorJanne Änäkkälä <janne.anakkala@fudeco.com>
Thu, 25 Mar 2010 11:01:39 +0000 (13:01 +0200)
committerJanne Änäkkälä <janne.anakkala@fudeco.com>
Thu, 25 Mar 2010 11:01:39 +0000 (13:01 +0200)
1  2 
Client/carmainwindow.cpp
Client/carmainwindow.h

diff --combined Client/carmainwindow.cpp
@@@ -14,8 -14,8 +14,8 @@@
  #include "carmainwindow.h"
  #include "math.h"
  
 -#define kAccelerometerSampleRate    50
 -#define kFilteringFactor            0.2
 +#define kAccelerometerSampleRate    40
 +#define kFilteringFactor            0.1
  #define kSecondsInHour              3600
  
  /**
@@@ -26,11 -26,6 +26,11 @@@ CarMainWindow::CarMainWindow(QWidget *p
  {
      ui->setupUi(this);
      ui->tabWidget->setCurrentWidget(this->ui->StartTab);
 +
 +    //Disable start buttons before calibration
 +    ui->autoStartButton->setEnabled(false);
 +    ui->manualStartButton->setEnabled(false);
 +
      result = new ResultDialog();
      //measure = new MeasureDialog();
      welcomeDialog = new WelcomeDialog();
@@@ -75,7 -70,7 +75,7 @@@
      isNewRun = true;
      isSetup = false;
      stopTime = 0;
 -    accelerationStartThreshold = 0.02;
 +    accelerationStartThreshold = 0.1;
  
      accelerometerTimer = new QTimer(this);
      connect(accelerometerTimer, SIGNAL(timeout()), this, SLOT(readAccelerometerData()));
@@@ -88,7 -83,7 +88,7 @@@
      resetAccelerometerMeasurements();
  
      measures = new Measures();
-     this->initializeMeasures();
+     measures->initializeMembers();
  
      this->timer->setInterval(100);
  
@@@ -167,7 -162,7 +167,7 @@@ void CarMainWindow::on_listViewStartTab
    */
  void CarMainWindow::on_autoStartButton_clicked()
  {
-     initializeMeasures();
+     measures->initializeMembers();
      resetAccelerometerMeasurements();
      ui->pushButtonSendResult->setEnabled(false);
      ui->pushButtonShowResultDialog->setEnabled(false);
@@@ -359,27 -354,20 +359,20 @@@ void CarMainWindow::on_manualStartButto
    */
  void CarMainWindow::after_timeout()
  {
-     if ( gpsSpeed > 1.0 )
+     //IF GPS checkbox is ON
+     if (ui->gpsOnCheckBox->isChecked())
      {
-         timeFromGps += 0.1;
+         if ( gpsSpeed > 1.0 )
+         {
+             timeFromGps += 0.1;
+         }
      }
- }
  
- /**
-   * Initializes measures class's member variables.
-   */
- void CarMainWindow::initializeMeasures()
- {
-     measures->setTime10kmh(0);
-     measures->setTime20kmh(0);
-     measures->setTime30kmh(0);
-     measures->setTime40kmh(0);
-     measures->setTime50kmh(0);
-     measures->setTime60kmh(0);
-     measures->setTime70kmh(0);
-     measures->setTime80kmh(0);
-     measures->setTime90kmh(0);
-     measures->setTime100kmh(0);
+     else
+     {
+         ui->labelMeasureTabSpeed->setText(QString::number(this->speed)); //Set speed. //Measure-tab view.
+         ui->labelMeasureTabTime->setText(QString::number(this->time)); //Set time. //Measure-tab view.
+     }
  }
  
  /**
@@@ -392,16 -380,7 +385,7 @@@ void CarMainWindow::on_pushButtonMeasur
      ui->labelMeasureTabResult->hide();
      ui->labelMeasureTabTime->setText("");
      ui->labelMeasureTabSpeed->setText("");
-     measures->setTime10kmh(0);
-     measures->setTime20kmh(0);
-     measures->setTime30kmh(0);
-     measures->setTime40kmh(0);
-     measures->setTime50kmh(0);
-     measures->setTime60kmh(0);
-     measures->setTime70kmh(0);
-     measures->setTime80kmh(0);
-     measures->setTime90kmh(0);
-     measures->setTime100kmh(0);
+     measures->initializeMembers();
      this->accelerometerTimer->stop();
      this->timer->stop();
      this->time = 0;
@@@ -484,13 -463,13 +468,13 @@@ void CarMainWindow::resetAccelerometerM
      currentSpeed = "";
      currentTime = 0;
      distanceTraveled = "";
 -    firstAcceleration = 0;
 +    //firstAcceleration = 0;
      //horsepower = null;
      isNewRun = true;
      //lastScreenUpdateInSeconds = 0;
      previousTime = 0;
      reverseAccelerationFlag = false;
 -    stopWatch.setHMS(0, 0, 0, 0);
 +    stopWatch.start();
      //accelerometer->stop();
      totalTime = "";
      vehicleStartedMoving = false;
@@@ -603,11 -582,7 +587,11 @@@ void CarMainWindow::readAccelerometerDa
      qreal x, y, z;
  
      accelerometer->getAcceleration(x, y, z);
 -    accelerometer->smoothData(x, y, z);
 +
 +    //  keep the following line as close to the SetKinematicsProperties method as possible
 +    currentTime = stopWatch.elapsed();
 +
 +    //accelerometer->smoothData(x, y, z);
  
      // Apply calibration
      x -= accelerometer->getCalibrationX();
                            "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
 +    currentAcceleration = z;//sqrt(x*x + y*y + z*z);
 +    changeInAcceleration = currentAcceleration;
  
      if (((fabs(changeInAcceleration) <= accelerationStartThreshold)
                  && !vehicleStartedMoving))
      {
          return;
      }
 -
 -    if (reverseAccelerationFlag)
 +    else if(!vehicleStartedMoving)
      {
 -        // will be false until after 1st calculation
 -        if ((changeInAcceleration <= 0))
 -        {
 -            // actually increasing here...
 -            changeInAcceleration = fabs(changeInAcceleration);
 -        }
 -        else
 -        {
 -            // actually decreasing here...
 -            changeInAcceleration = (changeInAcceleration * -1);
 -        }
 -    }
 -    if (!vehicleStartedMoving)
 -    {
 -        if ((changeInAcceleration < 0))
 -        {
 -            // we started to move backwards first time through
 -            reverseAccelerationFlag = true;
 -            changeInAcceleration = fabs(changeInAcceleration);
 -        }
          vehicleStartedMoving = true;
 -
 -        stopWatch.setHMS(0, 0, 0, 0);
          stopWatch.start();
 +        previousTime = 0;
 +        currentTime = 0;
      }
 -    //  keep the following line as close to the SetKinematicsProperties method as possible
 -    currentTime = stopWatch.elapsed();
 +
      calculate->calculateParameters(changeInAcceleration, (currentTime - previousTime)/1000);
      previousTime = currentTime;
  
  
      speed = 0.0;
      speed = calculate->getCurrentSpeed();
 -    speed = ((speed*1000)/kSecondsInHour);
 -    s.sprintf("%.2f", speed);
 +    speed = speed*3.6;//((speed*1000)/kSecondsInHour);
 +    s.sprintf("%.1f", speed);
      currentSpeed = s;
  
      s.sprintf("%.2f", calculate->getDistanceTraveled());
@@@ -840,11 -847,3 +824,11 @@@ void CarMainWindow::setTimeAxisGapAndSh
          result->setDiagramGapHorizontal(20);
      }
  }
 +
 +void CarMainWindow::on_calibrateButton_clicked()
 +{
 +    ui->autoStartButton->setEnabled(true);
 +    ui->manualStartButton->setEnabled(true);
 +
 +    this->accelerometer->calibrate();
 +}
diff --combined Client/carmainwindow.h
@@@ -78,7 -78,6 +78,6 @@@ private
      //void initCategoryCompoBox();
      void initComboBoxStartTabUnits();                   //Start-tab view
      void initListViewStartTabAccelerationCategories();  //Start-tab view
-     void initializeMeasures();
      void setListViewTopList(QString category, int size);    //Top-tab view
      void resetAccelerometerMeasurements();
      void calibrateAccelerometer();
@@@ -111,7 -110,7 +110,7 @@@ private
      double currentAcceleration;
      double currentTime;
      double previousTime;
 -    double firstAcceleration;
 +    //double firstAcceleration;
  
      QTimer *accelerometerTimer;
      QTime stopWatch;
@@@ -138,7 -137,6 +137,7 @@@ signals
      void userNameChanged();
  
  private slots:
 +    void on_calibrateButton_clicked();
      void gpsTimerTimeout();                             //Route-tab view
      void on_startRecPushButton_clicked();               //Route-tab view
      void on_pushButtonShowResultDialog_clicked();