Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
New Developer
KernelPanic
Posts: 13
Registered: ‎02-08-2011
My Carrier: O2
Accepted Solution

LED frequency?

I'm looking for a way to manipulate the blinking frequency of the device LED using Cascades.

So far I'm able to  access the LED and change its color. I can't find any mention about the blinking frequency in the API documentation. Does one have a pointer on how to achieve this?

 

Thanks 

Chris

Please use plain text.
Developer
rlvl
Posts: 38
Registered: ‎02-17-2013
My Carrier: Tata Docomo

Re: LED frequency?

Looking at this http://developer.blackberry.com/cascades/reference/bb__device__led.html I see no way to manipulate the frequency :No:

Please use plain text.
New Developer
KernelPanic
Posts: 13
Registered: ‎02-08-2011
My Carrier: O2

Re: LED frequency?

Thanks for your answer and your reference to the documentation. Too bad this isn't possible.

Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

Re: LED frequency?

there's currently an open feature request to be able to do more with the LED api

 

suggest your use case & hopefully they'll do it, there's several other reasons why the api should be updated

 

https://www.blackberry.com/jira/browse/BBTEN-847

Please use plain text.
New Developer
KernelPanic
Posts: 13
Registered: ‎02-08-2011
My Carrier: O2

Re: LED frequency?

[x] Done.

Thanks for the pointer.

Please use plain text.
Developer
Zmey
Posts: 902
Registered: ‎12-18-2012

Re: LED frequency?

Even with current API blink frequency can be controlled by using a QTimer and calling led() function as frequently as needed.

However, specifying 1 as blink count does not work correctly, so don't specify it and call stop() manually when done.

Of course this won't work if the app is paused. But it works when the app is running in background.
Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

Re: LED frequency?

for apps working with the led is it possible to tell if a incoming message has been read & stop it then

Please use plain text.
New Developer
KernelPanic
Posts: 13
Registered: ‎02-08-2011
My Carrier: O2

Re: LED frequency?

[ Edited ]

I don't get it to work. Is it possible to show me a code snippet illustrating this?

 

Edit: I mean the use of led() with a timer.

Please use plain text.
Developer
Zmey
Posts: 902
Registered: ‎12-18-2012

Re: LED frequency?

I've created a test project where you can move the slider to set the led frequency.

'Start' button starts the blinking.

 

Download:

Test.zip

 

 

Test.hpp:

namespace bb { namespace device { class Led; }}
class QTimer;

class Test : public QObject { Q_OBJECT public: Test(bb::cascades::Application *app); virtual ~Test() {} Q_INVOKABLE void blink(int frequency); Q_INVOKABLE void stopBlinking(); public slots: void onTimer(); protected: QTimer *timer_; bb::device::Led *led_; };

 Test.cpp:

#include <bb/device/Led>
#include <QTimer>

using namespace bb::cascades;
using namespace bb::device;

Test::Test(bb::cascades::Application *app)
: QObject(app)
{
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    qml->setContextProperty("app", this);
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    app->setScene(root);

    led_ = new Led(LedColor::Green, this);

    timer_ = new QTimer(this);
    QObject::connect(timer_, SIGNAL(timeout()),
    		this, SLOT(onTimer()));
}

void Test::blink(int frequency)
{
    timer_->start(frequency);
    led_->flash();
}

void Test::stopBlinking()
{
    led_->cancel();
    timer_->stop();
}

void Test::onTimer()
{
    led_->cancel();
    led_->flash();
}

Test.pro:

LIBS += -lbbdevice

 bar-descriptor.xml:

    <permission>access_led_control</permission>

 main.qml:

import bb.cascades 1.0

Page {
    property bool stopped: true
    Container {
        Slider {
            id: frequencySlider
            fromValue: 1000
            toValue: 30
            value: 500
            onValueChanged: {
                if (!stopped)
                    app.blink(frequencySlider.value)
            }
        }
        Label {
            text: 'Frequency: ' + Math.floor(frequencySlider.value) + ' msec'
        }
        Button {
            text: "Start"
            onClicked: {
                app.blink(frequencySlider.value)
                stopped = false
            }
        }
        Button {
            text: "Stop"
            onClicked: {
                app.stopBlinking()
                stopped = true
            }
        }
    }
}

 

 

 

Please use plain text.
New Developer
KernelPanic
Posts: 13
Registered: ‎02-08-2011
My Carrier: O2

Re: LED frequency?

Wow - thank you very much for your effort, I really appreciate that.
That is exactly what I was looking for but failed to discover it in the documentation.
Please use plain text.