Revision:
1:9d8fe1f0ee36
Parent:
0:bb84da068c45
--- a/YMotorDriverSupplier.cpp	Sun Aug 23 15:17:57 2015 +0000
+++ b/YMotorDriverSupplier.cpp	Wed Oct 14 06:04:26 2015 +0000
@@ -2,59 +2,28 @@
 #include "YMotorDriverSupplier.h"
 #include "mbed.h"
 
-const float YMotorDriverSupplier::mDuty = 0.30f;
-const PinName YMotorDriverSupplier::mDinPinName[] = {
-    dp2,    // lazer
-    dp4     // photointerrupter
-};
-const float YMotorDriverSupplier::mTimeout_sec = 2.5f;
+const float YMotorDriverSupplier::mDuty = 0.20f;
+const PinName YMotorDriverSupplier::mLazerPinName = dp2;
+//const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 40 * 1000;
+//const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 17 * 1000;
+const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 10;
 
-YMotorDriverSupplier::YMotorDriverSupplier( char address ) : YMotorDriverBase( address ){
-    mLazerDin           = new DigitalIn( mDinPinName[ LAZER ] );
-    mPhotointerrupter   = new InterruptIn( mDinPinName[ PHOTOINTERRUPTER ] );
-    mPhotointerrupter->fall( this, &YMotorDriverSupplier::itr );
-    mPhotointerrupter->rise( this, &YMotorDriverSupplier::itr );
-    mTimer = new Timer;
-    mTimer->stop();
-    mTimer->reset();
-    mLazerTimer = new Timer;
+YMotorDriverSupplier::YMotorDriverSupplier( char address ) : YMotorDriverBase( address, /* id = */ 5 ){
+    mLazer = new InterruptIn( mLazerPinName );
+    mLazer->rise( this, &YMotorDriverSupplier::itr );
+    mTimer      = new Timer;
     mIsWorking  = false;
-    mIsMayStoppable = false;
-    mHasFinished    = false;
-    mPrevInterrupterState = mPhotointerrupter->read();
 }
 
 void YMotorDriverSupplier::itr(){
-    /*
-    bool newState = mPhotointerrupter->read();
-    if ( newState != mPrevInterrupterState ){
+    if ( ( mTimer->read_us() > mValidSignalWidth_us ) && mLazer->read() ){
         mIsWorking = false;
-        mPrevInterrupterState = newState;
-    }
-    */
-    float validSignalWidth_us = 80  * 1000;
-    //
-    if ( mTimer->read_us() > validSignalWidth_us ){
-        //
-        //mIsWorking = false;
-        
-        mHasFinished = true;
         mTimer->reset();
         mTimer->stop();
-        mLazerTimer->reset();
-        mLazerTimer->start();
-        //
     }
-    //
-    
-    /*
-    mIsStoppable = true;
-    mNewInterrupterState = mPhotointerrupter->read();
-    mTimer->start();
-    */
 }
 
-void YMotorDriverSupplier::update(){
+void YMotorDriverSupplier::updateI2CSlave(){
     switch ( mI2C->receive() ){
         case I2CSlave::ReadAddressed:{
             char buf = mIsWorking;
@@ -68,12 +37,10 @@
             char buf;
             mI2C->read( &buf, 1 );
             
-            //
             if ( buf && !mIsWorking ){
                 mTimer->reset();
                 mTimer->start();
             }
-            //
             
             mIsWorking = buf;
             break;
@@ -82,60 +49,15 @@
         case I2CSlave::NoData:
             break;
     }
-    
-    updateSupplier();
-    write();
 }
 
-void YMotorDriverSupplier::updateSupplier(){
-    /*
-    bool hasFinished = mIsWorking;
-    hasFinished &= !mLazerDin->read();
-    hasFinished |= ( mTimer->read() > mTimeout_sec );
-    if ( hasFinished ){
-        mIsWorking = false;
-        mTimer->stop();
-        mTimer->reset();
-    }
-    */
-    /*
-    float validSignalWidth_us = 100;
-    if ( mIsMayStoppable ){
-        if ( mTimer->read_us() > validSignalWidth_us ){
-            mIsMayStoppable = false;
-            mIsWorking = false;
-            mTimer->stop();
-            mTimer->reset();
-        }
-    }
-    */
-    
+void YMotorDriverSupplier::updateSpecial(){
     MotorAction action = BRAKE;
     
-    int fallingAmmoTime_us = 500 * 1000;
-    if ( mHasFinished ){
-        if ( !mLazerDin->read() ){
-            mIsWorking = false;
-            mHasFinished = false;
-            mLazerTimer->stop();
-            mLazerTimer->reset();
-        } else if ( mLazerTimer->read_us() > fallingAmmoTime_us ){
-            mHasFinished = false;
-            mLazerTimer->stop();
-            mLazerTimer->reset();
-            mTimer->reset();
-            mTimer->start();
-        }
-    } else if ( mIsWorking ){
+    if ( mIsWorking ){
         action = FORWARD;
         setDuty( mDuty );
     }
     
-    /*
-    if ( mIsWorking ){
-        action = FORWARD;
-        setDuty( mDuty );
-    }
-    */
     setMotorAction( action );
 }