fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Wed May 23 15:15:03 2018 +0000
Revision:
4:fcf597f82632
Parent:
3:991c6d5ce19d
Child:
5:849446d19406
make Pair mode work

Who changed what in which revision?

UserRevisionLine numberNew 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 3:991c6d5ce19d 27 // reset interrupt events
gwappa 3:991c6d5ce19d 28 licking_events.clear();
gwappa 3:991c6d5ce19d 29 whisking_events.clear();
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 3:991c6d5ce19d 44 IO::write("wait%u",waiting);
gwappa 3:991c6d5ce19d 45 trialtime_t zero = (response == Responses::Reset)? starting : cuestarting;
gwappa 3:991c6d5ce19d 46 IO::write(";whisk");
gwappa 3:991c6d5ce19d 47 whisking_events.writeToSerial(zero);
gwappa 3:991c6d5ce19d 48 IO::write(";lick");
gwappa 3:991c6d5ce19d 49 licking_events.writeToSerial(zero);
gwappa 4:fcf597f82632 50 IO::write(";\r\n");
gwappa 2:0c241937eabd 51 }