kh
Dependencies: Adafruit_SGP30_mbed mbed CCS811 mbed-rtos ALPHASENSE Adafruit_ADS1015_ BME680
SDS011/NovaSDS011.cpp@0:43070b2dfc87, 2019-03-06 (annotated)
- Committer:
- etiene32
- Date:
- Wed Mar 06 14:03:41 2019 +0000
- Revision:
- 0:43070b2dfc87
,hb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
etiene32 | 0:43070b2dfc87 | 1 | #include "NovaSDS011.h" |
etiene32 | 0:43070b2dfc87 | 2 | |
etiene32 | 0:43070b2dfc87 | 3 | NovaSDS011::NovaSDS011(Serial* serial) |
etiene32 | 0:43070b2dfc87 | 4 | { |
etiene32 | 0:43070b2dfc87 | 5 | this->serial = serial; |
etiene32 | 0:43070b2dfc87 | 6 | serial->baud(9600); |
etiene32 | 0:43070b2dfc87 | 7 | pm10_count = 0; |
etiene32 | 0:43070b2dfc87 | 8 | pm2_5_count = 0; |
etiene32 | 0:43070b2dfc87 | 9 | } |
etiene32 | 0:43070b2dfc87 | 10 | |
etiene32 | 0:43070b2dfc87 | 11 | float NovaSDS011::getPM10() |
etiene32 | 0:43070b2dfc87 | 12 | { |
etiene32 | 0:43070b2dfc87 | 13 | return pm10_count; |
etiene32 | 0:43070b2dfc87 | 14 | } |
etiene32 | 0:43070b2dfc87 | 15 | |
etiene32 | 0:43070b2dfc87 | 16 | float NovaSDS011::getPM2_5() |
etiene32 | 0:43070b2dfc87 | 17 | { |
etiene32 | 0:43070b2dfc87 | 18 | return pm2_5_count; |
etiene32 | 0:43070b2dfc87 | 19 | } |
etiene32 | 0:43070b2dfc87 | 20 | |
etiene32 | 0:43070b2dfc87 | 21 | void NovaSDS011::read() |
etiene32 | 0:43070b2dfc87 | 22 | { |
etiene32 | 0:43070b2dfc87 | 23 | while(serial->readable()==0){} |
etiene32 | 0:43070b2dfc87 | 24 | if(serial->readable()==1){ |
etiene32 | 0:43070b2dfc87 | 25 | serial->read(buffer, PACKET_SIZE, NULL); |
etiene32 | 0:43070b2dfc87 | 26 | printf("%d %d %d %d %d %d %d %d %d %d\r\n",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],buffer[8],buffer[9]); |
etiene32 | 0:43070b2dfc87 | 27 | } |
etiene32 | 0:43070b2dfc87 | 28 | if(buffer[9] == 0xAB) { |
etiene32 | 0:43070b2dfc87 | 29 | printf("yo\r\n"); |
etiene32 | 0:43070b2dfc87 | 30 | pm10_count = ((buffer[6] << 8) + buffer[3]) / 10.0; |
etiene32 | 0:43070b2dfc87 | 31 | pm2_5_count = ((buffer[4] << 8) + buffer[3]) / 10.0; |
etiene32 | 0:43070b2dfc87 | 32 | } |
etiene32 | 0:43070b2dfc87 | 33 | } |