TastyCode devblog
21lis/092

Using LED on N810 Tablets in Python

I think that in Poland we don't have much NIT developers, and... Here we go - first post in English ;)
I was looking for an API in Python for manipulating color (and brightness ofc ;) ) of builtin LED on my N810. I drilled through some sites, and i found that FlipClock (which is written in Python) uses LED in some cases. I downloaded it, and found that you can set color of LED with these two simple functions.
Manipulating LEDs rely on writing to virtual files in /sys/ directory.

import time

# This function changes color of LED
def setLED(r,g,b):
 val = "%X:%X:%X" % (r, g, b)
 f = open('/sys/devices/platform/i2c_omap.2/i2c-0/0-0032/color', 'w')
 f.write(val)
 f.close()
# This functions sets LED mode ("run" - default mode. "direct" - in this mode you can change color of LED)
def setLEDMode(mode):
 f = open('/sys/devices/platform/i2c_omap.2/i2c-0/0-0032/', 'w')
 f.write(mode)
 f.close()

# using:
# 1. First we need to set mode to "direct"
setLEDMode('direct')
# 2. Now set color of LED
setLED(255, 255, 255) # no, it won't be really white, blue led is too strong, so it will be like lightblue =)

# Let it sleep for a while
time.sleep(5)

# 3. Set everything to 0, so next time we won't see ugly "blink" of last color.
setLED(0, 0, 0)
# 4. Return to "default mode" (run)
setLEDMode('run')

Let's do some fireworks on your N810! :D
I'm really sure, that it should work also on N800 and family (770 have led? ;) )

PS. I have just found out strange thing - when I close keyboard while LED is on it automagicaly turns off :D I must try it ;)
PS2. And also when i lock keypad... It's not a big deal, when you are just blinking LED, but when you must turn it on for a long time, you can set color and sleep for 0.5sec in loop instead of setting color and waiting Xsec. :)

Edit!
Today I found out this post on some forum: http://forum.mobile-review.com/showpost.php?s=936a897dcf4ba22136a9fb1fc0904dd9&p=2120483&postcount=441
So on N900 (Maemo 5) LED is controlled in similar way, expect thing, that path pattern is like this:
/sys/class/led/[some unique/unknown ID]/brightness
I don't have N900, so i can't try it (and i don't know if my mother and GTranslate translated this post correctly ;) )
I think that it should work :)