fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Revision:
26:b4421d1ee57a
Parent:
25:56c4b22ec034
Child:
27:b31ea8d74f9e
--- a/states.cpp	Wed Jul 04 13:26:58 2018 +0000
+++ b/states.cpp	Thu Jul 05 20:15:37 2018 +0000
@@ -1,7 +1,6 @@
 #include "states.h"
 #include "rig.h"
 #include "automaton.h"
-#include "events.h"
 #include "IO.h"
 
 #define STATE_IS_LOGGED
@@ -21,7 +20,6 @@
     
     // initialize the trial-related params
     trial.reset(task);
-    events::setup(true, task.whisk_debounce_ms.value, task.lick_debounce_ms.value);
     
     // set up the timeout for the next state
     switch (task.mode.value) {
@@ -46,8 +44,7 @@
     LOGSTATE(Prepare)
     
     // configure the interrupts
-    // no whisk handler
-    events::lickhandler = &automaton::jump<Prepare,Abort>;
+    lickIn.attach(&automaton::jump<Prepare,Abort>);
     
     // set timeout for the next state
     stateTimeout.attach_us(&automaton::jump<Prepare,Cued>, ms_to_us(task.prep_dur_ms.value));
@@ -55,7 +52,7 @@
 
 void Prepare::teardown() {
     // de-register lick inhibition
-    events::lickhandler = 0;
+    lickIn.detach();
 }
 
 void Cued::setup() {
@@ -78,42 +75,24 @@
     // configure lick handler
     if (task.mode.value != MotionAlt) {
         // licking without a visual "go-cue" will be considered a "catch" response
-        events::lickhandler = &automaton::jump<Cued,WithResp>;
+        lickIn.attach(&automaton::jump<Cued,WithResp>);
     } else {
         // for MotionAlt
     }
     
-    // configure whisk handler
-    // matters only for Motion & MotionAlt conditions
-    switch (task.mode.value) {
-    case Motion:
-        events::whiskhandler = &events::gate;
-        break;
-    case MotionAlt:
-        events::whiskhandler = &automaton::jump<Cued,WithResp>;
-        break;
-    default:
-        // do nothing
-        break;
-    }
-    
     // configure gate handler
-    // "gating" comes from the visual cue for Report & Associate
-    // from the whisking for Motion
-    if (task.mode.value != MotionAlt) {
-        events::gatehandler      = &Cued::gate;
-    }
-    
-    // configure visual stimulus callback
-    // only for Pair/Report/Associate
+    // use visual feedback trigger as the "gate" response
     switch (task.mode.value) {
     case Pair:
     case Report:
     case Associate:
-        visualOut.attachTurnOnCallback(&events::gate);
+    case Motion:
+        gateIn.attach(&Cued::gate);
         break;
-    case Motion:
     case MotionAlt:
+        gateIn.attach(&automaton::jump<Cued,WithResp>);
+        break;
+    default:
         // do nothing
         break;
     }
@@ -127,16 +106,13 @@
 }
 
 void Cued::gate() {
-    events::gatehandler  = 0;
-    events::whiskhandler = 0;
-    trial.flag.cued      = true;
-    events::lickhandler  = &automaton::jump<Cued,WithResp>;
+    gateIn.detach();
+    lickIn.attach(&automaton::jump<Cued,WithResp>);
+    trial.flag.cued = true; // in case it has not been (as in Pair/Report/Associate)
 }
 
 void Cued::teardown() {
-    events::whiskhandler = 0;
-    events::lickhandler  = 0;
-    events::gatehandler  = 0;
+    lickIn.detach();
     
     // end cue output
     switch (task.mode.value) {
@@ -155,9 +131,8 @@
 
 void Abort::setup() {
     LOGSTATE(Abort)
-    events::whiskhandler = 0;
-    events::lickhandler  = 0;
-    events::gatehandler  = 0;
+    lickIn.detach(); // if any
+    gateIn.detach(); // if any
     trial.markEndOfWait();
     trial.flag.reset     = true;
     stateTimeout.attach_us(&automaton::done<Abort>, ms_to_us(task.post_dur_ms.value));
@@ -171,9 +146,8 @@
     LOGSTATE(WithResp)
     
     trial.flag.responded = true;
-    events::whiskhandler = 0;
-    events::lickhandler  = 0;
-    events::gatehandler  = 0;
+    lickIn.detach(); // if any
+    gateIn.detach(); // if any
     
     // open/close the valve, only when the cue was there
     // (for Pair, reward will be there no matter the response)
@@ -190,9 +164,8 @@
 
 void NoResp::setup() {
     LOGSTATE(NoResp)
-    events::whiskhandler = 0;
-    events::lickhandler  = 0;
-    events::gatehandler  = 0;
+    lickIn.detach(); // if any
+    gateIn.detach(); // if any
     
     // no reward here, except for Pair
     if (task.mode.value == Pair) {