led: Add support for initializing onboard LEDs based on board definition
1. Add support for initializing onboard LEDs based on board definition. Maximum LED count has been set to 12. 2. Introduce mraa_led_init_raw API for initializing LEDs based on function name. This API can be used by platforms which doesn't have mapping in board definition. Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
This commit is contained in:
committed by
Manivannan Sadhasivam
parent
6c0ec10ba1
commit
6fcd882d58
@@ -46,16 +46,24 @@ extern "C" {
|
||||
*/
|
||||
typedef struct _led* mraa_led_context;
|
||||
|
||||
/**
|
||||
* Initialise led_context, based on led index.
|
||||
*
|
||||
* @param led ID of the LED
|
||||
* @returns LED context or NULL
|
||||
*/
|
||||
mraa_led_context mraa_led_init(int led);
|
||||
|
||||
/**
|
||||
* Initialise led_context, based on led function name.
|
||||
* The structure of LED entry in sysfs is "devicename:colour:function"
|
||||
* This api expects only one unique LED identifier which would be
|
||||
* "function" name most often. For instance, `mraa_led_init("user4");`
|
||||
* "function" name most often. For instance, `mraa_led_init_raw("user4");`
|
||||
*
|
||||
* @param led Name of the LED
|
||||
* @param led_dev Name of the LED device
|
||||
* @returns LED context or NULL
|
||||
*/
|
||||
mraa_led_context mraa_led_init(const char* led);
|
||||
mraa_led_context mraa_led_init_raw(const char* led_dev);
|
||||
|
||||
/**
|
||||
* Set LED brightness
|
||||
|
||||
@@ -44,9 +44,9 @@ class Led
|
||||
/**
|
||||
* Instantiates an LED object
|
||||
*
|
||||
* @param led LED fuction name to use
|
||||
* @param led LED index to use
|
||||
*/
|
||||
Led(const char* led)
|
||||
Led(int led)
|
||||
{
|
||||
m_led = mraa_led_init(led);
|
||||
|
||||
@@ -55,6 +55,20 @@ class Led
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates an LED object
|
||||
*
|
||||
* @param led_dev LED function name to use
|
||||
*/
|
||||
Led(std::string led_dev)
|
||||
{
|
||||
m_led = mraa_led_init_raw(led_dev.c_str());
|
||||
|
||||
if (m_led == NULL) {
|
||||
throw std::invalid_argument("Invalid LED name specified");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LED Constructor, takes a pointer to a LED context and initialises
|
||||
* the LED class
|
||||
|
||||
Reference in New Issue
Block a user