tortuga DataLogging Library: battery, speed, time, average...
Fork of DataLogging by
Diff: Data.cpp
- Revision:
- 2:f3c2bf5521e5
- Parent:
- 1:6e25c2b5c20c
- Child:
- 3:610ace66d7af
--- a/Data.cpp Fri Apr 29 15:51:04 2016 +0000 +++ b/Data.cpp Sat Apr 30 13:29:23 2016 +0000 @@ -1,56 +1,46 @@ #include "mbed.h" #include "Data.h" -//#include "eeprom.h" -#define Period 1 //1000ms #define PPR 1 // Pulses Per Rotation #define periphery 2.233168 //periphery of the wheel, in this example a 28" wheel. -/*#define EEPROM_ADDR 0x0 // I2c EEPROM address is 0x00 -#define SDA PB_9 // I2C SDA pin -#define SCL PB_8 // I2C SCL pin - -EEPROM mem(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);*/ +#define Period 1 //1000ms -int count; -time_t StartTime; -double distance; -double lastDistance; -int lastCount; - -void Data::interval(void){ +//CONSTRUCTOR +Data::Data( float startDistance, uint32_t startTime) : + //count(0), + distance(startDistance), + lastDistance(startDistance), + StartTime(time(NULL)-startTime) + { + + } + +void Data::interval(int count){ lastDistance = count * periphery / PPR; distance += lastDistance; lastCount = count; - count = 0; + //count = 0; printf("distance: %f \r\nTime Passed: %i:%i\nAverage: %f\nSpeed: %f\n\n",distance, (time(NULL) - StartTime)/60, (time(NULL) - StartTime)%60, (distance/(time(NULL) - StartTime) * 3.6),(lastDistance/Period * 3.6)); } -void Data::pressed(){ +/*void Data::pressed(){ count++; -} +}*/ -Data::Data(PinName pin) : button(pin){ - StartTime = time(NULL); - count = 0; - distance = 0; - tick.attach(this,&Data::interval,Period); - button.fall(this,&Data::pressed); - } - -double Data::getDistance(void){ +float Data::getDistance(void){ return distance; } -int Data::getTime(void){ - return time(NULL) - StartTime; +uint32_t Data::getTime(void){ + return (uint32_t)(time(NULL) - StartTime); } -double Data::getSpeed(void){ +float Data::getSpeed(void){ return lastDistance/Period * 3.6; } -double Data::getAverage(void){ +float Data::getAverage(void){ return distance/(time(NULL) - StartTime) * 3.6; }