1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/aio.h>
28 
29 namespace upm {
30 
31   /**
32    * @brief MQ303A Alcohol Sensor library
33    * @defgroup mq303a libupm-mq303a
34    * @ingroup seeed analog gpio gaseous tsk
35    */
36   /**
37    * @library mq303a
38    * @sensor mq303a
39    * @comname MQ303A Alcohol Sensor
40    * @altname Grove Alcohol Sensor
41    * @type gaseous
42    * @man seeed
43    * @web http://www.seeedstudio.com/wiki/Grove_-_Alcohol_Sensor
44    * @con analog gpio
45    * @kit tsk
46    *
47    * @brief API for the MQ303A Alcohol Sensor
48    *
49    * UPM module for the MQ303A alcohol sensor.
50    * This sensor needs to be warmed up before stable results are
51    * obtained. The higher the value returned from value(),
52    * the higher the amount of alcohol detected.
53    *
54    * @image html mq303a.jpg
55    * @snippet mq303a.cxx Interesting
56    */
57   class MQ303A {
58   public:
59     /**
60      * MQ303A constructor
61      *
62      * @param pin Analog pin to use
63      * @param heaterPin Digital pin mapped to the analog pin to use
64      */
65     MQ303A(int pin, int heaterPin);
66 
67     /**
68      * MQ303A destructor
69      */
70     ~MQ303A();
71 
72     /**
73      * Gets the alcohol reading from the sensor.
74      * The value read from the analog pin is inverted.
75      * A higher returned value means a higher amount of alcohol detected.
76      *
77      * @return Alcohol reading
78      */
79     int value();
80 
81     /**
82      * Enables the heater
83      *
84      * @param enable Enables the heater if true; otherwise, disables it
85      */
86     void heaterEnable(bool enable);
87 
88   private:
89     mraa_aio_context m_aio;
90     mraa_gpio_context m_gpio;
91   };
92 }
93 
94 
95