Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PMS.h
00001 #ifndef PMS_H 00002 #define PMS_H 00003 00004 #include "mbed.h" 00005 #define DUST_BUFFER 64 00006 class PMS 00007 { 00008 public: 00009 static const uint16_t SINGLE_RESPONSE_TIME = 1000; 00010 static const uint16_t TOTAL_RESPONSE_TIME = 1000 * 10; 00011 static const uint16_t STEADY_RESPONSE_TIME = 1000 * 30; 00012 00013 static const uint16_t BAUD_RATE = 9600; 00014 00015 struct DATA { 00016 // Standard Particles, CF=1 00017 uint16_t PM_SP_UG_1_0; 00018 uint16_t PM_SP_UG_2_5; 00019 uint16_t PM_SP_UG_10_0; 00020 00021 // Atmospheric environment 00022 uint16_t PM_AE_UG_1_0; 00023 uint16_t PM_AE_UG_2_5; 00024 uint16_t PM_AE_UG_10_0; 00025 }; 00026 00027 PMS(RawSerial&); 00028 PMS(PinName tx, PinName rx); 00029 ~PMS() { 00030 delete _stream; 00031 delete _data; 00032 } 00033 void begin(DATA&); 00034 void activeMode(); 00035 void passiveMode(); 00036 void requestRead(); 00037 bool available(); 00038 private: 00039 enum STATUS { STATUS_WAITING, STATUS_OK }; 00040 enum MODE { MODE_ACTIVE, MODE_PASSIVE }; 00041 00042 uint8_t _payload[12]; 00043 RawSerial* _stream; 00044 Timer _tmr; 00045 DATA* _data; 00046 volatile STATUS _status; 00047 MODE _mode = MODE_PASSIVE; 00048 volatile char buf[DUST_BUFFER]; 00049 uint8_t _index = 0; 00050 uint16_t _frameLen; 00051 uint16_t _checksum; 00052 uint16_t _calculatedChecksum; 00053 00054 uint16_t makeWord(uint8_t high, uint8_t low); 00055 00056 void RxInterrupt(); 00057 void Caculate(); 00058 }; 00059 00060 #endif
Generated on Sat Aug 13 2022 18:37:56 by
1.7.2