Keisuke Sehara / Mbed 2 deprecated STM32_Whisking

Dependencies:   mbed

trial.h

Committer:
gwappa
Date:
2018-06-25
Revision:
13:8ea85a33e37a
Parent:
11:897ecd5413e0
Child:
15:20f7f737c256

File content as of revision 13:8ea85a33e37a:

#ifndef TRIAL_H_
#define TRIAL_H_

#include "task.h"
#include "arraylist.h"
#include "random.h"

typedef int trialtime_t;

namespace TrialFlags {
    // nothing
    const char Clear     = 0x00;
    // flags if the auditory cue is there during the trial
    const char Cues      = 0x01;
    // flags if any "response" is detected during the response window
    const char Responded = 0x02;
    // flags if licking event is detected during the preparatory/pre-response window
    const char Licked    = 0x04;
}

namespace Responses {
    const char Hit     = 0x03; // cues && responded
    const char Miss    = 0x01; // cues && ~responded
    const char Catch   = 0x02; // ~cues && responded
    const char Reject  = 0x00; // ~cues && ~responded
    const char Reset   = 0x04; // invalid lick
    const char NA      = 0x08; // default
}

struct Trial {
    /**
    * whether the animal whisked during the cue.
    * + whether the animal waited for the cue.
    */
    char          response;
    /**
    * the timestamp when the trial started.
    */
    trialtime_t   starting;
    /**
    * the timestamp when the cue started
    */
    trialtime_t   cuestarting;
    /**
    * the total waiting period for the animal during this trial before the cue.
    */
    unsigned long waiting;   // used for calculation of waiting period
    /**
    * the duration of the delay period for this trial.
    */
    uint16_t      delay_dur_ms;
    
    // (passive) visual cue-related params
    bool          vis_cued;
    uint16_t      vis_onset_ms;
    uint16_t      vis_dur_ms;
    
    uint64_t      aud_ticker_cycle;
    
    ArrayList<trialtime_t>  licking_events;
    ArrayList<trialtime_t>  whisking_events;
    
    void reset(const Task& task);
    
    /**
    *   a helper function to assign onset & duration randomly for the (passive) visual cue.
    *
    *   the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`.
    *   the `duration` will distribute uniformly from `mindur` to `phasedur - onset`.
    */
    void assignRandomStim(const Task& task);
    
    void markTrialStart();
    void markEndOfWait();
    void markTrialEnd();
    
    void writeToSerial();
};

#endif