I2CServo.h

Committer:
inst
Date:
2015-08-21
Revision:
1:e06cf312e9f0
Parent:
0:d4e07340fb0e
Child:
2:0f03a5729afc

File content as of revision 1:e06cf312e9f0:

#ifndef INCLUDED_I2C_SERVO_H
#define INCLUDED_I2C_SERVO_H

#include "mbed.h"
#include "I2CDevice.h"

class I2CServo : public I2CDevice{
public:
    I2CServo( char address, int id );
    
    void setTargetPosition( float p ){
        if ( p < 0.0f ){
            p = 0.0f;
        } else if ( p > 1.0f ){
            p = 1.0f;
        }
        
        if ( p != mTargetPosition ){
            mIsStop = false;
        }
        
        mTargetPosition = p;
    }
    
    bool isStop(){
        return mIsStop;
    }
    float getPosition(){
        return mPosition;
    }
    
    virtual void write();
    virtual void read();
    
private:
    float mTargetPosition;
    bool mIsStop;
    float mPosition;
    
    int mID;
    
    static const float mRangeMax[];
    static const float mRangeMin[];
};

#endif