There several ways for controlling buttons in OpenWrt.
<a href="http://bi.du.haochici.xyz/browse.php?u=9edoPwh0ar%2FhtXlJ%2Fi1D0z42oVUjVm61%2FTsWdC26vfy8cmeN3%2B62Dl4TDp6Mew%3D%3D&b=13">buttons using procd</a>
Kernel configuration
If a target platform is known to support buttons, appropriate kernel modules are selected by default.
If a platform is not known to support buttons, you are required to install various kernel modules yourself such as <code>diag</code>,<code>input-gpio-buttons</code>, <code>gpio-button-hotplug</code>, and others.
However, installing various modules will not necessarily yield a successful result.
native button handling in procd is handled by scripts in <code>'/etc/rc.button/*</code>'
These scripts receive the same environment as older style hotplug buttons received. However, the script files have to be named after the button. I am unaware of a way of getting the button name. (Other than using hotplug compatible scripts with procd ;)
Button Action
Script Environment
Script return value
Press
ACTION="pressed"
Seconds before "timeout"
Held "timeout" seconds
ACTION="timeout" SEEN="<timeout secs>"
n/a
Release1
ACTION="released" SEEN="<seconds held>"
1 - "released" action is sent on release even if "timeout" has been sent.
The cat /sys/kernel/debug/gpio command queries the current pin state. Lo, low level, hi is high level
The first step is to find out the internal name of the button you want to use: some images use generic names such as <code>BTN_1</code>, <code>BTN_2</code>, others have more specific ones like <code>reset</code>,<code>wps</code>, etc. Run the following:
Create the file <code>/etc/hotplug.d/button/buttons</code> with your favorite text editor, paste the following:
Save and exit. Now press the button you want to use, then run <code>logread</code>.
<code>BTN_1</code> is the name of the button you want to use. If you want or need to use another button, replace every instance of <code>BTN_1</code> in the rest of this document with the correct text. From now on, there are several possible approaches: the first uses the <code>00-button</code> script from the <code>atheros</code> target, the other a simpler shell script.
notice
If you want to run programs from hotplug's scripts you need to be sure <code>PATH</code> and the like are initialized properly, scripts invoked by hotplug only have a default env. Especially if you install stuff into nonstandard locations like /opt/usr/bin. It's possible by adding <code>. /etc/profile</code> after <code>#!/bin/sh</code>
If you've installed the full version of <code>wget</code>, run the following:
If you only have <code>wget-nossl</code> and don't want to or can't upgrade, create <code>/etc/hotplug.d/button/00-button</code> with your favorite editor, then paste the following:
Please note that after r34793 /etc/functions.sh → /lib/functions.sh so if you are using an old version change it!
Save and exit, then issue these commands:
<code>button</code> is the name as the button, <code>action</code> is the event (two values: <code>pressed</code> and <code>released</code>), handler contains the command line to be run when the event is detected (can be a script as well).
You may need to reboot the router the make the change effective (mine would work with the simple shell script just fine but wouldn't budge when using the 00-button script — Frex 2011/03/25 22:29). If this works, you can change the handler to something more useful, and add more button handlers.
Example 1: Toggle Wi-Fi radio with a button press
Example 2: Assign two different functions to the same button: short press VS long press. This relies on tracking the released event rather than the pressed event.
Example 3: Unmount USB storage using a long-ish press
Example 4: Restore defaults
Example 5: Toggle Wi-Fi using a script
You'll have to create the file <code>/usr/bin/wifionoff</code> and paste this:
Another option for wifionoff is this script (doesn't store the state in uci, so it remains what is set in the configuration) You can also call this script eg. from cron, to switch off your wifi at night.
Example 6: Set transmission-daemon alt-speed, enable or disable.Short press will activate alt-speed or longer press will deactivate alt-speed and also turns on qss led about speed status on tl-wr1043nd
Edit your alt-speed limits from transmission-daemon , settings.json file.To execute script, you need to install transmission-remote package from opkg.
If you decide to use the <code>wifitoggle</code> package, you will need to change a few things on the default configuration. The following will work and make the QSS led blink "slowly" when wifi is on:
To manage the router buttons and also other HID buttons (i.e pad buttons or keys of an usb device) we can use an application like triggerhappy.
Install the triggerhappy package and the kmod-hid kernel module
list your available buttons: execute
press your buttons
<code>EV_KEY KEY_WPS_BUTTON 1 /dev/input/event0 # KEY_WPS_BUTTON 1 command EV_KEY KEY_WPS_BUTTON 0 /dev/input/event0 # KEY_WPS_BUTTON 0 command EV_KEY KEY_VOLUMEDOWN 1 /dev/input/event1 # KEY_VOLUMEDOWN 1 command EV_KEY KEY_VOLUMEDOWN 0 /dev/input/event1 # KEY_VOLUMEDOWN 0 command</code>
Now associate your buttons to commands or scripts
path /etc/triggerhappy/triggers.d/example.conf
run triggerhappy
enable triggerhappy permanently
kernel modules: kmod-hid and kmod-hid-generic both should be installed
The kmod-hid-generic kernel module must be installed for buttons on USB devices such as USB sound cards to work in OpenWrt trunk. Only then the /dev/input/event0 node for the buttons was created on the DIR-505 router with attached USB sound card.
Another simpler application to manage buttons.
original text:http://bi.du.haochici.xyz/browse.php?u=9edoPwh0ar%2FhtXlJ%2Fi1D0z42oVUjVm61%2FTsWdC26vfy8cmeN3%2B62Dl4TDp6Mew%3D%3D&b=13
本文转自 Linux_woniu 51CTO博客,原文链接:http://blog.51cto.com/linuxcgi/2047945