Jump to content

Disable onboard leds from shell, any ideas?


v0id9

Recommended Posts

So I've been working on some things, and one of the things I want to implement in my script is the ability to turn all 3 leds to always_off, red, blue and green, and then remain off til a certain event happens at which point it will turn the led on to a certain color, as visual feedback, and then return the leds back to their original setting.

I figured out how to do all those things, except for 1 thing, turning the led settings to "always_off". 

I can manipulate the led colors and brightness via the brightness file in /sys/class/leds/<specific:led>, but if the ui for example is set to be "heartbeat", then I can't really control it via that file since there is a process elsewhere that will keep setting the file content to 0 and 255 and back continuously.

I've had a look in the "police" binary to see how that handles it, but that only seems to manipulate the brightness file directly and nothing else..

Anybody got any ideas on how I could do this?

Link to comment
Share on other sites

Edit: NVM, seems I found it, you can manipulate the led with the LED command, now I just need to figure out if it's possible to get the current state using that command, I can at least turn it off

Edit2: I seem to be able to use that to set the LED to whatever I want it to do, color and patternwise, but I still cannot figure out how I'm supposed to be able to retrieve what the current applied setting is for LEDs so that I can set them back to default afterwards

Link to comment
Share on other sites

The usecase is to provide an option for the led to be turned off so that it's less noticeable, unless there is a hit in the portal let's say, and then provide the user with feedback on wether that attempt was incorrect: slow red blinking, or wether it was correct: solid green, then revert back to what the state it was beforehand.

I am having a scroll through the LED binary right now in /sbin, but I don't see a way to get the current state from there, nor in any of the files in /sys/class/leds/red:system for example

Link to comment
Share on other sites

What LED binary? There's just a script file that controls the LED.

Just cat the files below and if it returns a 1, that LED state is activated

/sys/class/leds/red:system/brightness

/sys/class/leds/green:system/brightness

/sys/class/leds/blue:system/brightness

To turn off the LED, just execute LED OFF

 

Link to comment
Share on other sites

yea that LED script is the one I mean, that's /sbin/LED, I can control it with that, but I can't seem to get the current setting that's in the UI from it, for example it would be possible to grab it from /sys/class/leds/red:system/brightness if the setting in the UI was set to "Always On" or "Always Off", then it would be pretty straightforward, but if it was set to say "Heartbeat" or "Network", then it constantly manipulates /sys/class/leds/red:system/brightness to be 0 or 255, but it would constantly change, so then it gets pretty difficult for me to discern what the original setting was..

But the setting that's set in the UI gets saved somewhere because it retains the setting on a reboot, so it should be stored somewhere right?

 

Edit: Found it I think, it's in the trigger file

Edit2: Never mind, I need to learn to read.... I don't have to find the current state anywhere, I can simply do LED RESET for it to go back to the previous setting

Link to comment
Share on other sites

Hmm, maybe, I don't really know if it's necessary yet but I'll try to implement this first, but that does look like what I was initially looking for and looks worthwhile, thanks

Edit: That file actually looks a lot easier to grep instead of needing to grep 3 files

Link to comment
Share on other sites

Would that be simpler? That's like an openwrt thing right? This is already my first time messing around with php and I'm kinda learning as I go along, maybe I should just stick to what I'm familiar with, or would using uci be more effective?

Link to comment
Share on other sites

It depends on what you want to do, and how

I think using uci is far easier if the settings are a part of what's within the "uci scope"

To show not just the value, but the whole "uci path" as well, for a LED setting (using red LED as an example here):
uci show system.led_red.trigger

To show just the value itself:
uci get system.led_red.trigger

Set a value for a LED color:
uci set system.led_red.trigger='default-on'
uci commit system
/etc/init.d/system restart

Addressing green and blue is done in the same way:
uci set system.led_green.trigger='off'
uci set system.led_blue.trigger='off'

Possible trigger settings should be:
default-on
off
heartbeat
netdev
    with extended options for netdev specifically:
    option mode 'tx rx'
    option dev 'eth0'
    option dev 'wlan0'
    option dev 'wlan0-1'
    option dev 'wlan0-2'
    option dev 'wlan0-3'
    option dev 'wlan1mon'
    option dev 'wlan2'
    option dev 'wlan3mon'

Link to comment
Share on other sites

That's perfect, I can just do uci get system.led_red.trigger to get the value I need then, and uci set system.led_blue.trigger='<value>' to set it and do LED RESET to apply it, that's by far the simplest and cleanest method, thanks!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...