marko puric / DustSenzor

Dependents:   PMS5003

Fork of DustSenzor by marko puric

DustSenzor.h

Committer:
mpuric
Date:
2017-06-08
Revision:
6:f6a93c155525
Parent:
5:fd42a3f8c7eb
Child:
7:067de0268900

File content as of revision 6:f6a93c155525:

#ifndef DUSTSENZOR_H
#define DUSTSENZOR_H
#include"mbed.h"

/** Simple class for reading values from Plantower PMS5003 dust concentration sensor.

    * Example:
    * @code:
    * #include "mbed.h"
    * #include "DustSenzor.h"
    
    * DustSenzor ds(p5, p9, p10);
    * float values [6];
    * float *ptr;
    
    * int main() {
    *   ds.start();
    *   ptr = ds.read();
        
    *       for( int i = 0; i < 6; i++) {
    *           values [i] = *(ptr + i);
    *           }
    *   }
    * @endcode
*/

class DustSenzor {
    
    public:
        DustSenzor ( PinName set, PinName uartTx, PinName uartRx );
        /** Start the communication with sensor.
        */
        void start();
        
        /** Stop the communication with sensor.
        */
        
        void stop();
        /** Read the values from a float array with 9 elements. Function is returnig a pointer to the first element of array.
        */
        float* read();
        
        /** Reset the sensor. Low reset.
        */
        void reset();  
        
    private:
        float value[9];
        Serial uart;
        DigitalOut set;
        unsigned char buff[32];
        bool provjera;
        int br;
        void serialSensor();
        void readBuffer();
        void save( unsigned char *);
       
};
#endif