Diff: YMotorDriverShooter.cpp
- Revision:
- 0:9b3bf538a693
- Child:
- 1:b6face630ed3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/YMotorDriverShooter.cpp Sun Aug 23 15:18:25 2015 +0000 @@ -0,0 +1,48 @@ +#include "YMotorDriverShooter.h" +#include "YMotorDriverBase.h" +#include "mbed.h" + +const PinName YMotorDriverShooter::mRelayDriveDoutPinName[] = { + dp6, + dp13, + dp14 +}; + +YMotorDriverShooter::YMotorDriverShooter( char address ) : YMotorDriverBase( address ){ + mRelayDriveDout = new DigitalOut*[ 3 ]; + for ( int i = 0; i < 3; ++i ){ + mRelayDriveDout[ i ] = new DigitalOut( mRelayDriveDoutPinName[ i ] ); + } + + mActionType = STOP; +} + +void YMotorDriverShooter::update(){ + switch ( mI2C->receive() ){ + case I2CSlave::ReadAddressed:{ + char buf = mActionType; + mI2C->write( &buf, 1 ); + break; + } + case I2CSlave::WriteGeneral: + break; + + case I2CSlave::WriteAddressed:{ + char buf; + mI2C->read( &buf, 1 ); + mActionType = static_cast< ShooterActionType >( buf ); + break; + } + + case I2CSlave::NoData: + break; + } + + write(); +} + +void YMotorDriverShooter::write(){ + for ( int i = 0; i < 3; ++i ){ + mRelayDriveDout[ i ]->write( ( mActionType >> i ) & 0x01 ); + } +}