Tools - "Built Ins"

LED Indicator

BlackBerry 10 Cascades LED Comic

How To Add LED Access & Controls To Your App

LED is a pretty easy to use once you have it set up, but there are quite a few permissions and definitions required to get it working, so here's a quick run down of those.

1. Add permission to the bar-descriptor.xml file:

<permission>access_led_control</permission>

2. Add the device library to the .pro file:

LIBS += -lbbdevice

3. Include the LED library to your main.cpp:

#include <bb/device/Led>

4. Register Led and LedColor in your main.cpp file:

qmlRegisterType("bb.device", 1, 0, "Led");
qmlRegisterUncreatableType("bb.device", 1, 0, "LedColor", "");

5. Import the device library into any .qml files that will use the LED:

import bb.device 1.0

 

Now we are ready to use Led {} in our qml file.  It is an attachedObject within the Page{} such as:

import bb.cascades 1.0
import bb.device 1.0


Page {
    Container {
 ...
    }
    attachedObjects: [
        Led {
            id: redLED
            color: LedColor.Red
        },
        Led {
            id: blueLED
            color: LedColor.Blue
        },
        Led {
            id: greenLED
            color: LedColor.Green
        },
        Led {
            id: whiteLED
            color: LedColor.White
        }
    ]
}

Here I have defined 4 different LED objects attached, each with their own id and color defined. (NOTE: It is possible to have just one Led {} defined and have the function that calls the LED decide the color but for the sake of this example I am showing that it is possible to have multiple objects defined.) Now let's create some kind of trigger to start/stop the LED.  So for instance Buttons:

Button {
                text: "Blink Red"
                onClicked: {
                    redLED.flash();
                }
            }
            Button {
                text: "Stop Red"
                onClicked: {
                    redLED.cancel();
                }
            }

The two buttons above control the redLED to begin flashing and stop flashing.  The same could be done for the other colors.  The flash() will blink indefinitely until a cancel() function stops it. Alternatively you can control the number of flashing by doing the following:

Button {
            text: "Blink White 3x"
            onClicked: {
                whiteLED.flash(3);
            }
            horizontalAlignment: HorizontalAlignment.Center
        }

This will result in the whiteLED blinking 3 times.

That about concludes LED, one thing I haven't seen is control of time between flashes or duration of flash.  Possibly something that will be added in the future? Or if you know, feel free to share in the comments.

 

-Brian

P.S. Here is the full list of colors available:
Red, Green, Blue, Yellow, Cyan, Magenta, White