tortuga DataLogging Library: battery, speed, time, average...

Dependents:   TORTUGA_BLE

Fork of DataLogging by aapje monkey

BikeData.cpp

Committer:
ptuytsch
Date:
2016-04-30
Revision:
2:f3c2bf5521e5
Child:
3:610ace66d7af

File content as of revision 2:f3c2bf5521e5:

#include "mbed.h"
#include "BikeData.h"
#include "Data.h"
#include "eeprom.h"

#define Period 1 //1000ms

#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);
/*
EEPROM ADRESSES:

0->3: overall distance
4->7: overall time
*/

//CONSTRUCTOR
BikeData::BikeData(PinName pin) : 
    button(pin),
    trackTrip(false),
    count(0)
    {
        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;
        tick.attach(this,&BikeData::interval,Period);
        button.fall(this,&BikeData::pressed);
    }
    
void BikeData::startTrip(){
    tripData = new Data(0,0);
    dataSet[TRIP] = tripData;
    trackTrip = true;
    }
    
void BikeData::pauzeTrip(){
    trackTrip = false;
    }

void BikeData::stopTrip(){
    trackTrip = false;
    }
    
void BikeData::pressed(void){
        count++;
    }
    
Data* BikeData::getDataSet(uint8_t type){
        return dataSet[type];
    }
    
void BikeData::interval(void){
        if(trackTrip){
             printf("Trip:\n");
             tripData->interval(count);
         }
        printf("Overall:\n");
        overallData->interval(count);
        mem.write(0,overallData->getDistance());
        mem.write(4,(int32_t)overallData->getTime());
        printf("batChange:\n");
        batChangeData->interval(count);
        count = 0;
    }