mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-26 04:32:02 +00:00
Read size bin counts for PMS5003 sensor
This commit is contained in:
parent
2e593ca6e4
commit
0e9b67c9db
@ -65,6 +65,18 @@ value(int type)
|
||||
return pms5003_pm2_5_atm();
|
||||
case PMS5003_SENSOR_PM10_ATM:
|
||||
return pms5003_pm10_atm();
|
||||
case PMS5003_SENSOR_DB0_3:
|
||||
return pms5003_db0_3();
|
||||
case PMS5003_SENSOR_DB0_5:
|
||||
return pms5003_db0_5();
|
||||
case PMS5003_SENSOR_DB1:
|
||||
return pms5003_db1();
|
||||
case PMS5003_SENSOR_DB2_5:
|
||||
return pms5003_db2_5();
|
||||
case PMS5003_SENSOR_DB5:
|
||||
return pms5003_db5();
|
||||
case PMS5003_SENSOR_DB10:
|
||||
return pms5003_db10();
|
||||
case PMS5003_SENSOR_TIMESTAMP:
|
||||
return pms5003_timestamp();
|
||||
}
|
||||
|
@ -47,6 +47,12 @@ extern const struct sensors_sensor pms5003_sensor;
|
||||
#define PMS5003_SENSOR_PM1_ATM 3
|
||||
#define PMS5003_SENSOR_PM2_5_ATM 4
|
||||
#define PMS5003_SENSOR_PM10_ATM 5
|
||||
#define PMS5003_SENSOR_TIMESTAMP 6
|
||||
#define PMS5003_SENSOR_DB0_3 6
|
||||
#define PMS5003_SENSOR_DB0_5 7
|
||||
#define PMS5003_SENSOR_DB1 8
|
||||
#define PMS5003_SENSOR_DB2_5 9
|
||||
#define PMS5003_SENSOR_DB5 10
|
||||
#define PMS5003_SENSOR_DB10 11
|
||||
#define PMS5003_SENSOR_TIMESTAMP 12
|
||||
|
||||
#endif /* PMS5003_SENSOR_H_ */
|
||||
|
@ -75,6 +75,7 @@ static unsigned long when_mode;
|
||||
/* Last readings of sensor data */
|
||||
static uint16_t PM1, PM2_5, PM10;
|
||||
static uint16_t PM1_ATM, PM2_5_ATM, PM10_ATM;
|
||||
static uint16_t DB0_3, DB0_5, DB1, DB2_5, DB5, DB10;
|
||||
/* Time when last sensor data was read, in clock_seconds()*/
|
||||
static unsigned long timestamp = 0;
|
||||
|
||||
@ -161,6 +162,36 @@ pms5003_pm10_atm()
|
||||
{
|
||||
return PM10_ATM;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db0_3()
|
||||
{
|
||||
return DB0_3;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db0_5()
|
||||
{
|
||||
return DB0_5;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db1()
|
||||
{
|
||||
return DB1;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db2_5()
|
||||
{
|
||||
return DB2_5;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db5()
|
||||
{
|
||||
return DB5;
|
||||
}
|
||||
uint16_t
|
||||
pms5003_db10()
|
||||
{
|
||||
return DB10;
|
||||
}
|
||||
uint32_t
|
||||
pms5003_timestamp()
|
||||
{
|
||||
@ -215,6 +246,8 @@ printpm()
|
||||
printf("PM1 = %04d, PM2.5 = %04d, PM10 = %04d\n", PM1, PM2_5, PM10);
|
||||
printf("PM1_ATM = %04d, PM2.5_ATM = %04d, PM10_ATM = %04d\n",
|
||||
PM1_ATM, PM2_5_ATM, PM10_ATM);
|
||||
printf(" DB0_3 = %04d, DB0_5 = %04d, DB1 = %04d, DB2_5 = %04d, DB5 = %04d, DB10 = %04d\n",
|
||||
DB0_3, DB0_5, DB1, DB2_5, DB5, DB10);
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -226,6 +259,8 @@ static int
|
||||
pmsframe(uint8_t *buf)
|
||||
{
|
||||
|
||||
int len;
|
||||
|
||||
if(check_pmsframe(buf)) {
|
||||
timestamp = clock_seconds();
|
||||
valid_frames++;
|
||||
@ -236,6 +271,21 @@ pmsframe(uint8_t *buf)
|
||||
PM1_ATM = (buf[10] << 8) | buf[11];
|
||||
PM2_5_ATM = (buf[12] << 8) | buf[13];
|
||||
PM10_ATM = (buf[14] << 8) | buf[15];
|
||||
/* Not all Plantower sensors report dust size bins.
|
||||
* PMS3003 (frame length 20) doesn't.
|
||||
* PMS5003 (frame length 28) does.
|
||||
* Use length field to detect if the frame has size bins.
|
||||
*/
|
||||
len = (buf[2] << 8) + buf[3];
|
||||
if(len == 28) {
|
||||
DB0_3 = (buf[16] << 8) | buf[17];
|
||||
DB0_5 = (buf[18] << 8) | buf[19];
|
||||
DB1 = (buf[20] << 8) | buf[21];
|
||||
DB2_5 = (buf[22] << 8) | buf[23];
|
||||
DB5 = (buf[24] << 8) | buf[25];
|
||||
DB10 = (buf[26] << 8) | buf[27];
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printpm();
|
||||
#endif /* DEBUG */
|
||||
|
@ -101,6 +101,12 @@ uint16_t pms5003_pm10();
|
||||
uint16_t pms5003_pm1_atm();
|
||||
uint16_t pms5003_pm2_5_atm();
|
||||
uint16_t pms5003_pm10_atm();
|
||||
uint16_t pms5003_db0_3();
|
||||
uint16_t pms5003_db0_5();
|
||||
uint16_t pms5003_db1();
|
||||
uint16_t pms5003_db2_5();
|
||||
uint16_t pms5003_db5();
|
||||
uint16_t pms5003_db10();
|
||||
uint32_t pms5003_timestamp();
|
||||
|
||||
#endif /* PMS5003_H */
|
||||
|
Loading…
Reference in New Issue
Block a user