Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
Diff: states.cpp
- Revision:
- 29:1fb060aab1f8
- Parent:
- 28:797536a42b9f
- Child:
- 30:5f975f572ffb
--- a/states.cpp Sun Jul 22 16:25:25 2018 +0000 +++ b/states.cpp Mon Oct 01 14:54:37 2018 +0000 @@ -13,7 +13,7 @@ #endif void finalize() { - trial.markTrialEnd(); + trial.markTrialEnd(task); scheduler::reset(); } @@ -26,7 +26,7 @@ // set up the timeout for the next state switch (task.mode.value) { case Condition: - scheduler::set(ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value), &automaton::jump<Delay,Unconditioned>); + scheduler::set(ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value), &automaton::jump<Delay,Paired>); break; case MotionAlt: scheduler::set(ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value), &automaton::jump<Delay,Cued>); @@ -42,47 +42,30 @@ // do nothing } -void Unconditioned::setup() { - LOGSTATE(Unconditioned) +void Paired::setup() { + LOGSTATE(Paired) - lickIn.attach(&Unconditioned::responseCallback); - visualOut.attachTurnOnCallback(&Unconditioned::cueCallback); - visualOut.attachTurnOffCallback(&automaton::jump<Unconditioned,Conditioned>); visualOut.run(); + trial.flag.cued = true; + visualOut.attachTurnOffCallback(&automaton::jump<Paired,Monitor>); } -void Unconditioned::cueCallback() { - lickIn.attach(&Unconditioned::responseCallback); - trial.flag.cued = true; - visualOut.detachTurnOnCallback(); -} - -void Unconditioned::responseCallback() { - rewardOut.run(); - visualOut.attachTurnOffCallback(&automaton::jump<Unconditioned,WithResp>); -} - -void Unconditioned::teardown() { +void Paired::teardown() { visualOut.detachTurnOffCallback(); - lickIn.detach(); - if (trial.flag.responded == true) { - rewardOut.wait(); - } trial.markEndOfWait(); } -void Conditioned::setup() { - LOGSTATE(Conditioned) +void Monitor::setup() { + LOGSTATE(Monitor) rewardOut.run(); - lickIn.attach(&automaton::jump<Conditioned,WithResp>); - scheduler::set(ms_to_us(task.resp_dur_ms.value), &automaton::jump<Conditioned,NoResp>); + lickIn.attach(&automaton::jump<Monitor,WithResp>); + scheduler::set(ms_to_us(task.resp_dur_ms.value), &automaton::jump<Monitor,NoResp>); } -void Conditioned::teardown() { +void Monitor::teardown() { + lickIn.detach(); rewardOut.wait(); - lickIn.detach(); - scheduler::reset(); } void Prepare::setup() { @@ -129,7 +112,7 @@ audioOut.run(); // sets the timeout for the next state - scheduler::set(trial.cued_dur_us, &automaton::jump<Cued,NoResp>); + scheduler::set(ms_to_us(task.aud_dur_ms.value), &automaton::jump<Cued,NoResp>); } void Cued::gate() { @@ -177,7 +160,7 @@ lickIn.detach(); // if any gateIn.detach(); // if any - if ( trial.flag.cued ) { + if ( trial.flag.cued && (task.mode.value != Condition) ) { // reward will be there only when the cue was there rewardOut.start(); }