MX-12W Servo Library

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

MX12.h

Committer:
tsoul
Date:
2020-12-11
Revision:
2:b4d4c281f174
Parent:
1:d0c3878f77ee
Child:
3:513956de75d7

File content as of revision 2:b4d4c281f174:

#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();
    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 */