1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 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 <iostream>
27 #include <string>
28 #include <mraa/aio.hpp>
29 
30 namespace upm {
31   /**
32    * @brief Generic loudness sensors
33    * @defgroup loudness libupm-loudness
34    * @ingroup dfrobot seeed analog sound
35    */
36 
37   /**
38    * @library loudness
39    * @sensor loudness
40    * @comname Loudness Sensor
41    * @altname Grove loudness hyld9767
42    * @type sound
43    * @man dfrobot seeed
44    * @web http://www.dfrobot.com/index.php?route=product/product&product_id=83
45    * @con analog
46    *
47    * @brief API for the Loudness Sensor
48    *
49    * This sensor family returns an analog voltage proportional to the
50    * loudness of the ambient environment.  It's output does not
51    * correspond to a particular sound level in decibels.  The higher
52    * the output voltage, the louder the ambient noise level.
53    *
54    * This device uses an electret microphone for sound input.
55    *
56    * This driver was developed using the DFRobot Loudness Sensor V2
57    * and the Grove Loudness sensor.
58    *
59    * @image html groveloudness.jpg
60    * @snippet loudness.cxx Interesting
61    */
62 
63   class Loudness {
64   public:
65 
66     /**
67      * Loudness constructor
68      *
69      * @param pin Analog pin to use
70      * @param aref Analog reference voltage; default is 5.0 V
71      */
72     Loudness(int pin, float aref=5.0);
73 
74     /**
75      * Loudness destructor
76      */
77     ~Loudness();
78 
79     /**
80      * Returns the voltage detected on the analog pin
81      *
82      * @return The detected voltage
83      */
84     float loudness();
85 
86   protected:
87     mraa::Aio m_aio;
88 
89   private:
90     float m_aref;
91     // ADC resolution
92     int m_aRes;
93   };
94 }
95 
96 
97