bike datalogging basic

Dependents:   BLEPrototype

Files at this revision

API Documentation at this revision

Comitter:
ptuytsch
Date:
Sat Apr 16 14:55:37 2016 +0000
Commit message:
basic logging

Changed in this revision

Data.cpp Show annotated file Show diff for this revision Revisions of this file
Data.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Data.cpp	Sat Apr 16 14:55:37 2016 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "Data.h"
+#define Period 1 //5000ms
+#define PPR 1
+#define periphery 2.233168 //periphery of the wheel, in this example a 28" wheel.
+
+
+
+int count;
+time_t StartTime;
+double distance;
+double lastDistance;
+int lastCount;
+
+void interval(void){
+    lastDistance = count * periphery / PPR;
+    distance += lastDistance;
+    lastCount = count;
+    count = 0;
+    }
+    
+void pressed(void){
+    count++;
+}
+    
+Data::Data(PinName pin) : button(pin){
+    StartTime = time(NULL);
+    count = 0;
+    distance = 0;
+    tick.attach(interval,Period);
+    button.fall(pressed);
+    }
+    
+double Data::getDistance(void){
+    return distance;
+    }
+
+int Data::getTime(void){
+    return time(NULL) - StartTime;
+    }
+    
+double Data::getSpeed(void){
+    return lastDistance/Period * 3.6;
+    }
+    
+double Data::getAverage(void){
+    return distance/(time(NULL) - StartTime) * 3.6;
+    }
+    
+int Data::getLastCount(void){
+    return lastCount;
+   } 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Data.h	Sat Apr 16 14:55:37 2016 +0000
@@ -0,0 +1,21 @@
+#ifndef DATA_H
+#define DATA_H
+
+#include "mbed.h"
+
+class Data{
+    //Ticker voor peroidieke metingen.
+protected:
+    InterruptIn button;
+    Ticker tick;
+public:
+    Data(PinName pin);
+    double getDistance(void);
+    int getTime(void);
+    double getSpeed(void);
+    double getAverage(void);
+    int getLastCount(void);
+    
+};
+    
+#endif
\ No newline at end of file