Brian Daniels / ISD1820P

Dependents:   Seeed_Grove_Recorder_Example

GroveRecorder.cpp

Committer:
bridadan
Date:
2015-04-30
Revision:
0:2d4b0841e58c

File content as of revision 0:2d4b0841e58c:

#include "GroveRecorder.h"

GroveRecorder::GroveRecorder(PinName recordPin, PinName playPin)
        : maxSoundTime(defaultMaxSoundTime), record(recordPin, 0), play(playPin, 0) {
    // Empty
}

void GroveRecorder::stopRecording() {
    record = 0;
}

void GroveRecorder::startRecording(float time) {
    if (!record) {
        if (time > maxSoundTime) {
            time = maxSoundTime;
        }        
        
        record = 1;
        recordTimeout.attach(this, &GroveRecorder::stopRecording, time);
    }
}

void GroveRecorder::startRecordingMaxTime() {
    startRecording(maxSoundTime);
}

void GroveRecorder::stopPlaying() {
    play = 0;
}

void GroveRecorder::startPlaying(float time) {
    if (!play && !record) {
        if (time > maxSoundTime) {
            time = maxSoundTime;
        }
        
        play = 1;
        playTimeout.attach(this, &GroveRecorder::stopPlaying, time);
    }
}

void GroveRecorder::startPlayingMaxTime() {
    startPlaying(maxSoundTime);
}