Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
trial.cpp@11:897ecd5413e0, 2018-06-21 (annotated)
- Committer:
- gwappa
- Date:
- Thu Jun 21 17:57:22 2018 +0000
- Revision:
- 11:897ecd5413e0
- Parent:
- 8:973dcd190672
- Child:
- 12:06ea96546af1
add auditory cue tickering
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gwappa | 2:0c241937eabd | 1 | #include "trial.h" |
gwappa | 11:897ecd5413e0 | 2 | #include "rig.h" |
gwappa | 2:0c241937eabd | 3 | #include "IO.h" |
gwappa | 2:0c241937eabd | 4 | #include "random.h" |
gwappa | 2:0c241937eabd | 5 | |
gwappa | 11:897ecd5413e0 | 6 | const uint64_t MicrosecondsInSecond = 1000000; |
gwappa | 11:897ecd5413e0 | 7 | |
gwappa | 2:0c241937eabd | 8 | void Trial::reset(const Task& task){ |
gwappa | 2:0c241937eabd | 9 | // reset score |
gwappa | 2:0c241937eabd | 10 | response = TrialFlags::Clear; |
gwappa | 2:0c241937eabd | 11 | |
gwappa | 2:0c241937eabd | 12 | // set delay duration |
gwappa | 5:849446d19406 | 13 | delay_dur_ms = task.delay_min_ms.value |
gwappa | 5:849446d19406 | 14 | + random::exponential(task.delay_var_ms.value, task.delay_var_ms.value*3); |
gwappa | 2:0c241937eabd | 15 | |
gwappa | 11:897ecd5413e0 | 16 | aud_ticker_cycle = MicrosecondsInSecond/(task.aud_tick_hz.value * 2); |
gwappa | 11:897ecd5413e0 | 17 | |
gwappa | 11:897ecd5413e0 | 18 | // TODO: generate visual stimulus (sequence) here |
gwappa | 2:0c241937eabd | 19 | |
gwappa | 3:991c6d5ce19d | 20 | // reset interrupt events |
gwappa | 3:991c6d5ce19d | 21 | licking_events.clear(); |
gwappa | 3:991c6d5ce19d | 22 | whisking_events.clear(); |
gwappa | 2:0c241937eabd | 23 | } |
gwappa | 2:0c241937eabd | 24 | |
gwappa | 11:897ecd5413e0 | 25 | void Trial::markTrialStart() { |
gwappa | 11:897ecd5413e0 | 26 | starting = timer.read_ms(); |
gwappa | 11:897ecd5413e0 | 27 | trialStart.start(); |
gwappa | 11:897ecd5413e0 | 28 | timer.start(); |
gwappa | 11:897ecd5413e0 | 29 | } |
gwappa | 11:897ecd5413e0 | 30 | |
gwappa | 11:897ecd5413e0 | 31 | void Trial::markEndOfWait() { |
gwappa | 11:897ecd5413e0 | 32 | cuestarting = timer.read_ms(); |
gwappa | 11:897ecd5413e0 | 33 | waiting = cuestarting - starting; |
gwappa | 11:897ecd5413e0 | 34 | } |
gwappa | 11:897ecd5413e0 | 35 | |
gwappa | 11:897ecd5413e0 | 36 | void Trial::markTrialEnd() { |
gwappa | 11:897ecd5413e0 | 37 | trialEnd.start(); |
gwappa | 11:897ecd5413e0 | 38 | trialEnd.wait(); |
gwappa | 11:897ecd5413e0 | 39 | writeToSerial(); |
gwappa | 11:897ecd5413e0 | 40 | timer.stop(); |
gwappa | 11:897ecd5413e0 | 41 | timer.reset(); |
gwappa | 11:897ecd5413e0 | 42 | } |
gwappa | 11:897ecd5413e0 | 43 | |
gwappa | 2:0c241937eabd | 44 | void Trial::writeToSerial() { |
gwappa | 2:0c241937eabd | 45 | switch(response){ |
gwappa | 2:0c241937eabd | 46 | #define WRITE_SCORE(SC,REPR) case SC: IO::write("%c%s;",IO::RESULT_HEADER,REPR); break; |
gwappa | 2:0c241937eabd | 47 | WRITE_SCORE(Responses::Hit, "hit") |
gwappa | 2:0c241937eabd | 48 | WRITE_SCORE(Responses::Miss, "miss") |
gwappa | 2:0c241937eabd | 49 | WRITE_SCORE(Responses::Catch, "catch") |
gwappa | 2:0c241937eabd | 50 | WRITE_SCORE(Responses::Reject, "reject") |
gwappa | 2:0c241937eabd | 51 | WRITE_SCORE(Responses::Reset, "reset") |
gwappa | 2:0c241937eabd | 52 | #undef WRITE_SCORE |
gwappa | 8:973dcd190672 | 53 | case Responses::NA: |
gwappa | 8:973dcd190672 | 54 | default: |
gwappa | 8:973dcd190672 | 55 | IO::write("%c%s(%x);",IO::RESULT_HEADER,"na",response); |
gwappa | 2:0c241937eabd | 56 | } |
gwappa | 2:0c241937eabd | 57 | |
gwappa | 3:991c6d5ce19d | 58 | IO::write("wait%u",waiting); |
gwappa | 3:991c6d5ce19d | 59 | trialtime_t zero = (response == Responses::Reset)? starting : cuestarting; |
gwappa | 3:991c6d5ce19d | 60 | IO::write(";whisk"); |
gwappa | 3:991c6d5ce19d | 61 | whisking_events.writeToSerial(zero); |
gwappa | 3:991c6d5ce19d | 62 | IO::write(";lick"); |
gwappa | 3:991c6d5ce19d | 63 | licking_events.writeToSerial(zero); |
gwappa | 4:fcf597f82632 | 64 | IO::write(";\r\n"); |
gwappa | 2:0c241937eabd | 65 | } |