X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fcalculate.cpp;h=edd4246ad88600341b7c9f2b154538c68c756779;hp=aa579ec76b04a8464c766ccd7afd98bc92ceac37;hb=8d6763a38ab1191e6f213e023f9b0d71ab500066;hpb=8cd1d43340327e94690cb13de6bb2dbef00c9ec0 diff --git a/Client/calculate.cpp b/Client/calculate.cpp index aa579ec..edd4246 100644 --- a/Client/calculate.cpp +++ b/Client/calculate.cpp @@ -2,6 +2,7 @@ * Calculate class to process accelerometer data * * @author Kai Rasilainen + * @author Jukka Kurttila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -36,7 +37,11 @@ Calculate::~Calculate() void Calculate::reset() { averageSpeed = 0; + averagePower = 0; + peakPower = 0; + currentPower = 0; currentSpeed = 0; + maxSpeed = 0; distanceTraveled = 0; lastAcceleration = 0; lastDistance = 0; @@ -45,10 +50,22 @@ void Calculate::reset() totalTime = 0; count = 0; - speedCheckPoints.append(10); - speedCheckPoints.append(20); - speedCheckPoints.append(30); - speedCheckPoints.append(40); + if(speedCheckPoints.count() == 0) + { + speedCheckPoints.append(10); + speedCheckPoints.append(20); + speedCheckPoints.append(30); + speedCheckPoints.append(40); + speedCheckPoints.append(50); + speedCheckPoints.append(60); + speedCheckPoints.append(70); + speedCheckPoints.append(80); + speedCheckPoints.append(90); + speedCheckPoints.append(100); + } + + checkPointCounter = 0; + checkPoint = speedCheckPoints[checkPointCounter]; } @@ -75,6 +92,10 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) // First integration of acceleration provides speed currentSpeed = (lastSpeed + (((currentAcceleration + lastAcceleration) * seconds) / 2)); + // Update maximum speed + if (currentSpeed > maxSpeed) + maxSpeed = currentSpeed; + // Second integration: distance. distanceTraveled = (lastDistance + (((currentSpeed + lastSpeed) * seconds) / 2)); @@ -106,27 +127,27 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) numOfIterations--; } - // Checkpoints - if ((lastSpeed == 0)) + if( (checkPoint > 0) && (currentSpeed*3.6 > checkPoint) ) { - lastCheckpoint = 0; - } - - // List of checkpoints - if (!(speedCheckPoints.isEmpty())) - { - foreach (double speed, speedCheckPoints) + //Update checkPoint + if( checkPointCounter <= speedCheckPoints.count() ) { - if ((lastCheckpoint != floor(speed)) && (floor(currentSpeed) == floor(speed))) + //Save time + valuesMap.insert( checkPoint, totalTime ); + if( checkPointCounter < speedCheckPoints.count() ) + { + checkPoint = speedCheckPoints[checkPointCounter]; + } + else { - emit checkPointReached(totalTime, currentSpeed); - lastCheckpoint = floor(currentSpeed); + checkPoint = 0; } + checkPointCounter++; } } // Check for movement - accelStoppedCheck(currentAcceleration); + //accelStoppedCheck(currentAcceleration); lastSpeed = currentSpeed; lastAcceleration = currentAcceleration; @@ -140,7 +161,6 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) */ void Calculate::accelStoppedCheck(double currentAcceleration) { - // counting number of acceleration samples that equals zero if (currentAcceleration==0) { count++; @@ -148,8 +168,8 @@ void Calculate::accelStoppedCheck(double currentAcceleration) count = 0; } - // if count exceeds 15, we assume that velocity is zero - if (count >= 15) + // if count exceeds 25, we assume that velocity is zero + if (count >= 25) { currentSpeed=0; } @@ -274,4 +294,17 @@ void Calculate::setAveragePower(double value) averagePower = value; } +double Calculate::getMaxSpeed() +{ + return maxSpeed; +} + +void Calculate::setMaxSpeed(double value) +{ + maxSpeed = value; +} +QMap Calculate::getValuesMap() +{ + return valuesMap; +}