Skip to content

Commit

Permalink
fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis committed Sep 14, 2018
1 parent 8580b83 commit c1578b8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ This is yet another SDS011 library, this time completely non blocling. It does c
## Installation

* For Arduino IDE: see [the Arduino Guide](https://www.arduino.cc/en/Guide/Libraries#toc4)

~~For Platformio: see the [Platfomio guide](http://docs.platformio.org/en/latest/projectconf/section_env_library.html)~~ Not yet registered
* For Platformio: see the [Platfomio guide](http://docs.platformio.org/en/latest/projectconf/section_env_library.html)

## Usage

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SDS011",
"version": "0.0.1",
"version": "1.0.0",
"keywords": "SDS011, dust, sensor, Arduino, ESP8266",
"description": "Non blocking SDS011 sensor library for ESP8266",
"homepage": "https://github.com/bertmelis/SDS011",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SDS011
version=0.0.1
version=1.0.0
author=Bert Melis
maintainer=Bert Melis
sentence=Non blocking SDS011 sensor library for ESP8266
Expand Down
8 changes: 5 additions & 3 deletions src/SDS011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ void SDS011::loop() {
} else {
// 2. check message type
if (_rxBuff[1] == 0xC5) { // 3. response or data?
if (_onResponse) _onResponse(); // 4. signal response
if (_onResponse) _onResponse(_rxBuff[2], _rxBuff[3], _rxBuff[4]); // 4. signal response
} else {
float pm2_5 = ((_rxBuff[3] * 256.0) + _rxBuff[2]) / 10.0;
float pm10 = ((_rxBuff[5] * 256.0) + _rxBuff[4]) / 10.0;
uint16_t pm2_5_raw = (_rxBuff[3] << 8) + _rxBuff[2];
float pm2_5 = pm2_5_raw / 10.0;
uint16_t pm10_raw = (_rxBuff[5] << 8) + _rxBuff[4];
float pm10 = pm10_raw / 10.0;
if (_onData) _onData(pm2_5, pm10);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SDS011.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <Arduino.h>

typedef std::function<void(float, float)> onDataHandler; // pm2.5, pm10
typedef std::function<void(void)> onResponseHandler;
typedef std::function<void(uint8_t, uint8_t, uint8_t)> onResponseHandler;
typedef std::function<void(int)> onErrorHandler;

class SDS011 {
Expand Down

0 comments on commit c1578b8

Please sign in to comment.