Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Wed Oct 14 06:04:53 2015 +0000
Parent:
0:4b3f0e4681c9
Commit message:

Changed in this revision

YMotorDriverPusher.cpp Show annotated file Show diff for this revision Revisions of this file
YMotorDriverPusher.h Show annotated file Show diff for this revision Revisions of this file
--- a/YMotorDriverPusher.cpp	Sun Aug 23 15:18:17 2015 +0000
+++ b/YMotorDriverPusher.cpp	Wed Oct 14 06:04:53 2015 +0000
@@ -2,7 +2,8 @@
 #include "YMotorDriverPusher.h"
 #include "mbed.h"
 
-const float YMotorDriverPusher::mDuty = 0.5f;
+//const float YMotorDriverPusher::mDuty = 0.75f;
+const float YMotorDriverPusher::mDuty = 1.0f;
 const PinName YMotorDriverPusher::mDinPinName[] = {
     dp2,
     dp4
@@ -13,10 +14,11 @@
     for ( int i = 0; i < 2; ++i ){
         mSwitchDin[ i ] = new DigitalIn( mDinPinName[ i ] );
     }
-    mState = NO_OPERATION;
+    mActionType = NO_OPERATION;
+    mState = BETWEEN;
 }
 
-void YMotorDriverPusher::update(){
+void YMotorDriverPusher::updateI2CSlave(){
     switch ( mI2C->receive() ){
         case I2CSlave::ReadAddressed:{
             char buf = mState;
@@ -29,31 +31,36 @@
         case I2CSlave::WriteAddressed:{
             char buf;
             mI2C->read( &buf, 1 );
-            mState = static_cast< State >( buf );
+            mActionType = static_cast< ActionType >( buf );
             break;
         }
         
         case I2CSlave::NoData:
             break;
     }
-    
-    updatePusher();
-    write();
 }
 
-void YMotorDriverPusher::updatePusher(){
-    for ( int i = 0; i < 2; ++i ){
-        // もしリミットスイッチに入力があったら止める
-        if ( mSwitchDin[ i ]->read() ){
-            mState = NO_OPERATION;
-            break;
+void YMotorDriverPusher::updateSpecial(){
+    if ( mSwitchDin[ DRAW_LIMIT_SWITCH ]->read() ){
+        if ( mActionType == DRAWING ){
+            // スイッチが押されているのにその方向に動こうとしていたら止める
+            mActionType = NO_OPERATION;
         }
+        mState = HAS_FINISHED_DRAWING;
+    } else if ( mSwitchDin[ PUSH_LIMIT_SWITCH ]->read() ){
+        if ( mActionType == PUSHING ){
+            // スイッチが押されているのにその方向に動こうとしていたら止める
+            mActionType = NO_OPERATION;
+        }
+        mState = HAS_FINISHED_PUSHING;
+    } else {
+        mState = BETWEEN;
     }
     
     MotorAction action = BRAKE;
-    if ( mState == DRAWING ){
+    if ( mActionType == DRAWING ){
         action = REVERSE;
-    } else if ( mState == PUSHING ){
+    } else if ( mActionType == PUSHING ){
         action = FORWARD;
     }
     
--- a/YMotorDriverPusher.h	Sun Aug 23 15:18:17 2015 +0000
+++ b/YMotorDriverPusher.h	Wed Oct 14 06:04:53 2015 +0000
@@ -9,22 +9,29 @@
     enum DinID{
         DRAW_LIMIT_SWITCH,
         PUSH_LIMIT_SWITCH
+    };  
+    enum ActionType{
+        NO_OPERATION,
+        DRAWING,
+        PUSHING
     };
     enum State{
-        DRAWING,
-        PUSHING,
-        NO_OPERATION
+        BETWEEN,
+        HAS_FINISHED_DRAWING,
+        HAS_FINISHED_PUSHING
     };
 
     YMotorDriverPusher( char address );
-    virtual void update();
+    
 private:
-    void updatePusher();
+    virtual void updateI2CSlave();
+    virtual void updateSpecial();
     
     static const float mDuty;
     static const PinName mDinPinName[];
     
     DigitalIn** mSwitchDin;
+    ActionType mActionType;
     State mState;
 };