From 053d9aef7010724139f255ce31f9549a95aee4f3 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 2 Jul 2014 17:09:34 +0100 Subject: [PATCH] mraa: add common hpp * Wraps some of the C functions that libmraa has into the mraa namespace * Not included in swig bindings as of yet Signed-off-by: Thomas Ingleby --- api/mraa.hpp | 2 +- api/mraa/common.hpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 api/mraa/common.hpp diff --git a/api/mraa.hpp b/api/mraa.hpp index 4ad155c..6df8970 100644 --- a/api/mraa.hpp +++ b/api/mraa.hpp @@ -24,7 +24,7 @@ #pragma once -#include "mraa/common.h" +#include "mraa/common.hpp" #include "mraa/pwm.hpp" #include "mraa/aio.hpp" #include "mraa/gpio.hpp" diff --git a/api/mraa/common.hpp b/api/mraa/common.hpp new file mode 100644 index 0000000..893799b --- /dev/null +++ b/api/mraa/common.hpp @@ -0,0 +1,95 @@ +/* + * Author: Thomas Ingleby + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "common.h" +#include + +namespace mraa { + +/** + * @brief C++ API to common functions of MRAA + * + * This file defines the C++ interface for libmraa common functions + */ + +/** + * Get libmraa version. + * + * @return libmraa version (e.g. v0.4.0-20-gb408207) +*/ +std::string getVersion() +{ + std::string ret = mraa_get_version(); + return ret; +} + +/** + * This function attempts to set the mraa process to a given priority and the + * scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0. + * This function * will set to MAX if * priority is > MAX. Function will return + * -1 on failure. + * + * @param priority Value from typically 0 to 99 + * @return The priority value set +*/ +int setPriority(const unsigned int priority) +{ + return mraa_set_priority(priority); +} + +/** + * Get platform type, board must be initialised. + * + * @return mraa_platform_t Platform type enum + */ +mraa_platform_t getPlatformType() +{ + return mraa_get_platform_type(); +} + +/** + * Print a textual representation of the mraa_result_t + * + * @param result the result to print + */ +void printError(mraa_result_t result) +{ + mraa_result_print(result); +} + +/** + * Checks if a pin is able to use the passed in mode. + * + * @param pin Physical Pin to be checked. + * @param mode the mode to be tested. + * @return boolean if the mode is supported, 0=false. + */ +bool pinModeTest(int pin, mraa_pinmodes_t mode) +{ + return (bool) mraa_pin_mode_test(pin,mode); +} + +}