Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
Diff: states.cpp
- Revision:
- 8:973dcd190672
- Parent:
- 7:6744ec9ccc25
- Child:
- 9:e136394bdb39
--- a/states.cpp Tue May 29 14:40:50 2018 +0000 +++ b/states.cpp Thu May 31 15:25:37 2018 +0000 @@ -11,11 +11,6 @@ #define LOGSTATE(S) #endif -inline us_timestamp_t ms_to_us(const uint16_t& ms) -{ - return ((us_timestamp_t)ms)*1000; -} - void (*whiskhandler)() = 0; void (*lickhandler)() = 0; bool logged = false; @@ -112,8 +107,9 @@ // configure the interrupts if (task.mode.value == Pair) { - whiskhandler = &automaton::jump<Cued,WithResp>; - lickhandler = 0; + whiskhandler = &automaton::jump<Cued,WithResp>; + trial.response |= TrialFlags::Cues; + lickhandler = 0; } else { whiskhandler = &Cued::gate; @@ -133,6 +129,7 @@ void Cued::gate() { whiskhandler = 0; // logging only + trial.response |= TrialFlags::Cues; lickhandler = &automaton::jump<Cued,WithResp>; } @@ -151,8 +148,9 @@ void Abort::setup() { LOGSTATE(Abort) - trial.response |= TrialFlags::Licked; - automaton::done<Abort>(); + trial.waiting = timer.read_ms() - trial.starting; + trial.response = TrialFlags::Licked; + stateTimeout.attach_us(&automaton::done<Abort>, ms_to_us(task.post_dur_ms.value)); } void Abort::teardown() { @@ -185,12 +183,23 @@ void NoResp::setup() { LOGSTATE(NoResp) - trial.response &= ~TrialFlags::Responded; - // no reward here stateTimeout.attach_us(&automaton::done<NoResp>, ms_to_us(task.post_dur_ms.value)); } void NoResp::teardown() { finalize(); +} + +void TestReward::setup() { + LOGSTATE(TestReward) + + // open/close the valve + rewardOut.write(1); + rewardTimeout.attach_us(&WithResp::stopReward, ms_to_us(task.reward_ms.value)); + stateTimeout.attach_us(&automaton::done<TestReward>, ms_to_us(task.reward_ms.value+20)); +} + +void TestReward::teardown() { + // do nothing } \ No newline at end of file