keskiviikko 23. kesäkuuta 2010

LED patterns made easy (and detailed too)

Maybe the most popular "advanced" (need root access or download and use a non-trivial app, risk of bricking the device) configuration task for the N900 is modifying the status LED patterns.

N900 has an RGB LED component whose red, green and blue LEDs can be controlled separately. For programming, there are two LED engines that can be attached to one or more LEDs (one LED can't be attached to two engines however) and run their own programs to get more colorful effects.

HC programmers whose middle name is "D4nger" will enable root access, cd to /etc/mce and vi mce.ini, calculating the hex numbers in their heads. The rest might be more comfortable with downloading "LED Pattern Editor" from the Maemo Extras repository.

After installing, you should find "LED Patterns" in the Personalisation section of the Control Panel. After starting that, you'll see a list of the current patterns visually shown by the Pattern Editor.

Hit one of the existing patterns to edit it, you can start from the "Example" pattern that won't really affect anything.

When you open a pattern, you will see the pattern graphically displayed, as well as the program steps used for the pattern. Program steps can be edited or deleted by touching them, new entries can be added with the "New command" entry in the end of the list. The different commands that can be added are:

LED pattern commands



Set PWM
Set the LED brightness value to a level between 0 and 255; 0 would be black and 255 full brightness. The brightness will stay that way until another command changes it.

Ramp
A ramp gradually slides brightness up/down over time.
For a ramp you can define:
* Milliseconds per step
* If brightness is increased (+) or decreased (-) on each step
* Number of steps
The default is the shortest full ramp, 255 steps of 0.49 ms, direction alternating between + and -. The time taken by the ramp is step time * number of steps, this
default ramp would thus take 255*0.49 ms ~ 124.51 ms ~ 1/8 of a second.

Ramps can also be used as long waits, brightness is not adjusted if you create a "minus" ramp when brightness is already zero, or a "plus" ramp when brightness is 255. Slowly changing brightness can't be noticed, you could for example set PWM to 64 and then create a minus ramp of four 250ms steps for a one second wait without any perceivable change in the brightness.

Wait
Defines the time of how long to wait, 0.49-484.38 ms, until continuing processing commands. See below for possible values. The interface is shared with Ramp; leave step count to zero and adjust the duration lever.

Trigger
Create a trigger or from another engine or wait for a trigger for another engine. Only useful if both LED engines are used in the program, trigger can be used to synchronize them.

Go To Start
Jump to the beginning of the program and continue. Ends looping programs.

End
End the program here. Ends non-looping programs.

Normally you would start programs with a Set PWM command to set brightness to the desired levels and end using a "Go To Start" or "End", depending on if you want it looping or not. Between those create "Set PWM"'s, Ramps and Waits to create the pattern you wish.

Wait times


Wait times can be adjusted by 0.49 ms (or 1000 ms/2048 to be exact) steps when the wait time is between 0.49-15.62 ms, and by 15.63 ms (1000 ms/64) steps when the wait time is between 15.62-484.38 ms. Thus, the possible values in ms are:

0.494.398.312.2131.25156.25281.25406.25
0.984.888.7912.746.88171.88296.88421.88
1.465.379.2813.1862.5187.5312.5437.5
1.955.869.7713.6778.12203.12328.12453.12
2.446.3510.2514.1693.75218.75343.75468.75
2.936.8410.7414.65109.38234.38359.38484.38
3.427.3211.2315.14125250375
3.917.8111.7215.62140.62265.62390.62

Thus, to get a wait of exactly one second, you could use for example four 250ms waits, or two 375's and one 250.

As the steps are 1000/2028 ms, some "exact" values would be:

FractionWait timeFractionWait time
1/2048 s0.49 ms1/64 s15.62 ms
1/1024 s0.98 ms1/32 s31.25 ms
1/512 s1.96 ms1/16 s62.5 ms
1/256 s3.92 ms1/8 s125 ms
1/128 s7.84 ms1/4 s250 ms

These can be used with the ramps, for example a ramp of 128 7.84 ms steps would take exactly one second. The default ramp of 255 0.49 ms steps takes 1/8 of second (minus 0.49 ms as we can't choose "256"), so a 0-255-0 would take 1/4 of a second. To pad a 0-255-0 pulse to one second, you'd need to add another 3/4 seconds which could be achieved simply by adding a "minus" ramp with three 250ms steps (or two 375's).


Much more information at maemo.org.

Ei kommentteja:

Lähetä kommentti