Diff: YMotorDriverPusher.cpp
- Revision:
- 0:4b3f0e4681c9
- Child:
- 1:9af02800ffac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/YMotorDriverPusher.cpp Sun Aug 23 15:18:17 2015 +0000 @@ -0,0 +1,62 @@ +#include "YMotorDriverBase.h" +#include "YMotorDriverPusher.h" +#include "mbed.h" + +const float YMotorDriverPusher::mDuty = 0.5f; +const PinName YMotorDriverPusher::mDinPinName[] = { + dp2, + dp4 +}; + +YMotorDriverPusher::YMotorDriverPusher( char address ) : YMotorDriverBase( address ){ + mSwitchDin = new DigitalIn*[ 2 ]; + for ( int i = 0; i < 2; ++i ){ + mSwitchDin[ i ] = new DigitalIn( mDinPinName[ i ] ); + } + mState = NO_OPERATION; +} + +void YMotorDriverPusher::update(){ + switch ( mI2C->receive() ){ + case I2CSlave::ReadAddressed:{ + char buf = mState; + mI2C->write( &buf, 1 ); + break; + } + case I2CSlave::WriteGeneral: + break; + + case I2CSlave::WriteAddressed:{ + char buf; + mI2C->read( &buf, 1 ); + mState = static_cast< State >( buf ); + break; + } + + case I2CSlave::NoData: + break; + } + + updatePusher(); + write(); +} + +void YMotorDriverPusher::updatePusher(){ + for ( int i = 0; i < 2; ++i ){ + // もしリミットスイッチに入力があったら止める + if ( mSwitchDin[ i ]->read() ){ + mState = NO_OPERATION; + break; + } + } + + MotorAction action = BRAKE; + if ( mState == DRAWING ){ + action = REVERSE; + } else if ( mState == PUSHING ){ + action = FORWARD; + } + + setMotorAction( action ); + setDuty( mDuty ); +}