api/mraa: add mraa_get_pin_name
authorMichael Ring <michael.ring@swisscom.com>
Wed, 18 Mar 2015 19:48:14 +0000 (20:48 +0100)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Thu, 19 Mar 2015 00:16:32 +0000 (00:16 +0000)
Add mraa_get_pin_name to get the real world name of the pin.

Signed-off-by: Michael Ring <mail@michael-ring.org>
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
api/mraa/common.h
api/mraa/common.hpp
src/mraa.c

index b4c0839..9c75536 100644 (file)
@@ -149,6 +149,15 @@ mraa_platform_t mraa_get_platform_type();
  */
 unsigned int mraa_get_pin_count();
 
+/**
+* Get name of pin, board must be initialised.
+*
+* @param pin number
+*
+* @return char* of pin name
+*/
+char* mraa_get_pin_name(int pin);
+
 #ifdef __cplusplus
 }
 #endif
index 7c9fe12..fb4bb40 100644 (file)
@@ -152,6 +152,19 @@ inline unsigned int getPinCount()
 }
 
 /**
+* Get name of pin, board must be initialised.
+*
+* @param pin number
+*
+* @return char* of pin name
+*/
+inline std::string getPinName(int pin)
+{
+    std::string ret_val(mraa_get_pin_name(pin));
+    return ret_val;
+}
+
+/**
  * Sets the log level to use from 0-7 where 7 is very verbose. These are the
  * syslog log levels, see syslog(3) for more information on the levels.
  *
index 5ecbae4..c2bd2a0 100644 (file)
@@ -328,6 +328,17 @@ mraa_file_exist(char *filename) {
 }
 
 char*
+mraa_get_pin_name(int pin)
+{
+    if (plat == NULL) {
+        return NULL;
+    }
+    if (pin > (plat->phy_pin_count -1) || pin < 0)
+        return NULL;
+    return (char*) plat->pins[pin].name;
+}
+
+char*
 mraa_file_unglob(char *filename) {
     glob_t results;
     char *res = NULL;