Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL
process_data.cpp
- Committer:
- ellingjp
- Date:
- 2014-06-07
- Revision:
- 21:2fa676f214fe
- Parent:
- 15:002bac432234
- Child:
- 24:f2503d1256ad
File content as of revision 21:2fa676f214fe:
#include "mbed.h" #include "process_data.h" #include "SystemTime.h" #include "debug.h" #include "MovingAverage.h" #include "PeakDetector.h" #include "FloatingThresholdPeakDetector.h" #include "SimplePeakDetector.h" #include "main.h" PeakDetector::PeakDetector *peakDetector; PeakDetector::PeakDetector *startDetector; Timer split_timer; enum SwimState {WAITING, TIMING}; SwimState swimState; /* Creates a new peak detector */ bool process_init() { swimState = WAITING; peakDetector = new FloatingThresholdPeakDetector(); startDetector = new SimplePeakDetector(30, 4000); split_timer.reset(); return true; } /* If true, loads latest split time into split */ bool process_data(int xdata, int ydata, int *split) { static int start_time; if (swimState == WAITING) { if (startDetector->onPeak(xdata)) { swimState = TIMING; split_timer.start(); start_time = SystemTime::read_ms(); OLED_PRINTPF("xpeak - %d ", start_time, 0, 30); } } else if (swimState == TIMING) { if (peakDetector->onPeak(ydata) && SystemTime::read_ms() - start_time > 5000 ) { *split = split_timer.read_ms(); OLED_PRINTPF("ypeak - %d ", *split, 0, 40); return true; } } return false; } bool process_close() { split_timer.reset(); split_timer.stop(); delete peakDetector; delete startDetector; return true; }