Reading SenseAir LP8 CO2 sensor over bluetooth low energy
Dependencies: BLE_API mbed nRF51822
Diff: LP8.h
- Revision:
- 4:320febe026ed
- Parent:
- 3:933dd59ad44d
--- a/LP8.h Fri Aug 18 18:20:41 2017 +0000 +++ b/LP8.h Mon Aug 21 08:44:33 2017 +0000 @@ -233,6 +233,9 @@ //read response from lp8 void Response( int bytesToRead ){ int Count = 0; + + lp8Wait.start(); /* timeout timer if something goes wrong */ + do { if(Device.readable()) { response[Count] = Device.getc(); @@ -240,7 +243,10 @@ --bytesToRead; } } - while( bytesToRead > 0); + while( (bytesToRead > 0) || (lp8Wait.read() < 0.2 )); + + lp8Wait.stop(); + lp8Wait.reset(); }; //transmit data over serial lines