amt102-vのライブラリです

Files at this revision

API Documentation at this revision

Comitter:
taisyou
Date:
Thu Feb 20 08:59:27 2020 +0000
Commit message:
release

Changed in this revision

incenc.cpp Show annotated file Show diff for this revision Revisions of this file
incenc.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 60d903b5752f incenc.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/incenc.cpp	Thu Feb 20 08:59:27 2020 +0000
@@ -0,0 +1,61 @@
+#include "incenc.h"
+//Xは使いませええん!!なので4ピンでだいじょうぶでs
+incEnc::incEnc(PinName p1,PinName p2):A(p1), B(p2)
+{
+    A.rise(&Ar_f);//関数に引数を入れてはいけない
+    A.fall(&Af_f);
+    B.rise(&Br_f);
+    B.fall(&Bf_f);  
+}
+incEnc incenc[enc_MAX]= {
+    incEnc(PC_10,PC_9),
+    incEnc(PC_3,PC_4)
+};
+void Ar_f()//引数なしにするために
+{
+    Ar(incenc,enc_MAX);
+}
+void Af_f()
+{
+    Af(incenc,enc_MAX);
+}
+void Br_f()
+{
+    Br(incenc,enc_MAX);
+}
+void Bf_f()
+{
+    Bf(incenc,enc_MAX);
+}
+void Ar(incEnc *e,uint8_t MAX)
+{
+    for(int i=0; i<MAX; i++) {
+        if(e[i].B==0)e[i].read_buf++;
+        else e[i].read_buf--;
+        e[i].degree=e[i].read_buf*360/8192;
+    }
+}
+void Af(incEnc *e,uint8_t MAX)
+{
+    for(int i=0; i<MAX; i++) {
+        if(e[i].B==1)e[i].read_buf++;
+        else e[i].read_buf--;
+        e[i].degree=e[i].read_buf*360/8192;
+    }
+}
+void Br(incEnc *e,uint8_t MAX)
+{
+    for(int i=0; i<MAX; i++) {
+        if(e[i].A==1)e[i].read_buf++;
+        else e[i].read_buf--;
+        e[i].degree=e[i].read_buf*360/8192;
+    }
+}
+void Bf(incEnc *e,uint8_t MAX)
+{
+    for(int i=0; i<MAX; i++) {
+        if(e[i].A==0)e[i].read_buf++;
+        else e[i].read_buf--;
+        e[i].degree=e[i].read_buf*360/8192;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 60d903b5752f incenc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/incenc.h	Thu Feb 20 08:59:27 2020 +0000
@@ -0,0 +1,31 @@
+#ifndef INCLDUED_incenc_h_
+#define INCLDUED_incenc_h_
+#include "mbed.h"
+#define INCENC_GET_VAL(__ENCODER__, __NUMBER__) \
+(((__ENCODER__)+ (__NUMBER__))->read_buf)
+
+#define INCENC_GET_DEGREE(__MD_DATA__, __NUMBER__)\
+(((__MD_DATA__) + (__NUMBER__))->degree)
+#define enc_MAX 2//使う個数を書いてね
+
+class incEnc
+{
+public:
+    InterruptIn A;
+    InterruptIn B;
+    incEnc(PinName p1,PinName p2);
+    int16_t             degree;
+    int32_t            read_buf;
+};
+void Ar_f();
+void Af_f();
+void Br_f();
+void Bf_f();
+void Ar(incEnc *e,uint8_t);
+void Af(incEnc *e,uint8_t);
+void Br(incEnc *e,uint8_t);
+void Bf(incEnc *e,uint8_t);
+
+extern incEnc incenc[enc_MAX];
+
+#endif //INCLDUED_incenc_h_
\ No newline at end of file