-
Notifications
You must be signed in to change notification settings - Fork 2
/
Conplug_PMS5003T.h
136 lines (108 loc) · 2.4 KB
/
Conplug_PMS5003T.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// Copyright (c) 2019 Conplug (https://conplug.com.tw)
// Author: Hartman Hsieh
//
// Description :
// Dust sensor - PMS5003T or PMS3003
// Environment:
// NodeMCU 1.0
// Arduino 1.8.9
//
// Connections :
// PMS5003T => Serial Port
//
// Required Library :
// None
//
#ifndef __CONPLUG_PMS5003T_H__
#define __CONPLUG_PMS5003T_H__
#include "SoftwareSerial.h"
#define MAX_PMS_DATA_SIZE 32
#pragma pack(push)
#pragma pack(1)
struct PMS5003T_DATA {
uint8_t SIG_1;
uint8_t SIG_2;
uint16_t DATA_LENGTH;
//
// Standard Particles, CF=1
//
uint16_t PM_SP_UG_1_0;
uint16_t PM_SP_UG_2_5;
uint16_t PM_SP_UG_10_0;
//
// Atmospheric environment
//
uint16_t PM_AE_UG_1_0;
uint16_t PM_AE_UG_2_5;
uint16_t PM_AE_UG_10_0;
uint16_t PM_NUM_0_3;
uint16_t PM_NUM_0_5;
uint16_t PM_NUM_1_0;
uint16_t PM_NUM_2_5;
uint16_t PM_TEMP;
uint16_t PM_HUMI;
uint8_t ERRCODE;
uint8_t VERCODE;
uint16_t CHECKSUM;
};
struct PMS3003_DATA {
uint8_t SIG_1;
uint8_t SIG_2;
uint16_t DATA_LENGTH;
//
// Standard Particles, CF=1
//
uint16_t PM_SP_UG_1_0;
uint16_t PM_SP_UG_2_5;
uint16_t PM_SP_UG_10_0;
//
// Atmospheric environment
//
uint16_t PM_AE_UG_1_0;
uint16_t PM_AE_UG_2_5;
uint16_t PM_AE_UG_10_0;
uint16_t RSV7;
uint16_t RSV8;
uint16_t RSV9;
uint16_t CHECKSUM;
};
#pragma pack(pop)
const uint8_t PMS_CMD_PASSIVE_MODE[] = { 0x42, 0x4D, 0xE1, 0x00, 0x00, 0x01, 0x70 };
const uint8_t PMS_CMD_REQUEST_READ[] = { 0x42, 0x4D, 0xE2, 0x00, 0x00, 0x01, 0x71 };
class Conplug_PMS5003T
{
public:
typedef enum {
PMS5003T,
PMS3003
}
PMS_TYPE;
typedef enum {
AFTER_SEND_PASSIVE_CMD,
AFTER_SEND_REQUEST_CMD,
SERIAL_READ
}
PMS_DELAY;
int LastErr;
Conplug_PMS5003T(SoftwareSerial* pPmsSerial);
void begin();
PMS5003T_DATA* readPms();
int pm1_0(); // PM1.0 ug/m^3
int pm2_5(); // PM2.5 ug/m^3
int pm10_0(); // PM10 ug/m^3
float temp();
float humi();
PMS_TYPE readDeviceType();
//
// The function must be run before begin.
//
void setDelay(PMS_DELAY PmsDelay, int Value);
private:
SoftwareSerial* PmsSerial;
uint8_t Buff[MAX_PMS_DATA_SIZE];
PMS5003T_DATA* Pd;
PMS_TYPE DeviceType;
int DelayValue[3];
};
#endif // __CONPLUG_PMS5003T_H__