fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Wed Jul 04 13:26:58 2018 +0000
Revision:
25:56c4b22ec034
Parent:
22:41163fb3fdc6
Child:
27:b31ea8d74f9e
add whisk debouncing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gwappa 1:871d3066c2ab 1 #ifndef TASK_H_
gwappa 1:871d3066c2ab 2 #define TASK_H_
gwappa 1:871d3066c2ab 3
gwappa 1:871d3066c2ab 4 #include "mbed.h"
gwappa 5:849446d19406 5 #include "config.h"
gwappa 1:871d3066c2ab 6
gwappa 1:871d3066c2ab 7 /*
gwappa 1:871d3066c2ab 8 * command characters
gwappa 1:871d3066c2ab 9 */
gwappa 9:e136394bdb39 10
gwappa 11:897ecd5413e0 11 #define CMD_TEST_REWARD 'T'
gwappa 11:897ecd5413e0 12 #define CMD_EXECUTE 'X'
gwappa 1:871d3066c2ab 13
gwappa 25:56c4b22ec034 14 #define CFG_DELAY_MIN 'm', (5000)
gwappa 18:66246d6c5476 15 #define CFG_DELAY_VAR 'd', (3000)
gwappa 18:66246d6c5476 16 #define CFG_PREP_DUR 'p', (1500)
gwappa 25:56c4b22ec034 17 #define CFG_AUD_DUR 'a', (8000)
gwappa 18:66246d6c5476 18 #define CFG_AUD_FREQ 'f', (4)
gwappa 25:56c4b22ec034 19 #define CFG_RESP_DUR 'y', (4000)
gwappa 18:66246d6c5476 20 #define CFG_POST_DUR 'n', (4000)
gwappa 25:56c4b22ec034 21 #define CFG_REWARD_DUR 'r', (50)
gwappa 18:66246d6c5476 22 #define CFG_PRE_MIN 'o', (1000)
gwappa 25:56c4b22ec034 23 #define CFG_VIS_MIN 'j', (1000)
gwappa 25:56c4b22ec034 24 #define CFG_VIS_AVG 'v', (2000)
gwappa 25:56c4b22ec034 25 #define CFG_VIS_FREQ 'b', (6)
gwappa 18:66246d6c5476 26 #define CFG_VIS_FAIL 'q', (30)
gwappa 25:56c4b22ec034 27 #define CFG_WHISK_DEBOUNCE 'w', (5)
gwappa 25:56c4b22ec034 28 #define CFG_LICK_DEBOUNCE 'l', (80)
gwappa 1:871d3066c2ab 29
gwappa 1:871d3066c2ab 30 enum Mode {
gwappa 1:871d3066c2ab 31 Pair,
gwappa 4:fcf597f82632 32 Report,
gwappa 11:897ecd5413e0 33 Associate,
gwappa 16:33c17c62840e 34 Motion,
gwappa 16:33c17c62840e 35 MotionAlt
gwappa 1:871d3066c2ab 36 };
gwappa 1:871d3066c2ab 37
gwappa 5:849446d19406 38 struct ModeSelection: public config::CommandResponder
gwappa 5:849446d19406 39 {
gwappa 9:e136394bdb39 40 static const char CMD_ID_MODE;
gwappa 9:e136394bdb39 41 static const char CMD_MODE_PAIR;
gwappa 9:e136394bdb39 42 static const char CMD_MODE_REPORT;
gwappa 11:897ecd5413e0 43 static const char CMD_MODE_ASSOCIATE;
gwappa 11:897ecd5413e0 44 static const char CMD_MODE_MOTION;
gwappa 16:33c17c62840e 45 static const char CMD_MODE_MOTION_ALT;
gwappa 9:e136394bdb39 46
gwappa 5:849446d19406 47 ModeSelection(); // not allowed
gwappa 5:849446d19406 48
gwappa 5:849446d19406 49 explicit ModeSelection(const Mode& defaultValue);
gwappa 1:871d3066c2ab 50
gwappa 5:849446d19406 51 virtual ~ModeSelection();
gwappa 5:849446d19406 52
gwappa 5:849446d19406 53 virtual bool parse(const char& c);
gwappa 5:849446d19406 54
gwappa 5:849446d19406 55 virtual bool writeSettings();
gwappa 1:871d3066c2ab 56
gwappa 5:849446d19406 57 virtual void echoback();
gwappa 5:849446d19406 58
gwappa 5:849446d19406 59 Mode value;
gwappa 5:849446d19406 60 };
gwappa 5:849446d19406 61
gwappa 5:849446d19406 62 struct Task {
gwappa 5:849446d19406 63 ModeSelection mode; // the trial mode.
gwappa 5:849446d19406 64
gwappa 5:849446d19406 65 Property<uint16_t> delay_min_ms; // the minimum duration for the delay.
gwappa 5:849446d19406 66
gwappa 5:849446d19406 67 Property<uint16_t> delay_var_ms; // the average for the (exponential) variable
gwappa 5:849446d19406 68 // duration of the delay.
gwappa 1:871d3066c2ab 69
gwappa 5:849446d19406 70 Property<uint16_t> prep_dur_ms; // the duration of the "preparatory period",
gwappa 1:871d3066c2ab 71 // during which licking is not allowed.
gwappa 1:871d3066c2ab 72
gwappa 11:897ecd5413e0 73 Property<uint16_t> aud_dur_ms; // the auditory cue duration.
gwappa 11:897ecd5413e0 74
gwappa 11:897ecd5413e0 75 Property<uint16_t> aud_tick_hz; // the frequency of auditory cue flickering.
gwappa 5:849446d19406 76
gwappa 13:8ea85a33e37a 77 Property<uint16_t> resp_dur_ms; // the size of the minimal 'response window' for the passive paradigms.
gwappa 13:8ea85a33e37a 78
gwappa 5:849446d19406 79 Property<uint16_t> post_dur_ms; // the post-reward recording duration.
gwappa 1:871d3066c2ab 80
gwappa 16:33c17c62840e 81 Property<uint16_t> reward_dur_ms; // the duration of reward.
gwappa 1:871d3066c2ab 82
gwappa 15:20f7f737c256 83 Property<uint16_t> pre_min_ms; // the minimum onset for the (passive) visual cue.
gwappa 15:20f7f737c256 84
gwappa 11:897ecd5413e0 85 Property<uint16_t> vis_min_ms; // the minimum duration for the (passive) visual cue.
gwappa 11:897ecd5413e0 86
gwappa 14:af3adf5d5ddf 87 Property<uint16_t> vis_avg_ms; // the average duration for the (passive) visual cue.
gwappa 14:af3adf5d5ddf 88
gwappa 20:4c06d3041337 89 Property<uint16_t> vis_blink_hz; // the blinking frequency (any positive number), or disabled (0)
gwappa 20:4c06d3041337 90
gwappa 13:8ea85a33e37a 91 Property<uint16_t> vis_fail_perc; // the 'failure rate' of the (passive) visual cue.
gwappa 11:897ecd5413e0 92
gwappa 25:56c4b22ec034 93 Property<uint16_t> whisk_debounce_ms; // the debounce period for whisking events.
gwappa 25:56c4b22ec034 94
gwappa 22:41163fb3fdc6 95 Property<uint16_t> lick_debounce_ms; // the debouncing period for licking events.
gwappa 22:41163fb3fdc6 96
gwappa 5:849446d19406 97 Action test_reward;
gwappa 5:849446d19406 98
gwappa 5:849446d19406 99 Action run;
gwappa 1:871d3066c2ab 100
gwappa 1:871d3066c2ab 101 explicit Task(const Mode& mode=Pair);
gwappa 1:871d3066c2ab 102
gwappa 1:871d3066c2ab 103 void parseFromSerial();
gwappa 1:871d3066c2ab 104
gwappa 1:871d3066c2ab 105 private:
gwappa 5:849446d19406 106 void testReward();
gwappa 5:849446d19406 107 void runTrial();
gwappa 1:871d3066c2ab 108 void writeSettingsToSerial();
gwappa 1:871d3066c2ab 109 };
gwappa 1:871d3066c2ab 110 #endif