kh

Dependencies:   Adafruit_SGP30_mbed mbed CCS811 mbed-rtos ALPHASENSE Adafruit_ADS1015_ BME680

Committer:
etiene32
Date:
Wed Mar 06 14:03:41 2019 +0000
Revision:
0:43070b2dfc87
,hb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
etiene32 0:43070b2dfc87 1 #include "PMS7003.h"
etiene32 0:43070b2dfc87 2
etiene32 0:43070b2dfc87 3 PMS7003::PMS7003(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 PMS7003::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 PMS7003::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 float PMS7003::getPM1()
etiene32 0:43070b2dfc87 22 {
etiene32 0:43070b2dfc87 23 return pm1_count;
etiene32 0:43070b2dfc87 24 }
etiene32 0:43070b2dfc87 25
etiene32 0:43070b2dfc87 26 void PMS7003::read()
etiene32 0:43070b2dfc87 27 {
etiene32 0:43070b2dfc87 28 serial->read(buffer, PACKET_SIZE, NULL);
etiene32 0:43070b2dfc87 29 if(buffer[1]==0x42){
etiene32 0:43070b2dfc87 30 if(buffer[2]==0x4d){
etiene32 0:43070b2dfc87 31 pm10_count = ((buffer[9] << 8) + buffer[10]);
etiene32 0:43070b2dfc87 32 pm2_5_count = ((buffer[7] << 8) + buffer[8]);
etiene32 0:43070b2dfc87 33 pm1_count = ((buffer[5] << 8) + buffer[6]);
etiene32 0:43070b2dfc87 34 }
etiene32 0:43070b2dfc87 35 }
etiene32 0:43070b2dfc87 36 }