Shinnyei PPD42NJ particles sensor reading
Library to read values out of a Shinyei PPD42NJ particles sensor
Shinyei.h@0:995d42a37328, 2017-01-26 (annotated)
- Committer:
- abouillot
- Date:
- Thu Jan 26 15:07:26 2017 +0000
- Revision:
- 0:995d42a37328
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abouillot | 0:995d42a37328 | 1 | /*! |
abouillot | 0:995d42a37328 | 2 | * Shinyei.cpp |
abouillot | 0:995d42a37328 | 3 | * |
abouillot | 0:995d42a37328 | 4 | * Read the particle concentration using a Shinyei PPD42NJ sensor |
abouillot | 0:995d42a37328 | 5 | * |
abouillot | 0:995d42a37328 | 6 | * Copyright (c) 2017 - Alexandre Bouillot github.com/abouillot |
abouillot | 0:995d42a37328 | 7 | * |
abouillot | 0:995d42a37328 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
abouillot | 0:995d42a37328 | 9 | * of this software and associated documnetation files (the "Software"), to deal |
abouillot | 0:995d42a37328 | 10 | * in the Software without restriction, including without limitation the rights |
abouillot | 0:995d42a37328 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
abouillot | 0:995d42a37328 | 12 | * copies of the Software, and to permit persons to whom the Software is |
abouillot | 0:995d42a37328 | 13 | * furished to do so, subject to the following conditions: |
abouillot | 0:995d42a37328 | 14 | * |
abouillot | 0:995d42a37328 | 15 | * The above copyright notice and this permission notice shall be included in |
abouillot | 0:995d42a37328 | 16 | * all copies or substantial portions of the Software. |
abouillot | 0:995d42a37328 | 17 | * |
abouillot | 0:995d42a37328 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
abouillot | 0:995d42a37328 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
abouillot | 0:995d42a37328 | 20 | * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
abouillot | 0:995d42a37328 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
abouillot | 0:995d42a37328 | 22 | * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
abouillot | 0:995d42a37328 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
abouillot | 0:995d42a37328 | 24 | * THE SOFTWARE. |
abouillot | 0:995d42a37328 | 25 | */ |
abouillot | 0:995d42a37328 | 26 | |
abouillot | 0:995d42a37328 | 27 | #include "mbed.h" |
abouillot | 0:995d42a37328 | 28 | #include "PwmReader.h" |
abouillot | 0:995d42a37328 | 29 | |
abouillot | 0:995d42a37328 | 30 | class Shinyei |
abouillot | 0:995d42a37328 | 31 | { |
abouillot | 0:995d42a37328 | 32 | public: |
abouillot | 0:995d42a37328 | 33 | Shinyei(PinName pin) : _pwm(pin), _dataReady(false) { |
abouillot | 0:995d42a37328 | 34 | }; |
abouillot | 0:995d42a37328 | 35 | void startSampling(int duration = 30); |
abouillot | 0:995d42a37328 | 36 | void startSampling(Callback< void()>, int duration = 30); |
abouillot | 0:995d42a37328 | 37 | void stopSampling(); |
abouillot | 0:995d42a37328 | 38 | bool dataReady() { |
abouillot | 0:995d42a37328 | 39 | return _dataReady; |
abouillot | 0:995d42a37328 | 40 | }; |
abouillot | 0:995d42a37328 | 41 | float concentration() { |
abouillot | 0:995d42a37328 | 42 | if (_dataReady) |
abouillot | 0:995d42a37328 | 43 | return _concentration; |
abouillot | 0:995d42a37328 | 44 | else |
abouillot | 0:995d42a37328 | 45 | return -1; |
abouillot | 0:995d42a37328 | 46 | }; |
abouillot | 0:995d42a37328 | 47 | private: |
abouillot | 0:995d42a37328 | 48 | void samplingComplete(); |
abouillot | 0:995d42a37328 | 49 | void init(); |
abouillot | 0:995d42a37328 | 50 | PwmReader _pwm; |
abouillot | 0:995d42a37328 | 51 | bool _dataReady; |
abouillot | 0:995d42a37328 | 52 | Timeout _samplingTimer; |
abouillot | 0:995d42a37328 | 53 | float _concentration; |
abouillot | 0:995d42a37328 | 54 | Callback<void()> _callback; |
abouillot | 0:995d42a37328 | 55 | bool _callbackSet; |
abouillot | 0:995d42a37328 | 56 | }; |