Dependents:   ShootingSystem

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Wed Oct 14 03:52:34 2015 +0000
Parent:
1:42d2772575c5
Commit message:

Changed in this revision

AmmoPusher.cpp Show annotated file Show diff for this revision Revisions of this file
AmmoPusher.h Show annotated file Show diff for this revision Revisions of this file
diff -r 42d2772575c5 -r 5ec2a3097d4c AmmoPusher.cpp
--- a/AmmoPusher.cpp	Fri Aug 21 04:52:43 2015 +0000
+++ b/AmmoPusher.cpp	Wed Oct 14 03:52:34 2015 +0000
@@ -1,55 +1,21 @@
 #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;
+#include "I2CDevice.h"
 
-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 );
-    }
+AmmoPusher::AmmoPusher( char address ) : I2CDevice( address ){
+    mState      = BETWEEN;
+    mActionType = NO_OPERATION;
 }
 
-void AmmoPusher::draw(){
-    // スイッチが押されたらブレーキ
-    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
-        mDrawerMotor->setActionType( I2CMotor::BRAKE );
-    } else {
-        mDrawerMotor->setActionType( I2CMotor::REVERSE );
-    }
+int AmmoPusher::write(){
+    char buf = mActionType;
+    return I2CDevice::write( &buf, 1 );
 }
 
-void AmmoPusher::push(){
-    // スイッチが押されたらブレーキ
-    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
-        mDrawerMotor->setActionType( I2CMotor::BRAKE );
-    } else {
-        mDrawerMotor->setActionType( I2CMotor::FORWARD );
-    }
+int AmmoPusher::read(){
+    char buf;
+    int val = I2CDevice::read( &buf, 1 );
+    mState = static_cast< State >( buf );
+    return val;
 }
-
-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;
-}
diff -r 42d2772575c5 -r 5ec2a3097d4c AmmoPusher.h
--- a/AmmoPusher.h	Fri Aug 21 04:52:43 2015 +0000
+++ b/AmmoPusher.h	Wed Oct 14 03:52:34 2015 +0000
@@ -2,27 +2,51 @@
 #define INCLUDED_AMMO_PUSHER_H
 
 #include "mbed.h"
-class I2CMotor;
+#include "I2CDevice.h"
 
-class AmmoPusher {
+class AmmoPusher : public I2CDevice{
 public:
-    AmmoPusher( I2CMotor* drawerMotor );
+    enum ActionType{
+        NO_OPERATION,
+        DRAWING,
+        PUSHING
+    };
+    enum State{
+        BETWEEN,
+        HAS_FINISHED_DRAWING,
+        HAS_FINISHED_PUSHING
+    };
+
+    AmmoPusher( char address );
     
-    void update();
-    void draw();
-    void push();
+    void push(){
+        setActionType( PUSHING );
+    }
+    void draw(){
+        setActionType( DRAWING );
+    }
+    void setActionType( ActionType action ){
+        mActionType = action;
+    }
+    State getState(){
+        return mState;
+    }
+    bool isWorking(){
+        return ( ( mState == BETWEEN ) && ( mActionType != NO_OPERATION ) );
+    }
+    bool hasPushed(){
+        return ( mState ==  HAS_FINISHED_PUSHING );
+    }
+    bool hasDrawn(){
+        return ( mState ==  HAS_FINISHED_DRAWING );
+    }
     
-    bool hasPusherFinishedDrawing();
-    bool hasPusherFinishedPushing();
+    virtual int write();
+    virtual int read();
     
 private:
-    static const float mDuty;
-    static const PinName mDrawingLimitSwitchPinName;
-    static const PinName mPushingLimitSwitchPinName;
-
-    DigitalIn* mDrawingLimitSwitch;
-    DigitalIn* mPushingLimitSwitch;
-    I2CMotor* mDrawerMotor;
+    ActionType mActionType;
+    State mState;
 };
 
 #endif