fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Revision:
20:4c06d3041337
Parent:
19:50663f8815b8
Child:
21:e51733fc1c36
--- a/states.cpp	Mon Jul 02 08:26:44 2018 +0000
+++ b/states.cpp	Mon Jul 02 09:04:45 2018 +0000
@@ -12,12 +12,7 @@
 #define LOGSTATE(S)
 #endif
 
-void tickBuzzer() {
-    audioOut = !audioOut;
-}
-
 void finalize() {
-    audioOut.write(0); // if any
     trial.markTrialEnd();
 }
 
@@ -26,7 +21,6 @@
     
     // initialize the trial-related params
     trial.reset(task);
-    audioOut.write(0);
     events::setup(true);
     
     // set up the timeout for the next state
@@ -147,16 +141,11 @@
     // start cue output
     switch(task.mode.value) {
     case Report:
-        visualOut.run();
-        // no auditory cue
-        break;
     case Associate:
-        visualOut.run();
-        // fallthrough (with auditory cue)
     case Motion:
     case MotionAlt:
-        audioOut.write(1);
-        buzzerTicker.attach_us(&tickBuzzer, trial.aud_ticker_cycle);
+        visualOut.run();
+        audioOut.run();
     }
     
     // sets the timeout for the next state
@@ -174,12 +163,20 @@
     events::whiskhandler = 0;
     events::lickhandler  = 0;
     events::gatehandler  = 0;
+    
     // end cue output
-    buzzerTicker.detach();
-    audioOut.write(0);
-    if ((task.mode.value != Motion) && (task.mode.value != MotionAlt)) {
+    switch (task.mode.value) {
+    case Report:
+    case Associate:
         visualOut.stop();
     }
+    
+    switch (task.mode.value) {
+    case Associate:
+    case Motion:
+    case MotionAlt:
+        audioOut.stop();
+    }
 }
 
 void Abort::setup() {
@@ -204,7 +201,7 @@
     events::lickhandler  = 0;
     events::gatehandler  = 0;
     
-    if ((task.mode.value != Pair) && ((trial.response &= TrialFlags::Cues)!= 0)) {
+    if ((task.mode.value == Pair) || trial.flag.cued ) {
         // open/close the valve, only when the cue was there
         rewardOut.start();
     }