mraa  1.5.1
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 
53 inline Result
55 {
56  return (Result) mraa_init();
57 }
58 
64 inline std::string
66 {
67  std::string ret = mraa_get_version();
68  return ret;
69 }
70 
80 inline int
81 setPriority(const int priority)
82 {
83  return mraa_set_priority(priority);
84 }
85 
91 inline Platform
93 {
95 }
96 
102 inline void
104 {
106 }
107 
115 inline bool
116 pinModeTest(int pin, Pinmodes mode)
117 {
118  return (bool) mraa_pin_mode_test(pin, (mraa_pinmodes_t) mode);
119 }
120 
126 inline unsigned int
128 {
129  return mraa_adc_raw_bits();
130 }
131 
137 inline unsigned int
139 {
140  return mraa_adc_supported_bits();
141 }
142 
148 inline std::string
150 {
151  std::string ret_val(mraa_get_platform_name());
152  return ret_val;
153 }
154 
161 inline std::string
162 getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
163 {
164  std::string ret_val(mraa_get_platform_version(platform_offset));
165  return ret_val;
166 }
167 
173 inline unsigned int
175 {
176  return mraa_get_pin_count();
177 }
178 
185 inline int
187 {
188  return mraa_get_i2c_bus_count();
189 }
190 
197 inline int
198 getI2cBusId(int i2c_bus)
199 {
200  return mraa_get_i2c_bus_id(i2c_bus);
201 }
202 
210 inline std::string
211 getPinName(int pin)
212 {
213  std::string ret_val(mraa_get_pin_name(pin));
214  return ret_val;
215 }
216 
224 inline Result
225 setLogLevel(int level)
226 {
227  return (Result) mraa_set_log_level(level);
228 }
229 
235 inline bool
237 {
238  return static_cast<bool>(mraa_has_sub_platform());
239 }
240 
248 inline bool
249 isSubPlatformId(int pin_or_bus_id)
250 {
251  return static_cast<bool>(mraa_is_sub_platform_id(pin_or_bus_id));
252 }
253 
261 inline int
262 getSubPlatformId(int pin_or_bus_index)
263 {
264  return mraa_get_sub_platform_id(pin_or_bus_index);
265 }
266 
274 inline int
275 getSubPlatformIndex(int pin_or_bus_id)
276 {
277  return mraa_get_sub_platform_index(pin_or_bus_id);
278 }
279 
286 inline int
287 getDefaultI2cBus(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
288 {
289  return mraa_get_default_i2c_bus(platform_offset);
290 }
291 
300 inline Result
301 addSubplatform(Platform subplatformtype, std::string uart_dev)
302 {
303  return (Result) mraa_add_subplatform((mraa_platform_t) subplatformtype, uart_dev.c_str());
304 }
305 
306 inline Result
307 removeSubplatform(Platform subplatformtype)
308 {
309  return (Result) mraa_remove_subplatform((mraa_platform_t) subplatformtype);
310 }
311 
323 template <class T>
324 inline T*
325 initIo(std::string desc)
326 {
327  return new T(mraa_init_io(desc.c_str()));
328 }
329 
338 inline Result
339 initJsonPlatform(std::string path)
340 {
341  return (Result) mraa_init_json_platform(path.c_str());
342 }
343 
344 }
Result
Definition: types.hpp:197
std::string getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
Definition: common.hpp:162
Result setLogLevel(int level)
Definition: common.hpp:225
Result addSubplatform(Platform subplatformtype, std::string uart_dev)
Definition: common.hpp:301
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype)
const char * mraa_get_version()
Result initJsonPlatform(std::string path)
Definition: common.hpp:339
Result init()
Definition: common.hpp:54
std::string getVersion()
Definition: common.hpp:65
Platform getPlatformType()
Definition: common.hpp:92
const char * mraa_get_platform_name()
mraa_platform_t
Definition: types.h:39
mraa_platform_t mraa_get_platform_type()
void printError(Result result)
Definition: common.hpp:103
int getI2cBusCount()
Definition: common.hpp:186
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()
int getI2cBusId(int i2c_bus)
Definition: common.hpp:198
bool isSubPlatformId(int pin_or_bus_id)
Definition: common.hpp:249
int mraa_get_i2c_bus_count()
int getDefaultI2cBus(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
Definition: common.hpp:287
int mraa_get_i2c_bus_id(int i2c_bus)
mraa_boolean_t mraa_is_sub_platform_id(int pin_or_bus_id)
T * initIo(std::string desc)
Definition: common.hpp:325
unsigned int adcSupportedBits()
Definition: common.hpp:138
int mraa_set_priority(const int priority)
char * mraa_get_pin_name(int pin)
unsigned int getPinCount()
Definition: common.hpp:174
Platform
Definition: types.hpp:40
mraa_result_t mraa_init_json_platform(const char *path)
mraa_result_t mraa_init() __attribute__((constructor))
std::string getPlatformName()
Definition: common.hpp:149
bool pinModeTest(int pin, Pinmodes mode)
Definition: common.hpp:116
bool hasSubPlatform()
Definition: common.hpp:236
int mraa_get_sub_platform_id(int pin_or_bus_index)
unsigned int mraa_adc_raw_bits()
mraa_result_t
Definition: types.h:204
void * mraa_init_io(const char *desc)
int setPriority(const int priority)
Definition: common.hpp:81
mraa_pinmodes_t
Definition: types.h:227
std::string getPinName(int pin)
Definition: common.hpp:211
const char * mraa_get_platform_version(int platform_offset)
mraa_boolean_t mraa_has_sub_platform()
mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char *uart_dev)
unsigned int adcRawBits()
Definition: common.hpp:127
Pinmodes
Definition: types.hpp:220
void mraa_result_print(mraa_result_t result)
int getSubPlatformId(int pin_or_bus_index)
Definition: common.hpp:262
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:275
unsigned int mraa_get_pin_count()