Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control Android LED from shell

Tags:

android

shell

led

I have seen several questions (and blog posts, elsewhere) with Java code for controlling the notification LED on an Android device. That's not what I'm looking for.

I'm wondering if there is any way to access the appropriate commands / controls / frameworks from the shell (Perl, ruby).

What I want, ultimately, is a very simple "heartbeat" pulse - when the device is on and the display is off, blink at me.

Alternatively, if anyone has written a really simple "toy" app that blinks the LED, I'd love to play with it.

like image 486
Vicki B Avatar asked Jun 19 '13 21:06

Vicki B


Video Answer


1 Answers

You can find all leds of your device under

/sys/class/leds/

In my case, I have the following leds

amber
button-backlight
flashlight
green
lcd-backlight

If I have a look inside "green", I see

> cd green
> ls
blink
brightness
currents
device
lut_coefficient
max_brightness
off_timer
power
pwm_coefficient
subsystem
trigger
uevent

These files are interfaces to the kernel module, which controls leds. In this case, I think they are char-devices. You can use the command "echo" and "cat" to communicate with the kernel module. Here an example..

echo 1 > brightness  # Turn on led
echo 0 > brightness  # Turn off led

For implementing a "heartbeat" pulse as you mentioned, I would have a look into "blink". If you not want to perform reverse engineering, this could be a good entry point to check what happens in the kernel leds-gpio.c

like image 145
Adrian Schneider Avatar answered Oct 03 '22 01:10

Adrian Schneider