fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Mon Jun 25 12:10:31 2018 +0000
Revision:
12:06ea96546af1
Child:
15:20f7f737c256
extend Pulse class to accommodate the usage for visual cue output

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 12:06ea96546af1 32 void setOnset(const uint64_t& value_us);
gwappa 12:06ea96546af1 33 void setDuration(const uint64_t& value_us);
gwappa 12:06ea96546af1 34 void attachTurnOnCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 35 void attachTurnOffCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 36 void detachTurnOnCallback();
gwappa 12:06ea96546af1 37 void detachTurnOffCallback();
gwappa 12:06ea96546af1 38
gwappa 12:06ea96546af1 39 /**
gwappa 12:06ea96546af1 40 * runs the pulse output.
gwappa 12:06ea96546af1 41 *
gwappa 12:06ea96546af1 42 * the state of this Pulse can be retrieved via getStatus().
gwappa 12:06ea96546af1 43 */
gwappa 12:06ea96546af1 44 void run();
gwappa 12:06ea96546af1 45
gwappa 12:06ea96546af1 46 /**
gwappa 12:06ea96546af1 47 * force-start the output.
gwappa 12:06ea96546af1 48 */
gwappa 12:06ea96546af1 49 void start();
gwappa 12:06ea96546af1 50
gwappa 12:06ea96546af1 51 /**
gwappa 12:06ea96546af1 52 * aborts the output.
gwappa 12:06ea96546af1 53 */
gwappa 12:06ea96546af1 54 void stop();
gwappa 12:06ea96546af1 55
gwappa 12:06ea96546af1 56 /**
gwappa 12:06ea96546af1 57 * use this output as a normal DigitalOut
gwappa 12:06ea96546af1 58 */
gwappa 12:06ea96546af1 59 void direct(const bool& value);
gwappa 12:06ea96546af1 60
gwappa 12:06ea96546af1 61 Status getStatus();
gwappa 12:06ea96546af1 62
gwappa 12:06ea96546af1 63 /**
gwappa 12:06ea96546af1 64 * busy-wait until its status becomes from Active to Rest.
gwappa 12:06ea96546af1 65 * if the status is already at Rest, then it returns immediately.
gwappa 12:06ea96546af1 66 */
gwappa 12:06ea96546af1 67 void wait();
gwappa 12:06ea96546af1 68
gwappa 12:06ea96546af1 69 private:
gwappa 12:06ea96546af1 70
gwappa 12:06ea96546af1 71 DigitalOut out_;
gwappa 12:06ea96546af1 72 Timeout timer_;
gwappa 12:06ea96546af1 73 uint64_t onset_;
gwappa 12:06ea96546af1 74 uint64_t dur_;
gwappa 12:06ea96546af1 75 Callback<void ()> turnon_;
gwappa 12:06ea96546af1 76 Callback<void ()> turnoff_;
gwappa 12:06ea96546af1 77
gwappa 12:06ea96546af1 78 volatile Status stat_;
gwappa 12:06ea96546af1 79 };
gwappa 12:06ea96546af1 80
gwappa 12:06ea96546af1 81 #endif