fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Revision:
21:e51733fc1c36
Parent:
20:4c06d3041337
Child:
22:41163fb3fdc6
--- a/states.cpp	Mon Jul 02 09:04:45 2018 +0000
+++ b/states.cpp	Mon Jul 02 11:51:16 2018 +0000
@@ -26,8 +26,6 @@
     // set up the timeout for the next state
     switch (task.mode.value) {
     case Pair:
-        stateTimeout.attach_us(&automaton::jump<Delay,Paired>, ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value));
-        break;
     case MotionAlt:
         stateTimeout.attach_us(&automaton::jump<Delay,Cued>, ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value));
         break;
@@ -42,33 +40,6 @@
     // do nothing
 }
 
-void Paired::setup() {
-    LOGSTATE(Paired)
-    trial.markEndOfWait();
-    
-    events::gatehandler  = &Paired::gate;
-    events::lickhandler  = &automaton::jump<Paired,WithResp>;
-    
-    // reward & visual feedback
-    visualOut.start();
-    rewardOut.start();
-    
-    stateTimeout.attach_us(&automaton::jump<Paired,NoResp>, ms_to_us(task.aud_dur_ms.value));
-}
-
-void Paired::gate() {
-    events::gatehandler  = 0;
-    events::whiskhandler = 0;
-    trial.flag.cued      = true;
-    events::lickhandler  = &automaton::jump<Cued,WithResp>;
-}
-
-void Paired::teardown() {
-    visualOut.stop();
-    events::gatehandler = 0;
-    events::lickhandler = 0;
-}
-
 void Prepare::setup() {
     // mostly the same with for Delay
     // except that the animal cannot lick freely
@@ -92,8 +63,16 @@
     
     trial.markEndOfWait();
     
-    if (task.mode.value != Report) {
+    switch (task.mode.value) {
+    case Pair:
+    case Report:
+    case Associate:
+        // wait for the visual cue to flag "cued"
+        break;
+    case Motion:
+    case MotionAlt:
         trial.flag.cued = true;
+        break;
     }
     
     // configure lick handler
@@ -108,7 +87,7 @@
     // matters only for Motion & MotionAlt conditions
     switch (task.mode.value) {
     case Motion:
-        events::whiskhandler = &Cued::gate;
+        events::whiskhandler = &events::gate;
         break;
     case MotionAlt:
         events::whiskhandler = &automaton::jump<Cued,WithResp>;
@@ -125,28 +104,23 @@
         events::gatehandler      = &Cued::gate;
     }
     
+    // configure visual stimulus callback
+    // only for Pair/Report/Associate
     switch (task.mode.value) {
+    case Pair:
     case Report:
     case Associate:
         visualOut.attachTurnOnCallback(&events::gate);
         break;
     case Motion:
-        events::whiskhandler = &events::gate;
-        break;
     case MotionAlt:
-        events::whiskhandler = &automaton::jump<Cued,WithResp>;
+        // do nothing
         break;
     }
     
     // start cue output
-    switch(task.mode.value) {
-    case Report:
-    case Associate:
-    case Motion:
-    case MotionAlt:
-        visualOut.run();
-        audioOut.run();
-    }
+    visualOut.run();
+    audioOut.run();
     
     // sets the timeout for the next state
     stateTimeout.attach_us(&automaton::jump<Cued,NoResp>, ms_to_us(task.aud_dur_ms.value));