blink_onboard.c: explain use of calamari lure in example
[contrib/mraa.git] / api / mraa / common.hpp
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 <string>
29
30 /**
31  * @namespace mraa namespace
32  */
33 namespace mraa {
34
35 /**
36  * @file
37  * @brief API to common functions of MRAA
38  *
39  * This file defines the interface for libmraa common functions
40  */
41
42 /**
43  * Get libmraa version.
44  *
45  * @return libmraa version (e.g. v0.4.0-20-gb408207)
46  */
47 inline std::string getVersion()
48 {
49     std::string ret = mraa_get_version();
50     return ret;
51 }
52
53 /**
54  * This function attempts to set the mraa process to a given priority and the
55  * scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0.
56  * This function * will set to MAX if * priority is > MAX. Function will return
57  * -1 on failure.
58  *
59  * @param priority Value from typically 0 to 99
60  * @return The priority value set
61  */
62 inline int setPriority(const unsigned int priority)
63 {
64     return mraa_set_priority(priority);
65 }
66
67 /**
68  * Get platform type, board must be initialised.
69  *
70  * @return mraa_platform_t Platform type enum
71  */
72 inline mraa_platform_t getPlatformType()
73 {
74     return mraa_get_platform_type();
75 }
76
77 /**
78  * Print a textual representation of the mraa_result_t
79  *
80  * @param result the result to print
81  */
82 inline void printError(mraa_result_t result)
83 {
84     mraa_result_print(result);
85 }
86
87 /**
88  * Checks if a pin is able to use the passed in mode.
89  *
90  * @param pin Physical Pin to be checked.
91  * @param mode the mode to be tested.
92  * @return boolean if the mode is supported, 0=false.
93  */
94 inline bool pinModeTest(int pin, mraa_pinmodes_t mode)
95 {
96     return (bool) mraa_pin_mode_test(pin,mode);
97 }
98
99 /**
100  * Check the board's bit size when reading the value
101  *
102  * @return raw bits being read from kernel module. Zero if no ADC
103  */
104 inline unsigned int adcRawBits()
105 {
106     return mraa_adc_raw_bits();
107 }
108
109 /**
110  * Return value that the raw value should be shifted to. Zero if no ADC
111  *
112  * @return return actual bit size the adc value should be understood as.
113  */
114 inline unsigned int adcSupportedBits()
115 {
116     return mraa_adc_supported_bits();
117 }
118
119 /**
120  * Return Platform Name. "Unknown" if no platform inited.
121  *
122  * @return platform name
123  */
124 inline std::string getPlatformName()
125 {
126     std::string ret_val(mraa_get_platform_name());
127     return ret_val;
128 }
129
130 /**
131  * Sets the log level to use from 0-7 where 7 is very verbose. These are the
132  * syslog log levels, see syslog(3) for more information on the levels.
133  *
134  * @param level
135  * @return Result of operation
136  */
137 inline mraa_result_t setLogLevel(int level)
138 {
139     return mraa_set_log_level(level);
140 }
141
142 }