upm  0.7.1
Sensor/Actuator repository for libmraa (v1.0.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
grove.hpp
1 /*
2  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3  * Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
4  * Contributions: Sarah Knepper <sarah.knepper@intel.com>
5  * Copyright (c) 2014 Intel Corporation.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <mraa/aio.hpp>
30 #include <mraa/gpio.hpp>
31 
32 namespace upm {
33 
39 class Grove {
40  public:
41  virtual ~Grove() {}
42  std::string name()
43  {
44  return m_name;
45  }
46  protected:
47  std::string m_name;
48 };
49 
65 class GroveLed: public Grove {
66  public:
72  GroveLed(int pin);
76  ~GroveLed();
88  mraa_result_t write(int value);
94  mraa_result_t off();
100  mraa_result_t on();
101  private:
102  mraa_gpio_context m_gpio;
103 };
104 
117 class GroveRelay: public Grove {
118  public:
124  GroveRelay(unsigned int pin);
128  ~GroveRelay();
135  mraa_result_t on();
142  mraa_result_t off();
148  bool isOn();
154  bool isOff();
155  private:
156  mraa_gpio_context m_gpio;
157 };
158 
168 class GroveTemp: public Grove {
169  public:
177  GroveTemp(unsigned int pin, float scale = 1.0);
181  ~GroveTemp();
187  float raw_value();
193  int value();
194  private:
195  mraa_aio_context m_aio;
196  float m_scale;
197 };
198 
212 class GroveLight: public Grove {
213  public:
219  GroveLight(unsigned int pin);
223  ~GroveLight();
229  float raw_value();
235  int value();
236  private:
237  mraa_aio_context m_aio;
238 };
239 
251 class GroveRotary: public Grove {
252  public:
258  GroveRotary(unsigned int pin);
262  ~GroveRotary();
268  float abs_value();
274  float abs_deg();
280  float abs_rad();
286  float rel_value();
292  float rel_deg();
298  float rel_rad();
299  private:
300  mraa_aio_context m_aio;
301  static const int m_max_angle = 300;
302 };
303 
314 class GroveSlide: public Grove {
315  public:
323  GroveSlide(unsigned int pin, float ref_voltage = 5.0);
327  ~GroveSlide();
333  float raw_value();
339  float voltage_value();
345  float ref_voltage();
346  private:
347  mraa_aio_context m_aio;
348  float m_ref_voltage;
349 };
350 
360 class GroveButton: public Grove {
361  public:
367  GroveButton(unsigned int pin);
371  ~GroveButton();
377  std::string name();
383  int value();
384 
393 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
394  void installISR(mraa::Edge level, jobject runnable);
395 #else
396  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
397 #endif
398 
402  void uninstallISR();
403 
404  private:
405 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
406  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
407 #endif
408  bool m_isrInstalled;
409  std::string m_name;
410  mraa_gpio_context m_gpio;
411 };
412 
413 }
~GroveLight()
Definition: grove.cxx:156
mraa_result_t on()
Definition: grove.cxx:90
float raw_value()
Definition: grove.cxx:240
mraa_result_t off()
Definition: grove.cxx:67
bool isOn()
Definition: grove.cxx:100
int value()
Definition: grove.cxx:281
API for the Grove LED.
Definition: grove.hpp:65
float rel_rad()
Definition: grove.cxx:217
API for the Grove Button.
Definition: grove.hpp:360
~GroveRelay()
Definition: grove.cxx:85
GroveSlide(unsigned int pin, float ref_voltage=5.0)
Definition: grove.cxx:224
float abs_deg()
Definition: grove.cxx:197
GroveLed(int pin)
Definition: grove.cxx:38
float raw_value()
Definition: grove.cxx:170
~GroveRotary()
Definition: grove.cxx:187
mraa_result_t write(int value)
Definition: grove.cxx:54
API for the Grove Relay.
Definition: grove.hpp:117
~GroveLed()
Definition: grove.cxx:49
void uninstallISR()
Definition: grove.cxx:303
std::string name()
Definition: grove.cxx:276
GroveButton(unsigned int pin)
Definition: grove.cxx:260
float ref_voltage()
Definition: grove.cxx:253
GroveRotary(unsigned int pin)
Definition: grove.cxx:177
float voltage_value()
Definition: grove.cxx:245
float rel_value()
Definition: grove.cxx:207
API for the Grove Light Sensor.
Definition: grove.hpp:212
API for the Grove Slide Potentiometer.
Definition: grove.hpp:314
GroveRelay(unsigned int pin)
Definition: grove.cxx:74
~GroveTemp()
Definition: grove.cxx:123
API for the Grove Temperature Sensor.
Definition: grove.hpp:168
float abs_value()
Definition: grove.cxx:192
float rel_deg()
Definition: grove.cxx:212
GroveLight(unsigned int pin)
Definition: grove.cxx:146
mraa_result_t off()
Definition: grove.cxx:95
float raw_value()
Definition: grove.cxx:139
int value()
Definition: grove.cxx:128
float abs_rad()
Definition: grove.cxx:202
bool isOff()
Definition: grove.cxx:105
Definition: grove.hpp:39
API for the Grove Rotary Angle Sensor (Knob)
Definition: grove.hpp:251
mraa_result_t on()
Definition: grove.cxx:62
int value()
Definition: grove.cxx:161
~GroveButton()
Definition: grove.cxx:271
GroveTemp(unsigned int pin, float scale=1.0)
Definition: grove.cxx:112
~GroveSlide()
Definition: grove.cxx:235
void installISR(mraa::Edge level, void(*isr)(void *), void *arg)
Definition: grove.cxx:293