tarou yamada / YMotorDriverShooter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers YMotorDriverShooter.cpp Source File

YMotorDriverShooter.cpp

00001 #include "YMotorDriverShooter.h"
00002 #include "YMotorDriverBase.h"
00003 #include "YMotorDriver.h"
00004 #include "mbed.h"
00005 
00006 const PinName YMotorDriverShooter::mRelayDriveDoutPinName[] = {
00007     dp14,
00008     dp11,
00009     dp4,
00010     dp2
00011 };
00012 
00013 YMotorDriverShooter::YMotorDriverShooter( char address ) : YMotorDriverBase( address, YMotorDriver::SHOOTER_ID ){
00014     mRelayDriveDout = new DigitalOut*[ 4 ];
00015     for ( int i = 0; i < 4; ++i ){
00016         mRelayDriveDout[ i ] = new DigitalOut( mRelayDriveDoutPinName[ i ] );
00017     }
00018     
00019     mActionType = STOP;
00020 }
00021 
00022 void YMotorDriverShooter::updateI2CSlave(){
00023     switch ( mI2C->receive() ){
00024         case I2CSlave::ReadAddressed:{
00025             char buf = mActionType;
00026             mI2C->write( &buf, 1 );
00027             break;
00028         }
00029         case I2CSlave::WriteGeneral:
00030             break;
00031         
00032         case I2CSlave::WriteAddressed:{
00033             char buf;
00034             mI2C->read( &buf, 1 );
00035             mActionType = static_cast< ShooterActionType >( buf );
00036             break;
00037         }
00038         
00039         case I2CSlave::NoData:
00040             break;
00041     }
00042 }
00043 
00044 void YMotorDriverShooter::write(){
00045     for ( int i = 0; i < 4; ++i ){
00046         mRelayDriveDout[ i ]->write( ( mActionType >> i ) & 0x01 );
00047     }
00048 }