MX-12W Servo Library

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

MX12.h

Committer:
tsoul
Date:
2020-12-11
Revision:
3:513956de75d7
Parent:
2:b4d4c281f174
Child:
4:9ffc4009a463

File content as of revision 3:513956de75d7:

#ifndef MBED_MX12_H
#define MBED_MX12_H

#include "mbed.h"

#define MX12_ANSWER_MAX_SIZE 32

class MX12 {
public:
    enum Status {
        InstructionError,
        OverloadError,
        ChecksumError,
        RangeError,
        OverheatingError,
        AngleLimitError,
        InputVoltageError,
        Unknown,
        Ok
    };

    MX12(PinName tx, PinName rx, int baud=115200);
    
    void SetSpeed(unsigned char mot_id, float speed);
    MX12::Status GetStatus();
    float ReadPosition(unsigned char mot_id);
    void PrintAnswer();
    
    void rw(unsigned char mot_id, char adress, char len, char *data);
    
    void _ReadCallback();

private:
    UnbufferedSerial _mx12;
    MX12::Status _status;
    
    char _res[MX12_ANSWER_MAX_SIZE];
    char _res_count;
    int _baud;
};

#endif /* MBED_MX12_H */