Dependents:   ShootingSystem

Revision:
1:42d2772575c5
Parent:
0:fac139a6b77c
Child:
2:5ec2a3097d4c
--- a/AmmoPusher.cpp	Wed Aug 19 06:24:33 2015 +0000
+++ b/AmmoPusher.cpp	Fri Aug 21 04:52:43 2015 +0000
@@ -1,1 +1,55 @@
 #include "AmmoPusher.h"
+#include "mbed.h"
+#include "I2CMotor.h"
+
+const float AmmoPusher::mDuty = 0.8f;
+const PinName AmmoPusher::mDrawingLimitSwitchPinName = D7;
+const PinName AmmoPusher::mPushingLimitSwitchPinName = D6;
+
+AmmoPusher::AmmoPusher( I2CMotor* drawerMotor ){
+    mDrawerMotor = drawerMotor;
+    mDrawerMotor->setDuty( mDuty );
+    mDrawingLimitSwitch = new DigitalIn( mDrawingLimitSwitchPinName );
+    mPushingLimitSwitch = new DigitalIn( mPushingLimitSwitchPinName );
+}
+
+void AmmoPusher::update(){
+    // スイッチが押されたらブレーキ
+    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
+        mDrawerMotor->setActionType( I2CMotor::BRAKE );
+    }
+}
+
+void AmmoPusher::draw(){
+    // スイッチが押されたらブレーキ
+    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
+        mDrawerMotor->setActionType( I2CMotor::BRAKE );
+    } else {
+        mDrawerMotor->setActionType( I2CMotor::REVERSE );
+    }
+}
+
+void AmmoPusher::push(){
+    // スイッチが押されたらブレーキ
+    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
+        mDrawerMotor->setActionType( I2CMotor::BRAKE );
+    } else {
+        mDrawerMotor->setActionType( I2CMotor::FORWARD );
+    }
+}
+
+bool AmmoPusher::hasPusherFinishedPushing(){
+    if ( mPushingLimitSwitch->read() ){
+        mDrawerMotor->setActionType( I2CMotor::BRAKE );
+        return true;
+    }
+    return false;
+}
+
+bool AmmoPusher::hasPusherFinishedDrawing(){
+    if ( mDrawingLimitSwitch->read() ){
+        mDrawerMotor->setActionType( I2CMotor::BRAKE );
+        return true;
+    }
+    return false;
+}