Dust sensor
Fork of DustSenzor by
DustSenzor.h@10:d846eb9ef8e6, 2017-06-28 (annotated)
- Committer:
- mpuric
- Date:
- Wed Jun 28 18:35:18 2017 +0000
- Revision:
- 10:d846eb9ef8e6
- Parent:
- 9:93fe9ccde2a9
added api doc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mpuric | 0:513b42c738f3 | 1 | #ifndef DUSTSENZOR_H |
mpuric | 0:513b42c738f3 | 2 | #define DUSTSENZOR_H |
mpuric | 0:513b42c738f3 | 3 | #include"mbed.h" |
mpuric | 6:f6a93c155525 | 4 | |
mpuric | 10:d846eb9ef8e6 | 5 | /** Simple class for reading values from Plantower PMS5003 dust concentration sensor. |
mpuric | 10:d846eb9ef8e6 | 6 | * |
mpuric | 6:f6a93c155525 | 7 | * Example: |
mpuric | 6:f6a93c155525 | 8 | * @code: |
mpuric | 6:f6a93c155525 | 9 | * #include "mbed.h" |
mpuric | 6:f6a93c155525 | 10 | * #include "DustSenzor.h" |
mpuric | 6:f6a93c155525 | 11 | |
mpuric | 6:f6a93c155525 | 12 | * DustSenzor ds(p5, p9, p10); |
mpuric | 6:f6a93c155525 | 13 | * float values [6]; |
mpuric | 6:f6a93c155525 | 14 | * float *ptr; |
mpuric | 10:d846eb9ef8e6 | 15 | * |
mpuric | 6:f6a93c155525 | 16 | * int main() { |
mpuric | 6:f6a93c155525 | 17 | * ds.start(); |
mpuric | 6:f6a93c155525 | 18 | * ptr = ds.read(); |
mpuric | 10:d846eb9ef8e6 | 19 | * |
mpuric | 6:f6a93c155525 | 20 | * for( int i = 0; i < 6; i++) { |
mpuric | 6:f6a93c155525 | 21 | * values [i] = *(ptr + i); |
mpuric | 6:f6a93c155525 | 22 | * } |
mpuric | 6:f6a93c155525 | 23 | * } |
mpuric | 6:f6a93c155525 | 24 | * @endcode |
mpuric | 10:d846eb9ef8e6 | 25 | */ |
mpuric | 6:f6a93c155525 | 26 | class DustSenzor { |
mpuric | 6:f6a93c155525 | 27 | |
mpuric | 0:513b42c738f3 | 28 | public: |
mpuric | 10:d846eb9ef8e6 | 29 | /** Create DustSenzor instance. |
mpuric | 10:d846eb9ef8e6 | 30 | * @param set Sensor set pin. |
mpuric | 10:d846eb9ef8e6 | 31 | * @param uartTx Sensor Tx pin. |
mpuric | 10:d846eb9ef8e6 | 32 | * @param uartRx Sensor Rx pin. |
mpuric | 10:d846eb9ef8e6 | 33 | */ |
mpuric | 6:f6a93c155525 | 34 | DustSenzor ( PinName set, PinName uartTx, PinName uartRx ); |
mpuric | 9:93fe9ccde2a9 | 35 | |
mpuric | 6:f6a93c155525 | 36 | /** Start the communication with sensor. |
mpuric | 6:f6a93c155525 | 37 | */ |
mpuric | 5:fd42a3f8c7eb | 38 | void start(); |
mpuric | 6:f6a93c155525 | 39 | |
mpuric | 6:f6a93c155525 | 40 | /** Stop the communication with sensor. |
mpuric | 6:f6a93c155525 | 41 | */ |
mpuric | 9:93fe9ccde2a9 | 42 | void stop(); |
mpuric | 6:f6a93c155525 | 43 | |
mpuric | 9:93fe9ccde2a9 | 44 | /** Read the values from a float array with 6 elements. |
mpuric | 10:d846eb9ef8e6 | 45 | * Function is returnig a pointer to the first element of array. |
mpuric | 6:f6a93c155525 | 46 | */ |
mpuric | 5:fd42a3f8c7eb | 47 | float* read(); |
mpuric | 8:faa84647167c | 48 | |
mpuric | 0:513b42c738f3 | 49 | private: |
mpuric | 8:faa84647167c | 50 | float value[6]; |
mpuric | 0:513b42c738f3 | 51 | Serial uart; |
mpuric | 0:513b42c738f3 | 52 | DigitalOut set; |
mpuric | 2:4c3bdadb6bc4 | 53 | unsigned char buff[32]; |
mpuric | 2:4c3bdadb6bc4 | 54 | bool provjera; |
mpuric | 0:513b42c738f3 | 55 | int br; |
mpuric | 7:067de0268900 | 56 | void serialRead(); |
mpuric | 6:f6a93c155525 | 57 | void readBuffer(); |
mpuric | 5:fd42a3f8c7eb | 58 | void save( unsigned char *); |
mpuric | 5:fd42a3f8c7eb | 59 | |
mpuric | 0:513b42c738f3 | 60 | }; |
mpuric | 0:513b42c738f3 | 61 | #endif |
mpuric | 0:513b42c738f3 | 62 | |
mpuric | 0:513b42c738f3 | 63 |