Committer:
inst
Date:
Sun Aug 23 15:18:25 2015 +0000
Revision:
0:9b3bf538a693
Child:
1:b6face630ed3
first

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:9b3bf538a693 1 #include "YMotorDriverShooter.h"
inst 0:9b3bf538a693 2 #include "YMotorDriverBase.h"
inst 0:9b3bf538a693 3 #include "mbed.h"
inst 0:9b3bf538a693 4
inst 0:9b3bf538a693 5 const PinName YMotorDriverShooter::mRelayDriveDoutPinName[] = {
inst 0:9b3bf538a693 6 dp6,
inst 0:9b3bf538a693 7 dp13,
inst 0:9b3bf538a693 8 dp14
inst 0:9b3bf538a693 9 };
inst 0:9b3bf538a693 10
inst 0:9b3bf538a693 11 YMotorDriverShooter::YMotorDriverShooter( char address ) : YMotorDriverBase( address ){
inst 0:9b3bf538a693 12 mRelayDriveDout = new DigitalOut*[ 3 ];
inst 0:9b3bf538a693 13 for ( int i = 0; i < 3; ++i ){
inst 0:9b3bf538a693 14 mRelayDriveDout[ i ] = new DigitalOut( mRelayDriveDoutPinName[ i ] );
inst 0:9b3bf538a693 15 }
inst 0:9b3bf538a693 16
inst 0:9b3bf538a693 17 mActionType = STOP;
inst 0:9b3bf538a693 18 }
inst 0:9b3bf538a693 19
inst 0:9b3bf538a693 20 void YMotorDriverShooter::update(){
inst 0:9b3bf538a693 21 switch ( mI2C->receive() ){
inst 0:9b3bf538a693 22 case I2CSlave::ReadAddressed:{
inst 0:9b3bf538a693 23 char buf = mActionType;
inst 0:9b3bf538a693 24 mI2C->write( &buf, 1 );
inst 0:9b3bf538a693 25 break;
inst 0:9b3bf538a693 26 }
inst 0:9b3bf538a693 27 case I2CSlave::WriteGeneral:
inst 0:9b3bf538a693 28 break;
inst 0:9b3bf538a693 29
inst 0:9b3bf538a693 30 case I2CSlave::WriteAddressed:{
inst 0:9b3bf538a693 31 char buf;
inst 0:9b3bf538a693 32 mI2C->read( &buf, 1 );
inst 0:9b3bf538a693 33 mActionType = static_cast< ShooterActionType >( buf );
inst 0:9b3bf538a693 34 break;
inst 0:9b3bf538a693 35 }
inst 0:9b3bf538a693 36
inst 0:9b3bf538a693 37 case I2CSlave::NoData:
inst 0:9b3bf538a693 38 break;
inst 0:9b3bf538a693 39 }
inst 0:9b3bf538a693 40
inst 0:9b3bf538a693 41 write();
inst 0:9b3bf538a693 42 }
inst 0:9b3bf538a693 43
inst 0:9b3bf538a693 44 void YMotorDriverShooter::write(){
inst 0:9b3bf538a693 45 for ( int i = 0; i < 3; ++i ){
inst 0:9b3bf538a693 46 mRelayDriveDout[ i ]->write( ( mActionType >> i ) & 0x01 );
inst 0:9b3bf538a693 47 }
inst 0:9b3bf538a693 48 }