Committer:
inst
Date:
Sun Aug 23 15:18:17 2015 +0000
Revision:
0:4b3f0e4681c9
Child:
1:9af02800ffac
first

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:4b3f0e4681c9 1 #include "YMotorDriverBase.h"
inst 0:4b3f0e4681c9 2 #include "YMotorDriverPusher.h"
inst 0:4b3f0e4681c9 3 #include "mbed.h"
inst 0:4b3f0e4681c9 4
inst 0:4b3f0e4681c9 5 const float YMotorDriverPusher::mDuty = 0.5f;
inst 0:4b3f0e4681c9 6 const PinName YMotorDriverPusher::mDinPinName[] = {
inst 0:4b3f0e4681c9 7 dp2,
inst 0:4b3f0e4681c9 8 dp4
inst 0:4b3f0e4681c9 9 };
inst 0:4b3f0e4681c9 10
inst 0:4b3f0e4681c9 11 YMotorDriverPusher::YMotorDriverPusher( char address ) : YMotorDriverBase( address ){
inst 0:4b3f0e4681c9 12 mSwitchDin = new DigitalIn*[ 2 ];
inst 0:4b3f0e4681c9 13 for ( int i = 0; i < 2; ++i ){
inst 0:4b3f0e4681c9 14 mSwitchDin[ i ] = new DigitalIn( mDinPinName[ i ] );
inst 0:4b3f0e4681c9 15 }
inst 0:4b3f0e4681c9 16 mState = NO_OPERATION;
inst 0:4b3f0e4681c9 17 }
inst 0:4b3f0e4681c9 18
inst 0:4b3f0e4681c9 19 void YMotorDriverPusher::update(){
inst 0:4b3f0e4681c9 20 switch ( mI2C->receive() ){
inst 0:4b3f0e4681c9 21 case I2CSlave::ReadAddressed:{
inst 0:4b3f0e4681c9 22 char buf = mState;
inst 0:4b3f0e4681c9 23 mI2C->write( &buf, 1 );
inst 0:4b3f0e4681c9 24 break;
inst 0:4b3f0e4681c9 25 }
inst 0:4b3f0e4681c9 26 case I2CSlave::WriteGeneral:
inst 0:4b3f0e4681c9 27 break;
inst 0:4b3f0e4681c9 28
inst 0:4b3f0e4681c9 29 case I2CSlave::WriteAddressed:{
inst 0:4b3f0e4681c9 30 char buf;
inst 0:4b3f0e4681c9 31 mI2C->read( &buf, 1 );
inst 0:4b3f0e4681c9 32 mState = static_cast< State >( buf );
inst 0:4b3f0e4681c9 33 break;
inst 0:4b3f0e4681c9 34 }
inst 0:4b3f0e4681c9 35
inst 0:4b3f0e4681c9 36 case I2CSlave::NoData:
inst 0:4b3f0e4681c9 37 break;
inst 0:4b3f0e4681c9 38 }
inst 0:4b3f0e4681c9 39
inst 0:4b3f0e4681c9 40 updatePusher();
inst 0:4b3f0e4681c9 41 write();
inst 0:4b3f0e4681c9 42 }
inst 0:4b3f0e4681c9 43
inst 0:4b3f0e4681c9 44 void YMotorDriverPusher::updatePusher(){
inst 0:4b3f0e4681c9 45 for ( int i = 0; i < 2; ++i ){
inst 0:4b3f0e4681c9 46 // もしリミットスイッチに入力があったら止める
inst 0:4b3f0e4681c9 47 if ( mSwitchDin[ i ]->read() ){
inst 0:4b3f0e4681c9 48 mState = NO_OPERATION;
inst 0:4b3f0e4681c9 49 break;
inst 0:4b3f0e4681c9 50 }
inst 0:4b3f0e4681c9 51 }
inst 0:4b3f0e4681c9 52
inst 0:4b3f0e4681c9 53 MotorAction action = BRAKE;
inst 0:4b3f0e4681c9 54 if ( mState == DRAWING ){
inst 0:4b3f0e4681c9 55 action = REVERSE;
inst 0:4b3f0e4681c9 56 } else if ( mState == PUSHING ){
inst 0:4b3f0e4681c9 57 action = FORWARD;
inst 0:4b3f0e4681c9 58 }
inst 0:4b3f0e4681c9 59
inst 0:4b3f0e4681c9 60 setMotorAction( action );
inst 0:4b3f0e4681c9 61 setDuty( mDuty );
inst 0:4b3f0e4681c9 62 }