Une version perso de PwmOut
Une version à peine modifié de la librairie PwmOut
JMAPwmOut.hpp@0:b2ab9e77dd7e, 2017-05-26 (annotated)
- Committer:
- jmambroi
- Date:
- Fri May 26 14:15:14 2017 +0000
- Revision:
- 0:b2ab9e77dd7e
Ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmambroi | 0:b2ab9e77dd7e | 1 | #ifndef _JMAPWMOUT_HPP_ |
jmambroi | 0:b2ab9e77dd7e | 2 | #define _JMAPWMOUT_HPP_ |
jmambroi | 0:b2ab9e77dd7e | 3 | |
jmambroi | 0:b2ab9e77dd7e | 4 | #define POSITIVE true |
jmambroi | 0:b2ab9e77dd7e | 5 | #define NEGATIVE false |
jmambroi | 0:b2ab9e77dd7e | 6 | |
jmambroi | 0:b2ab9e77dd7e | 7 | #include "mbed.h" |
jmambroi | 0:b2ab9e77dd7e | 8 | |
jmambroi | 0:b2ab9e77dd7e | 9 | class JMAPwmOut { |
jmambroi | 0:b2ab9e77dd7e | 10 | public : |
jmambroi | 0:b2ab9e77dd7e | 11 | JMAPwmOut(PinName); |
jmambroi | 0:b2ab9e77dd7e | 12 | // void attach_us(int); |
jmambroi | 0:b2ab9e77dd7e | 13 | void start(); |
jmambroi | 0:b2ab9e77dd7e | 14 | void write(float); |
jmambroi | 0:b2ab9e77dd7e | 15 | float read(); |
jmambroi | 0:b2ab9e77dd7e | 16 | void pulsewidth(float); |
jmambroi | 0:b2ab9e77dd7e | 17 | void pulsewidth_ms(int); |
jmambroi | 0:b2ab9e77dd7e | 18 | void pulsewidth_us(int); |
jmambroi | 0:b2ab9e77dd7e | 19 | void period(float); |
jmambroi | 0:b2ab9e77dd7e | 20 | void period_ms(int); |
jmambroi | 0:b2ab9e77dd7e | 21 | void period_us(int); |
jmambroi | 0:b2ab9e77dd7e | 22 | void stop(); |
jmambroi | 0:b2ab9e77dd7e | 23 | operator float() { |
jmambroi | 0:b2ab9e77dd7e | 24 | if ( _width <= 0 ) return 0.0; |
jmambroi | 0:b2ab9e77dd7e | 25 | if ( _width > 1 ) return 1.0; |
jmambroi | 0:b2ab9e77dd7e | 26 | return _width / _interval; |
jmambroi | 0:b2ab9e77dd7e | 27 | } |
jmambroi | 0:b2ab9e77dd7e | 28 | JMAPwmOut& operator=(float duty) { |
jmambroi | 0:b2ab9e77dd7e | 29 | _width = _interval * duty; |
jmambroi | 0:b2ab9e77dd7e | 30 | if ( duty <= 0 ) _width = 0.0; |
jmambroi | 0:b2ab9e77dd7e | 31 | if ( duty > 1 ) _width = _interval; |
jmambroi | 0:b2ab9e77dd7e | 32 | return *this; |
jmambroi | 0:b2ab9e77dd7e | 33 | } |
jmambroi | 0:b2ab9e77dd7e | 34 | |
jmambroi | 0:b2ab9e77dd7e | 35 | private : |
jmambroi | 0:b2ab9e77dd7e | 36 | Timeout _timeout; |
jmambroi | 0:b2ab9e77dd7e | 37 | Ticker _ticker; |
jmambroi | 0:b2ab9e77dd7e | 38 | void TickerInterrupt(); |
jmambroi | 0:b2ab9e77dd7e | 39 | void end(); |
jmambroi | 0:b2ab9e77dd7e | 40 | DigitalOut _outPin; |
jmambroi | 0:b2ab9e77dd7e | 41 | float _width; |
jmambroi | 0:b2ab9e77dd7e | 42 | float _interval; |
jmambroi | 0:b2ab9e77dd7e | 43 | |
jmambroi | 0:b2ab9e77dd7e | 44 | }; |
jmambroi | 0:b2ab9e77dd7e | 45 | #endif |