mraa  0.9.6
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
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 
163 inline std::string
164 getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
165 {
166  std::string ret_val(mraa_get_platform_version(platform_offset));
167  return ret_val;
168 }
169 
175 inline unsigned int
177 {
178  return mraa_get_pin_count();
179 }
180 
187 inline int
189 {
190  return mraa_get_i2c_bus_count();
191 }
192 
199 inline int
200 getI2cBusId(unsigned int i2c_bus)
201 {
202  return mraa_get_i2c_bus_id(i2c_bus);
203 }
204 
212 inline std::string
213 getPinName(int pin)
214 {
215  std::string ret_val(mraa_get_pin_name(pin));
216  return ret_val;
217 }
218 
226 inline Result
227 setLogLevel(int level)
228 {
229  return (Result) mraa_set_log_level(level);
230 }
231 
237 inline bool
239 {
240  return static_cast<bool>(mraa_has_sub_platform());
241 }
242 
250 inline bool
251 isSubPlatformId(int pin_or_bus_id)
252 {
253  return static_cast<bool>(mraa_is_sub_platform_id(pin_or_bus_id));
254 }
255 
263 inline int
264 getSubPlatformId(int pin_or_bus_index)
265 {
266  return mraa_get_sub_platform_id(pin_or_bus_index);
267 }
268 
276 inline int
277 getSubPlatformIndex(int pin_or_bus_id)
278 {
279  return mraa_get_sub_platform_index(pin_or_bus_id);
280 }
281 
288 inline int
289 getDefaultI2cBus(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
290 {
291  return mraa_get_default_i2c_bus(platform_offset);
292 }
293 }
Result
Definition: types.hpp:185
std::string getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
Definition: common.hpp:164
Result setLogLevel(int level)
Definition: common.hpp:227
const char * mraa_get_version()
Result init()
Definition: common.hpp:56
std::string getVersion()
Definition: common.hpp:67
Platform getPlatformType()
Definition: common.hpp:94
const char * mraa_get_platform_name()
mraa_platform_t mraa_get_platform_type()
void printError(Result result)
Definition: common.hpp:105
int getI2cBusCount()
Definition: common.hpp:188
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:251
int mraa_get_i2c_bus_count()
int getDefaultI2cBus(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
Definition: common.hpp:289
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:176
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:238
int mraa_get_sub_platform_id(int pin_or_bus_index)
unsigned int mraa_adc_raw_bits()
int setPriority(const unsigned int priority)
Definition: common.hpp:83
mraa_result_t
Definition: types.h:193
mraa_pinmodes_t
Definition: types.h:214
int getI2cBusId(unsigned int i2c_bus)
Definition: common.hpp:200
std::string getPinName(int pin)
Definition: common.hpp:213
const char * mraa_get_platform_version(int platform_offset)
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:264
mraa_result_t mraa_set_log_level(int level)
int mraa_get_default_i2c_bus(uint8_t platform_offset)
int getSubPlatformIndex(int pin_or_bus_id)
Definition: common.hpp:277
unsigned int mraa_get_pin_count()