natsu tsumagari
/
test_cadenceClass
回転数計のクラスです。
Cadence.h
- Committer:
- tsumagari
- Date:
- 2016-11-23
- Revision:
- 2:b492f029a2f4
- Parent:
- 1:6bceac3446ff
- Child:
- 4:2def7f5f7fed
File content as of revision 2:b492f029a2f4:
#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, 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 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",&cadenceV); sscanf(strC.c_str(),"%lf",&cadence); //cadence /= 6.0; // cadenceV *= 0.001; } } }; #endif