From fa40262d89c8bad93f838330287b8431bed0aa2d Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Tue, 13 Mar 2018 16:17:51 -0700 Subject: [PATCH] api: Fixes for missing mraa methods. This commit includes a set of small fixes flushed out from the google unit tests. * Fixed missing implementations of mraa_get_*_count methods. * Fix for NULL string * Fix for MOCK platform C++ define. * Switched (void) -> () function definitions for consistency. Signed-off-by: Noel Eck --- api/mraa/common.h | 10 +++++----- api/mraa/common.hpp | 5 ++++- api/mraa/types.hpp | 1 + src/mraa.c | 10 +++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/api/mraa/common.h b/api/mraa/common.h index a8a0da6..2e14543 100644 --- a/api/mraa/common.h +++ b/api/mraa/common.h @@ -223,35 +223,35 @@ unsigned int mraa_get_pin_count(); * * @return number of usable UARTs on the platform, returns -1 on failure. */ -int mraa_get_uart_count(void); +int mraa_get_uart_count(); /** * Get the number of usable SPI buses, board must be initialised. * * @return number of usable SPI buses on the platform, returns -1 on failure. */ -int mraa_get_spi_bus_count(void); +int mraa_get_spi_bus_count(); /** * Get the number of usable PWM pins, board must be initialised. * * @return number of PWMs on the current platform, -1 on failure. */ -int mraa_get_pwm_count(void); +int mraa_get_pwm_count(); /** * Get the number of usable GPIOs, board must be initialised. * * @return number of usable external GPIO pins on the board, -1 on failure. */ -int mraa_get_gpio_count(void); +int mraa_get_gpio_count(); /** * Get the number of usable analog pins, board must be initialised. * * @return number of usable ADC inputs on the platform and -1 on failure. */ -int mraa_get_aio_bus_count(void); +int mraa_get_aio_count(); /** * Get platform usable I2C bus count, board must be initialised. diff --git a/api/mraa/common.hpp b/api/mraa/common.hpp index 4e1bc88..7f7fece 100644 --- a/api/mraa/common.hpp +++ b/api/mraa/common.hpp @@ -163,7 +163,10 @@ getPlatformName() inline std::string getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET) { - std::string ret_val(mraa_get_platform_version(platform_offset)); + std::string ret_val; + const char* pv = mraa_get_platform_version(platform_offset); + if (pv != NULL) + ret_val = pv; return ret_val; } diff --git a/api/mraa/types.hpp b/api/mraa/types.hpp index 1b533cb..1b7c7b4 100644 --- a/api/mraa/types.hpp +++ b/api/mraa/types.hpp @@ -62,6 +62,7 @@ typedef enum { GENERIC_FIRMATA = 1280, /**< Firmata uart platform/bridge */ ANDROID_PERIPHERALMANAGER = 95, /**< Android Things peripheral manager platform */ + MOCK_PLATFORM = 96, /**< Mock platform, which requires no real hardware */ NULL_PLATFORM = 98, UNKNOWN_PLATFORM = 99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */ } Platform; diff --git a/src/mraa.c b/src/mraa.c index cbb7597..148db9d 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -775,7 +775,7 @@ mraa_get_platform_version(int platform_offset) } int -mraa_get_uart_count(void) +mraa_get_uart_count() { if (plat == NULL) { return -1; @@ -784,7 +784,7 @@ mraa_get_uart_count(void) } int -mraa_get_spi_count(void) +mraa_get_spi_bus_count() { if (plat == NULL) { return -1; @@ -793,7 +793,7 @@ mraa_get_spi_count(void) } int -mraa_get_pwm_count(void) +mraa_get_pwm_count() { if (plat == NULL) { return -1; @@ -802,7 +802,7 @@ mraa_get_pwm_count(void) } int -mraa_get_gpio_count(void) +mraa_get_gpio_count() { if (plat == NULL) { return -1; @@ -811,7 +811,7 @@ mraa_get_gpio_count(void) } int -mraa_get_aio_count(void) +mraa_get_aio_count() { if (plat == NULL) { return -1;