class Pms
- class
Pms
represents PMS5003 sensor operations - class
Pms
constructors/destructor:- default constructor
Pms();
- does nothing (initializes fields representing state)
-
Do It Yourself: execute
addSerial(&pmsSerial);
-
Do It Yourself: execute
begin();
- constructor
explicit Pms(IPmsSerial* pmsSerial);
- initializes fields representing state
- executes
addSerial(pmsSerial);
-
(default) if symbol
PMS_DYNAMIC
is not defined: Do It Yourself: executebegin();
- if symbol
PMS_DYNAMIC
is defined: executesbegin();
- destructor
~Pms();
- if symbol
PMS_DYNAMIC
is defined: executesend();
- if symbol
- default constructor
- class
Pms
provides a few usable constants:-
static constexpr unsigned long int TIMEOUT_PASSIVE = 68U;
- it is used as serial port driver default timeout
- Calculation: transfer time of 1start + 32data + 1stop using 9600bps is 33 milliseconds. TIMEOUT_PASSIVE could be at least 34, Value of 68 is arbitrary doubled
-
static constexpr unsigned int WAKEUP_TIME = 2500U;
- used in
waitForData()
afterwrite()
command withCMD_WAKEUP
orCMD_RESET
- established experimentally
- used in
-
- more class
Pms
initialization methods:-
void addSerial(IPmsSerial* pmsSerial);
- Just defines serial port driver to be used during communication, nothing more
-
bool begin();
- initializes communication between PMS5003 and a serial driver
- if serial driver'
begin()
returnstrue
:Pms::begin()
returnstrue
too - otherwise it removes serial driver (
addSerial(nullptr);
) and returnsfalse
-
void end()
- stops communication between serial driver and PMS5003 (just
pmsSerial->end();
)
- stops communication between serial driver and PMS5003 (just
-
void setTimeout(unsigned long int);
- modifies timeout for serial port communication. Default timeout is set to
TIMEOUT_PASSIVE
(68 milliseconds)
- modifies timeout for serial port communication. Default timeout is set to
-
- class
Pms
provides information about sensor state:-
tribool isModeActive();
- state changes:
- yes:
CMD_RESET
,CMD_MODE_ACTIVE
from!isModeActive()
,CMD_WAKEUP
fromisModeSleep()
- no:
CMD_MODE_PASSIVE
fromisModeActive()
- unknown: initially
- yes:
- state changes:
-
tribool isModeSleep();
- state changes:
- yes:
CMD_SLEEP
from!isModeSleep()
- no:
CMD_RESET
,CMD_WAKEUP
fromisModeSleep()
- unknown: initially
- yes:
- state changes:
-
bool isWorking();
-
bool initialized();
- returns true if there is assigned a serial driver
-
unsigned long int getTimeout(void);
- returns current serial port operations timeout
- initially: TIMEOUT_PASSIVE
- can be changed by
setTimeout()
- returns current serial port operations timeout
-
- class
Pms
allows assigning PMS5003 pins 3 and 6 (white SET and violet RESET) to Arduino pins-
void setPinSleepMode(uint8_t value);
- assigns PMS5003 PIN3 (white) to Arduino PIN value
- no test is made after assignment
- it is OK to leave PMS5003 PIN3 not connected. Sleep/WakeUp command will be sent using serial communication
- assigns PMS5003 PIN3 (white) to Arduino PIN value
-
void setPinReset(uint8_t value);
- assigns PMS5003 PIN6 (violet) to Arduino PIN value
- no test is made after assignment
- it is OK to leave PMS5003 PIN6 not connected. Reset command can be emulated sending
CMD_SLEEP
+CMD_WAKEUP
sequence
- assigns PMS5003 PIN6 (violet) to Arduino PIN value
-
- class
Pms
allows simple monitoring of serial driver activity-
size_t available();
- returns number of bytes sent by PMS5003 but not read yet
-
available()
removes data from serial port buffer if they looks as a garbage- the first byte in the buffer should be
0x42
- the first byte of properly formatted data frame
- the first byte in the buffer should be
-
bool waitForData(unsigned int maxTime);
- waits
- not longer than maxTime
- wait for any data available from serial driver
- data can be even garbage
- returns
true
if there are ready any data in serial port buffer
- waits
-
bool waitForData(unsigned int maxTime, size_t nData );
,nData > 0
- waits
- not longer than maxTime
- wait for looking good data from serial driver
- garbage is removed using
available()
described above - to wait for the whole, well formatted frame:
pms.waitForData(pmsx::Pms::TIMEOUT_PASSIVE, pmsx::PmsData::FRAME_SIZE);
- returns true if there are waiting
nData
bytes in the serial port buffer - even if it returns
true
there is no guarantee that waiting frame is not corrupted
- waits
-
- class
Pms
allows driving PMS5003 sensor-
bool write(PmsCmd cmd);
-
bool write(PmsCmd cmd, unsigned int wakeupTime);
-
-
class
Pms
reads data from PMS5003 sensor
Notice about PMS5003 modes
Passive mode
In passive mode sensor waits for CMD_READ_DATA
command, then sends its data. Don't rely on that naive loop: