Tummas Tomasson / Mbed 2 deprecated PingDetector_mbedadc

Dependencies:   mbed

main.cpp

Committer:
tummastt
Date:
2012-08-21
Revision:
1:227db871d328
Parent:
0:efb27fbc92c0

File content as of revision 1:227db871d328:

/*
    Program to detect a pinger signal and send
    it back to the PC for processing
 */

#include "mbed.h"
#include "Parameters.h"
#include "PingDetect/PingDetect.h"

Ticker t;


DigitalOut l2(LED2);
DigitalOut l3(LED3);
DigitalOut l4(LED4);

bool Input=0, NewInput=0;

void Stop();

void Start();

void CalculateFFT();

void Run();

void Find();

int Command = doNothing;
int Found = notFound;

PingDetect PD;

int main() {

    while (1) {

        //
        switch (Command) {
            case start:
                Start();
                break;

            case calcFFT:
                CalculateFFT();
                break;

            case stop:
                Stop();
                break;
                
            case doNothing:
                
            default:
                break;
        }

        Command = PD.ReadSerial(Command);
    }
}

// Stops all functions.
void Stop() {
    t.detach();
    l2=0;
    l3=0;
    l4=0;
    Command = doNothing;
}

// sets the find function to run every 5ms
void Start() {
    l2=1;
    t.detach();
    t.attach_us(&Find,5000);
    Command = doNothing;
}

// Calculates the FFT and sends to the PC 100 times
void CalculateFFT() {
    t.detach();
    PD.CalculateFFT();    
    Command = doNothing;
}

// The run function samples the data from the filters
// and sends to it to the PC
void Run () {
    l4=0;
    l3=!l3;
    PD.Run();
}

// Run the find function, if the signal is is found,
// it sets the run function to run every second and 
// ensures the detected signal is in the centre of
// the sampling window
void Find() {
    l4=1;
    Found = PD.Search();
    if(Found == found){
        t.detach();
        wait_ms(1000-TIME_OFFSET);
        t.attach(&Run,1);
        Run();
    }
        
}