mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
grove: add grove button support and examples
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:

committed by
Brendan Le Foll

parent
c5369315e9
commit
801209678b
@ -193,3 +193,28 @@ float GroveSlide::ref_voltage()
|
||||
{
|
||||
return m_ref_voltage;
|
||||
}
|
||||
|
||||
//// GroveButton ////
|
||||
|
||||
GroveButton::GroveButton(unsigned int pin)
|
||||
{
|
||||
mraa_init();
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
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);
|
||||
}
|
||||
|
@ -247,4 +247,41 @@ class GroveSlide: public Grove {
|
||||
float m_ref_voltage;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove button
|
||||
*
|
||||
* Very basic UPM module for Grove button
|
||||
*
|
||||
* @ingroup grove gpio
|
||||
* @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();
|
||||
/**
|
||||
* Get name of sensor
|
||||
*
|
||||
* @return the name of this sensor
|
||||
*/
|
||||
std::string name();
|
||||
/**
|
||||
* Get value from GPIO pin
|
||||
*
|
||||
* @return the value from the GPIO pin
|
||||
*/
|
||||
int value();
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user