loudness: merge groveloudness and hyld9767 into a single driver

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-09-15 16:52:37 -06:00 committed by Mihai Tudor Panu
parent cd7815aa07
commit 9fe9d4aec2
21 changed files with 66 additions and 330 deletions

View File

@ -72,7 +72,6 @@ add_executable (grovelinefinder-example grovelinefinder.cxx)
add_executable (grovevdiv-example grovevdiv.cxx) add_executable (grovevdiv-example grovevdiv.cxx)
add_executable (grovewater-example grovewater.cxx) add_executable (grovewater-example grovewater.cxx)
add_executable (guvas12d-example guvas12d.cxx) add_executable (guvas12d-example guvas12d.cxx)
add_executable (groveloudness-example groveloudness.cxx)
add_executable (mpr121-example mpr121.cxx) add_executable (mpr121-example mpr121.cxx)
add_executable (ublox6-example ublox6.cxx) add_executable (ublox6-example ublox6.cxx)
add_executable (yg1006-example yg1006.cxx) add_executable (yg1006-example yg1006.cxx)
@ -140,7 +139,7 @@ add_executable (ak8975-example ak8975.cxx)
add_executable (lsm9ds0-example lsm9ds0.cxx) add_executable (lsm9ds0-example lsm9ds0.cxx)
add_executable (eboled-example eboled.cxx) add_executable (eboled-example eboled.cxx)
add_executable (mpu9250-example mpu9250.cxx) add_executable (mpu9250-example mpu9250.cxx)
add_executable (hyld9767-example hyld9767.cxx) add_executable (loudness-example loudness.cxx)
add_executable (mg811-example mg811.cxx) add_executable (mg811-example mg811.cxx)
add_executable (wheelencoder-example wheelencoder.cxx) add_executable (wheelencoder-example wheelencoder.cxx)
add_executable (sm130-example sm130.cxx) add_executable (sm130-example sm130.cxx)
@ -196,7 +195,6 @@ include_directories (${PROJECT_SOURCE_DIR}/src/grovelinefinder)
include_directories (${PROJECT_SOURCE_DIR}/src/grovevdiv) include_directories (${PROJECT_SOURCE_DIR}/src/grovevdiv)
include_directories (${PROJECT_SOURCE_DIR}/src/grovewater) include_directories (${PROJECT_SOURCE_DIR}/src/grovewater)
include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d) include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d)
include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
include_directories (${PROJECT_SOURCE_DIR}/src/mpr121) include_directories (${PROJECT_SOURCE_DIR}/src/mpr121)
include_directories (${PROJECT_SOURCE_DIR}/src/ublox6) include_directories (${PROJECT_SOURCE_DIR}/src/ublox6)
include_directories (${PROJECT_SOURCE_DIR}/src/yg1006) include_directories (${PROJECT_SOURCE_DIR}/src/yg1006)
@ -252,7 +250,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/rgbringcoder)
include_directories (${PROJECT_SOURCE_DIR}/src/hp20x) include_directories (${PROJECT_SOURCE_DIR}/src/hp20x)
include_directories (${PROJECT_SOURCE_DIR}/src/pn532) include_directories (${PROJECT_SOURCE_DIR}/src/pn532)
include_directories (${PROJECT_SOURCE_DIR}/src/lsm9ds0) include_directories (${PROJECT_SOURCE_DIR}/src/lsm9ds0)
include_directories (${PROJECT_SOURCE_DIR}/src/hyld9767) include_directories (${PROJECT_SOURCE_DIR}/src/loudness)
include_directories (${PROJECT_SOURCE_DIR}/src/mg811) include_directories (${PROJECT_SOURCE_DIR}/src/mg811)
include_directories (${PROJECT_SOURCE_DIR}/src/wheelencoder) include_directories (${PROJECT_SOURCE_DIR}/src/wheelencoder)
include_directories (${PROJECT_SOURCE_DIR}/src/sm130) include_directories (${PROJECT_SOURCE_DIR}/src/sm130)
@ -331,7 +329,6 @@ target_link_libraries (grovelinefinder-example grovelinefinder ${CMAKE_THREAD_LI
target_link_libraries (grovevdiv-example grovevdiv ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (grovevdiv-example grovevdiv ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovewater-example grovewater ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (grovewater-example grovewater ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (guvas12d-example guvas12d ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (guvas12d-example guvas12d ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT})
@ -399,7 +396,7 @@ target_link_libraries (ak8975-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lsm9ds0-example lsm9ds0 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (lsm9ds0-example lsm9ds0 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (eboled-example i2clcd ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (eboled-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mpu9250-example mpu9150 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (mpu9250-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (hyld9767-example hyld9767 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (loudness-example loudness ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mg811-example mg811 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (mg811-example mg811 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (wheelencoder-example wheelencoder ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (wheelencoder-example wheelencoder ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sm130-example sm130 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (sm130-example sm130 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -1,63 +0,0 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "groveloudness.h"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a Grove Loudness sensor on analog pin A0
upm::GroveLoudness* loudness = new upm::GroveLoudness(0);
// Print the loudness value every 0.1 seconds
while (shouldRun)
{
int val = loudness->value();
cout << "Loudness value (higher is louder): " << val << endl;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;
delete loudness;
return 0;
}

View File

@ -25,13 +25,13 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "hyld9767.h" #include "loudness.h"
using namespace std; using namespace std;
bool shouldRun = true; bool shouldRun = true;
#define HYLD9767_AREF 5.0 #define LOUDNESS_AREF 5.0
void sig_handler(int signo) void sig_handler(int signo)
{ {
@ -45,9 +45,9 @@ int main()
//! [Interesting] //! [Interesting]
// Instantiate a HYLD9767 on analog pin A0, with an analog // Instantiate a Loudness sensor on analog pin A0, with an analog
// reference voltage of HYLD9767_AREF // reference voltage of LOUDNESS_AREF
upm::HYLD9767 *loud = new upm::HYLD9767(0, HYLD9767_AREF); upm::Loudness *loud = new upm::Loudness(0, LOUDNESS_AREF);
// Every tenth of a second, sample the loudness and output it's // Every tenth of a second, sample the loudness and output it's
// corresponding analog voltage. // corresponding analog voltage.

View File

@ -1,43 +0,0 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*global */
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var loudnessSensor = require('jsupm_groveloudness');
// Instantiate a Grove Loudness sensor on analog pin A0
var myLoudnessSensor = new loudnessSensor.GroveLoudness(0);
// Print the loudness value every 0.1 seconds
setInterval(function()
{
console.log("Loudness value (higher is louder): " + myLoudnessSensor.value());
}, 100);
// Print message when exiting
process.on('SIGINT', function()
{
console.log("Exiting...");
process.exit(0);
});

View File

@ -26,11 +26,11 @@
*/ */
var sensorObj = require('jsupm_hyld9767'); var sensorObj = require('jsupm_loudness');
// Instantiate a HYLD9767 on analog pin A0, with an analog // Instantiate a Loudness sensor on analog pin A0, with an analog
// reference voltage of 5.0 // reference voltage of 5.0
var sensor = new sensorObj.HYLD9767(0, 5.0); var sensor = new sensorObj.Loudness(0, 5.0);
// Every tenth of a second, sample the loudness and output it's // Every tenth of a second, sample the loudness and output it's
// corresponding analog voltage. // corresponding analog voltage.

View File

@ -1,48 +0,0 @@
#!/usr/bin/python
# Author: Zion Orent <zorent@ics.com>
# Copyright (c) 2015 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_groveloudness as upmGroveloudness
# Instantiate a Grove Loudness sensor on analog pin A0
myLoudness = upmGroveloudness.GroveLoudness(0)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This lets you run code on exit, including functions from myLoudness
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
while (1):
print "Loudness value (higher is louder):", myLoudness.value()
time.sleep(.1)

View File

@ -22,11 +22,11 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit import time, sys, signal, atexit
import pyupm_hyld9767 as sensorObj import pyupm_loudness as sensorObj
# Instantiate a HYLD9767 on analog pin A0, with an analog # Instantiate a Loudness sensor on analog pin A0, with an analog
# reference voltage of 5.0 # reference voltage of 5.0
sensor = sensorObj.HYLD9767(0, 5.0) sensor = sensorObj.Loudness(0, 5.0)
## Exit handlers ## ## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C # This function stops python from printing a stacktrace when you hit control-C

View File

@ -1,5 +0,0 @@
set (libname "groveloudness")
set (libdescription "upm grove loudness module")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,77 +0,0 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
namespace upm {
/**
* @brief Grove Loudness sensor library
* @defgroup groveloudness libupm-groveloudness
* @ingroup seeed analog sound
*/
/**
* @library groveloudness
* @sensor groveloudness
* @comname Grove Loudness Sensor
* @type sound
* @man seeed
* @con analog
*
* @brief API for the Grove Loudness Sensor
*
* UPM module for the Grove Loudness Sensor. This sensor
* detects how loud the surrounding environment is.
* The higher the output analog value, the louder the sound.
*
* @image html groveloudness.jpg
* @snippet groveloudness.cxx Interesting
*/
class GroveLoudness {
public:
/**
* Grove analog loudness sensor constructor
*
* @param pin Analog pin to use
*/
GroveLoudness(int pin);
/**
* GroveLoudness destructor
*/
~GroveLoudness();
/**
* Gets the loudness value from the sensor
*
* @return Loudness reading
*/
int value();
private:
mraa_aio_context m_aio;
};
}

View File

@ -1,8 +0,0 @@
%module javaupm_groveloudness
%include "../upm.i"
%{
#include "groveloudness.h"
%}
%include "groveloudness.h"

View File

@ -1,8 +0,0 @@
%module jsupm_groveloudness
%include "../upm.i"
%{
#include "groveloudness.h"
%}
%include "groveloudness.h"

View File

@ -1,9 +0,0 @@
%module pyupm_groveloudness
%include "../upm.i"
%feature("autodoc", "3");
%include "groveloudness.h"
%{
#include "groveloudness.h"
%}

View File

@ -1,8 +0,0 @@
%module javaupm_hyld9767
%include "../upm.i"
%{
#include "hyld9767.h"
%}
%include "hyld9767.h"

View File

@ -1,8 +0,0 @@
%module jsupm_hyld9767
%include "../upm.i"
%{
#include "hyld9767.h"
%}
%include "hyld9767.h"

View File

@ -1,9 +0,0 @@
%module pyupm_hyld9767
%include "../upm.i"
%feature("autodoc", "3");
%include "hyld9767.h"
%{
#include "hyld9767.h"
%}

View File

@ -1,5 +1,5 @@
set (libname "hyld9767") set (libname "loudness")
set (libdescription "upm DFRobot loudness sensor") set (libdescription "upm loudness sensors")
set (module_src ${libname}.cxx) set (module_src ${libname}.cxx)
set (module_h ${libname}.h) set (module_h ${libname}.h)
upm_module_init() upm_module_init()

View File

@ -0,0 +1,8 @@
%module javaupm_loudness
%include "../upm.i"
%{
#include "loudness.h"
%}
%include "loudness.h"

View File

@ -0,0 +1,8 @@
%module jsupm_loudness
%include "../upm.i"
%{
#include "loudness.h"
%}
%include "loudness.h"

View File

@ -24,23 +24,23 @@
#include <iostream> #include <iostream>
#include "hyld9767.h" #include "loudness.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
HYLD9767::HYLD9767(int pin, float aref) : Loudness::Loudness(int pin, float aref) :
m_aio(pin) m_aio(pin)
{ {
m_aRes = m_aio.getBit(); m_aRes = m_aio.getBit();
m_aref = aref; m_aref = aref;
} }
HYLD9767::~HYLD9767() Loudness::~Loudness()
{ {
} }
float HYLD9767::loudness() float Loudness::loudness()
{ {
int val = m_aio.read(); int val = m_aio.read();

View File

@ -27,54 +27,54 @@
#include <string> #include <string>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
// EZ series is volts/512
#define HYLD9767_RES 512
namespace upm { namespace upm {
/** /**
* @brief DFRobot Loudness Sensor V2 * @brief Generic loudness sensors
* @defgroup hyld9767 libupm-hyld9767 * @defgroup loudness libupm-loudness
* @ingroup dfrobot analog sound * @ingroup dfrobot seeed analog sound
*/ */
/** /**
* @library hyld9767 * @library loudness
* @sensor hyld9767 * @sensor loudness
* @comname DFRobot Loudness Sensor V2 * @comname Loudness Sensor
* @altname HYLD9767 * @altname Grove loudness hyld9767
* @type sound * @type sound
* @man dfrobot * @man dfrobot seeed
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=83 * @web http://www.dfrobot.com/index.php?route=product/product&product_id=83
* @con analog * @con analog
* *
* @brief API for the DFRobot Loudness Sensor V2 * @brief API for the Loudness Sensor
* *
* This sensor returns an analog voltage proportional to the * This sensor family returns an analog voltage proportional to the
* loudness of the ambient environment. It's output does not * loudness of the ambient environment. It's output does not
* correspond to a particular sound level in decibels. * correspond to a particular sound level in decibels. The higher
* the output voltage, the louder the ambient noise level.
* *
* This device uses an HYLD9767 electret microphone for sound input. * This device uses an electret microphone for sound input.
* *
* This driver was developed using the DFRobot Loudness Sensor V2 * This driver was developed using the DFRobot Loudness Sensor V2
* and the Grove Loudness sensor.
* *
* @snippet hyld9767.cxx Interesting * @image html groveloudness.jpg
* @snippet loudness.cxx Interesting
*/ */
class HYLD9767 { class Loudness {
public: public:
/** /**
* HYLD9767 constructor * Loudness constructor
* *
* @param pin Analog pin to use * @param pin Analog pin to use
* @param aref Analog reference voltage; default is 5.0 V * @param aref Analog reference voltage; default is 5.0 V
*/ */
HYLD9767(int pin, float aref=5.0); Loudness(int pin, float aref=5.0);
/** /**
* HYLD9767 destructor * Loudness destructor
*/ */
~HYLD9767(); ~Loudness();
/** /**
* Returns the voltage detected on the analog pin * Returns the voltage detected on the analog pin

View File

@ -0,0 +1,9 @@
%module pyupm_loudness
%include "../upm.i"
%feature("autodoc", "3");
%include "loudness.h"
%{
#include "loudness.h"
%}