Dependents:   RobotBase

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Wed Oct 14 03:50:35 2015 +0000
Parent:
1:46cf8d086b38
Commit message:

Changed in this revision

I2CMotor.cpp Show annotated file Show diff for this revision Revisions of this file
I2CMotor.h Show annotated file Show diff for this revision Revisions of this file
--- a/I2CMotor.cpp	Fri Aug 21 04:51:31 2015 +0000
+++ b/I2CMotor.cpp	Wed Oct 14 03:50:35 2015 +0000
@@ -8,7 +8,9 @@
     
     char dutyLimit[ 2 ];
     
-    ( ( I2CDevice* )this )->read( ( char* )dutyLimit, ( size_t )2 );
+    if ( I2CDevice::read( ( char* )dutyLimit, ( size_t )2 ) ){
+        I2CDevice::resetI2C();
+    }
     //read( ( char* )dutyLimit, ( size_t )2 );
     
     mMinDuty = dutyLimit[ 0 ];
@@ -19,10 +21,10 @@
 }
 
 
-void I2CMotor::write(){
+int I2CMotor::write(){
     char trans[] = {
         static_cast< char >( mActionType ),
         static_cast< char >( mDuty * 255.0f )
     };
-    mI2C->write( mAddress, trans, 2 );
+    return I2CDevice::write( trans, 2 );
 }
--- a/I2CMotor.h	Fri Aug 21 04:51:31 2015 +0000
+++ b/I2CMotor.h	Wed Oct 14 03:50:35 2015 +0000
@@ -26,6 +26,9 @@
         
         mDuty = duty;
     }
+    void setPercent( float p ){
+        setDuty( p * mMaxDuty + ( 1.0f - p ) * mMinDuty );
+    }
     ActionType getActionType() const{
         return mActionType;
     }
@@ -41,8 +44,7 @@
     }
     
 protected:
-    virtual void write();
-    virtual void read(){}
+    virtual int write();
 private:
     ActionType mActionType;
     float mDuty;