upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
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 #ifdef JAVACALLBACK
33 #include "../IsrCallback.h"
34 #endif
35 
36 namespace upm {
37 
43 class Grove {
44  public:
45  virtual ~Grove() {}
46  std::string name()
47  {
48  return m_name;
49  }
50  protected:
51  std::string m_name;
52 };
53 
69 class GroveLed: public Grove {
70  public:
76  GroveLed(int pin);
80  ~GroveLed();
92  mraa_result_t write(int value);
98  mraa_result_t off();
104  mraa_result_t on();
105  private:
106  mraa_gpio_context m_gpio;
107 };
108 
121 class GroveRelay: public Grove {
122  public:
128  GroveRelay(unsigned int pin);
132  ~GroveRelay();
139  mraa_result_t on();
146  mraa_result_t off();
152  bool isOn();
158  bool isOff();
159  private:
160  mraa_gpio_context m_gpio;
161 };
162 
172 class GroveTemp: public Grove {
173  public:
179  GroveTemp(unsigned int pin);
183  ~GroveTemp();
189  float raw_value();
195  int value();
196  private:
197  mraa_aio_context m_aio;
198 };
199 
213 class GroveLight: public Grove {
214  public:
220  GroveLight(unsigned int pin);
224  ~GroveLight();
230  float raw_value();
236  int value();
237  private:
238  mraa_aio_context m_aio;
239 };
240 
252 class GroveRotary: public Grove {
253  public:
259  GroveRotary(unsigned int pin);
263  ~GroveRotary();
269  float abs_value();
275  float abs_deg();
281  float abs_rad();
287  float rel_value();
293  float rel_deg();
299  float rel_rad();
300  private:
301  mraa_aio_context m_aio;
302  static const int m_max_angle = 300;
303 };
304 
315 class GroveSlide: public Grove {
316  public:
324  GroveSlide(unsigned int pin, float ref_voltage = 5.0);
328  ~GroveSlide();
334  float raw_value();
340  float voltage_value();
346  float ref_voltage();
347  private:
348  mraa_aio_context m_aio;
349  float m_ref_voltage;
350 };
351 
361 class GroveButton: public Grove {
362  public:
368  GroveButton(unsigned int pin);
372  ~GroveButton();
378  std::string name();
384  int value();
385 
394 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
395  void installISR(mraa::Edge level, IsrCallback *cb);
396 #else
397  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
398 #endif
399 
403  void uninstallISR();
404 
405  private:
406 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
407  void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
408 #endif
409  bool m_isrInstalled;
410  std::string m_name;
411  mraa_gpio_context m_gpio;
412 };
413 
414 }
~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:69
float rel_rad()
Definition: grove.cxx:212
API for the Grove Button.
Definition: grove.h:361
~GroveRelay()
Definition: grove.cxx:85
GroveSlide(unsigned int pin, float ref_voltage=5.0)
Definition: grove.cxx:219
Definition: a110x.h:33
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:121
~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:213
API for the Grove Slide Potentiometer.
Definition: grove.h:315
GroveRelay(unsigned int pin)
Definition: grove.cxx:74
~GroveTemp()
Definition: grove.cxx:122
API for the Grove Temperature Sensor.
Definition: grove.h:172
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:43
API for the Grove Rotary Angle Sensor (Knob)
Definition: grove.h:252
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