X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fcalculate.cpp;h=fb56f1256001ced5d5f0a436cea72cc3227bf181;hp=769c92aa61d2d8de552a40af8097aac03578764c;hb=136f3e02fe3b835e46a473cb3c505ce7f10aa44a;hpb=29e2a0b959f6e0f55796a9b9da9952c34411ca50 diff --git a/Client/calculate.cpp b/Client/calculate.cpp index 769c92a..fb56f12 100644 --- a/Client/calculate.cpp +++ b/Client/calculate.cpp @@ -36,7 +36,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 +49,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]; } @@ -64,6 +80,8 @@ void Calculate::reset() void Calculate::calculateParameters(double currentAcceleration, double seconds) { double force, power1, power2; + + currentAcceleration *= G_ACCELERATION; numOfIterations++; totalTime = (totalTime + seconds); @@ -73,6 +91,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)); @@ -104,27 +126,27 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) numOfIterations--; } - // Checkpoints - if ((lastSpeed == 0)) - { - lastCheckpoint = 0; - } - - // List of checkpoints - if (!(speedCheckPoints.isEmpty())) + if( (checkPoint > 0) && (currentSpeed*3.6 > checkPoint) ) { - 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() ) { - emit checkPointReached(totalTime, currentSpeed); - lastCheckpoint = floor(currentSpeed); + checkPoint = speedCheckPoints[checkPointCounter]; } + else + { + checkPoint = 0; + } + checkPointCounter++; } } // Check for movement - accelStoppedCheck(currentAcceleration); + //accelStoppedCheck(currentAcceleration); lastSpeed = currentSpeed; lastAcceleration = currentAcceleration; @@ -138,7 +160,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++; @@ -146,8 +167,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; } @@ -272,4 +293,13 @@ void Calculate::setAveragePower(double value) averagePower = value; } +double Calculate::getMaxSpeed() +{ + return maxSpeed; +} + +void Calculate::setMaxSpeed(double value) +{ + maxSpeed = value; +}