mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
groveloudness: Initial implementation
This module implements support for the Grove Loudness sensor. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
This commit is contained in:
parent
38a14eb068
commit
2eb0047643
@ -64,6 +64,7 @@ add_executable (grovelinefinder-example grovelinefinder.cxx)
|
||||
add_executable (grovevdiv-example grovevdiv.cxx)
|
||||
add_executable (grovewater-example grovewater.cxx)
|
||||
add_executable (guvas12d-example guvas12d.cxx)
|
||||
add_executable (groveloudness-example groveloudness.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -115,6 +116,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/grovelinefinder)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovevdiv)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovewater)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -182,3 +184,4 @@ target_link_libraries (grovelinefinder-example grovelinefinder ${CMAKE_THREAD_LI
|
||||
target_link_libraries (grovevdiv-example grovevdiv ${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 (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
63
examples/groveloudness.cxx
Normal file
63
examples/groveloudness.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
43
examples/javascript/groveloudness.js
Normal file
43
examples/javascript/groveloudness.js
Normal file
@ -0,0 +1,43 @@
|
||||
/*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);
|
||||
});
|
5
src/groveloudness/CMakeLists.txt
Normal file
5
src/groveloudness/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "groveloudness")
|
||||
set (libdescription "upm grove loudness module")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
46
src/groveloudness/groveloudness.cxx
Normal file
46
src/groveloudness/groveloudness.cxx
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "groveloudness.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
GroveLoudness::GroveLoudness(int pin)
|
||||
{
|
||||
mraa_init();
|
||||
|
||||
m_aio = mraa_aio_init(pin);
|
||||
}
|
||||
|
||||
GroveLoudness::~GroveLoudness()
|
||||
{
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveLoudness::value()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
}
|
65
src/groveloudness/groveloudness.h
Normal file
65
src/groveloudness/groveloudness.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 C++ 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.
|
||||
*
|
||||
* @ingroup grove analog
|
||||
* @snippet groveloudness.cxx Interesting
|
||||
*/
|
||||
class GroveLoudness {
|
||||
public:
|
||||
/**
|
||||
* Grove analog loudness sensor constructor
|
||||
*
|
||||
* @param pin analog pin to use
|
||||
*/
|
||||
GroveLoudness(int pin);
|
||||
/**
|
||||
* GroveLoudness Destructor
|
||||
*/
|
||||
~GroveLoudness();
|
||||
/**
|
||||
* Get the loudness value from the sensor
|
||||
*
|
||||
* @return the loudness reading
|
||||
*/
|
||||
int value();
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
}
|
||||
|
||||
|
8
src/groveloudness/jsupm_groveloudness.i
Normal file
8
src/groveloudness/jsupm_groveloudness.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_groveloudness
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "groveloudness.h"
|
||||
%}
|
||||
|
||||
%include "groveloudness.h"
|
9
src/groveloudness/pyupm_groveloudness.i
Normal file
9
src/groveloudness/pyupm_groveloudness.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_groveloudness
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "groveloudness.h"
|
||||
%{
|
||||
#include "groveloudness.h"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user