natsu tsumagari
/
test_cadenceClass
回転数計のクラスです。
Cadence.h@5:871c2d6c1129, 2017-01-28 (annotated)
- Committer:
- tsumagari
- Date:
- Sat Jan 28 01:07:59 2017 +0000
- Revision:
- 5:871c2d6c1129
- Parent:
- 4:2def7f5f7fed
- Child:
- 6:93f90c5d0e5b
sscanf??????????int??????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsumagari | 0:57308daf8dfe | 1 | #ifndef CADENCE_H |
tsumagari | 0:57308daf8dfe | 2 | #define CADENCE_H |
tsumagari | 0:57308daf8dfe | 3 | |
tsumagari | 0:57308daf8dfe | 4 | #include "mbed.h" |
tsumagari | 4:2def7f5f7fed | 5 | #include "BufferedSoftSerial.h" |
tsumagari | 0:57308daf8dfe | 6 | #include <string> |
tsumagari | 0:57308daf8dfe | 7 | |
tsumagari | 4:2def7f5f7fed | 8 | |
tsumagari | 4:2def7f5f7fed | 9 | class Cadence : public /*BufferedSoft*/RawSerial{ |
tsumagari | 0:57308daf8dfe | 10 | private: |
tsumagari | 4:2def7f5f7fed | 11 | static const int DATAS_NUM = 69 + 4 + 1; //経過時間の文字数は最大4 |
tsumagari | 4:2def7f5f7fed | 12 | //;1816; 00 00000 0;168 ;001; 10133 e9;34 00;00 0e;00 00;10 70;06 89;G; -005; -009; -006; //2+4+67+2(\r\n) |
tsumagari | 4:2def7f5f7fed | 13 | // -- -- ---- |
tsumagari | 0:57308daf8dfe | 14 | protected: |
tsumagari | 0:57308daf8dfe | 15 | |
tsumagari | 0:57308daf8dfe | 16 | public: |
tsumagari | 4:2def7f5f7fed | 17 | char strC[4],strV[4]; |
tsumagari | 1:6bceac3446ff | 18 | char data[DATAS_NUM]; |
tsumagari | 1:6bceac3446ff | 19 | string strData; |
tsumagari | 1:6bceac3446ff | 20 | int data_count, data_num; |
tsumagari | 4:2def7f5f7fed | 21 | double cadence, voltage, safeflag; |
tsumagari | 4:2def7f5f7fed | 22 | int cadence_i, voltage_i; |
tsumagari | 4:2def7f5f7fed | 23 | Cadence(PinName tx, PinName rx, const char* name = NULL) : /*BufferedSoft*/RawSerial(tx, rx, NULL){ |
tsumagari | 0:57308daf8dfe | 24 | for(int i=0;i<DATAS_NUM;i++) data[i]= NULL; |
tsumagari | 0:57308daf8dfe | 25 | data_count=0; |
tsumagari | 0:57308daf8dfe | 26 | baud(115200); |
tsumagari | 0:57308daf8dfe | 27 | cadence=0; |
tsumagari | 4:2def7f5f7fed | 28 | voltage=0; |
tsumagari | 4:2def7f5f7fed | 29 | strC[0] = '0'; |
tsumagari | 4:2def7f5f7fed | 30 | strV[0] = '0'; |
tsumagari | 0:57308daf8dfe | 31 | } |
tsumagari | 2:b492f029a2f4 | 32 | void readData(){ //Ticker で定期的に呼び出して値を更新 |
tsumagari | 4:2def7f5f7fed | 33 | if(readable()){ |
tsumagari | 1:6bceac3446ff | 34 | data_count = 0; |
tsumagari | 0:57308daf8dfe | 35 | do{ |
tsumagari | 4:2def7f5f7fed | 36 | if(readable()){ |
tsumagari | 0:57308daf8dfe | 37 | data[data_count] = getc(); |
tsumagari | 4:2def7f5f7fed | 38 | if(data[data_count] != '\n') data_count++; |
tsumagari | 0:57308daf8dfe | 39 | } |
tsumagari | 4:2def7f5f7fed | 40 | }while( data[data_count-1] != '\r' && data_count < DATAS_NUM ); |
tsumagari | 4:2def7f5f7fed | 41 | if( data_count > 71 ) { |
tsumagari | 4:2def7f5f7fed | 42 | for(int i = 0; i<4; i++){ |
tsumagari | 4:2def7f5f7fed | 43 | strC[i] = data[data_count - 6 + i]; // 7 = 5 + 1 |
tsumagari | 4:2def7f5f7fed | 44 | pc.putc(strC[i]); |
tsumagari | 4:2def7f5f7fed | 45 | strV[i] = data[data_count - 43 + i]; // 44 = 42 + 1 |
tsumagari | 1:6bceac3446ff | 46 | } |
tsumagari | 5:871c2d6c1129 | 47 | sscanf(strC,"%4d",&cadence_i); |
tsumagari | 5:871c2d6c1129 | 48 | sscanf(strV,"%4d",&voltage_i); |
tsumagari | 5:871c2d6c1129 | 49 | cadence = cadence_i/6.0; |
tsumagari | 5:871c2d6c1129 | 50 | voltage = voltage_i/1000.0; |
tsumagari | 0:57308daf8dfe | 51 | } |
tsumagari | 4:2def7f5f7fed | 52 | } |
tsumagari | 0:57308daf8dfe | 53 | } |
tsumagari | 0:57308daf8dfe | 54 | }; |
tsumagari | 0:57308daf8dfe | 55 | #endif |