Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
duration.cpp@11:897ecd5413e0, 2018-06-21 (annotated)
- Committer:
- gwappa
- Date:
- Thu Jun 21 17:57:22 2018 +0000
- Revision:
- 11:897ecd5413e0
add auditory cue tickering
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gwappa | 11:897ecd5413e0 | 1 | #include "duration.h" |
gwappa | 11:897ecd5413e0 | 2 | |
gwappa | 11:897ecd5413e0 | 3 | Duration::Duration(PinName pin, const uint64_t& duration_us): |
gwappa | 11:897ecd5413e0 | 4 | out_(pin, 0), |
gwappa | 11:897ecd5413e0 | 5 | dur_(duration_us), |
gwappa | 11:897ecd5413e0 | 6 | stat_(Rest) |
gwappa | 11:897ecd5413e0 | 7 | { |
gwappa | 11:897ecd5413e0 | 8 | setDuration(duration_us); |
gwappa | 11:897ecd5413e0 | 9 | } |
gwappa | 11:897ecd5413e0 | 10 | |
gwappa | 11:897ecd5413e0 | 11 | void Duration::setDuration(const uint64_t& value_us) |
gwappa | 11:897ecd5413e0 | 12 | { |
gwappa | 11:897ecd5413e0 | 13 | dur_ = value_us; |
gwappa | 11:897ecd5413e0 | 14 | } |
gwappa | 11:897ecd5413e0 | 15 | |
gwappa | 11:897ecd5413e0 | 16 | void Duration::start() |
gwappa | 11:897ecd5413e0 | 17 | { |
gwappa | 11:897ecd5413e0 | 18 | stat_ = Active; |
gwappa | 11:897ecd5413e0 | 19 | out_.write(1); |
gwappa | 11:897ecd5413e0 | 20 | timer_.attach_us(callback(this, &Duration::stop), dur_); |
gwappa | 11:897ecd5413e0 | 21 | } |
gwappa | 11:897ecd5413e0 | 22 | |
gwappa | 11:897ecd5413e0 | 23 | void Duration::stop() |
gwappa | 11:897ecd5413e0 | 24 | { |
gwappa | 11:897ecd5413e0 | 25 | timer_.detach(); |
gwappa | 11:897ecd5413e0 | 26 | out_.write(0); |
gwappa | 11:897ecd5413e0 | 27 | stat_ = Rest; |
gwappa | 11:897ecd5413e0 | 28 | } |
gwappa | 11:897ecd5413e0 | 29 | |
gwappa | 11:897ecd5413e0 | 30 | Duration::Status Duration::getStatus() |
gwappa | 11:897ecd5413e0 | 31 | { |
gwappa | 11:897ecd5413e0 | 32 | return stat_; |
gwappa | 11:897ecd5413e0 | 33 | } |
gwappa | 11:897ecd5413e0 | 34 | |
gwappa | 11:897ecd5413e0 | 35 | void Duration::wait() |
gwappa | 11:897ecd5413e0 | 36 | { |
gwappa | 11:897ecd5413e0 | 37 | while(stat_ != Rest); |
gwappa | 11:897ecd5413e0 | 38 | } |
gwappa | 11:897ecd5413e0 | 39 |