tortuga DataLogging Library: battery, speed, time, average...
Fork of DataLogging by
Diff: BikeData.cpp
- Revision:
- 3:610ace66d7af
- Parent:
- 2:f3c2bf5521e5
- Child:
- 4:f91f45d52f9b
--- a/BikeData.cpp Sat Apr 30 13:29:23 2016 +0000 +++ b/BikeData.cpp Tue Jul 12 11:54:41 2016 +0000 @@ -3,7 +3,9 @@ #include "Data.h" #include "eeprom.h" -#define Period 1 //1000ms +#define Period 1 //1000ms period of sampling +#define PPR 3 // Pulses Per Rotation +#define periphery 1.3 //periphery of the wheel in meters #define EEPROM_ADDR 0x0 // I2c EEPROM address is 0x00 #define SDA PB_9 // I2C SDA pin @@ -15,41 +17,68 @@ 0->3: overall distance 4->7: overall time +8: name size +9->...: bike name */ //CONSTRUCTOR BikeData::BikeData(PinName pin) : button(pin), - trackTrip(false), - count(0) + logging(false), + count(0), + lastDistance(0) { + //setting things up for logging the raw data. float readDistance; mem.read(0,readDistance); int32_t readTime; mem.read(4,readTime); - overallData = new Data(readDistance,readTime); - dataSet[OVERALL] = tripData; - batChangeData = new Data(0,0); - dataSet[BATCHANGE] = tripData; + overallData = new Data(readDistance,readTime,PPR,periphery); + dataSet[OVERALL] = overallData; + batChangeData = new Data(0.0,0,PPR,periphery); + dataSet[BATCHANGE] = batChangeData; tick.attach(this,&BikeData::interval,Period); button.fall(this,&BikeData::pressed); } +int8_t BikeData::getBikeNameSize(){ + int8_t size = 0; + mem.read(8,size); + return size; + } + +void BikeData::getBikeName(char *name){ + uint8_t size = getBikeNameSize(); + //uint8_t* name; + mem.read(9,name,size); + printf("name retrieved\n"); + //return name; + } + +void BikeData::setBikeName(char *name, uint8_t length){ + mem.write(8,length); + mem.write(9,name,length); + printf("name set\n"); + + } + void BikeData::startTrip(){ - tripData = new Data(0,0); - dataSet[TRIP] = tripData; - trackTrip = true; + //start trip function, creating new tripdata object + tripData = new Data(0.0,0,PPR,periphery); + dataSet[TRIP] = tripData; // setting the pointer position to the tripdata object + logging = true; // start logging } void BikeData::pauzeTrip(){ - trackTrip = false; + logging = !logging; } void BikeData::stopTrip(){ - trackTrip = false; + logging = false; } void BikeData::pressed(void){ + //count each pulse of the sensor count++; } @@ -57,16 +86,42 @@ return dataSet[type]; } +float BikeData::getSpeed(void){ + return lastDistance/Period * 3.6; + } + +uint8_t BikeData::getLastCount(void){ + return lastCount; + } + +bool BikeData::isLogging(void){ + return logging; + } + +//interval function is called each second to monitor the progress by the datasets void BikeData::interval(void){ - if(trackTrip){ - printf("Trip:\n"); - tripData->interval(count); + //keep the pointers well placed + dataSet[TRIP] = tripData; + dataSet[OVERALL] = overallData; + dataSet[BATCHANGE] = batChangeData; + //calculate the distances + lastDistance = count * periphery / PPR; + lastCount = count; + + //printf("\n==================\n\n"); // debugging + if(logging){ // only interval when needed + //printf("Trip:\n------------------\n"); + tripData->interval(count); // send interval to the tripdata object } - printf("Overall:\n"); + //printf("Overall:\n------------------\n"); overallData->interval(count); - mem.write(0,overallData->getDistance()); + mem.write(0,overallData->getDistance()); // update the eeprom values mem.write(4,(int32_t)overallData->getTime()); - printf("batChange:\n"); + + //printf("batChange:\n------------------\n"); batChangeData->interval(count); + + //printf("speed: %f\ncount: %i\n",lastDistance/Period * 3.6, lastCount); // debugging count = 0; - } \ No newline at end of file + } +