tortuga DataLogging Library: battery, speed, time, average...
Fork of DataLogging by
Data.cpp@3:610ace66d7af, 2016-07-12 (annotated)
- Committer:
- ptuytsch
- Date:
- Tue Jul 12 11:54:41 2016 +0000
- Revision:
- 3:610ace66d7af
- Parent:
- 2:f3c2bf5521e5
same as before
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptuytsch | 0:ec76b22829d5 | 1 | #include "mbed.h" |
ptuytsch | 0:ec76b22829d5 | 2 | #include "Data.h" |
ptuytsch | 1:6e25c2b5c20c | 3 | |
ptuytsch | 0:ec76b22829d5 | 4 | |
ptuytsch | 2:f3c2bf5521e5 | 5 | //CONSTRUCTOR |
ptuytsch | 3:610ace66d7af | 6 | Data::Data(float startDistance, uint32_t startTime, uint8_t ppr, float Periphery) : |
ptuytsch | 3:610ace66d7af | 7 | //setting start values up |
ptuytsch | 3:610ace66d7af | 8 | StartTime(time(NULL)-startTime), |
ptuytsch | 2:f3c2bf5521e5 | 9 | distance(startDistance), |
ptuytsch | 3:610ace66d7af | 10 | PPR(ppr), |
ptuytsch | 3:610ace66d7af | 11 | periphery(Periphery) |
ptuytsch | 2:f3c2bf5521e5 | 12 | { |
ptuytsch | 2:f3c2bf5521e5 | 13 | |
ptuytsch | 2:f3c2bf5521e5 | 14 | } |
ptuytsch | 2:f3c2bf5521e5 | 15 | |
ptuytsch | 2:f3c2bf5521e5 | 16 | void Data::interval(int count){ |
ptuytsch | 3:610ace66d7af | 17 | //log each interval and update the status |
ptuytsch | 3:610ace66d7af | 18 | distance += count * periphery / PPR; |
ptuytsch | 3:610ace66d7af | 19 | //debugging |
ptuytsch | 3:610ace66d7af | 20 | //printf("distance: %f \r\nTime Passed: %i:%i:%i\nAverage: %f\n\n",distance,(time(NULL) - StartTime)/3600, ((time(NULL) - StartTime)/60)%60, (time(NULL) - StartTime)%60, (distance/(time(NULL) - StartTime) * 3.6)); |
ptuytsch | 0:ec76b22829d5 | 21 | } |
ptuytsch | 0:ec76b22829d5 | 22 | |
ptuytsch | 2:f3c2bf5521e5 | 23 | float Data::getDistance(void){ |
ptuytsch | 0:ec76b22829d5 | 24 | return distance; |
ptuytsch | 0:ec76b22829d5 | 25 | } |
ptuytsch | 0:ec76b22829d5 | 26 | |
ptuytsch | 2:f3c2bf5521e5 | 27 | uint32_t Data::getTime(void){ |
ptuytsch | 3:610ace66d7af | 28 | return (time(NULL) - StartTime); |
ptuytsch | 0:ec76b22829d5 | 29 | } |
ptuytsch | 0:ec76b22829d5 | 30 | |
ptuytsch | 2:f3c2bf5521e5 | 31 | float Data::getAverage(void){ |
ptuytsch | 0:ec76b22829d5 | 32 | return distance/(time(NULL) - StartTime) * 3.6; |
ptuytsch | 0:ec76b22829d5 | 33 | } |
ptuytsch | 0:ec76b22829d5 | 34 |