mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Initial implementation of Grove PIR motion sensor with BISS0001 chip
jrvandr: removed unnecessary mraa_init() Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:
parent
9cda72b077
commit
5448e72975
@ -73,6 +73,7 @@ add_executable (ppd42ns-example ppd42ns.cxx)
|
||||
add_executable (mq303a-example mq303a.cxx)
|
||||
add_executable (grovespeaker-example grovespeaker.cxx)
|
||||
add_executable (rfr359f-example rfr359f.cxx)
|
||||
add_executable (biss0001-example biss0001.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -133,6 +134,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/ppd42ns)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mq303a)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovespeaker)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/rfr359f)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/biss0001)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -209,3 +211,4 @@ target_link_libraries (ppd42ns-example ppd42ns ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq303a-example mq303a ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovespeaker-example grovespeaker ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rfr359f-example rfr359f ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (biss0001-example biss0001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
68
examples/biss0001.cxx
Normal file
68
examples/biss0001.cxx
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "biss0001.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 Motion sensor on GPIO pin D2
|
||||
upm::BISS0001* motion = new upm::BISS0001(2);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = motion->value();
|
||||
|
||||
if (val)
|
||||
cout << "Detecting moving object";
|
||||
else
|
||||
cout << "No moving objects detected";
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete motion;
|
||||
return 0;
|
||||
}
|
45
examples/javascript/biss0001.js
Normal file
45
examples/javascript/biss0001.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*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.
|
||||
*/
|
||||
|
||||
//Load Grove Motion module
|
||||
var grove_motion = require('jsupm_biss0001');
|
||||
// Instantiate a Grove Motion sensor on GPIO pin D2
|
||||
var myMotionObj = new grove_motion.BISS0001(2);
|
||||
setInterval(function()
|
||||
{
|
||||
if (myMotionObj.value())
|
||||
console.log("Detecting moving object");
|
||||
else
|
||||
console.log("No moving objects detected");
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
5
src/biss0001/CMakeLists.txt
Normal file
5
src/biss0001/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "biss0001")
|
||||
set (libdescription "upm biss0001 motion module")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
45
src/biss0001/biss0001.cxx
Normal file
45
src/biss0001/biss0001.cxx
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Author: Zion Orent <sorent@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 "biss0001.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
BISS0001::BISS0001(int pin)
|
||||
{
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
|
||||
}
|
||||
|
||||
BISS0001::~BISS0001()
|
||||
{
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
|
||||
bool BISS0001::value()
|
||||
{
|
||||
return (mraa_gpio_read(m_gpio) ? true : false);
|
||||
}
|
63
src/biss0001/biss0001.h
Normal file
63
src/biss0001/biss0001.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: Zion Orent <sorent@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 BISS0001 Motion Sensor
|
||||
*
|
||||
* UPM module for the BISS0001 Motion Sensor
|
||||
*
|
||||
* @ingroup gpio
|
||||
* @snippet biss0001.cxx Interesting
|
||||
*/
|
||||
class BISS0001 {
|
||||
public:
|
||||
/**
|
||||
* BISS0001 motion sensor constructor
|
||||
*
|
||||
* @param pin digital pin to use
|
||||
*/
|
||||
BISS0001(int pin);
|
||||
/**
|
||||
* BISS0001 Destructor
|
||||
*/
|
||||
~BISS0001();
|
||||
/**
|
||||
* Get the motion value from the sensor
|
||||
*
|
||||
* @return the motion reading
|
||||
*/
|
||||
bool value();
|
||||
|
||||
private:
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
}
|
||||
|
||||
|
8
src/biss0001/jsupm_biss0001.i
Normal file
8
src/biss0001/jsupm_biss0001.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_biss0001
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "biss0001.h"
|
||||
%}
|
||||
|
||||
%include "biss0001.h"
|
9
src/biss0001/pyupm_biss0001.i
Normal file
9
src/biss0001/pyupm_biss0001.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_biss0001
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "biss0001.h"
|
||||
%{
|
||||
#include "biss0001.h"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user