fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

task.h

Committer:
gwappa
Date:
2018-06-18
Revision:
9:e136394bdb39
Parent:
5:849446d19406
Child:
11:897ecd5413e0

File content as of revision 9:e136394bdb39:

#ifndef TASK_H_
#define TASK_H_

#include "mbed.h"
#include "config.h"

/*
 * command characters
 */
 
#define CMD_TEST_REWARD   'T'
#define CMD_EXECUTE       'x'

#define CHR_DELAY_MIN     'm'
#define CHR_DELAY_VAR     'v'
#define CHR_PREP_DUR      'p'
#define CHR_CUE_DUR       'c'
#define CHR_POST_DUR      'n'
#define CHR_REWARD_DUR    'r'

enum Mode {
    Pair,
    WithCue,
    Report,
    Appear
};

struct ModeSelection: public config::CommandResponder
{
    static const char CMD_ID_MODE;
    static const char CMD_MODE_PAIR;
    static const char CMD_MODE_WITHCUE;
    static const char CMD_MODE_REPORT;
    static const char CMD_MODE_APPEAR;
    
    ModeSelection(); // not allowed
    
    explicit ModeSelection(const Mode& defaultValue);
    
    virtual ~ModeSelection();
    
    virtual bool parse(const char& c);
    
    virtual bool writeSettings();
    
    virtual void echoback();
    
    Mode value;
};

struct Task {
    ModeSelection       mode;           // the trial mode.
    
    Property<uint16_t>  delay_min_ms;   // the minimum duration for the delay.
    
    Property<uint16_t>  delay_var_ms;   // the average for the (exponential) variable 
                                        // duration of the delay.
                                
    Property<uint16_t>  prep_dur_ms;    // the duration of the "preparatory period", 
                                // during which licking is not allowed.
    
    Property<uint16_t>  cue_dur_ms;     // the cue duration.
    
    Property<uint16_t>  post_dur_ms;    // the post-reward recording duration.
    
    Property<uint16_t>  reward_ms;      // the duration of reward.
    
    Action              test_reward;
    
    Action              run;
    
    explicit Task(const Mode& mode=Pair);
    
    void parseFromSerial();
    
private:
    void testReward();
    void runTrial();
    void writeSettingsToSerial();
};
#endif