fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Mon Jun 25 17:43:40 2018 +0000
Revision:
15:20f7f737c256
Parent:
12:06ea96546af1
Child:
20:4c06d3041337
fix weird behavior and validate visual stim duration

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gwappa 12:06ea96546af1 1 #ifndef PULSE_H_
gwappa 12:06ea96546af1 2 #define PULSE_H_
gwappa 12:06ea96546af1 3
gwappa 12:06ea96546af1 4 #include "mbed.h"
gwappa 12:06ea96546af1 5
gwappa 12:06ea96546af1 6
gwappa 12:06ea96546af1 7 /**
gwappa 12:06ea96546af1 8 * implementation for turning on the port
gwappa 12:06ea96546af1 9 * for a specified duration (using a timer).
gwappa 12:06ea96546af1 10 *
gwappa 12:06ea96546af1 11 * the state of a Pulse instance follows the
gwappa 12:06ea96546af1 12 * sequence below, after calling the run() method:
gwappa 12:06ea96546af1 13 *
gwappa 12:06ea96546af1 14 * Rest -(user calling: run)-> Armed (output=L)
gwappa 12:06ea96546af1 15 * Armed -(after onset: start)-> Active (output=H)
gwappa 12:06ea96546af1 16 * Active -(after dur: stop)-> Rest (output=L)
gwappa 12:06ea96546af1 17 *
gwappa 12:06ea96546af1 18 * Although you can generate a force-transition to the specified state
gwappa 12:06ea96546af1 19 * by calling e.g. start() or stop(), it is not a recommended usage.
gwappa 12:06ea96546af1 20 */
gwappa 12:06ea96546af1 21 class Pulse
gwappa 12:06ea96546af1 22 {
gwappa 12:06ea96546af1 23 public:
gwappa 12:06ea96546af1 24 enum Status {
gwappa 12:06ea96546af1 25 Armed,
gwappa 12:06ea96546af1 26 Active,
gwappa 12:06ea96546af1 27 Interrupted,
gwappa 12:06ea96546af1 28 Rest
gwappa 12:06ea96546af1 29 };
gwappa 12:06ea96546af1 30
gwappa 12:06ea96546af1 31 Pulse(PinName pin, const uint64_t& onset_us=0, const uint64_t& duration_us=1000);
gwappa 15:20f7f737c256 32 void setEnabled(const bool& value);
gwappa 15:20f7f737c256 33 bool isEnabled();
gwappa 12:06ea96546af1 34 void setOnset(const uint64_t& value_us);
gwappa 12:06ea96546af1 35 void setDuration(const uint64_t& value_us);
gwappa 12:06ea96546af1 36 void attachTurnOnCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 37 void attachTurnOffCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 38 void detachTurnOnCallback();
gwappa 12:06ea96546af1 39 void detachTurnOffCallback();
gwappa 12:06ea96546af1 40
gwappa 12:06ea96546af1 41 /**
gwappa 12:06ea96546af1 42 * runs the pulse output.
gwappa 12:06ea96546af1 43 *
gwappa 12:06ea96546af1 44 * the state of this Pulse can be retrieved via getStatus().
gwappa 12:06ea96546af1 45 */
gwappa 12:06ea96546af1 46 void run();
gwappa 12:06ea96546af1 47
gwappa 12:06ea96546af1 48 /**
gwappa 12:06ea96546af1 49 * force-start the output.
gwappa 12:06ea96546af1 50 */
gwappa 12:06ea96546af1 51 void start();
gwappa 12:06ea96546af1 52
gwappa 12:06ea96546af1 53 /**
gwappa 12:06ea96546af1 54 * aborts the output.
gwappa 12:06ea96546af1 55 */
gwappa 12:06ea96546af1 56 void stop();
gwappa 12:06ea96546af1 57
gwappa 12:06ea96546af1 58 /**
gwappa 12:06ea96546af1 59 * use this output as a normal DigitalOut
gwappa 12:06ea96546af1 60 */
gwappa 12:06ea96546af1 61 void direct(const bool& value);
gwappa 12:06ea96546af1 62
gwappa 12:06ea96546af1 63 Status getStatus();
gwappa 12:06ea96546af1 64
gwappa 12:06ea96546af1 65 /**
gwappa 12:06ea96546af1 66 * busy-wait until its status becomes from Active to Rest.
gwappa 12:06ea96546af1 67 * if the status is already at Rest, then it returns immediately.
gwappa 12:06ea96546af1 68 */
gwappa 12:06ea96546af1 69 void wait();
gwappa 12:06ea96546af1 70
gwappa 12:06ea96546af1 71 private:
gwappa 12:06ea96546af1 72
gwappa 12:06ea96546af1 73 DigitalOut out_;
gwappa 12:06ea96546af1 74 Timeout timer_;
gwappa 15:20f7f737c256 75 bool enabled_;
gwappa 12:06ea96546af1 76 uint64_t onset_;
gwappa 12:06ea96546af1 77 uint64_t dur_;
gwappa 12:06ea96546af1 78 Callback<void ()> turnon_;
gwappa 12:06ea96546af1 79 Callback<void ()> turnoff_;
gwappa 12:06ea96546af1 80
gwappa 12:06ea96546af1 81 volatile Status stat_;
gwappa 12:06ea96546af1 82 };
gwappa 12:06ea96546af1 83
gwappa 12:06ea96546af1 84 #endif