-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpm900.cpp
More file actions
executable file
·94 lines (76 loc) · 1.82 KB
/
pm900.cpp
File metadata and controls
executable file
·94 lines (76 loc) · 1.82 KB
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
/*
pm900.cpp - Library for temtop PM900 dust sensor.
Created by Luca Marchiorello, February 13, 2020.
Released into the public domain.
*/
#include "pm900.h"
PM900::PM900() {
}
bool PM900::begin(HardwareSerial* s) {
serial = s;
serial->begin(9600);
valid = false;
return true;
}
bool PM900::read() {
// using while to empty the input buffer in case of incomplete or malformed data
while (serial->available() > 0) {
valid = false;
checksum = 0;
for (int i = sizeof(currentPacket) - 1; i >= 0 ; i--) {
*(currentByte + i) = serial->read();
checksum += *(currentByte + i);
delay(2);
}
checksum -= *(currentByte);
checksum -= *(currentByte + 1);
if (checksum == currentPacket.checksum
&& currentPacket.length == 28
&& currentPacket.start_b1 == 0x42
&& currentPacket.start_b2 == 0x4D
) valid = true;
}
return valid;
}
bool PM900::isValid() {
return valid;
}
uint16_t PM900::getcount10() {
return currentPacket.count10;
}
uint16_t PM900::getcount5() {
return currentPacket.count5;
}
uint16_t PM900::getcount2_5() {
return currentPacket.count2_5;
}
uint16_t PM900::getcount1() {
return currentPacket.count1;
}
uint16_t PM900::getcount0_5() {
return currentPacket.count0_5;
}
uint16_t PM900::getcount0_3() {
return currentPacket.count0_3;
}
uint16_t PM900::getatmpm10() {
return currentPacket.atmpm10;
}
uint16_t PM900::getatmpm2_5() {
return currentPacket.atmpm2_5;
}
uint16_t PM900::getatmpm1() {
return currentPacket.atmpm1;
}
uint16_t PM900::getpm10() {
return currentPacket.pm10;
}
uint16_t PM900::getpm2_5() {
return currentPacket.pm2_5;
}
uint16_t PM900::getpm1() {
return currentPacket.pm1;
}
void PM900::next(){
valid = false;
}