upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
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.h>
30 #include <mraa/gpio.h>
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 
64 class GroveLed: public Grove {
65  public:
71  GroveLed(int pin);
75  ~GroveLed();
87  mraa_result_t write(int value);
93  mraa_result_t off();
99  mraa_result_t on();
100  private:
101  mraa_gpio_context m_gpio;
102 };
103 
115 class GroveRelay: public Grove {
116  public:
122  GroveRelay(unsigned int pin);
126  ~GroveRelay();
133  mraa_result_t on();
140  mraa_result_t off();
146  bool isOn();
152  bool isOff();
153  private:
154  mraa_gpio_context m_gpio;
155 };
156 
165 class GroveTemp: public Grove {
166  public:
172  GroveTemp(unsigned int pin);
176  ~GroveTemp();
182  float raw_value();
188  int value();
189  private:
190  mraa_aio_context m_aio;
191 };
192 
205 class GroveLight: public Grove {
206  public:
212  GroveLight(unsigned int pin);
216  ~GroveLight();
222  float raw_value();
228  int value();
229  private:
230  mraa_aio_context m_aio;
231 };
232 
244 class GroveRotary: public Grove {
245  public:
251  GroveRotary(unsigned int pin);
255  ~GroveRotary();
261  float abs_value();
267  float abs_deg();
273  float abs_rad();
279  float rel_value();
285  float rel_deg();
291  float rel_rad();
292  private:
293  mraa_aio_context m_aio;
294  static const int m_max_angle = 300;
295 };
296 
307 class GroveSlide: public Grove {
308  public:
316  GroveSlide(unsigned int pin, float ref_voltage = 5.0);
320  ~GroveSlide();
326  float raw_value();
332  float voltage_value();
338  float ref_voltage();
339  private:
340  mraa_aio_context m_aio;
341  float m_ref_voltage;
342 };
343 
352 class GroveButton: public Grove {
353  public:
359  GroveButton(unsigned int pin);
363  ~GroveButton();
369  std::string name();
375  int value();
376  private:
377  std::string m_name;
378  mraa_gpio_context m_gpio;
379 };
380 
381 }
~GroveLight()
Definition: grove.cxx:138
GroveTemp(unsigned int pin)
Definition: grove.cxx:104
mraa_result_t on()
Definition: grove.cxx:82
float raw_value()
Definition: grove.cxx:215
mraa_result_t off()
Definition: grove.cxx:62
bool isOn()
Definition: grove.cxx:92
int value()
Definition: grove.cxx:253
C++ API for Grove LED.
Definition: grove.h:64
float rel_rad()
Definition: grove.cxx:195
C++ API for Grove button.
Definition: grove.h:352
~GroveRelay()
Definition: grove.cxx:77
GroveSlide(unsigned int pin, float ref_voltage=5.0)
Definition: grove.cxx:202
Definition: a110x.h:29
float abs_deg()
Definition: grove.cxx:175
GroveLed(int pin)
Definition: grove.cxx:36
float raw_value()
Definition: grove.cxx:151
~GroveRotary()
Definition: grove.cxx:165
mraa_result_t write(int value)
Definition: grove.cxx:49
C++ API for Grove Relay.
Definition: grove.h:115
~GroveLed()
Definition: grove.cxx:44
std::string name()
Definition: grove.cxx:248
GroveButton(unsigned int pin)
Definition: grove.cxx:235
float ref_voltage()
Definition: grove.cxx:228
GroveRotary(unsigned int pin)
Definition: grove.cxx:158
float voltage_value()
Definition: grove.cxx:220
float rel_value()
Definition: grove.cxx:185
C++ API for Grove light sensor.
Definition: grove.h:205
C++ API for Grove Slide Potentiometer.
Definition: grove.h:307
GroveRelay(unsigned int pin)
Definition: grove.cxx:69
~GroveTemp()
Definition: grove.cxx:111
C++ API for Grove temperature sensor.
Definition: grove.h:165
float abs_value()
Definition: grove.cxx:170
float rel_deg()
Definition: grove.cxx:190
GroveLight(unsigned int pin)
Definition: grove.cxx:131
mraa_result_t off()
Definition: grove.cxx:87
float raw_value()
Definition: grove.cxx:124
int value()
Definition: grove.cxx:116
float abs_rad()
Definition: grove.cxx:180
bool isOff()
Definition: grove.cxx:97
Definition: grove.h:39
C++ API for Grove Rotary Angle Sensor (Knob)
Definition: grove.h:244
mraa_result_t on()
Definition: grove.cxx:57
int value()
Definition: grove.cxx:143
~GroveButton()
Definition: grove.cxx:243
~GroveSlide()
Definition: grove.cxx:210