diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fb05ac16..8c6edec3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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}) diff --git a/examples/biss0001.cxx b/examples/biss0001.cxx new file mode 100644 index 00000000..1574c2fd --- /dev/null +++ b/examples/biss0001.cxx @@ -0,0 +1,68 @@ +/* + * Author: Zion Orent + * 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 +#include +#include +#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; +} diff --git a/examples/javascript/biss0001.js b/examples/javascript/biss0001.js new file mode 100644 index 00000000..830a88d5 --- /dev/null +++ b/examples/javascript/biss0001.js @@ -0,0 +1,45 @@ +/*jslint node:true, vars:true, bitwise:true, unparam:true */ +/*jshint unused:true */ +/*global */ +/* +* Author: Zion Orent +* 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); +}); diff --git a/src/biss0001/CMakeLists.txt b/src/biss0001/CMakeLists.txt new file mode 100644 index 00000000..1e1223ad --- /dev/null +++ b/src/biss0001/CMakeLists.txt @@ -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() diff --git a/src/biss0001/biss0001.cxx b/src/biss0001/biss0001.cxx new file mode 100644 index 00000000..34111528 --- /dev/null +++ b/src/biss0001/biss0001.cxx @@ -0,0 +1,45 @@ +/* + * Author: Zion Orent + * 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 + +#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); +} diff --git a/src/biss0001/biss0001.h b/src/biss0001/biss0001.h new file mode 100644 index 00000000..80f5a3c3 --- /dev/null +++ b/src/biss0001/biss0001.h @@ -0,0 +1,63 @@ +/* + * Author: Zion Orent + * 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 +#include + +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; + }; +} + + diff --git a/src/biss0001/jsupm_biss0001.i b/src/biss0001/jsupm_biss0001.i new file mode 100644 index 00000000..bff6ccff --- /dev/null +++ b/src/biss0001/jsupm_biss0001.i @@ -0,0 +1,8 @@ +%module jsupm_biss0001 +%include "../upm.i" + +%{ + #include "biss0001.h" +%} + +%include "biss0001.h" diff --git a/src/biss0001/pyupm_biss0001.i b/src/biss0001/pyupm_biss0001.i new file mode 100644 index 00000000..a4c88a91 --- /dev/null +++ b/src/biss0001/pyupm_biss0001.i @@ -0,0 +1,9 @@ +%module pyupm_biss0001 +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "biss0001.h" +%{ + #include "biss0001.h" +%}