From a9883bd1f2bffa31cab935323600a8685278f818 Mon Sep 17 00:00:00 2001 From: Abhishek Malik Date: Tue, 13 Sep 2016 16:32:04 -0700 Subject: [PATCH] Grove: Reverting Grove sources Signed-off-by: Abhishek Malik --- src/button/button.cxx | 1 + src/grove/CMakeLists.txt | 12 +- src/grove/grove.hpp | 6 +- src/grove/grovebutton.cxx | 82 ++++++++++ src/grove/grovebutton.hpp | 104 ++++++++++++ src/grove/grovelight.cxx | 63 +++++++ src/grove/grovelight.hpp | 82 ++++++++++ src/grove/groverelay.cxx | 69 ++++++++ src/grove/groverelay.hpp | 95 +++++++++++ src/grove/groverotary.cxx | 79 +++++++++ src/grove/groverotary.hpp | 106 ++++++++++++ src/grove/groveslide.cxx | 68 ++++++++ src/grove/groveslide.hpp | 87 ++++++++++ src/grove/javaupm_grove.i | 25 +++ src/grove/jsupm_grove.i | 25 +++ src/grove/pyupm_grove.i | 25 +++ src/grovecollision/CMakeLists.txt | 5 + src/grovecollision/grovecollision.cxx | 53 ++++++ src/grovecollision/grovecollision.hpp | 72 ++++++++ src/grovecollision/javaupm_grovecollision.i | 19 +++ src/grovecollision/jsupm_grovecollision.i | 8 + src/grovecollision/pyupm_grovecollision.i | 11 ++ src/groveehr/CMakeLists.txt | 5 + src/groveehr/groveehr.cxx | 130 +++++++++++++++ src/groveehr/groveehr.hpp | 126 ++++++++++++++ src/groveehr/javaupm_groveehr.i | 21 +++ src/groveehr/jsupm_groveehr.i | 8 + src/groveehr/pyupm_groveehr.i | 11 ++ src/groveelectromagnet/CMakeLists.txt | 5 + src/groveelectromagnet/groveelectromagnet.cxx | 62 +++++++ src/groveelectromagnet/groveelectromagnet.hpp | 77 +++++++++ .../javaupm_groveelectromagnet.i | 19 +++ .../jsupm_groveelectromagnet.i | 8 + .../pyupm_groveelectromagnet.i | 11 ++ src/groveemg/CMakeLists.txt | 5 + src/groveemg/groveemg.cxx | 69 ++++++++ src/groveemg/groveemg.hpp | 82 ++++++++++ src/groveemg/javaupm_groveemg.i | 19 +++ src/groveemg/jsupm_groveemg.i | 8 + src/groveemg/pyupm_groveemg.i | 11 ++ src/grovegprs/CMakeLists.txt | 5 + src/grovegprs/grovegprs.cxx | 74 +++++++++ src/grovegprs/grovegprs.hpp | 154 ++++++++++++++++++ src/grovegprs/javaupm_grovegprs.i | 22 +++ src/grovegprs/jsupm_grovegprs.i | 11 ++ src/grovegprs/pyupm_grovegprs.i | 14 ++ src/grovegsr/CMakeLists.txt | 5 + src/grovegsr/grovegsr.cxx | 70 ++++++++ src/grovegsr/grovegsr.hpp | 84 ++++++++++ src/grovegsr/javaupm_grovegsr.i | 19 +++ src/grovegsr/jsupm_grovegsr.i | 8 + src/grovegsr/pyupm_grovegsr.i | 11 ++ src/grovemoisture/CMakeLists.txt | 5 + src/grovemoisture/grovemoisture.cxx | 48 ++++++ src/grovemoisture/grovemoisture.hpp | 81 +++++++++ src/grovemoisture/javaupm_grovemoisture.i | 19 +++ src/grovemoisture/jsupm_grovemoisture.i | 8 + src/grovemoisture/pyupm_grovemoisture.i | 11 ++ src/groveo2/CMakeLists.txt | 5 + src/groveo2/groveo2.cxx | 56 +++++++ src/groveo2/groveo2.hpp | 73 +++++++++ src/groveo2/javaupm_groveo2.i | 19 +++ src/groveo2/jsupm_groveo2.i | 8 + src/groveo2/pyupm_groveo2.i | 11 ++ src/grovevdiv/CMakeLists.txt | 5 + src/grovevdiv/grovevdiv.cxx | 68 ++++++++ src/grovevdiv/grovevdiv.hpp | 98 +++++++++++ src/grovevdiv/javaupm_grovevdiv.i | 19 +++ src/grovevdiv/jsupm_grovevdiv.i | 8 + src/grovevdiv/pyupm_grovevdiv.i | 11 ++ src/grovewater/CMakeLists.txt | 5 + src/grovewater/grovewater.cxx | 54 ++++++ src/grovewater/grovewater.hpp | 74 +++++++++ src/grovewater/javaupm_grovewater.i | 19 +++ src/grovewater/jsupm_grovewater.i | 8 + src/grovewater/pyupm_grovewater.i | 11 ++ 76 files changed, 2967 insertions(+), 8 deletions(-) create mode 100644 src/grove/grovebutton.cxx create mode 100644 src/grove/grovebutton.hpp create mode 100644 src/grove/grovelight.cxx create mode 100644 src/grove/grovelight.hpp create mode 100644 src/grove/groverelay.cxx create mode 100644 src/grove/groverelay.hpp create mode 100644 src/grove/groverotary.cxx create mode 100644 src/grove/groverotary.hpp create mode 100644 src/grove/groveslide.cxx create mode 100644 src/grove/groveslide.hpp create mode 100644 src/grovecollision/CMakeLists.txt create mode 100644 src/grovecollision/grovecollision.cxx create mode 100644 src/grovecollision/grovecollision.hpp create mode 100644 src/grovecollision/javaupm_grovecollision.i create mode 100644 src/grovecollision/jsupm_grovecollision.i create mode 100644 src/grovecollision/pyupm_grovecollision.i create mode 100644 src/groveehr/CMakeLists.txt create mode 100644 src/groveehr/groveehr.cxx create mode 100644 src/groveehr/groveehr.hpp create mode 100644 src/groveehr/javaupm_groveehr.i create mode 100644 src/groveehr/jsupm_groveehr.i create mode 100644 src/groveehr/pyupm_groveehr.i create mode 100644 src/groveelectromagnet/CMakeLists.txt create mode 100644 src/groveelectromagnet/groveelectromagnet.cxx create mode 100644 src/groveelectromagnet/groveelectromagnet.hpp create mode 100644 src/groveelectromagnet/javaupm_groveelectromagnet.i create mode 100644 src/groveelectromagnet/jsupm_groveelectromagnet.i create mode 100644 src/groveelectromagnet/pyupm_groveelectromagnet.i create mode 100644 src/groveemg/CMakeLists.txt create mode 100644 src/groveemg/groveemg.cxx create mode 100644 src/groveemg/groveemg.hpp create mode 100644 src/groveemg/javaupm_groveemg.i create mode 100644 src/groveemg/jsupm_groveemg.i create mode 100644 src/groveemg/pyupm_groveemg.i create mode 100644 src/grovegprs/CMakeLists.txt create mode 100644 src/grovegprs/grovegprs.cxx create mode 100644 src/grovegprs/grovegprs.hpp create mode 100644 src/grovegprs/javaupm_grovegprs.i create mode 100644 src/grovegprs/jsupm_grovegprs.i create mode 100644 src/grovegprs/pyupm_grovegprs.i create mode 100644 src/grovegsr/CMakeLists.txt create mode 100644 src/grovegsr/grovegsr.cxx create mode 100644 src/grovegsr/grovegsr.hpp create mode 100644 src/grovegsr/javaupm_grovegsr.i create mode 100644 src/grovegsr/jsupm_grovegsr.i create mode 100644 src/grovegsr/pyupm_grovegsr.i create mode 100644 src/grovemoisture/CMakeLists.txt create mode 100644 src/grovemoisture/grovemoisture.cxx create mode 100644 src/grovemoisture/grovemoisture.hpp create mode 100644 src/grovemoisture/javaupm_grovemoisture.i create mode 100644 src/grovemoisture/jsupm_grovemoisture.i create mode 100644 src/grovemoisture/pyupm_grovemoisture.i create mode 100644 src/groveo2/CMakeLists.txt create mode 100644 src/groveo2/groveo2.cxx create mode 100644 src/groveo2/groveo2.hpp create mode 100644 src/groveo2/javaupm_groveo2.i create mode 100644 src/groveo2/jsupm_groveo2.i create mode 100644 src/groveo2/pyupm_groveo2.i create mode 100644 src/grovevdiv/CMakeLists.txt create mode 100644 src/grovevdiv/grovevdiv.cxx create mode 100644 src/grovevdiv/grovevdiv.hpp create mode 100644 src/grovevdiv/javaupm_grovevdiv.i create mode 100644 src/grovevdiv/jsupm_grovevdiv.i create mode 100644 src/grovevdiv/pyupm_grovevdiv.i create mode 100644 src/grovewater/CMakeLists.txt create mode 100644 src/grovewater/grovewater.cxx create mode 100644 src/grovewater/grovewater.hpp create mode 100644 src/grovewater/javaupm_grovewater.i create mode 100644 src/grovewater/jsupm_grovewater.i create mode 100644 src/grovewater/pyupm_grovewater.i diff --git a/src/button/button.cxx b/src/button/button.cxx index e1f553c7..0b902a0a 100644 --- a/src/button/button.cxx +++ b/src/button/button.cxx @@ -30,6 +30,7 @@ #include "button.hpp" +using namespace std; using namespace upm; Button::Button(unsigned int pin) diff --git a/src/grove/CMakeLists.txt b/src/grove/CMakeLists.txt index 2319031c..ccf2f2d8 100644 --- a/src/grove/CMakeLists.txt +++ b/src/grove/CMakeLists.txt @@ -1,7 +1,5 @@ -upm_mixed_module_init (NAME grove - DESCRIPTION "upm grove module" - CPP_HDR groveled.hpp - grovetemp.hpp grovebase.hpp grove.hpp - CPP_SRC groveled.cxx - grovetemp.cxx - REQUIRES mraa) +set (libname "grove") +set (libdescription "upm grove module") +set (module_src grovebutton.cxx groveled.cxx grovelight.cxx groverelay.cxx groverotary.cxx groveslide.cxx grovetemp.cxx) +set (module_hpp grovebutton.hpp groveled.hpp grovelight.hpp groverelay.hpp groverotary.hpp groveslide.hpp grovetemp.hpp grovebase.hpp grove.hpp) +upm_module_init() diff --git a/src/grove/grove.hpp b/src/grove/grove.hpp index 6d42fcee..a7da8758 100644 --- a/src/grove/grove.hpp +++ b/src/grove/grove.hpp @@ -25,6 +25,10 @@ */ #pragma once -#include +#include #include +#include +#include +#include +#include #include diff --git a/src/grove/grovebutton.cxx b/src/grove/grovebutton.cxx new file mode 100644 index 00000000..a4926285 --- /dev/null +++ b/src/grove/grovebutton.cxx @@ -0,0 +1,82 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 "grovebutton.hpp" + +using namespace upm; + +GroveButton::GroveButton(unsigned int pin) +{ + if ( !(m_gpio = mraa_gpio_init(pin)) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + return; + } + mraa_gpio_dir(m_gpio, MRAA_GPIO_IN); + m_name = "Button Sensor"; +} + +GroveButton::~GroveButton() +{ + mraa_gpio_close(m_gpio); +} + +std::string GroveButton::name() +{ + return m_name; +} + +int GroveButton::value() +{ + return mraa_gpio_read(m_gpio); +} + +#ifdef JAVACALLBACK +void GroveButton::installISR(mraa::Edge level, jobject runnable) +{ + installISR(level, mraa_java_isr_callback, runnable); +} +#endif + +void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg) +{ + if (m_isrInstalled) + uninstallISR(); + + // install our interrupt handler + mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg); + m_isrInstalled = true; +} + +void GroveButton::uninstallISR() +{ + mraa_gpio_isr_exit(m_gpio); + m_isrInstalled = false; +} diff --git a/src/grove/grovebutton.hpp b/src/grove/grovebutton.hpp new file mode 100644 index 00000000..72eb4734 --- /dev/null +++ b/src/grove/grovebutton.hpp @@ -0,0 +1,104 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 +#include "grovebase.hpp" + +namespace upm { + +/** + * @library grove + * @sensor grovebutton + * @comname Grove Button + * @altname Grove Touch Sensor + * @type button touch + * @man seeed + * @con gpio + * @kit gsk + * + * @brief API for the Grove Button + * + * Basic UPM module for the Grove button + * + * @image html grovebutton.jpg + * @snippet grovebutton.cxx Interesting + */ +class GroveButton: public Grove { + public: + /** + * Grove button constructor + * + * @param gpio Pin to use + */ + GroveButton(unsigned int pin); + /** + * Grove button destructor + */ + ~GroveButton(); + /** + * Gets the name of the sensor + * + * @return Name of this sensor + */ + std::string name(); + /** + * Gets the value from the GPIO pin + * + * @return Value from the GPIO pin + */ + int value(); + + /** + * Installs an interrupt service routine (ISR) to be called when + * the button is activated or deactivated. + * + * @param fptr Pointer to a function to be called on interrupt + * @param arg Pointer to an object to be supplied as an + * argument to the ISR. + */ +#if defined(SWIGJAVA) || defined(JAVACALLBACK) + void installISR(mraa::Edge level, jobject runnable); +#else + void installISR(mraa::Edge level, void (*isr)(void *), void *arg); +#endif + /** + * Uninstalls the previously installed ISR + * + */ + void uninstallISR(); + + private: +#if defined(SWIGJAVA) || defined(JAVACALLBACK) + void installISR(mraa::Edge level, void (*isr)(void *), void *arg); +#endif + bool m_isrInstalled; + std::string m_name; + mraa_gpio_context m_gpio; +}; +} diff --git a/src/grove/grovelight.cxx b/src/grove/grovelight.cxx new file mode 100644 index 00000000..39313782 --- /dev/null +++ b/src/grove/grovelight.cxx @@ -0,0 +1,63 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 "grovelight.hpp" +#include "math.h" + +using namespace upm; + +GroveLight::GroveLight(unsigned int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } + m_name = "Light Sensor"; +} + +GroveLight::~GroveLight() +{ + mraa_aio_close(m_aio); +} + +int GroveLight::value() +{ + // rough conversion to lux, using formula from Grove Starter Kit booklet + float a = (float) mraa_aio_read(m_aio); + if (a == -1.0) return -1; + a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0); + return (int) round(a); +} + +float GroveLight::raw_value() +{ + return (float) mraa_aio_read(m_aio); +} diff --git a/src/grove/grovelight.hpp b/src/grove/grovelight.hpp new file mode 100644 index 00000000..10e45f72 --- /dev/null +++ b/src/grove/grovelight.hpp @@ -0,0 +1,82 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 +#include "grovebase.hpp" + +namespace upm { + +/** + * @library grove + * @sensor grovelight + * @comname Grove Light Sensor + * @type light + * @man seeed + * @con analog + * @kit gsk + * + * @brief API for the Grove Light Sensor + * + * The Grove light sensor detects the intensity of the ambient light. + * As the light intensity of the environment increases, the resistance + * of the sensor decreases. This means the raw value from the + * analog pin is larger in bright light and smaller in the dark. + * An approximate lux value can also be returned. + * + * @image html grovelight.jpg + * @snippet grovelight.cxx Interesting + */ +class GroveLight: public Grove { + public: + /** + * Grove analog light sensor constructor + * + * @param pin Analog pin to use + */ + GroveLight(unsigned int pin); + /** + * GroveLight destructor + */ + ~GroveLight(); + /** + * Gets the raw value from the AIO pin + * + * @return Raw value from the ADC + */ + float raw_value(); + /** + * Gets an approximate light value, in lux, from the sensor + * + * @return Normalized light reading in lux + */ + int value(); + private: + mraa_aio_context m_aio; +}; +} diff --git a/src/grove/groverelay.cxx b/src/grove/groverelay.cxx new file mode 100644 index 00000000..53fba212 --- /dev/null +++ b/src/grove/groverelay.cxx @@ -0,0 +1,69 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 "groverelay.hpp" + +using namespace upm; + +GroveRelay::GroveRelay(unsigned int pin) +{ + if ( !(m_gpio = mraa_gpio_init(pin)) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + return; + } + mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT); + m_name = "Relay Switch"; +} + +GroveRelay::~GroveRelay() +{ + mraa_gpio_close(m_gpio); +} + +mraa_result_t GroveRelay::on() +{ + return mraa_gpio_write(m_gpio, 1); +} + +mraa_result_t GroveRelay::off() +{ + return mraa_gpio_write(m_gpio, 0); +} + +bool GroveRelay::isOn() +{ + return mraa_gpio_read(m_gpio) == 1; +} + +bool GroveRelay::isOff() +{ + return mraa_gpio_read(m_gpio) == 0; +} diff --git a/src/grove/groverelay.hpp b/src/grove/groverelay.hpp new file mode 100644 index 00000000..325e1ac0 --- /dev/null +++ b/src/grove/groverelay.hpp @@ -0,0 +1,95 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 +#include "grovebase.hpp" + +namespace upm { + +/** + * @library grove + * @sensor groverelay + * @comname Grove Relay + * @type relay + * @man seeed + * @con gpio + * @kit gsk eak hak + * + * @brief API for the Grove Relay + * + * UPM module for the Grove relay switch. The Grove relay is a + * digital normally-open switch that uses low voltage or current to + * control a higher voltage and/or higher current. When closed, + * the indicator LED lights up and current is allowed to flow. + * + * @image html groverelay.jpg + * @snippet groverelay.cxx Interesting + */ +class GroveRelay: public Grove { + public: + /** + * Grove relay constructor + * + * @param gpio Pin to use + */ + GroveRelay(unsigned int pin); + /** + * Grove relay destructor + */ + ~GroveRelay(); + /** + * Sets the relay switch to on (closed). This allows current + * to flow and lights up the indicator LED. + * + * @return 0 if successful, non-zero otherwise + */ + mraa_result_t on(); + /** + * Sets the relay switch to off (open). This stops current + * from flowing and the indicator LED is not lit. + * + * @return 0 if successful, non-zero otherwise + */ + mraa_result_t off(); + /** + * Defines whether the relay switch is closed. + * + * @return True if the switch is on (closed), false otherwise + */ + bool isOn(); + /** + * Defines whether the relay switch is open. + * + * @return True if the switch is off (open), false otherwise + */ + bool isOff(); + private: + mraa_gpio_context m_gpio; +}; +} diff --git a/src/grove/groverotary.cxx b/src/grove/groverotary.cxx new file mode 100644 index 00000000..925c97fd --- /dev/null +++ b/src/grove/groverotary.cxx @@ -0,0 +1,79 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 "groverotary.hpp" +#include "math.h" + +using namespace upm; + +GroveRotary::GroveRotary(unsigned int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } + m_name = "Rotary Angle Sensor"; +} + +GroveRotary::~GroveRotary() +{ + mraa_aio_close(m_aio); +} + +float GroveRotary::abs_value() +{ + return (float) mraa_aio_read(m_aio); +} + +float GroveRotary::abs_deg() +{ + return GroveRotary::abs_value() * (float) m_max_angle / 1023.0; +} + +float GroveRotary::abs_rad() +{ + return GroveRotary::abs_deg() * M_PI / 180.0; +} + +float GroveRotary::rel_value() +{ + return GroveRotary::abs_value() - 512.0; +} + +float GroveRotary::rel_deg() +{ + return GroveRotary::rel_value() * (float) m_max_angle / 1023.0; +} + +float GroveRotary::rel_rad() +{ + return GroveRotary::rel_deg() * M_PI / 180.0; +} diff --git a/src/grove/groverotary.hpp b/src/grove/groverotary.hpp new file mode 100644 index 00000000..86c8ad6c --- /dev/null +++ b/src/grove/groverotary.hpp @@ -0,0 +1,106 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 +#include "grovebase.hpp" + +namespace upm { + +/** + * @library grove + * @sensor groverotary + * @comname Grove Rotary Angle Sensor + * @altname Rotary Potentiometer + * @type ainput + * @man seeed + * @con analog + * @kit gsk + * + * @brief API for the Grove Rotary Angle Sensor (Knob) + * + * Basic UPM module for the Grove rotary angle sensor (knob) on analog. Provides + * a set of functions to read the absolute pin value, degrees or radians, and another set + * to do the same relative to the center of the knob's range. + * + * @image html groverotary.jpeg + * @snippet groverotary.cxx Interesting + */ +class GroveRotary: public Grove { + public: + /** + * Grove rotary angle sensor constructor + * + * @param pin Number of the analog pin to use + */ + GroveRotary(unsigned int pin); + /** + * GroveRotary destructor + */ + ~GroveRotary(); + /** + * Gets the absolute raw value from the AIO pin + * + * @return Unsigned value from the ADC + */ + float abs_value(); + /** + * Gets absolute raw degrees from the AIO pin + * + * @return Unsigned degrees from the ADC + */ + float abs_deg(); + /** + * Gets absolute raw radians from the AIO pin + * + * @return Unsigned radians from the ADC + */ + float abs_rad(); + /** + * Gets the relative value from the AIO pin + * + * @return Signed value from the ADC + */ + float rel_value(); + /** + * Gets relative degrees from the AIO pin + * + * @return Signed degrees from the ADC + */ + float rel_deg(); + /** + * Gets relative radians from the AIO pin + * + * @return Signed radians from the ADC + */ + float rel_rad(); + private: + mraa_aio_context m_aio; + static const int m_max_angle = 300; +}; +} diff --git a/src/grove/groveslide.cxx b/src/grove/groveslide.cxx new file mode 100644 index 00000000..d3c511fb --- /dev/null +++ b/src/grove/groveslide.cxx @@ -0,0 +1,68 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 "groveslide.hpp" +#include "math.h" + +using namespace upm; + +GroveSlide::GroveSlide(unsigned int pin, float ref_voltage) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } + m_ref_voltage = ref_voltage; + m_name = "Slide Potentiometer"; +} + +GroveSlide::~GroveSlide() +{ + mraa_aio_close(m_aio); +} + +float GroveSlide::raw_value() +{ + return (float) mraa_aio_read(m_aio); +} + +float GroveSlide::voltage_value() +{ + // conversion to Volts + float a = GroveSlide::raw_value(); + a = m_ref_voltage * a / 1023.0 ; + return a; +} + +float GroveSlide::ref_voltage() +{ + return m_ref_voltage; +} diff --git a/src/grove/groveslide.hpp b/src/grove/groveslide.hpp new file mode 100644 index 00000000..7fa35f61 --- /dev/null +++ b/src/grove/groveslide.hpp @@ -0,0 +1,87 @@ +/* + * Authors: Brendan Le Foll + * Mihai Tudor Panu + * Sarah Knepper + * Copyright (c) 2014 - 2016 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 +#include "grovebase.hpp" + +namespace upm { + +/** + * @library grove + * @sensor groveslide + * @comname Grove Slide Potentiometer + * @type ainput + * @man seeed + * @con analog + * + * @brief API for the Grove Slide Potentiometer + * + * Basic UPM module for the Grove slide potentiometer on analog that + * returns either a raw value or a scaled voltage value. + * + * @image html groveslide.jpeg + * @snippet groveslide.cxx Interesting + */ +class GroveSlide: public Grove { + public: + /** + * Grove analog slide potentiometer constructor + * + * @param pin Number of the analog pin to use + * + * @param ref_voltage Reference voltage the board is set to, as a floating-point value; default is 5.0V + */ + GroveSlide(unsigned int pin, float ref_voltage = 5.0); + /** + * GroveSlide destructor + */ + ~GroveSlide(); + /** + * Gets the raw value from the AIO pin + * + * @return Raw value from the ADC + */ + float raw_value(); + /** + * Gets the voltage value from the pin + * + * @return Voltage reading based on the reference voltage + */ + float voltage_value(); + /** + * Gets the board's reference voltage passed on object initialization + * + * @return Reference voltage the class was set for + */ + float ref_voltage(); + private: + mraa_aio_context m_aio; + float m_ref_voltage; +}; +} diff --git a/src/grove/javaupm_grove.i b/src/grove/javaupm_grove.i index ac758500..a70cdea1 100644 --- a/src/grove/javaupm_grove.i +++ b/src/grove/javaupm_grove.i @@ -14,11 +14,36 @@ #include "grovebase.hpp" %} +%include "grovebutton.hpp" +%{ + #include "grovebutton.hpp" +%} + %include "groveled.hpp" %{ #include "groveled.hpp" %} +%include "grovelight.hpp" +%{ + #include "grovelight.hpp" +%} + +%include "groverelay.hpp" +%{ + #include "groverelay.hpp" +%} + +%include "groverotary.hpp" +%{ + #include "groverotary.hpp" +%} + +%include "groveslide.hpp" +%{ + #include "groveslide.hpp" +%} + %include "grovetemp.hpp" %{ #include "grovetemp.hpp" diff --git a/src/grove/jsupm_grove.i b/src/grove/jsupm_grove.i index 6e96fd68..e3390235 100644 --- a/src/grove/jsupm_grove.i +++ b/src/grove/jsupm_grove.i @@ -11,11 +11,36 @@ #include "grovebase.hpp" %} +%include "grovebutton.hpp" +%{ + #include "grovebutton.hpp" +%} + %include "groveled.hpp" %{ #include "groveled.hpp" %} +%include "grovelight.hpp" +%{ + #include "grovelight.hpp" +%} + +%include "groverelay.hpp" +%{ + #include "groverelay.hpp" +%} + +%include "groverotary.hpp" +%{ + #include "groverotary.hpp" +%} + +%include "groveslide.hpp" +%{ + #include "groveslide.hpp" +%} + %include "grovetemp.hpp" %{ #include "grovetemp.hpp" diff --git a/src/grove/pyupm_grove.i b/src/grove/pyupm_grove.i index 818ee35f..31412d02 100644 --- a/src/grove/pyupm_grove.i +++ b/src/grove/pyupm_grove.i @@ -15,11 +15,36 @@ #include "grovebase.hpp" %} +%include "grovebutton.hpp" +%{ + #include "grovebutton.hpp" +%} + %include "groveled.hpp" %{ #include "groveled.hpp" %} +%include "grovelight.hpp" +%{ + #include "grovelight.hpp" +%} + +%include "groverelay.hpp" +%{ + #include "groverelay.hpp" +%} + +%include "groverotary.hpp" +%{ + #include "groverotary.hpp" +%} + +%include "groveslide.hpp" +%{ + #include "groveslide.hpp" +%} + %include "grovetemp.hpp" %{ #include "grovetemp.hpp" diff --git a/src/grovecollision/CMakeLists.txt b/src/grovecollision/CMakeLists.txt new file mode 100644 index 00000000..38a5b34d --- /dev/null +++ b/src/grovecollision/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovecollision") +set (libdescription "upm grovecollision sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init("-lrt") diff --git a/src/grovecollision/grovecollision.cxx b/src/grovecollision/grovecollision.cxx new file mode 100644 index 00000000..d83e02ea --- /dev/null +++ b/src/grovecollision/grovecollision.cxx @@ -0,0 +1,53 @@ +/* + * Author: Zion Orent + * 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. + */ + +#include +#include + +#include "grovecollision.hpp" + +using namespace upm; + +GroveCollision::GroveCollision(int pin) +{ + + if ( !(m_gpio = mraa_gpio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + return; + } + mraa_gpio_dir(m_gpio, MRAA_GPIO_IN); +} + +GroveCollision::~GroveCollision() +{ + mraa_gpio_close(m_gpio); +} + +bool GroveCollision::isColliding() +{ + // Collisions cause 0; no collision is 1 + return (!(bool)mraa_gpio_read(m_gpio)); +} diff --git a/src/grovecollision/grovecollision.hpp b/src/grovecollision/grovecollision.hpp new file mode 100644 index 00000000..57b93f61 --- /dev/null +++ b/src/grovecollision/grovecollision.hpp @@ -0,0 +1,72 @@ +/* + * Author: Zion Orent + * 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. + */ +#pragma once + +#include + +namespace upm { + /** + * @brief Grove Collision Sensor library + * @defgroup grovecollision libupm-grovecollision + * @ingroup seeed gpio accelerometer + */ + + /** + * @library grovecollision + * @sensor grovecollision + * @comname Grove Collision Sensor + * @type accelerometer + * @man seeed + * @con gpio + * + * @brief API for the Grove Collision Sensor + * + * The Grove Collision Sensor can detect whether any + * collision movement or vibration happens. + * It outputs a low pulse signal when vibration is detected. + * + * @image html grovecollision.jpg + * @snippet grovecollision.cxx Interesting + */ + class GroveCollision { + public: + /** + * Grove collision sensor constructor + * + * @param pin Digital pin to use + */ + GroveCollision(int pin); + /** + * GroveCollision destructor + */ + ~GroveCollision(); + /** + * @return bool Defines whether something is colliding with sensor + */ + bool isColliding(); + + private: + mraa_gpio_context m_gpio; + }; +} diff --git a/src/grovecollision/javaupm_grovecollision.i b/src/grovecollision/javaupm_grovecollision.i new file mode 100644 index 00000000..39b50252 --- /dev/null +++ b/src/grovecollision/javaupm_grovecollision.i @@ -0,0 +1,19 @@ +%module javaupm_grovecollision +%include "../upm.i" + +%{ + #include "grovecollision.hpp" +%} + +%include "grovecollision.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovecollision"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovecollision/jsupm_grovecollision.i b/src/grovecollision/jsupm_grovecollision.i new file mode 100644 index 00000000..7cd1ca0b --- /dev/null +++ b/src/grovecollision/jsupm_grovecollision.i @@ -0,0 +1,8 @@ +%module jsupm_grovecollision +%include "../upm.i" + +%{ + #include "grovecollision.hpp" +%} + +%include "grovecollision.hpp" diff --git a/src/grovecollision/pyupm_grovecollision.i b/src/grovecollision/pyupm_grovecollision.i new file mode 100644 index 00000000..7ce2d3f7 --- /dev/null +++ b/src/grovecollision/pyupm_grovecollision.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovecollision +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "grovecollision.hpp" +%{ + #include "grovecollision.hpp" +%} diff --git a/src/groveehr/CMakeLists.txt b/src/groveehr/CMakeLists.txt new file mode 100644 index 00000000..f53d9c2e --- /dev/null +++ b/src/groveehr/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "groveehr") +set (libdescription "upm grove ear-clip heart rate sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/groveehr/groveehr.cxx b/src/groveehr/groveehr.cxx new file mode 100644 index 00000000..953e5f5a --- /dev/null +++ b/src/groveehr/groveehr.cxx @@ -0,0 +1,130 @@ +/* + * Author: Jon Trulson + * 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 "groveehr.hpp" + +using namespace upm; +using namespace std; + +GroveEHR::GroveEHR(int pin) +{ + if ( !(m_gpio = mraa_gpio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } + + mraa_gpio_dir(m_gpio, MRAA_GPIO_IN); + + initClock(); + m_beatCounter = 0; +} + +GroveEHR::~GroveEHR() +{ + mraa_gpio_close(m_gpio); +} + +void GroveEHR::initClock() +{ + gettimeofday(&m_startTime, NULL); +} + +uint32_t GroveEHR::getMillis() +{ + struct timeval elapsed, now; + uint32_t elapse; + + // get current time + gettimeofday(&now, NULL); + + // compute the delta since m_startTime + if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 ) + { + elapsed.tv_usec += 1000000; + elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec - 1; + } + else + { + elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec; + } + + elapse = (uint32_t)((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000)); + + // never return 0 + if (elapse == 0) + elapse = 1; + + return elapse; +} + +void GroveEHR::clearBeatCounter() +{ + m_beatCounter = 0; +} + +void GroveEHR::startBeatCounter() +{ + // install our interrupt handler + mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING, + &beatISR, this); +} + +void GroveEHR::stopBeatCounter() +{ + // remove the interrupt handler + mraa_gpio_isr_exit(m_gpio); +} + +uint32_t GroveEHR::beatCounter() +{ + return m_beatCounter; +} + +void GroveEHR::beatISR(void *ctx) +{ + upm::GroveEHR *This = (upm::GroveEHR *)ctx; + This->m_beatCounter++; +} + +int GroveEHR::heartRate() +{ + uint32_t millis = getMillis(); + uint32_t beats = beatCounter(); + + float heartRate = 0; + // wait at least 5 seconds before attempting to compute the + // heart rate + if (millis > 5000) + { + heartRate = (float(beats) / (float(millis) / 1000.0)) * 60.0; + } + + return int(heartRate); +} diff --git a/src/groveehr/groveehr.hpp b/src/groveehr/groveehr.hpp new file mode 100644 index 00000000..371fe83f --- /dev/null +++ b/src/groveehr/groveehr.hpp @@ -0,0 +1,126 @@ +/* + * Author: Jon Trulson + * 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 +#include +#include + +namespace upm { + /** + * @brief Grove Ear-clip Heart Rate Sensor library + * @defgroup groveehr libupm-groveehr + * @ingroup seeed gpio medical + */ + + /** + * @library groveehr + * @sensor groveehr + * @comname Grove Ear-clip Heart Rate Sensor + * @type medical + * @man seeed + * @con gpio + * + * @brief API for the Grove Ear-clip Heart Rate Sensor + * + * UPM module for the Grove ear-clip heart rate sensor. It is used to measure your + * heart rate. + * + * @image html groveehr.jpg + * @snippet groveehr.cxx Interesting + */ + class GroveEHR { + public: + /** + * GroveEHR constructor + * + * @param pin Digital pin to use + */ + GroveEHR(int pin); + /** + * GroveEHR destructor + */ + ~GroveEHR(); + /** + * Returns the time of milliseconds elapsed since initClock() + * was last called. + * + * @return Elapsed milliseconds + */ + uint32_t getMillis(); + + /** + * Resets the clock + * + */ + void initClock(); + + /** + * Resets the beat counter to 0. The beat counter should be + * stopped via stopBeatCounter() prior to calling this function. + * + */ + void clearBeatCounter(); + + /** + * Starts the beat counter + * + */ + void startBeatCounter(); + + /** + * Stops the beat counter + * + */ + void stopBeatCounter(); + + /** + * Gets the beat Counter + * + * @return Beat counter + */ + uint32_t beatCounter(); + + /** + * Computes the heart rate + * + * @return Computed heart rate + */ + int heartRate(); + + private: + /** + * Beat interrupt service routine (ISR) + * + */ + static void beatISR(void *ctx); + + volatile uint32_t m_beatCounter; + struct timeval m_startTime; + mraa_gpio_context m_gpio; + }; +} + + diff --git a/src/groveehr/javaupm_groveehr.i b/src/groveehr/javaupm_groveehr.i new file mode 100644 index 00000000..2ac1d9c4 --- /dev/null +++ b/src/groveehr/javaupm_groveehr.i @@ -0,0 +1,21 @@ +%module javaupm_groveehr +%include "../upm.i" + +%ignore beatISR; + +%{ + #include "groveehr.hpp" +%} + +%include "groveehr.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_groveehr"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/groveehr/jsupm_groveehr.i b/src/groveehr/jsupm_groveehr.i new file mode 100644 index 00000000..3005cc9f --- /dev/null +++ b/src/groveehr/jsupm_groveehr.i @@ -0,0 +1,8 @@ +%module jsupm_groveehr +%include "../upm.i" + +%{ + #include "groveehr.hpp" +%} + +%include "groveehr.hpp" diff --git a/src/groveehr/pyupm_groveehr.i b/src/groveehr/pyupm_groveehr.i new file mode 100644 index 00000000..002a85e1 --- /dev/null +++ b/src/groveehr/pyupm_groveehr.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_groveehr +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "groveehr.hpp" +%{ + #include "groveehr.hpp" +%} diff --git a/src/groveelectromagnet/CMakeLists.txt b/src/groveelectromagnet/CMakeLists.txt new file mode 100644 index 00000000..a12d3715 --- /dev/null +++ b/src/groveelectromagnet/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "groveelectromagnet") +set (libdescription "upm groveelectromagnet sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init("-lrt") diff --git a/src/groveelectromagnet/groveelectromagnet.cxx b/src/groveelectromagnet/groveelectromagnet.cxx new file mode 100644 index 00000000..e7206f7e --- /dev/null +++ b/src/groveelectromagnet/groveelectromagnet.cxx @@ -0,0 +1,62 @@ +/* + * Author: Zion Orent + * 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. + */ + +#include +#include + +#include "groveelectromagnet.hpp" + +using namespace upm; + +GroveElectromagnet::GroveElectromagnet(int pin) +{ + if ( !(m_gpio = mraa_gpio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + return; + } + mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT); +} + +GroveElectromagnet::~GroveElectromagnet() +{ + mraa_gpio_close(m_gpio); +} + +void GroveElectromagnet::on() +{ + mraa_result_t error = MRAA_SUCCESS; + error = mraa_gpio_write (m_gpio, HIGH); + if (error != MRAA_SUCCESS) + mraa_result_print(error); +} + +void GroveElectromagnet::off() +{ + mraa_result_t error = MRAA_SUCCESS; + error = mraa_gpio_write (m_gpio, LOW); + if (error != MRAA_SUCCESS) + mraa_result_print(error); +} diff --git a/src/groveelectromagnet/groveelectromagnet.hpp b/src/groveelectromagnet/groveelectromagnet.hpp new file mode 100644 index 00000000..c39ae4ca --- /dev/null +++ b/src/groveelectromagnet/groveelectromagnet.hpp @@ -0,0 +1,77 @@ +/* + * Author: Zion Orent + * 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. + */ +#pragma once + +#include + +#define HIGH 1 +#define LOW 0 + +namespace upm { + /** + * @brief Grove Electromagnet library + * @defgroup groveelectromagnet libupm-groveelectromagnet + * @ingroup seeed gpio electric + */ + + /** + * @library groveelectromagnet + * @sensor groveelectromagnet + * @comname Grove Electromagnet + * @type electric + * @man seeed + * @con gpio + * + * @brief API for the Grove Electromagnet + * + * The Grove Electromagnet can hold up to 1 kg (approximately 2.2 lbs) + * + * @image html groveelectromagnet.jpg + * @snippet groveelectromagnet.cxx Interesting + */ + class GroveElectromagnet { + public: + /** + * Grove Electromagnet constructor + * + * @param pin Digital pin to use + */ + GroveElectromagnet(int pin); + /** + * Grove Electromagnet destructor + */ + ~GroveElectromagnet(); + /** + * Turns the magnet on + */ + void on(); + /** + * Turns the magnet off + */ + void off(); + + private: + mraa_gpio_context m_gpio; + }; +} diff --git a/src/groveelectromagnet/javaupm_groveelectromagnet.i b/src/groveelectromagnet/javaupm_groveelectromagnet.i new file mode 100644 index 00000000..ecfffde1 --- /dev/null +++ b/src/groveelectromagnet/javaupm_groveelectromagnet.i @@ -0,0 +1,19 @@ +%module javaupm_groveelectromagnet +%include "../upm.i" + +%{ + #include "groveelectromagnet.hpp" +%} + +%include "groveelectromagnet.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_groveelectromagnet"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/groveelectromagnet/jsupm_groveelectromagnet.i b/src/groveelectromagnet/jsupm_groveelectromagnet.i new file mode 100644 index 00000000..62d5ac9b --- /dev/null +++ b/src/groveelectromagnet/jsupm_groveelectromagnet.i @@ -0,0 +1,8 @@ +%module jsupm_groveelectromagnet +%include "../upm.i" + +%{ + #include "groveelectromagnet.hpp" +%} + +%include "groveelectromagnet.hpp" diff --git a/src/groveelectromagnet/pyupm_groveelectromagnet.i b/src/groveelectromagnet/pyupm_groveelectromagnet.i new file mode 100644 index 00000000..82492c30 --- /dev/null +++ b/src/groveelectromagnet/pyupm_groveelectromagnet.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_groveelectromagnet +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "groveelectromagnet.hpp" +%{ + #include "groveelectromagnet.hpp" +%} diff --git a/src/groveemg/CMakeLists.txt b/src/groveemg/CMakeLists.txt new file mode 100644 index 00000000..a65dec3d --- /dev/null +++ b/src/groveemg/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "groveemg") +set (libdescription "upm groveemg muscle signal reader sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/groveemg/groveemg.cxx b/src/groveemg/groveemg.cxx new file mode 100644 index 00000000..538c6b50 --- /dev/null +++ b/src/groveemg/groveemg.cxx @@ -0,0 +1,69 @@ +/* + * Author: Zion Orent + * 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. + */ + +#include +#include +#include + +#include "groveemg.hpp" + +using namespace upm; +using namespace std; + +GroveEMG::GroveEMG(int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } +} + +GroveEMG::~GroveEMG() +{ + mraa_aio_close(m_aio); +} + +void GroveEMG::calibrate() +{ + int val, sum = 0; + + for (int i=0; i<1100; i++) + { + val = mraa_aio_read(m_aio); + if (val != -1) throw std::runtime_error(std::string(__FUNCTION__) + + ": Failed to do an aio read."); + sum += val; + usleep(1000); + } + sum /= 1100; + cout << "Static analog data = " << sum << endl; +} + +int GroveEMG::value() +{ + int val = mraa_aio_read(m_aio); + return val; +} diff --git a/src/groveemg/groveemg.hpp b/src/groveemg/groveemg.hpp new file mode 100644 index 00000000..eef5fa34 --- /dev/null +++ b/src/groveemg/groveemg.hpp @@ -0,0 +1,82 @@ +/* + * Author: Zion Orent + * 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. + */ +#pragma once + +#include +#include + +namespace upm { + /** + * @brief Grove EMG Muscle Signal Reader library + * @defgroup groveemg libupm-groveemg + * @ingroup seeed analog electric + */ + + /** + * @library groveemg + * @sensor groveemg + * @comname Grove EMG Sensor + * @type electric + * @man seeed + * @con analog + * + * @brief API for the Grove EMG Muscle Signal Reader + * + * Grove EMG muscle signal reader gathers small muscle signals, + * then processes them, and returns the result + * + * @image html groveemg.jpg + * @snippet groveemg.cxx Interesting + */ + class GroveEMG { + public: + /** + * Grove EMG reader constructor + * + * @param pin Analog pin to use + */ + GroveEMG(int pin); + /** + * GroveEMG destructor + */ + ~GroveEMG(); + + /** + * Calibrates the Grove EMG reader + */ + void calibrate(); + + /** + * Measures muscle signals from the reader + * + * @return Muscle output as analog voltage + */ + int value(); + + private: + mraa_aio_context m_aio; + }; +} + + diff --git a/src/groveemg/javaupm_groveemg.i b/src/groveemg/javaupm_groveemg.i new file mode 100644 index 00000000..9c66328b --- /dev/null +++ b/src/groveemg/javaupm_groveemg.i @@ -0,0 +1,19 @@ +%module javaupm_groveemg +%include "../upm.i" + +%{ + #include "groveemg.hpp" +%} + +%include "groveemg.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_groveemg"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/groveemg/jsupm_groveemg.i b/src/groveemg/jsupm_groveemg.i new file mode 100644 index 00000000..99041721 --- /dev/null +++ b/src/groveemg/jsupm_groveemg.i @@ -0,0 +1,8 @@ +%module jsupm_groveemg +%include "../upm.i" + +%{ + #include "groveemg.hpp" +%} + +%include "groveemg.hpp" diff --git a/src/groveemg/pyupm_groveemg.i b/src/groveemg/pyupm_groveemg.i new file mode 100644 index 00000000..09ce0c92 --- /dev/null +++ b/src/groveemg/pyupm_groveemg.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_groveemg +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "groveemg.hpp" +%{ + #include "groveemg.hpp" +%} diff --git a/src/grovegprs/CMakeLists.txt b/src/grovegprs/CMakeLists.txt new file mode 100644 index 00000000..85a8397d --- /dev/null +++ b/src/grovegprs/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovegprs") +set (libdescription "upm grove GPRS module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/grovegprs/grovegprs.cxx b/src/grovegprs/grovegprs.cxx new file mode 100644 index 00000000..8634cd48 --- /dev/null +++ b/src/grovegprs/grovegprs.cxx @@ -0,0 +1,74 @@ +/* + * Author: Jon Trulson + * 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. + */ + +#include + +#include "grovegprs.hpp" + +using namespace upm; +using namespace std; + +static const int defaultDelay = 100; // max wait time for read + +GroveGPRS::GroveGPRS(int uart) : + m_uart(uart) +{ +} + +GroveGPRS::~GroveGPRS() +{ +} + +bool GroveGPRS::dataAvailable(unsigned int millis) +{ + return m_uart.dataAvailable(millis); +} + +int GroveGPRS::readData(char *buffer, unsigned int len) +{ + return m_uart.read(buffer, len); +} + +std::string GroveGPRS::readDataStr(int len) +{ + return m_uart.readStr(len); +} + +int GroveGPRS::writeData(char *buffer, unsigned int len) +{ + m_uart.flush(); + return m_uart.write(buffer, len); +} + +int GroveGPRS::writeDataStr(std::string data) +{ + m_uart.flush(); + return m_uart.writeStr(data); +} + +mraa::Result GroveGPRS::setBaudRate(int baud) +{ + return m_uart.setBaudRate(baud); +} + diff --git a/src/grovegprs/grovegprs.hpp b/src/grovegprs/grovegprs.hpp new file mode 100644 index 00000000..1aa774f6 --- /dev/null +++ b/src/grovegprs/grovegprs.hpp @@ -0,0 +1,154 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2015 Intel Corporation. + * + * Thanks to Adafruit for supplying a google translated version of the + * Chinese datasheet and some clues in their code. + * + * 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 + +#include +#include +#include + +#include +#include + +#define GROVEGPRS_DEFAULT_UART 0 + +namespace upm { + /** + * @brief Grove GPRS Module library + * @defgroup grovegprs libupm-grovegprs + * @ingroup seeed uart wifi + */ + + /** + * @library grovegprs + * @sensor grovegprs + * @comname Grove GPRS Module + * @type wifi + * @man seeed + * @con uart + * @web http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0 + * + * @brief API for the Grove GPRS Module + * + * The driver was tested with the Grove GPRS Module, V2. It's a + * GSM GPRS module based on the SIM900. This module uses a + * standard 'AT' command set. See the datasheet for a full list + * of available commands and their possible responses: + * + * http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf + * + * It is connected via a UART at 19200 baud. + * + * @image html grovegprs.jpg + * @snippet grovegprs.cxx Interesting + */ + + class GroveGPRS { + public: + + /** + * GroveGPRS object constructor + * + * @param uart Default UART to use (0 or 1). Default is 0. + */ + GroveGPRS(int uart=GROVEGPRS_DEFAULT_UART); + + /** + * GroveGPRS object destructor + */ + ~GroveGPRS(); + + /** + * Checks to see if there is data available for reading + * + * @param millis Number of milliseconds to wait; 0 means no waiting + * @return true if there is data available for reading + */ + bool dataAvailable(unsigned int millis); + + /** + * Reads any available data into a user-supplied buffer. Note: the + * call blocks until data is available for reading. Use + * dataAvailable() to determine whether there is data available + * beforehand, to avoid blocking. + * + * @param buffer Buffer to hold the data read + * @param len Length of the buffer + * @return Number of bytes read + */ + int readData(char *buffer, unsigned int len); + + /** + * Reads any available data and returns it in a std::string. Note: + * the call blocks until data is available for reading. Use + * dataAvailable() to determine whether there is data available + * beforehand, to avoid blocking. + * + * @param len Maximum length of the data to be returned + * @return Number of bytes read + */ + std::string readDataStr(int len); + + /** + * Writes the data in the buffer to the device. If you are + * writing a command, be sure to terminate it with a carriage + * return (\r) + * + * @param buffer Buffer to hold the data to write + * @param len Length of the buffer + * @return Number of bytes written + */ + int writeData(char *buffer, unsigned len); + + /** + * Writes the std:string data to the device. If you are writing a + * command, be sure to terminate it with a carriage return (\r) + * + * @param data Buffer to write to the device + * @return Number of bytes written + */ + int writeDataStr(std::string data); + + /** + * Sets the baud rate for the device. The default is 19200. + * + * @param baud Desired baud rate. + * @return true if successful + */ + mraa::Result setBaudRate(int baud=19200); + + + protected: + mraa::Uart m_uart; + + private: + }; +} + + diff --git a/src/grovegprs/javaupm_grovegprs.i b/src/grovegprs/javaupm_grovegprs.i new file mode 100644 index 00000000..29972361 --- /dev/null +++ b/src/grovegprs/javaupm_grovegprs.i @@ -0,0 +1,22 @@ +%module javaupm_grovegprs +%include "../upm.i" +%include "carrays.i" +%include "std_string.i" + +%{ + #include "grovegprs.hpp" +%} + +%include "grovegprs.hpp" +%array_class(char, charArray); + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovegprs"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovegprs/jsupm_grovegprs.i b/src/grovegprs/jsupm_grovegprs.i new file mode 100644 index 00000000..bd14764f --- /dev/null +++ b/src/grovegprs/jsupm_grovegprs.i @@ -0,0 +1,11 @@ +%module jsupm_grovegprs +%include "../upm.i" +%include "carrays.i" +%include "std_string.i" + +%{ + #include "grovegprs.hpp" +%} + +%include "grovegprs.hpp" +%array_class(char, charArray); diff --git a/src/grovegprs/pyupm_grovegprs.i b/src/grovegprs/pyupm_grovegprs.i new file mode 100644 index 00000000..04e11787 --- /dev/null +++ b/src/grovegprs/pyupm_grovegprs.i @@ -0,0 +1,14 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovegprs +%include "../upm.i" +%include "carrays.i" +%include "std_string.i" + +%feature("autodoc", "3"); + +%{ + #include "grovegprs.hpp" +%} +%include "grovegprs.hpp" +%array_class(char, charArray); diff --git a/src/grovegsr/CMakeLists.txt b/src/grovegsr/CMakeLists.txt new file mode 100644 index 00000000..d352cdd7 --- /dev/null +++ b/src/grovegsr/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovegsr") +set (libdescription "upm grovegsr galvanic skin response sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/grovegsr/grovegsr.cxx b/src/grovegsr/grovegsr.cxx new file mode 100644 index 00000000..17b19c58 --- /dev/null +++ b/src/grovegsr/grovegsr.cxx @@ -0,0 +1,70 @@ +/* + * Author: Zion Orent + * 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. + */ + +#include +#include +#include + +#include "grovegsr.hpp" + +using namespace upm; +using namespace std; + +GroveGSR::GroveGSR(int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } +} + +GroveGSR::~GroveGSR() +{ + mraa_aio_close(m_aio); +} + +void GroveGSR::calibrate() +{ + sleep(1); + int val, threshold, sum = 0; + + for(int i=0; i<500; i++) + { + val = mraa_aio_read(m_aio); + if (val != -1) throw std::runtime_error(std::string(__FUNCTION__) + + ": Failed to do an aio read."); + sum += val; + usleep(5000); + } + threshold = sum / 500; + cout << "Threshold = " << threshold << endl; +} + +int GroveGSR::value() +{ + int val = mraa_aio_read(m_aio); + return val; +} diff --git a/src/grovegsr/grovegsr.hpp b/src/grovegsr/grovegsr.hpp new file mode 100644 index 00000000..32666abf --- /dev/null +++ b/src/grovegsr/grovegsr.hpp @@ -0,0 +1,84 @@ +/* + * Author: Zion Orent + * 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. + */ +#pragma once + +#include +#include + +namespace upm { + /** + * @brief Grove GSR Galvanic Skin Response Sensor library + * @defgroup grovegsr libupm-grovegsr + * @ingroup seeed analog electric + */ + + /** + * @library grovegsr + * @sensor grovegsr + * @comname Grove GSR Sensor + * @type electric + * @man seeed + * @con analog + * + * @brief API for the Grove GSR Galvanic Skin Response Sensor + * + * Measures the electrical conductance of skin + * to measure strong emotional reactions. + * In other words, it measures sweat on your fingers + * as an indicator of strong emotional reactions. + * + * @image html grovegsr.jpg + * @snippet grovegsr.cxx Interesting + */ + class GroveGSR { + public: + /** + * Grove GSR sensor constructor + * + * @param pin Analog pin to use + */ + GroveGSR(int pin); + /** + * GroveGSR destructor + */ + ~GroveGSR(); + + /** + * Calibrates the Grove GSR sensor + */ + void calibrate(); + + /** + * Gets the electrical conductance of the skin from the sensor + * + * @return Electrical conductance of the skin + */ + int value(); + + private: + mraa_aio_context m_aio; + }; +} + + diff --git a/src/grovegsr/javaupm_grovegsr.i b/src/grovegsr/javaupm_grovegsr.i new file mode 100644 index 00000000..22e27b0c --- /dev/null +++ b/src/grovegsr/javaupm_grovegsr.i @@ -0,0 +1,19 @@ +%module javaupm_grovegsr +%include "../upm.i" + +%{ + #include "grovegsr.hpp" +%} + +%include "grovegsr.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovegsr"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovegsr/jsupm_grovegsr.i b/src/grovegsr/jsupm_grovegsr.i new file mode 100644 index 00000000..5ee875bc --- /dev/null +++ b/src/grovegsr/jsupm_grovegsr.i @@ -0,0 +1,8 @@ +%module jsupm_grovegsr +%include "../upm.i" + +%{ + #include "grovegsr.hpp" +%} + +%include "grovegsr.hpp" diff --git a/src/grovegsr/pyupm_grovegsr.i b/src/grovegsr/pyupm_grovegsr.i new file mode 100644 index 00000000..92a30c2f --- /dev/null +++ b/src/grovegsr/pyupm_grovegsr.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovegsr +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "grovegsr.hpp" +%{ + #include "grovegsr.hpp" +%} diff --git a/src/grovemoisture/CMakeLists.txt b/src/grovemoisture/CMakeLists.txt new file mode 100644 index 00000000..c7fbf14f --- /dev/null +++ b/src/grovemoisture/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovemoisture") +set (libdescription "upm grove moisture module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/grovemoisture/grovemoisture.cxx b/src/grovemoisture/grovemoisture.cxx new file mode 100644 index 00000000..aa44e783 --- /dev/null +++ b/src/grovemoisture/grovemoisture.cxx @@ -0,0 +1,48 @@ +/* + * Author: Jon Trulson + * 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 "grovemoisture.hpp" + +using namespace upm; + +GroveMoisture::GroveMoisture(int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); +} + +GroveMoisture::~GroveMoisture() +{ + mraa_aio_close(m_aio); +} + +int GroveMoisture::value() +{ + return mraa_aio_read(m_aio); +} diff --git a/src/grovemoisture/grovemoisture.hpp b/src/grovemoisture/grovemoisture.hpp new file mode 100644 index 00000000..2b08170e --- /dev/null +++ b/src/grovemoisture/grovemoisture.hpp @@ -0,0 +1,81 @@ +/* + * Author: Jon Trulson + * 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 Grove Moisture Sensor library + * @defgroup grovemoisture libupm-grovemoisture + * @ingroup seeed analog liquid eak hak + */ + + /** + * @library grovemoisture + * @sensor grovemoisture + * @comname Grove Moisture Sensor + * @type liquid + * @man seeed + * @con analog + * @kit eak hak + * + * @brief API for the Grove Moisture Sensor + * + * UPM module for the Grove Moisture Sensor. + * This sensor can be used to detect the moisture content + * of soil or whether there is water around the sensor. + * As the moisture content increases, so does the value that is read. + * Note: this sensor is not designed to be left in soil + * nor to be used outdoors. + * + * @image html grovemoisture.jpg + * @snippet grovemoisture.cxx Interesting + */ + class GroveMoisture { + public: + /** + * Grove analog moisture sensor constructor + * + * @param pin Analog pin to use + */ + GroveMoisture(int pin); + /** + * GroveMoisture destructor + */ + ~GroveMoisture(); + /** + * Gets the moisture value from the sensor + * + * @return Moisture reading + */ + int value(); + + private: + mraa_aio_context m_aio; + }; +} + + diff --git a/src/grovemoisture/javaupm_grovemoisture.i b/src/grovemoisture/javaupm_grovemoisture.i new file mode 100644 index 00000000..1cf217c7 --- /dev/null +++ b/src/grovemoisture/javaupm_grovemoisture.i @@ -0,0 +1,19 @@ +%module javaupm_grovemoisture +%include "../upm.i" + +%{ + #include "grovemoisture.hpp" +%} + +%include "grovemoisture.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovemoisture"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovemoisture/jsupm_grovemoisture.i b/src/grovemoisture/jsupm_grovemoisture.i new file mode 100644 index 00000000..40a877ee --- /dev/null +++ b/src/grovemoisture/jsupm_grovemoisture.i @@ -0,0 +1,8 @@ +%module jsupm_grovemoisture +%include "../upm.i" + +%{ + #include "grovemoisture.hpp" +%} + +%include "grovemoisture.hpp" diff --git a/src/grovemoisture/pyupm_grovemoisture.i b/src/grovemoisture/pyupm_grovemoisture.i new file mode 100644 index 00000000..e661aadf --- /dev/null +++ b/src/grovemoisture/pyupm_grovemoisture.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovemoisture +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "grovemoisture.hpp" +%{ + #include "grovemoisture.hpp" +%} diff --git a/src/groveo2/CMakeLists.txt b/src/groveo2/CMakeLists.txt new file mode 100644 index 00000000..d0be3539 --- /dev/null +++ b/src/groveo2/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "groveo2") +set (libdescription "upm groveO2 oxygen concentration sensor module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/groveo2/groveo2.cxx b/src/groveo2/groveo2.cxx new file mode 100644 index 00000000..b982d3ff --- /dev/null +++ b/src/groveo2/groveo2.cxx @@ -0,0 +1,56 @@ +/* + * Author: Zion Orent + * 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. + */ + +#include +#include +#include + +#include "groveo2.hpp" + +using namespace upm; +using namespace std; + +GroveO2::GroveO2(int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } +} + +GroveO2::~GroveO2() +{ + mraa_aio_close(m_aio); +} + +float GroveO2::voltageValue() +{ + int val = mraa_aio_read(m_aio); + if (val == -1) return -1.0f; + float sensorVoltage = (val/1024.0) * 5.0; + sensorVoltage = (sensorVoltage/201.0) * 10000.0; + return sensorVoltage; +} diff --git a/src/groveo2/groveo2.hpp b/src/groveo2/groveo2.hpp new file mode 100644 index 00000000..16081d23 --- /dev/null +++ b/src/groveo2/groveo2.hpp @@ -0,0 +1,73 @@ +/* + * Author: Zion Orent + * 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. + */ +#pragma once + +#include +#include + +namespace upm { + /** + * @brief Grove O2 Oxygen Gas Sensor library + * @defgroup groveo2 libupm-groveo2 + * @ingroup seeed analog gaseous + */ + + /** + * @library groveo2 + * @sensor groveo2 + * @comname Grove O2 Sensor + * @type gaseous + * @man seeed + * @con analog + * + * @brief API for the Grove O2 Oxygen Gas Sensor + * + * The Grove O2 Oxygen Gas sensor measures the oxygen concentration in the air + * + * @image html groveo2.jpg + * @snippet groveo2.cxx Interesting + */ + class GroveO2 { + public: + /** + * Grove O2 Oxygen Gas sensor constructor + * + * @param pin Analog pin to use + */ + GroveO2(int pin); + /** + * GroveO2 destructor + */ + ~GroveO2(); + /** + * Measures O2 from the sensor + * + * @return Oxygen concentration as voltage + */ + float voltageValue(); + + private: + mraa_aio_context m_aio; + }; +} diff --git a/src/groveo2/javaupm_groveo2.i b/src/groveo2/javaupm_groveo2.i new file mode 100644 index 00000000..a7611088 --- /dev/null +++ b/src/groveo2/javaupm_groveo2.i @@ -0,0 +1,19 @@ +%module javaupm_groveo2 +%include "../upm.i" + +%{ + #include "groveo2.hpp" +%} + +%include "groveo2.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_groveo2"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/groveo2/jsupm_groveo2.i b/src/groveo2/jsupm_groveo2.i new file mode 100644 index 00000000..11d849e2 --- /dev/null +++ b/src/groveo2/jsupm_groveo2.i @@ -0,0 +1,8 @@ +%module jsupm_groveo2 +%include "../upm.i" + +%{ + #include "groveo2.hpp" +%} + +%include "groveo2.hpp" diff --git a/src/groveo2/pyupm_groveo2.i b/src/groveo2/pyupm_groveo2.i new file mode 100644 index 00000000..79bf2061 --- /dev/null +++ b/src/groveo2/pyupm_groveo2.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_groveo2 +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "groveo2.hpp" +%{ + #include "groveo2.hpp" +%} diff --git a/src/grovevdiv/CMakeLists.txt b/src/grovevdiv/CMakeLists.txt new file mode 100644 index 00000000..66d925be --- /dev/null +++ b/src/grovevdiv/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovevdiv") +set (libdescription "upm grove voltage divider module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/grovevdiv/grovevdiv.cxx b/src/grovevdiv/grovevdiv.cxx new file mode 100644 index 00000000..b1ebe154 --- /dev/null +++ b/src/grovevdiv/grovevdiv.cxx @@ -0,0 +1,68 @@ +/* + * Author: Jon Trulson + * 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 "grovevdiv.hpp" + +using namespace upm; +using namespace std; + +GroveVDiv::GroveVDiv(int pin) +{ + if ( !(m_aio = mraa_aio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } +} + +GroveVDiv::~GroveVDiv() +{ + mraa_aio_close(m_aio); +} + +unsigned int GroveVDiv::value(unsigned int samples) +{ + unsigned int sum = 0; + + for (int i=0; i + * 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 +#include +#include + +// reference voltage in millivolts +#define GROVEVDIV_VREF 4980 + +// default ADC resolution +#define GROVEVDIV_ADC_RES 1024 + +namespace upm { + /** + * @brief Grove Voltage Divider Sensor library + * @defgroup grovevdiv libupm-grovevdiv + * @ingroup seeed analog electric robok + */ + + /** + * @library grovevdiv + * @sensor grovevdiv + * @comname Grove Voltage Divider + * @type electric + * @man seeed + * @con analog + * @kit robok + * + * @brief API for the Grove Voltage Divider Sensor + * + * UPM module for the Grove Voltage Divider sensor + * + * @image html grovevdiv.jpg + * @snippet grovevdiv.cxx Interesting + */ + class GroveVDiv { + public: + /** + * Grove Voltage Divider sensor constructor + * + * @param pin Analog pin to use + */ + GroveVDiv(int pin); + + /** + * Grove Voltage Divider destructor + */ + ~GroveVDiv(); + + /** + * Gets the conversion value from the sensor + * + * @param samples Specifies how many samples to average over + * @return Average ADC conversion value + */ + unsigned int value(unsigned int samples); + + /** + * Computes the measured voltage + * + * @param gain Gain switch, either 3 or 10 for Grove + * @param val Measured voltage (from value()) + * @param vref Reference voltage in millivolts + * @param res ADC resolution + * + * @return Measured voltage + */ + float computedValue(uint8_t gain, unsigned int val, int vref=GROVEVDIV_VREF, + int res=GROVEVDIV_ADC_RES); + + private: + mraa_aio_context m_aio; + }; +} diff --git a/src/grovevdiv/javaupm_grovevdiv.i b/src/grovevdiv/javaupm_grovevdiv.i new file mode 100644 index 00000000..b3c5e02f --- /dev/null +++ b/src/grovevdiv/javaupm_grovevdiv.i @@ -0,0 +1,19 @@ +%module javaupm_grovevdiv +%include "../upm.i" + +%{ + #include "grovevdiv.hpp" +%} + +%include "grovevdiv.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovevdiv"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovevdiv/jsupm_grovevdiv.i b/src/grovevdiv/jsupm_grovevdiv.i new file mode 100644 index 00000000..ab9bedfe --- /dev/null +++ b/src/grovevdiv/jsupm_grovevdiv.i @@ -0,0 +1,8 @@ +%module jsupm_grovevdiv +%include "../upm.i" + +%{ + #include "grovevdiv.hpp" +%} + +%include "grovevdiv.hpp" diff --git a/src/grovevdiv/pyupm_grovevdiv.i b/src/grovevdiv/pyupm_grovevdiv.i new file mode 100644 index 00000000..5ad7aafb --- /dev/null +++ b/src/grovevdiv/pyupm_grovevdiv.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovevdiv +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "grovevdiv.hpp" +%{ + #include "grovevdiv.hpp" +%} diff --git a/src/grovewater/CMakeLists.txt b/src/grovewater/CMakeLists.txt new file mode 100644 index 00000000..6561276b --- /dev/null +++ b/src/grovewater/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "grovewater") +set (libdescription "upm grove water module") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) +upm_module_init() diff --git a/src/grovewater/grovewater.cxx b/src/grovewater/grovewater.cxx new file mode 100644 index 00000000..9220adcf --- /dev/null +++ b/src/grovewater/grovewater.cxx @@ -0,0 +1,54 @@ +/* + * Author: Jon Trulson + * 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 "grovewater.hpp" + +using namespace upm; +using namespace std; + +GroveWater::GroveWater(int pin) +{ + if ( !(m_gpio = mraa_gpio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + return; + } + + mraa_gpio_dir(m_gpio, MRAA_GPIO_IN); +} + +GroveWater::~GroveWater() +{ + mraa_gpio_close(m_gpio); +} + +bool GroveWater::isWet() +{ + return (!mraa_gpio_read(m_gpio) ? true : false); +} diff --git a/src/grovewater/grovewater.hpp b/src/grovewater/grovewater.hpp new file mode 100644 index 00000000..50e74b4e --- /dev/null +++ b/src/grovewater/grovewater.hpp @@ -0,0 +1,74 @@ +/* + * Author: Jon Trulson + * 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 Grove Water Sensor library + * @defgroup grovewater libupm-grovewater + * @ingroup seeed gpio liquid eak + */ + + /** + * @library grovewater + * @sensor grovewater + * @comname Grove Water Sensor + * @type liquid + * @man seeed + * @con gpio + * @kit eak + * + * @brief API for the Grove Water Sensor + * + * UPM module for the Grove Water sensor + * + * @image html grovewater.jpg + * @snippet grovewater.cxx Interesting + */ + class GroveWater { + public: + /** + * Grove digital water sensor constructor + * + * @param pin Digital pin to use + */ + GroveWater(int pin); + /** + * GroveWater destructor + */ + ~GroveWater(); + /** + * Gets the water (wet/not wet) value from the sensor + * + * @return True if the sensor is wet, false otherwise + */ + bool isWet(); + + private: + mraa_gpio_context m_gpio; + }; +} diff --git a/src/grovewater/javaupm_grovewater.i b/src/grovewater/javaupm_grovewater.i new file mode 100644 index 00000000..0c074171 --- /dev/null +++ b/src/grovewater/javaupm_grovewater.i @@ -0,0 +1,19 @@ +%module javaupm_grovewater +%include "../upm.i" + +%{ + #include "grovewater.hpp" +%} + +%include "grovewater.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_grovewater"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} \ No newline at end of file diff --git a/src/grovewater/jsupm_grovewater.i b/src/grovewater/jsupm_grovewater.i new file mode 100644 index 00000000..48c5deeb --- /dev/null +++ b/src/grovewater/jsupm_grovewater.i @@ -0,0 +1,8 @@ +%module jsupm_grovewater +%include "../upm.i" + +%{ + #include "grovewater.hpp" +%} + +%include "grovewater.hpp" diff --git a/src/grovewater/pyupm_grovewater.i b/src/grovewater/pyupm_grovewater.i new file mode 100644 index 00000000..0af321c7 --- /dev/null +++ b/src/grovewater/pyupm_grovewater.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_grovewater +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "grovewater.hpp" +%{ + #include "grovewater.hpp" +%}