Grove: Reverting Grove sources

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik 2016-09-13 16:32:04 -07:00 committed by Noel Eck
parent 67848a7a5c
commit a9883bd1f2
76 changed files with 2967 additions and 8 deletions

View File

@ -30,6 +30,7 @@
#include "button.hpp"
using namespace std;
using namespace upm;
Button::Button(unsigned int pin)

View File

@ -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()

View File

@ -25,6 +25,10 @@
*/
#pragma once
#include <button.hpp>
#include <grovebutton.hpp>
#include <groveled.hpp>
#include <grovelight.hpp>
#include <groverelay.hpp>
#include <groverotary.hpp>
#include <groveslide.hpp>
#include <grovetemp.hpp>

82
src/grove/grovebutton.cxx Normal file
View File

@ -0,0 +1,82 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <iostream>
#include <string>
#include <stdexcept>
#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;
}

104
src/grove/grovebutton.hpp Normal file
View File

@ -0,0 +1,104 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <string>
#include <mraa/gpio.hpp>
#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;
};
}

63
src/grove/grovelight.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <iostream>
#include <string>
#include <stdexcept>
#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);
}

82
src/grove/grovelight.hpp Normal file
View File

@ -0,0 +1,82 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <string>
#include <mraa/aio.hpp>
#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;
};
}

69
src/grove/groverelay.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <iostream>
#include <string>
#include <stdexcept>
#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;
}

95
src/grove/groverelay.hpp Normal file
View File

@ -0,0 +1,95 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <string>
#include <mraa/gpio.hpp>
#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;
};
}

79
src/grove/groverotary.cxx Normal file
View File

@ -0,0 +1,79 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <iostream>
#include <string>
#include <stdexcept>
#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;
}

106
src/grove/groverotary.hpp Normal file
View File

@ -0,0 +1,106 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <string>
#include <mraa/aio.hpp>
#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;
};
}

68
src/grove/groveslide.cxx Normal file
View File

@ -0,0 +1,68 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <iostream>
#include <string>
#include <stdexcept>
#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;
}

87
src/grove/groveslide.hpp Normal file
View File

@ -0,0 +1,87 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* 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 <string>
#include <mraa/aio.hpp>
#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;
};
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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")

View File

@ -0,0 +1,53 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include <stdexcept>
#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));
}

View File

@ -0,0 +1,72 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <mraa/gpio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_grovecollision
%include "../upm.i"
%{
#include "grovecollision.hpp"
%}
%include "grovecollision.hpp"

View File

@ -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"
%}

View File

@ -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()

130
src/groveehr/groveehr.cxx Normal file
View File

@ -0,0 +1,130 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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);
}

126
src/groveehr/groveehr.hpp Normal file
View File

@ -0,0 +1,126 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <stdint.h>
#include <sys/time.h>
#include <mraa/gpio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_groveehr
%include "../upm.i"
%{
#include "groveehr.hpp"
%}
%include "groveehr.hpp"

View File

@ -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"
%}

View File

@ -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")

View File

@ -0,0 +1,62 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include <stdexcept>
#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);
}

View File

@ -0,0 +1,77 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <mraa/gpio.h>
#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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_groveelectromagnet
%include "../upm.i"
%{
#include "groveelectromagnet.hpp"
%}
%include "groveelectromagnet.hpp"

View File

@ -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"
%}

View File

@ -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()

69
src/groveemg/groveemg.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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;
}

82
src/groveemg/groveemg.hpp Normal file
View File

@ -0,0 +1,82 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_groveemg
%include "../upm.i"
%{
#include "groveemg.hpp"
%}
%include "groveemg.hpp"

View File

@ -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"
%}

View File

@ -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()

View File

@ -0,0 +1,74 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#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);
}

154
src/grovegprs/grovegprs.hpp Normal file
View File

@ -0,0 +1,154 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* 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 <string>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <mraa/common.hpp>
#include <mraa/uart.hpp>
#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:
};
}

View File

@ -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);
}
}
%}

View File

@ -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);

View File

@ -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);

View File

@ -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()

70
src/grovegsr/grovegsr.cxx Normal file
View File

@ -0,0 +1,70 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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;
}

84
src/grovegsr/grovegsr.hpp Normal file
View File

@ -0,0 +1,84 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_grovegsr
%include "../upm.i"
%{
#include "grovegsr.hpp"
%}
%include "grovegsr.hpp"

View File

@ -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"
%}

View File

@ -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()

View File

@ -0,0 +1,48 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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);
}

View File

@ -0,0 +1,81 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
namespace upm {
/**
* @brief Grove 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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_grovemoisture
%include "../upm.i"
%{
#include "grovemoisture.hpp"
%}
%include "grovemoisture.hpp"

View File

@ -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"
%}

View File

@ -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()

56
src/groveo2/groveo2.cxx Normal file
View File

@ -0,0 +1,56 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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;
}

73
src/groveo2/groveo2.hpp Normal file
View File

@ -0,0 +1,73 @@
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_groveo2
%include "../upm.i"
%{
#include "groveo2.hpp"
%}
%include "groveo2.hpp"

View File

@ -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"
%}

View File

@ -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()

View File

@ -0,0 +1,68 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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<samples; i++)
{
sum += mraa_aio_read(m_aio);
if (sum == -1) return 0;
usleep(2000);
}
return (sum / samples);
}
float GroveVDiv::computedValue(uint8_t gain, unsigned int val, int vref, int res)
{
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
}

View File

@ -0,0 +1,98 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <iostream>
#include <stdint.h>
#include <mraa/aio.h>
// 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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_grovevdiv
%include "../upm.i"
%{
#include "grovevdiv.hpp"
%}
%include "grovevdiv.hpp"

View File

@ -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"
%}

View File

@ -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()

View File

@ -0,0 +1,54 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#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);
}

View File

@ -0,0 +1,74 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/gpio.h>
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;
};
}

View File

@ -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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_grovewater
%include "../upm.i"
%{
#include "grovewater.hpp"
%}
%include "grovewater.hpp"

View File

@ -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"
%}