MX-12W Servo Library

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

Revision:
4:9ffc4009a463
Parent:
3:513956de75d7
Child:
5:4bdd101ce4ec
--- a/MX12.h	Fri Dec 11 11:05:33 2020 +0000
+++ b/MX12.h	Fri Jan 15 09:15:47 2021 +0000
@@ -4,6 +4,7 @@
 #include "mbed.h"
 
 #define MX12_ANSWER_MAX_SIZE 32
+#define MX12_MOTOR_COUNT 16
 
 class MX12 {
 public:
@@ -18,17 +19,27 @@
         Unknown,
         Ok
     };
+    
+    enum State {
+        ReadingPosition,
+        Writing,
+        Available,
+    };
 
     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);
+    char IsAvailable(void);
+    MX12::Status GetStatus(void);
+    void ReadPosition(unsigned char mot_id);
+    float GetPosition(unsigned char mot_id);
     void PrintAnswer();
     
     void rw(unsigned char mot_id, char adress, char len, char *data);
     
     void _ReadCallback();
+    
+    char _chksm;
 
 private:
     UnbufferedSerial _mx12;
@@ -36,6 +47,10 @@
     
     char _res[MX12_ANSWER_MAX_SIZE];
     char _res_count;
+    char _len;
+    
+    MX12::State _state;
+    float _angle[MX12_MOTOR_COUNT];
     int _baud;
 };