Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
Diff: states.cpp
- Revision:
- 28:797536a42b9f
- Parent:
- 27:b31ea8d74f9e
- Child:
- 29:1fb060aab1f8
--- a/states.cpp Sat Jul 21 00:36:38 2018 +0000 +++ b/states.cpp Sun Jul 22 16:25:25 2018 +0000 @@ -25,7 +25,9 @@ // set up the timeout for the next state switch (task.mode.value) { - case Pair: + case Condition: + scheduler::set(ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value), &automaton::jump<Delay,Unconditioned>); + break; case MotionAlt: scheduler::set(ms_to_us(trial.delay_dur_ms + task.prep_dur_ms.value), &automaton::jump<Delay,Cued>); break; @@ -40,6 +42,49 @@ // do nothing } +void Unconditioned::setup() { + LOGSTATE(Unconditioned) + + lickIn.attach(&Unconditioned::responseCallback); + visualOut.attachTurnOnCallback(&Unconditioned::cueCallback); + visualOut.attachTurnOffCallback(&automaton::jump<Unconditioned,Conditioned>); + visualOut.run(); +} + +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() { + visualOut.detachTurnOffCallback(); + lickIn.detach(); + if (trial.flag.responded == true) { + rewardOut.wait(); + } + trial.markEndOfWait(); +} + +void Conditioned::setup() { + LOGSTATE(Conditioned) + + rewardOut.run(); + lickIn.attach(&automaton::jump<Conditioned,WithResp>); + scheduler::set(ms_to_us(task.resp_dur_ms.value), &automaton::jump<Conditioned,NoResp>); +} + +void Conditioned::teardown() { + rewardOut.wait(); + lickIn.detach(); + scheduler::reset(); +} + void Prepare::setup() { // mostly the same with for Delay // except that the animal cannot lick freely @@ -63,7 +108,6 @@ trial.markEndOfWait(); switch (task.mode.value) { - case Pair: case Report: case Associate: case Motion: @@ -133,9 +177,8 @@ 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) - if ((task.mode.value == Pair) || trial.flag.cued ) { + if ( trial.flag.cued ) { + // reward will be there only when the cue was there rewardOut.start(); } @@ -151,11 +194,6 @@ lickIn.detach(); // if any gateIn.detach(); // if any - // no reward here, except for Pair - if (task.mode.value == Pair) { - rewardOut.start(); - } - scheduler::set(ms_to_us(task.post_dur_ms.value), &automaton::done<NoResp>); } void NoResp::teardown() {