CSE477 / swimate_v2

Dependencies:   Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL

Committer:
ellingjp
Date:
Thu Jun 05 19:03:42 2014 +0000
Revision:
15:002bac432234
Parent:
9:a711b5b34d73
Child:
21:2fa676f214fe
Using updated peak detection

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ellingjp 8:8430a5c0914c 1 #include "mbed.h"
ellingjp 8:8430a5c0914c 2 #include "process_data.h"
ellingjp 8:8430a5c0914c 3 #include "SystemTime.h"
ellingjp 8:8430a5c0914c 4 #include "debug.h"
ellingjp 15:002bac432234 5 #include "MovingAverage.h"
ellingjp 15:002bac432234 6 #include "PeakDetector.h"
ellingjp 15:002bac432234 7 #include "FloatingThresholdPeakDetector.h"
ellingjp 15:002bac432234 8 #include "SimplePeakDetector.h"
ellingjp 9:a711b5b34d73 9
ellingjp 15:002bac432234 10 PeakDetector::PeakDetector *detector;
ellingjp 8:8430a5c0914c 11 Timer split_timer;
ellingjp 8:8430a5c0914c 12
ellingjp 15:002bac432234 13 /* Creates a new peak detector */
ellingjp 8:8430a5c0914c 14 bool process_init()
ellingjp 8:8430a5c0914c 15 {
ellingjp 15:002bac432234 16 detector = new FloatingThresholdPeakDetector();
ellingjp 8:8430a5c0914c 17
ellingjp 8:8430a5c0914c 18 split_timer.start();
ellingjp 8:8430a5c0914c 19 return true;
ellingjp 8:8430a5c0914c 20 }
ellingjp 8:8430a5c0914c 21
ellingjp 15:002bac432234 22 enum length {ZERO, ONE, TWO};
ellingjp 15:002bac432234 23 static enum length Length = ZERO;
ellingjp 15:002bac432234 24 static int l_zero, l_two;
ellingjp 8:8430a5c0914c 25
ellingjp 15:002bac432234 26 /* If true, loads latest split time into split */
ellingjp 15:002bac432234 27 bool process_data(int data, int *split)
ellingjp 8:8430a5c0914c 28 {
ellingjp 15:002bac432234 29 if (detector->onPeak(data)) {//
ellingjp 15:002bac432234 30 *split = SystemTime::read_ms();
ellingjp 15:002bac432234 31 return true;
ellingjp 15:002bac432234 32 // PC_PRINTLNF("Peak detected @ %d", SystemTime::read_ms());
ellingjp 15:002bac432234 33 // if (Length == ZERO) {
ellingjp 15:002bac432234 34 // l_zero = split_timer.read_ms();
ellingjp 15:002bac432234 35 // Length = ONE;
ellingjp 15:002bac432234 36 // return false;
ellingjp 15:002bac432234 37 // } else if (Length == ONE) {
ellingjp 15:002bac432234 38 //// l_one = SystemTime::read_ms();
ellingjp 15:002bac432234 39 // Length = TWO;
ellingjp 15:002bac432234 40 // return false;
ellingjp 15:002bac432234 41 // } else {
ellingjp 15:002bac432234 42 // l_two = split_timer.read_ms();
ellingjp 15:002bac432234 43 // Length = ZERO;
ellingjp 15:002bac432234 44 // split_timer.reset();
ellingjp 15:002bac432234 45 //
ellingjp 15:002bac432234 46 // *split = abs((l_two - l_zero));
ellingjp 15:002bac432234 47 // return true;
ellingjp 15:002bac432234 48 // }
ellingjp 8:8430a5c0914c 49 }
ellingjp 15:002bac432234 50
ellingjp 8:8430a5c0914c 51 return false;
ellingjp 8:8430a5c0914c 52 }
ellingjp 8:8430a5c0914c 53
ellingjp 8:8430a5c0914c 54 bool process_close() {
ellingjp 8:8430a5c0914c 55 split_timer.reset();
ellingjp 8:8430a5c0914c 56 split_timer.stop();
ellingjp 15:002bac432234 57 Length = ZERO;
ellingjp 15:002bac432234 58 l_zero = l_two = 0;
ellingjp 15:002bac432234 59
ellingjp 15:002bac432234 60 delete detector;
ellingjp 8:8430a5c0914c 61 return true;
ellingjp 8:8430a5c0914c 62 }