upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
grove.h
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:
175  GroveTemp(unsigned int pin);
179  ~GroveTemp();
185  float raw_value();
191  int value();
192  private:
193  mraa_aio_context m_aio;
194 };
195 
209 class GroveLight: public Grove {
210  public:
216  GroveLight(unsigned int pin);
220  ~GroveLight();
226  float raw_value();
232  int value();
233  private:
234  mraa_aio_context m_aio;
235 };
236 
248 class GroveRotary: public Grove {
249  public:
255  GroveRotary(unsigned int pin);
259  ~GroveRotary();
265  float abs_value();
271  float abs_deg();
277  float abs_rad();
283  float rel_value();
289  float rel_deg();
295  float rel_rad();
296  private:
297  mraa_aio_context m_aio;
298  static const int m_max_angle = 300;
299 };
300 
311 class GroveSlide: public Grove {
312  public:
320  GroveSlide(unsigned int pin, float ref_voltage = 5.0);
324  ~GroveSlide();
330  float raw_value();
336  float voltage_value();
342  float ref_voltage();
343  private:
344  mraa_aio_context m_aio;
345  float m_ref_voltage;
346 };
347 
357 class GroveButton: public Grove {
358  public:
364  GroveButton(unsigned int pin);
368  ~GroveButton();
374  std::string name();
380  int value();
381 
390 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
391  void installISR(mraa::Edge level, jobject runnable);
392 #else
393  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
394 #endif
395 
399  void uninstallISR();
400 
401  private:
402 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
403  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
404 #endif
405  bool m_isrInstalled;
406  std::string m_name;
407  mraa_gpio_context m_gpio;
408 };
409 
410 }
~GroveLight()
Definition: grove.cxx:152
GroveTemp(unsigned int pin)
Definition: grove.cxx:112
mraa_result_t on()
Definition: grove.cxx:90
float raw_value()
Definition: grove.cxx:235
mraa_result_t off()
Definition: grove.cxx:67
bool isOn()
Definition: grove.cxx:100
int value()
Definition: grove.cxx:276
API for the Grove LED.
Definition: grove.h:65
float rel_rad()
Definition: grove.cxx:212
API for the Grove Button.
Definition: grove.h:357
~GroveRelay()
Definition: grove.cxx:85
GroveSlide(unsigned int pin, float ref_voltage=5.0)
Definition: grove.cxx:219
float abs_deg()
Definition: grove.cxx:192
GroveLed(int pin)
Definition: grove.cxx:38
float raw_value()
Definition: grove.cxx:165
~GroveRotary()
Definition: grove.cxx:182
mraa_result_t write(int value)
Definition: grove.cxx:54
API for the Grove Relay.
Definition: grove.h:117
~GroveLed()
Definition: grove.cxx:49
void uninstallISR()
Definition: grove.cxx:298
std::string name()
Definition: grove.cxx:271
GroveButton(unsigned int pin)
Definition: grove.cxx:255
float ref_voltage()
Definition: grove.cxx:248
GroveRotary(unsigned int pin)
Definition: grove.cxx:172
float voltage_value()
Definition: grove.cxx:240
float rel_value()
Definition: grove.cxx:202
API for the Grove Light Sensor.
Definition: grove.h:209
API for the Grove Slide Potentiometer.
Definition: grove.h:311
GroveRelay(unsigned int pin)
Definition: grove.cxx:74
~GroveTemp()
Definition: grove.cxx:122
API for the Grove Temperature Sensor.
Definition: grove.h:168
float abs_value()
Definition: grove.cxx:187
float rel_deg()
Definition: grove.cxx:207
GroveLight(unsigned int pin)
Definition: grove.cxx:142
mraa_result_t off()
Definition: grove.cxx:95
float raw_value()
Definition: grove.cxx:135
int value()
Definition: grove.cxx:127
float abs_rad()
Definition: grove.cxx:197
bool isOff()
Definition: grove.cxx:105
Definition: grove.h:39
API for the Grove Rotary Angle Sensor (Knob)
Definition: grove.h:248
mraa_result_t on()
Definition: grove.cxx:62
int value()
Definition: grove.cxx:157
~GroveButton()
Definition: grove.cxx:266
~GroveSlide()
Definition: grove.cxx:230
void installISR(mraa::Edge level, void(*isr)(void *), void *arg)
Definition: grove.cxx:288