2017年度の製作を開始します。

Dependencies:   BufferedSoftSerial2 SDFileSystem-RTOS mbed mbed-rtos INA226_ver1

Fork of keiki2016ver5 by albatross

Branch:
fusokukei
Revision:
15:6966299bea4c
Child:
16:22aae833bdae
Child:
21:8802034b7810
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Cadence.h	Sat Nov 26 01:12:10 2016 +0000
@@ -0,0 +1,62 @@
+#ifndef CADENCE_H
+#define CADENCE_H
+
+#include "mbed.h"
+#include <string>
+
+class Cadence : public Serial{
+    private:
+    static const int DATAS_NUM = 75;
+    
+    protected:
+    
+    public:
+    string strC,strV;
+    char data[DATAS_NUM];
+    string strData;
+    int data_count, data_num;
+    double cadence, voltage;
+    Cadence(PinName tx, PinName rx, const char* name = NULL) : Serial(tx, rx, NULL){
+        for(int i=0;i<DATAS_NUM;i++) data[i]= NULL;
+        data_num=0;
+        data_count=0;
+        baud(115200);
+        cadence=0;
+        voltage=0;
+    }
+    void readData(){ //Ticker で定期的に呼び出して値を更新
+        data_count = 0;
+        data_num = 0;
+        cadence = 0;
+        do{
+            if(readable()) {
+                data[data_count] = getc();
+                data_count++;
+            }
+        }while(data[data_count-1] != '\n');
+        
+        strData = data;
+        if(strData.length() > DATAS_NUM-4 ){
+            switch (strData.length()){
+                case DATAS_NUM-3 :
+                    strData.erase(0,2);
+                    break;
+                case DATAS_NUM-2 :
+                    strData.erase(0,3);
+                    break;
+                case DATAS_NUM-1 :
+                    strData.erase(0,4);
+                    break;
+                case DATAS_NUM :
+                    strData.erase(0,5);
+            }
+            strV = strData.substr(26,4);
+            strC = strData.substr(64,4);
+            sscanf(strV.c_str(),"%lf",&voltage);
+            sscanf(strC.c_str(),"%lf",&cadence);
+            //cadence /= 6.0;
+//            voltage *= 0.001;
+        }
+    }
+};
+#endif
\ No newline at end of file