回転数計のクラスです。

Dependencies:   mbed

Revision:
1:6bceac3446ff
Parent:
0:57308daf8dfe
Child:
2:b492f029a2f4
--- a/main.cpp	Wed Nov 23 04:40:06 2016 +0000
+++ b/main.cpp	Wed Nov 23 05:31:01 2016 +0000
@@ -1,76 +1,11 @@
 #include "mbed.h"
-#include <string>
-//#include "Cadence.h"
+#include "Cadence.h"
+//#include <string>
 
 DigitalOut myled(LED1);
 Ticker cadenceTicker;
 Serial pc(USBTX,USBRX); //for debug
 
-class Cadence : public Serial{
-    private:
-    static const int DATAS_NUM = 74;
-    string strData;
-    int gomi;
-    
-    protected:
-    
-    public:
-    char data[DATAS_NUM];
-    int data_count, data_num;
-    double cadence, cadenceV;
-    string strV,strC;
-    
-    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;
-        cadenceV=0;
-    }
-//    void Init(){
-//        for(int i=0;i<DATAS_NUM;i++) data[i]= NULL;
-//        data_num=0;
-//        data_count=0;
-//        baud(115200);
-//    }
-    void cadenceRead(){ //Ticker で定期的に呼び出して値を更新
-        data_count=0;
-        data_num=0;
-        do{
-            if(readable()) {
-                data[data_count] = getc();
-                data_count++;
-            }
-        }while(data[data_count-1] != '\r');
-        
-        if(data_count > DATAS_NUM-4 ){
-            strData = data;
-            switch (strData.length()){
-                case DATAS_NUM-3 :
-                    strData.erase(0,1);
-                    break;
-                case DATAS_NUM-2 :
-                    strData.erase(0,2);
-                    break;
-                case DATAS_NUM-1 :
-                    strData.erase(0,3);
-                    break;
-                case DATAS_NUM :
-                    strData.erase(0,4);
-            }
-            strV = strData.substr(27,4);
-            strC = strData.substr(64,4);
-            sscanf(strC.c_str(),"%lf",&cadence);
-            sscanf(strV.c_str(),"%lf",&cadenceV);
-            cadence /= 6.0;
-            cadenceV *=0.001;
-        }
-    }
-};
-
-
-
 Cadence cadence(p13,p14);
 
 int main() {
@@ -83,7 +18,7 @@
         pc.printf("test\n\r");
         pc.printf("cadence: %f\n\r",cadence.cadence);
         pc.printf("voltage: %f\n\r",cadence.cadenceV);
-        pc.printf("%d,\n\r",cadence.data_count);
+        pc.printf("'%c'\n\r",cadence.data[cadence.data_count-1]);
         cadence.cadenceRead();
     }
 }