mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 18:01:18 +03:00
Grove: Reverting Grove sources
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
@ -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()
|
||||
|
@ -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
82
src/grove/grovebutton.cxx
Normal 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
104
src/grove/grovebutton.hpp
Normal 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
63
src/grove/grovelight.cxx
Normal 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
82
src/grove/grovelight.hpp
Normal 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
69
src/grove/groverelay.cxx
Normal 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
95
src/grove/groverelay.hpp
Normal 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
79
src/grove/groverotary.cxx
Normal 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
106
src/grove/groverotary.hpp
Normal 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
68
src/grove/groveslide.cxx
Normal 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
87
src/grove/groveslide.hpp
Normal 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;
|
||||
};
|
||||
}
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user