Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
task.h@32:1416e015016c, 2018-12-13 (annotated)
- Committer:
- gwappa
- Date:
- Thu Dec 13 07:18:43 2018 +0000
- Revision:
- 32:1416e015016c
- Parent:
- 31:b320ca61a8c0
change to use the Staged state
Who changed what in which revision?
User | Revision | Line number | New 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 | 31:b320ca61a8c0 | 12 | #define CMD_CLEAR_INDEX 'O' |
gwappa | 11:897ecd5413e0 | 13 | #define CMD_EXECUTE 'X' |
gwappa | 1:871d3066c2ab | 14 | |
gwappa | 32:1416e015016c | 15 | #define CFG_DELAY_MIN 'm', (1000) |
gwappa | 18:66246d6c5476 | 16 | #define CFG_DELAY_VAR 'd', (3000) |
gwappa | 32:1416e015016c | 17 | #define CFG_PREP_DUR 'p', (500) |
gwappa | 29:1fb060aab1f8 | 18 | #define CFG_AUD_DUR 'a', (5000) |
gwappa | 18:66246d6c5476 | 19 | #define CFG_AUD_FREQ 'f', (4) |
gwappa | 32:1416e015016c | 20 | #define CFG_RESP_DUR 'y', (1500) |
gwappa | 32:1416e015016c | 21 | #define CFG_POST_DUR 'n', (3000) |
gwappa | 25:56c4b22ec034 | 22 | #define CFG_REWARD_DUR 'r', (50) |
gwappa | 29:1fb060aab1f8 | 23 | #define CFG_ONSET_MIN 'o', (500) |
gwappa | 29:1fb060aab1f8 | 24 | #define CFG_ONSET_STEPS 's', (10) |
gwappa | 29:1fb060aab1f8 | 25 | #define CFG_VIS_DUR 'v', (800) |
gwappa | 29:1fb060aab1f8 | 26 | #define CFG_VIS_TEST_EVERY '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 | 32:1416e015016c | 31 | Pair, |
gwappa | 4:fcf597f82632 | 32 | Report, |
gwappa | 32:1416e015016c | 33 | Stage, |
gwappa | 11:897ecd5413e0 | 34 | Associate, |
gwappa | 16:33c17c62840e | 35 | Motion, |
gwappa | 16:33c17c62840e | 36 | MotionAlt |
gwappa | 1:871d3066c2ab | 37 | }; |
gwappa | 1:871d3066c2ab | 38 | |
gwappa | 5:849446d19406 | 39 | struct ModeSelection: public config::CommandResponder |
gwappa | 5:849446d19406 | 40 | { |
gwappa | 9:e136394bdb39 | 41 | static const char CMD_ID_MODE; |
gwappa | 32:1416e015016c | 42 | static const char CMD_MODE_PAIR; |
gwappa | 32:1416e015016c | 43 | static const char CMD_MODE_STAGE; |
gwappa | 9:e136394bdb39 | 44 | static const char CMD_MODE_REPORT; |
gwappa | 11:897ecd5413e0 | 45 | static const char CMD_MODE_ASSOCIATE; |
gwappa | 11:897ecd5413e0 | 46 | static const char CMD_MODE_MOTION; |
gwappa | 16:33c17c62840e | 47 | static const char CMD_MODE_MOTION_ALT; |
gwappa | 9:e136394bdb39 | 48 | |
gwappa | 5:849446d19406 | 49 | ModeSelection(); // not allowed |
gwappa | 5:849446d19406 | 50 | |
gwappa | 5:849446d19406 | 51 | explicit ModeSelection(const Mode& defaultValue); |
gwappa | 1:871d3066c2ab | 52 | |
gwappa | 5:849446d19406 | 53 | virtual ~ModeSelection(); |
gwappa | 5:849446d19406 | 54 | |
gwappa | 29:1fb060aab1f8 | 55 | // the interface function defined in CommandResponder |
gwappa | 5:849446d19406 | 56 | virtual bool parse(const char& c); |
gwappa | 5:849446d19406 | 57 | |
gwappa | 29:1fb060aab1f8 | 58 | // the interface function defined in CommandResponder |
gwappa | 5:849446d19406 | 59 | virtual bool writeSettings(); |
gwappa | 1:871d3066c2ab | 60 | |
gwappa | 29:1fb060aab1f8 | 61 | // the interface function defined in CommandResponder |
gwappa | 5:849446d19406 | 62 | virtual void echoback(); |
gwappa | 5:849446d19406 | 63 | |
gwappa | 5:849446d19406 | 64 | Mode value; |
gwappa | 5:849446d19406 | 65 | }; |
gwappa | 5:849446d19406 | 66 | |
gwappa | 5:849446d19406 | 67 | struct Task { |
gwappa | 5:849446d19406 | 68 | ModeSelection mode; // the trial mode. |
gwappa | 5:849446d19406 | 69 | |
gwappa | 5:849446d19406 | 70 | Property<uint16_t> delay_min_ms; // the minimum duration for the delay. |
gwappa | 5:849446d19406 | 71 | |
gwappa | 5:849446d19406 | 72 | Property<uint16_t> delay_var_ms; // the average for the (exponential) variable |
gwappa | 5:849446d19406 | 73 | // duration of the delay. |
gwappa | 1:871d3066c2ab | 74 | |
gwappa | 5:849446d19406 | 75 | Property<uint16_t> prep_dur_ms; // the duration of the "preparatory period", |
gwappa | 1:871d3066c2ab | 76 | // during which licking is not allowed. |
gwappa | 1:871d3066c2ab | 77 | |
gwappa | 11:897ecd5413e0 | 78 | Property<uint16_t> aud_dur_ms; // the auditory cue duration. |
gwappa | 11:897ecd5413e0 | 79 | |
gwappa | 11:897ecd5413e0 | 80 | Property<uint16_t> aud_tick_hz; // the frequency of auditory cue flickering. |
gwappa | 5:849446d19406 | 81 | |
gwappa | 13:8ea85a33e37a | 82 | Property<uint16_t> resp_dur_ms; // the size of the minimal 'response window' for the passive paradigms. |
gwappa | 13:8ea85a33e37a | 83 | |
gwappa | 5:849446d19406 | 84 | Property<uint16_t> post_dur_ms; // the post-reward recording duration. |
gwappa | 1:871d3066c2ab | 85 | |
gwappa | 16:33c17c62840e | 86 | Property<uint16_t> reward_dur_ms; // the duration of reward. |
gwappa | 1:871d3066c2ab | 87 | |
gwappa | 29:1fb060aab1f8 | 88 | Property<uint16_t> onset_min_ms; // the minimum onset for the (passive) visual cue during the Associate mode. |
gwappa | 15:20f7f737c256 | 89 | |
gwappa | 29:1fb060aab1f8 | 90 | Property<uint16_t> onset_steps_n; // the number of steps in the onset during the Associate mode. |
gwappa | 11:897ecd5413e0 | 91 | |
gwappa | 29:1fb060aab1f8 | 92 | Property<uint16_t> vis_dur_ms; // the duration for the (passive) visual cue. |
gwappa | 14:af3adf5d5ddf | 93 | |
gwappa | 32:1416e015016c | 94 | Property<uint16_t> vis_test_every; // the frequency of 'test' trials during the Pair/Report modes. |
gwappa | 11:897ecd5413e0 | 95 | |
gwappa | 25:56c4b22ec034 | 96 | Property<uint16_t> whisk_debounce_ms; // the debounce period for whisking events. |
gwappa | 25:56c4b22ec034 | 97 | |
gwappa | 22:41163fb3fdc6 | 98 | Property<uint16_t> lick_debounce_ms; // the debouncing period for licking events. |
gwappa | 22:41163fb3fdc6 | 99 | |
gwappa | 5:849446d19406 | 100 | Action test_reward; |
gwappa | 5:849446d19406 | 101 | |
gwappa | 30:5f975f572ffb | 102 | Action clear_index; |
gwappa | 30:5f975f572ffb | 103 | |
gwappa | 5:849446d19406 | 104 | Action run; |
gwappa | 1:871d3066c2ab | 105 | |
gwappa | 32:1416e015016c | 106 | explicit Task(const Mode& mode=Pair); |
gwappa | 1:871d3066c2ab | 107 | |
gwappa | 1:871d3066c2ab | 108 | void parseFromSerial(); |
gwappa | 1:871d3066c2ab | 109 | |
gwappa | 1:871d3066c2ab | 110 | private: |
gwappa | 5:849446d19406 | 111 | void testReward(); |
gwappa | 30:5f975f572ffb | 112 | void clearTrialIndex(); |
gwappa | 5:849446d19406 | 113 | void runTrial(); |
gwappa | 1:871d3066c2ab | 114 | void writeSettingsToSerial(); |
gwappa | 1:871d3066c2ab | 115 | }; |
gwappa | 1:871d3066c2ab | 116 | #endif |