mraa  0.9.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
common.hpp
Go to the documentation of this file.
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include "common.h"
28 #include "types.hpp"
29 #include <string>
30 
34 namespace mraa
35 {
36 
55 inline Result
57 {
58  return (Result) mraa_init();
59 }
60 
66 inline std::string
68 {
69  std::string ret = mraa_get_version();
70  return ret;
71 }
72 
82 inline int
83 setPriority(const unsigned int priority)
84 {
85  return mraa_set_priority(priority);
86 }
87 
93 inline Platform
95 {
97 }
98 
104 inline void
106 {
108 }
109 
117 inline bool
118 pinModeTest(int pin, Pinmodes mode)
119 {
120  return (bool) mraa_pin_mode_test(pin, (mraa_pinmodes_t) mode);
121 }
122 
128 inline unsigned int
130 {
131  return mraa_adc_raw_bits();
132 }
133 
139 inline unsigned int
141 {
142  return mraa_adc_supported_bits();
143 }
144 
150 inline std::string
152 {
153  std::string ret_val(mraa_get_platform_name());
154  return ret_val;
155 }
156 
162 inline unsigned int
164 {
165  return mraa_get_pin_count();
166 }
167 
174 inline int
176 {
177  return mraa_get_i2c_bus_count();
178 }
179 
186 inline int
187 getI2cBusId(unsigned int i2c_bus)
188 {
189  return mraa_get_i2c_bus_id(i2c_bus);
190 }
191 
199 inline std::string
200 getPinName(int pin)
201 {
202  std::string ret_val(mraa_get_pin_name(pin));
203  return ret_val;
204 }
205 
213 inline Result
214 setLogLevel(int level)
215 {
216  return (Result) mraa_set_log_level(level);
217 }
218 
224 inline bool
226 {
227  return static_cast<bool>(mraa_has_sub_platform());
228 }
229 
230 
231 
239 inline bool
240 isSubPlatformId(int pin_or_bus_id)
241 {
242  return static_cast<bool>(mraa_is_sub_platform_id(pin_or_bus_id));
243 }
244 
252 inline int
253 getSubPlatformId(int pin_or_bus_index)
254 {
255  return mraa_get_sub_platform_id(pin_or_bus_index);
256 }
257 
265 inline int
266 getSubPlatformIndex(int pin_or_bus_id)
267 {
268  return mraa_get_sub_platform_index(pin_or_bus_id);
269 }
270 }
Result
Definition: types.hpp:185
Result setLogLevel(int level)
Definition: common.hpp:214
char * mraa_get_platform_name()
const char * mraa_get_version()
Result init()
Definition: common.hpp:56
std::string getVersion()
Definition: common.hpp:67
Platform getPlatformType()
Definition: common.hpp:94
mraa_platform_t mraa_get_platform_type()
void printError(Result result)
Definition: common.hpp:105
int getI2cBusCount()
Definition: common.hpp:175
mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
int mraa_get_sub_platform_index(int pin_or_bus_id)
unsigned int mraa_adc_supported_bits()
bool isSubPlatformId(int pin_or_bus_id)
Definition: common.hpp:240
int mraa_get_i2c_bus_count()
mraa_boolean_t mraa_is_sub_platform_id(int pin_or_bus_id)
unsigned int adcSupportedBits()
Definition: common.hpp:140
char * mraa_get_pin_name(int pin)
unsigned int getPinCount()
Definition: common.hpp:163
Platform
Definition: types.hpp:40
mraa_result_t mraa_init() __attribute__((constructor))
int mraa_get_i2c_bus_id(unsigned int i2c_bus)
std::string getPlatformName()
Definition: common.hpp:151
bool pinModeTest(int pin, Pinmodes mode)
Definition: common.hpp:118
bool hasSubPlatform()
Definition: common.hpp:225
int mraa_get_sub_platform_id(int pin_or_bus_index)
unsigned int mraa_adc_raw_bits()
Definition: aio.hpp:31
int setPriority(const unsigned int priority)
Definition: common.hpp:83
mraa_result_t
Definition: types.h:191
mraa_pinmodes_t
Definition: types.h:212
int getI2cBusId(unsigned int i2c_bus)
Definition: common.hpp:187
std::string getPinName(int pin)
Definition: common.hpp:200
mraa_boolean_t mraa_has_sub_platform()
int mraa_set_priority(const unsigned int priority)
unsigned int adcRawBits()
Definition: common.hpp:129
Pinmodes
Definition: types.hpp:206
void mraa_result_print(mraa_result_t result)
int getSubPlatformId(int pin_or_bus_index)
Definition: common.hpp:253
mraa_result_t mraa_set_log_level(int level)
int getSubPlatformIndex(int pin_or_bus_id)
Definition: common.hpp:266
unsigned int mraa_get_pin_count()