I2CMotor.h@2:5b17e7dffb3d, 2015-10-14 (annotated)
- Committer:
- inst
- Date:
- Wed Oct 14 03:50:35 2015 +0000
- Revision:
- 2:5b17e7dffb3d
- Parent:
- 1:46cf8d086b38
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
inst | 0:89910534fad4 | 1 | #ifndef INCLUDED_I2C_MOTOR_H |
inst | 0:89910534fad4 | 2 | #define INCLUDED_I2C_MOTOR_H |
inst | 0:89910534fad4 | 3 | |
inst | 0:89910534fad4 | 4 | #include "I2CDevice.h" |
inst | 0:89910534fad4 | 5 | #include "mbed.h" |
inst | 0:89910534fad4 | 6 | |
inst | 0:89910534fad4 | 7 | class I2CMotor : public I2CDevice{ |
inst | 0:89910534fad4 | 8 | public: |
inst | 0:89910534fad4 | 9 | enum ActionType{ |
inst | 1:46cf8d086b38 | 10 | FORWARD, |
inst | 1:46cf8d086b38 | 11 | REVERSE, |
inst | 1:46cf8d086b38 | 12 | BRAKE, |
inst | 0:89910534fad4 | 13 | RELEASE, |
inst | 0:89910534fad4 | 14 | }; |
inst | 1:46cf8d086b38 | 15 | I2CMotor( char address ); |
inst | 0:89910534fad4 | 16 | |
inst | 0:89910534fad4 | 17 | void setActionType( ActionType action ){ |
inst | 0:89910534fad4 | 18 | mActionType = action; |
inst | 0:89910534fad4 | 19 | } |
inst | 0:89910534fad4 | 20 | void setDuty( float duty ){ |
inst | 1:46cf8d086b38 | 21 | if ( duty > mMaxDuty ){ |
inst | 1:46cf8d086b38 | 22 | duty = mMaxDuty; |
inst | 1:46cf8d086b38 | 23 | } else if ( duty < mMinDuty ){ |
inst | 1:46cf8d086b38 | 24 | duty = mMinDuty; |
inst | 0:89910534fad4 | 25 | } |
inst | 0:89910534fad4 | 26 | |
inst | 0:89910534fad4 | 27 | mDuty = duty; |
inst | 0:89910534fad4 | 28 | } |
inst | 2:5b17e7dffb3d | 29 | void setPercent( float p ){ |
inst | 2:5b17e7dffb3d | 30 | setDuty( p * mMaxDuty + ( 1.0f - p ) * mMinDuty ); |
inst | 2:5b17e7dffb3d | 31 | } |
inst | 1:46cf8d086b38 | 32 | ActionType getActionType() const{ |
inst | 0:89910534fad4 | 33 | return mActionType; |
inst | 0:89910534fad4 | 34 | } |
inst | 1:46cf8d086b38 | 35 | float getDuty() const{ |
inst | 0:89910534fad4 | 36 | return mDuty; |
inst | 0:89910534fad4 | 37 | } |
inst | 0:89910534fad4 | 38 | |
inst | 1:46cf8d086b38 | 39 | float getMaxDuty() const{ |
inst | 0:89910534fad4 | 40 | return mMaxDuty; |
inst | 0:89910534fad4 | 41 | } |
inst | 1:46cf8d086b38 | 42 | float getMinDuty() const{ |
inst | 0:89910534fad4 | 43 | return mMinDuty; |
inst | 0:89910534fad4 | 44 | } |
inst | 0:89910534fad4 | 45 | |
inst | 0:89910534fad4 | 46 | protected: |
inst | 2:5b17e7dffb3d | 47 | virtual int write(); |
inst | 0:89910534fad4 | 48 | private: |
inst | 0:89910534fad4 | 49 | ActionType mActionType; |
inst | 0:89910534fad4 | 50 | float mDuty; |
inst | 0:89910534fad4 | 51 | |
inst | 0:89910534fad4 | 52 | float mMaxDuty; |
inst | 0:89910534fad4 | 53 | float mMinDuty; |
inst | 0:89910534fad4 | 54 | }; |
inst | 0:89910534fad4 | 55 | |
inst | 0:89910534fad4 | 56 | #endif |