回転数計のクラスです。
Dependencies: mbed
Fork of test_cadenceClass by
Diff: Cadence.h
- Revision:
- 0:57308daf8dfe
- Child:
- 1:6bceac3446ff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Cadence.h Wed Nov 23 04:40:06 2016 +0000 @@ -0,0 +1,67 @@ +#ifndef CADENCE_H +#define CADENCE_H + +#include "mbed.h" +#include <string> + +#define CADENCE_READ_TIME 0.1 + +//Serial cadenceTwe(p13,p14); +Ticker cadenceReadTicker; + +class Cadence : public Serial{ + private: + static const int DATAS_NUM = 74; + int data_count, data_num; + char data[DATAS_NUM]; + string strData; + int gomi; + + protected: + + public: + double cadence, cadenceV; + 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 で定期的に呼び出して値を更新 + do{ + if(readable()) { + data[data_count] = getc(); + data_count++; + } + }while(data[--data_count] == '\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); + } + sscanf(strData.substr(27,4).c_str(),"%f",&cadenceV); + sscanf(strData.substr(64,4).c_str(),"%f",&cadence); + cadence /= 6.0; + } +}; +#endif \ No newline at end of file