BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-07-2008, 07:12 AM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down SOLVED: Problem Blinking LED with STATE_PATTERN

Please Login to Remove!

mostly just messing around trying to familiarize myself with the apis for the blackberry before I get around to semi serious apps. I've been trying to get the LED to go through multiple colours using LED.setState(LED.STATE_PATTERN); and while it does make the LED go through the proper colours it also throws an IllegalArgumentException and I can't for the life of me figure out why... which I probably wouldn'tmindso much but it leave the LED blinking and I can't turn it off without a seperate program or resetting.

Heres the code in full (it's just tacked onto a helloworld so I have something to look at...

Code:
package com.sample;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.LED;

public class HelloWorld extends UiApplication
{
        public static void main(String[] args)
        {
                HelloWorld theApp = new HelloWorld();
                theApp.enterEventDispatcher();
        }

        public HelloWorld()
        {
                pushScreen(new HelloWorldScreen());
        }
}

final class HelloWorldScreen extends MainScreen
{
        public HelloWorldScreen()
        {

                super();

                LabelField title = new LabelField("HelloWorld Sample",
                       LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
                setTitle(title);

               add(new RichTextField("Hello World!"));
               int[] pattern = { 0x007f0000, 150, 50, 0x00007f00, 150, 50 , 0x0000007f, 150, 50 };
               LED.isPolychromatic();
           //    LED.setColorConfiguration(1000, 1000, 0x000000ff);
           //    LED.setConfiguration(1000,1000,LED.BRIGHTNESS_100) ;
               LED.setColorPattern(pattern,true);
               LED.setState(LED.STATE_PATTERN); 
}

        public boolean onClose()
        {
            LED.setState(LED.STATE_OFF); 
            Dialog.alert("Goodbye!");
            System.exit(0);
            return true;
        }
}
the commented out sections are left overs from me just blinking it in a normal fashion, and with the rest of the code left the same (except of course STATE_PATTERN being changed to STATE_BLINK, and removing the pattern specific stuff) it works fine... I'll be honest I'm having a heck of a time making sense of the debugger for the BBJDE, I'm assuming the invalidArgument is referring to the part of the code with the patterns as that's the only thing to change from the working version, but unless I'm missing something obvious my pattern is right, and I don't know what else could be wrong. On furhter inspection I think perhaps it's throwing the exception on LED.setState(LED.STATE_PATTERN); don't understand why though. BTW running BBJDE and BB OS 4.5

Last edited by koosemose : 11-11-2008 at 05:59 AM.
Offline  
Old 11-07-2008, 07:58 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The call to isPolychromatic doesn't do anything. That returns true or false if the LED is RGB, but you aren't doing anything with the return value.

I'm totally shooting from the hip here, but try setState(LED.LED_TYPE_STATUS, LED.STATE_PATTERN);

STATE_PATTERN is JDE 4.2.0, and so is the version of setState that takes two parameters. So maybe it will work with the newer function. I notice the documents do not list STATE_PATTERN as a valid state value for either function though.
Offline  
Old 11-07-2008, 08:03 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, since the code is working, it may not be necessary to explicitly set the LED state at all. The documentation isn't exactly comprehensive.
Offline  
Old 11-09-2008, 11:31 PM   #4 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

bah, posted a reply to this... or typed it anyways, but apparently I ate it without posting it...

Anyways... thanks for the help I had become convinced that STATE_PATTERN was an appropriate parameter for setState, probably due to it looking rather like the other STATE_s removd the setStates and it worked just fine. and in regards to LED.isPolychromatic(); I realize it does nothing here, it's just a left over for some if then that I stripped out to reduce to minimal functional (well non-functioning in the same way the main was anyway) program. But it's all working now, and I'm just about done with my first semi-useful Blackberry Program (no name yet, basically just type text and it will flash the LED in morse code) silly but amusing.
Offline  
Old 11-10-2008, 07:11 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

As an amateur radio operator, that's just the kind of silliness I like.
Offline  
Old 11-11-2008, 05:55 AM   #6 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

heh it all started because I ran accross a program that used the backlight for morse code and I thought it was interesting but I was unable to download it so thought to roll my own then thought of using the LED. Unfortunately, while I technically have the program functional, there is either a limitation on the size of patterns (array length = 96 / 32 pattern tuplettes) which limits the size of messages, so I can send an SOS but not a Hello. Currently trying to find out if this is in fact a limitation on the size of patterns or a strange problem in my coding, because it reliably doesn't work on anything requiring a pattern bigger than 32 tuplettes, but works just fine up to 32, if so I'll have to find out an alternate solution, as is I'm working on eliminating unnesseccarry patterns (such as one cause by how I was originally generating the patterns having several successive "quiet" patterns instead of merging them into on long "quiet).
Offline  
Old 11-11-2008, 06:55 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

If it provided a callback notification when the pattern was done playing then you could pass in the next chunk of data. That's one thing I keep noticing with the Blackberry API - many portions of it were designed with only a specific use in mind (which is great if you are using hardware / software for the intended use), which limits what can be done with the hardware as a more generic computing device.
A couple that come right to mind is the inability, via API or otherwise, to turn on the bright camera "flash" LED for use as a flashlight without actually initializing the camera and capturing video, and the inability to access the display buffer in its native 16-bit format for maximum performance (for gaming and other video intensive applications).

You can always process the LED in real time, sort of how you "bitbang" a serial port via software in the olden days (or still do with microcontrollers). Just have a switch statement of sleeps of various durations (for dits, dahs, pauses between them and pauses between letters), enclosed in two loops - one that iterates the individual parts of a letter and turns the LED on or off, and an outer loop that iterates characters in the string.

Last edited by Dan East : 11-11-2008 at 07:03 AM.
Offline  
Old 11-11-2008, 07:09 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, the advantage with doing it in real-time is you can then generate audio in time to your flashes. You can also display the letters on-screen for training and practice. You could also flash the entire LCD display panel's backlight (turn the display white and turn on the backlight, or set it to black and turn off the backlight) for maximum visibility.
Offline  
Old 11-11-2008, 07:44 AM   #9 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm good points. thought the audio would probably be the last thing I add on, as personally I make little use of any sound, mainly due to the commoness of people being asleep when I'm active and not at work. Guess my next programming session will be reworking my flashing logic...
Offline  
Old 11-12-2008, 06:47 AM   #10 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm if this works, I'll be pleasantly surprised as it's taken very little alteration just turn on the LED and feed the pattern information into a surprisingly short uhhh method I think is the right term, that basically uses the color to set a color with SetColorConfiguration, and the sleeps for the on time, and doesn't do anything with the transition time, assuming setting the color to 0x00000000 with SetColorConfiguration with the LED on will actually turn it off like it does with SetColorPattern,, I'll just have to wait until tomorow to get access to the windows computer so I can compile and test.

I know this adds pretty much nothing to the running conversation but I tend to think out what I'm doing more clearly if I post about it in a semipublic forum, in a way that in code comments never seem to do... I'm the type of guy that even though I know better ends up with things like:
Print "Hello" //Prints Hello to the screen
Offline  
Old 11-13-2008, 07:57 AM   #11 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8330
OS: 4.5.0.77
PIN: N/A
Carrier: Sprint
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

yay it's functional now, now just to pretty up the interface, add a bit of customization (led color and wpm) and I suppose the options for sound and backlight flashing, shouln't be to difficult.

The hard part will be cleaning up my code and making it semi-presentable, I'm horrible with modularization, and have no grasp of what should be shoved in a class together and what should be seperated...

hmmm perhaps I should stop rambling on to myself in my thread that's already been resolved.... eh I hate starting new threads... especially if I'm just rambling, might as well do it where few will notice me. I suppose tomorow I'll post my code... hmm should anyone still be wondering through this thread, is it considered acceptable to post (what one considers) functional code for review, (assuming it's not excessively long)? perhaps that should also be it's own thread. bah, I'll figure it out tomorow.

:/ I REALLY need to stop posting before going to sleep :D
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.