Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
trial.cpp@2:0c241937eabd, 2018-05-14 (annotated)
- Committer:
- gwappa
- Date:
- Mon May 14 18:07:57 2018 +0000
- Revision:
- 2:0c241937eabd
- Child:
- 3:991c6d5ce19d
add (part of) trial implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gwappa | 2:0c241937eabd | 1 | #include "trial.h" |
gwappa | 2:0c241937eabd | 2 | #include "IO.h" |
gwappa | 2:0c241937eabd | 3 | #include "random.h" |
gwappa | 2:0c241937eabd | 4 | |
gwappa | 2:0c241937eabd | 5 | void Trial::reset(const Task& task){ |
gwappa | 2:0c241937eabd | 6 | // reset score |
gwappa | 2:0c241937eabd | 7 | response = TrialFlags::Clear; |
gwappa | 2:0c241937eabd | 8 | |
gwappa | 2:0c241937eabd | 9 | // set delay duration |
gwappa | 2:0c241937eabd | 10 | delay_dur_ms = task.delay_min_ms |
gwappa | 2:0c241937eabd | 11 | + random::exponential(task.delay_var_ms, task.delay_var_ms*3); |
gwappa | 2:0c241937eabd | 12 | |
gwappa | 2:0c241937eabd | 13 | // set stim size |
gwappa | 2:0c241937eabd | 14 | switch(task.mode) |
gwappa | 2:0c241937eabd | 15 | { |
gwappa | 2:0c241937eabd | 16 | case Appear: |
gwappa | 2:0c241937eabd | 17 | if (random::unif(2) == 1) { |
gwappa | 2:0c241937eabd | 18 | response |= TrialFlags::Cues; |
gwappa | 2:0c241937eabd | 19 | } |
gwappa | 2:0c241937eabd | 20 | break; |
gwappa | 2:0c241937eabd | 21 | case Pair: |
gwappa | 2:0c241937eabd | 22 | default: |
gwappa | 2:0c241937eabd | 23 | response |= TrialFlags::Cues; |
gwappa | 2:0c241937eabd | 24 | break; |
gwappa | 2:0c241937eabd | 25 | } |
gwappa | 2:0c241937eabd | 26 | |
gwappa | 2:0c241937eabd | 27 | // TODO: reset interrupt events |
gwappa | 2:0c241937eabd | 28 | // LICK::clearEvents(); |
gwappa | 2:0c241937eabd | 29 | // WHISK::clearEvents(); |
gwappa | 2:0c241937eabd | 30 | } |
gwappa | 2:0c241937eabd | 31 | |
gwappa | 2:0c241937eabd | 32 | void Trial::writeToSerial() { |
gwappa | 2:0c241937eabd | 33 | switch(response){ |
gwappa | 2:0c241937eabd | 34 | #define WRITE_SCORE(SC,REPR) case SC: IO::write("%c%s;",IO::RESULT_HEADER,REPR); break; |
gwappa | 2:0c241937eabd | 35 | WRITE_SCORE(Responses::Hit, "hit") |
gwappa | 2:0c241937eabd | 36 | WRITE_SCORE(Responses::Miss, "miss") |
gwappa | 2:0c241937eabd | 37 | WRITE_SCORE(Responses::Catch, "catch") |
gwappa | 2:0c241937eabd | 38 | WRITE_SCORE(Responses::Reject, "reject") |
gwappa | 2:0c241937eabd | 39 | WRITE_SCORE(Responses::Reset, "reset") |
gwappa | 2:0c241937eabd | 40 | WRITE_SCORE(Responses::NA, "na") |
gwappa | 2:0c241937eabd | 41 | #undef WRITE_SCORE |
gwappa | 2:0c241937eabd | 42 | } |
gwappa | 2:0c241937eabd | 43 | |
gwappa | 2:0c241937eabd | 44 | IO::write("wait%u\r\n",waiting); |
gwappa | 2:0c241937eabd | 45 | //unsigned long zero = (response == Responses::Reset)? starting : cuestarting; |
gwappa | 2:0c241937eabd | 46 | //Serial.print("whisk"); WHISK::writeLogToSerial(zero); Serial.print(DELIMITER); |
gwappa | 2:0c241937eabd | 47 | //Serial.print("lick"); LICK::writeLogToSerial(zero); Serial.print(DELIMITER); |
gwappa | 2:0c241937eabd | 48 | } |