2017年度の製作を開始します。
Dependencies: BufferedSoftSerial2 SDFileSystem-RTOS mbed mbed-rtos INA226_ver1
Fork of keiki2016ver5 by
Diff: Cadence.h
- Branch:
- Thread-gyogetsuMPU
- Revision:
- 34:c46f2f687c7b
- Parent:
- 27:d2955f29a3aa
- Child:
- 37:34aaa1951390
--- a/Cadence.h Sat Feb 18 03:03:25 2017 +0000 +++ b/Cadence.h Sat Feb 18 06:45:59 2017 +0000 @@ -2,9 +2,10 @@ #define CADENCE_H #include "mbed.h" -#include "BufferedSoftSerial.h" +//#include "BufferedSoftSerial.h" #include <string> +DigitalOut led3(LED3); double cadence; class Cadence : public /*BufferedSoft*/RawSerial{ @@ -30,26 +31,33 @@ strC[0] = '0'; strV[0] = '0'; } + int checkInt(char c[]){ + for(int i = 0; i< sizeof(c)/sizeof(c[0]); i++){ + if( c[i] - '0' >9 || c[i] - '0' < 0 ) return -1; + } + return 1; + } void readData(){ //Ticker で定期的に呼び出して値を更新 - if(readable()){ +// if(readable()){ data_count = 0; do{ if(readable()){ data[data_count] = getc(); if(data[data_count] != '\n') data_count++; + led3 = !led3; } }while( data[data_count-1] != '\r' && data_count < DATAS_NUM ); if( data_count > 71 ) { for(int i = 0; i<4; i++){ - strC[i] = data[data_count - 6 + i]; // 7 = 5 + 1 - strV[i] = data[data_count - 43 + i]; // 44 = 42 + 1 + strC[i] = data[data_count - 6 + i]; // 6 = 5 + 1 + strV[i] = data[data_count - 43 + i]; // 43 = 42 + 1 } - sscanf(strC,"%4d",&cadence_i); - sscanf(strV,"%4d",&voltage_i); + if(checkInt(strC)) sscanf(strC,"%4d",&cadence_i); + if(checkInt(strV)) sscanf(strV,"%4d",&voltage_i); cadence = cadence_i/6.0; voltage = voltage_i/1000.0; } - } +// } } }; #endif \ No newline at end of file