Swimate V2 without RTOS code

Dependencies:   Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL

process_data.cpp

Committer:
ellingjp
Date:
2014-06-05
Revision:
15:002bac432234
Parent:
9:a711b5b34d73
Child:
21:2fa676f214fe

File content as of revision 15:002bac432234:

#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"

PeakDetector::PeakDetector *detector;
Timer split_timer;

/* Creates a new peak detector */
bool process_init()
{
    detector = new FloatingThresholdPeakDetector();

    split_timer.start();
    return true;
}

enum length {ZERO, ONE, TWO};
static enum length Length = ZERO;
static int l_zero, l_two;

/* If true, loads latest split time into split  */
bool process_data(int data, int *split)
{
    if (detector->onPeak(data)) {//
        *split = SystemTime::read_ms();
        return true;
//        PC_PRINTLNF("Peak detected @ %d", SystemTime::read_ms());
//        if (Length == ZERO) {
//            l_zero = split_timer.read_ms();
//            Length = ONE;
//            return false;
//        } else if (Length == ONE) {
////            l_one = SystemTime::read_ms();
//            Length = TWO;
//            return false;
//        } else {
//            l_two = split_timer.read_ms();
//            Length = ZERO;
//            split_timer.reset();
//        
//            *split = abs((l_two - l_zero));
//            return true;
//        }
    }
    
    return false;
}

bool process_close() {
    split_timer.reset();
    split_timer.stop();
    Length = ZERO;
    l_zero = l_two = 0;
    
    delete detector;
    return true;
}