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

Dependents:   TORTUGA_BLE

Fork of DataLogging by aapje monkey

Committer:
ptuytsch
Date:
Fri Apr 29 15:51:04 2016 +0000
Revision:
1:6e25c2b5c20c
Parent:
0:ec76b22829d5
Child:
2:f3c2bf5521e5
good working base;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptuytsch 0:ec76b22829d5 1 #include "mbed.h"
ptuytsch 0:ec76b22829d5 2 #include "Data.h"
ptuytsch 1:6e25c2b5c20c 3 //#include "eeprom.h"
ptuytsch 1:6e25c2b5c20c 4
ptuytsch 1:6e25c2b5c20c 5 #define Period 1 //1000ms
ptuytsch 1:6e25c2b5c20c 6 #define PPR 1 // Pulses Per Rotation
ptuytsch 0:ec76b22829d5 7 #define periphery 2.233168 //periphery of the wheel, in this example a 28" wheel.
ptuytsch 0:ec76b22829d5 8
ptuytsch 1:6e25c2b5c20c 9 /*#define EEPROM_ADDR 0x0 // I2c EEPROM address is 0x00
ptuytsch 1:6e25c2b5c20c 10 #define SDA PB_9 // I2C SDA pin
ptuytsch 1:6e25c2b5c20c 11 #define SCL PB_8 // I2C SCL pin
ptuytsch 0:ec76b22829d5 12
ptuytsch 1:6e25c2b5c20c 13 EEPROM mem(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);*/
ptuytsch 0:ec76b22829d5 14
ptuytsch 0:ec76b22829d5 15 int count;
ptuytsch 0:ec76b22829d5 16 time_t StartTime;
ptuytsch 0:ec76b22829d5 17 double distance;
ptuytsch 0:ec76b22829d5 18 double lastDistance;
ptuytsch 0:ec76b22829d5 19 int lastCount;
ptuytsch 0:ec76b22829d5 20
ptuytsch 1:6e25c2b5c20c 21 void Data::interval(void){
ptuytsch 0:ec76b22829d5 22 lastDistance = count * periphery / PPR;
ptuytsch 0:ec76b22829d5 23 distance += lastDistance;
ptuytsch 0:ec76b22829d5 24 lastCount = count;
ptuytsch 0:ec76b22829d5 25 count = 0;
ptuytsch 1:6e25c2b5c20c 26 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));
ptuytsch 0:ec76b22829d5 27 }
ptuytsch 0:ec76b22829d5 28
ptuytsch 1:6e25c2b5c20c 29 void Data::pressed(){
ptuytsch 0:ec76b22829d5 30 count++;
ptuytsch 0:ec76b22829d5 31 }
ptuytsch 0:ec76b22829d5 32
ptuytsch 0:ec76b22829d5 33 Data::Data(PinName pin) : button(pin){
ptuytsch 0:ec76b22829d5 34 StartTime = time(NULL);
ptuytsch 0:ec76b22829d5 35 count = 0;
ptuytsch 0:ec76b22829d5 36 distance = 0;
ptuytsch 1:6e25c2b5c20c 37 tick.attach(this,&Data::interval,Period);
ptuytsch 1:6e25c2b5c20c 38 button.fall(this,&Data::pressed);
ptuytsch 0:ec76b22829d5 39 }
ptuytsch 0:ec76b22829d5 40
ptuytsch 0:ec76b22829d5 41 double Data::getDistance(void){
ptuytsch 0:ec76b22829d5 42 return distance;
ptuytsch 0:ec76b22829d5 43 }
ptuytsch 0:ec76b22829d5 44
ptuytsch 0:ec76b22829d5 45 int Data::getTime(void){
ptuytsch 0:ec76b22829d5 46 return time(NULL) - StartTime;
ptuytsch 0:ec76b22829d5 47 }
ptuytsch 0:ec76b22829d5 48
ptuytsch 0:ec76b22829d5 49 double Data::getSpeed(void){
ptuytsch 0:ec76b22829d5 50 return lastDistance/Period * 3.6;
ptuytsch 0:ec76b22829d5 51 }
ptuytsch 0:ec76b22829d5 52
ptuytsch 0:ec76b22829d5 53 double Data::getAverage(void){
ptuytsch 0:ec76b22829d5 54 return distance/(time(NULL) - StartTime) * 3.6;
ptuytsch 0:ec76b22829d5 55 }
ptuytsch 0:ec76b22829d5 56
ptuytsch 0:ec76b22829d5 57 int Data::getLastCount(void){
ptuytsch 0:ec76b22829d5 58 return lastCount;
ptuytsch 0:ec76b22829d5 59 }