Brian Daniels / ISD1820P

Dependents:   Seeed_Grove_Recorder_Example

Revision:
0:2d4b0841e58c
diff -r 000000000000 -r 2d4b0841e58c GroveRecorder.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GroveRecorder.cpp	Thu Apr 30 19:49:15 2015 +0000
@@ -0,0 +1,45 @@
+#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);
+}
+    
\ No newline at end of file