Differences

This shows you the differences between two versions of the page.

doc:howto:hardware.button [2012/11/02 17:26]
squonk Added missing dash bang to Shell script
doc:howto:hardware.button [2013/07/15 16:36] (current)
lorema
Line 1: Line 1:
-====== Attach functions to the hardware button ====== +====== Attach functions to a push button ======
-FIXME part of this article is not done.+
-  * Check the article [[doc/howto/wifitoggle]]. If you want, you can rewrite this. +| {{:meta:icons:tango:dialog-information.png?nolink}} | **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 ''diag'', ''input-gpio-buttons'', ''gpio-button-hotplug'', and others.\\ However, installing various modules will not necessarily yield a successful result. | 
-  * Some more inspiration: [[/toh/tp-link/tl-wr741nd#buttons]] TODO + 
-  * [[toh/linksys/nslu2/nslu2.hardware.button]] for the NSLU2+|  {{:meta:icons:tango:48px-outdated.svg.png?nolink}} | Please note the introduction of **''[[doc:techref:procd]]''** into OpenWrt; In [[https://dev.openwrt.org/changeset/37132|r37132]] the package ''hotplug2'' was removed from the default packages; this howto may need to be updated.\\ [[https://dev.openwrt.org/changeset/37336|r37336: procd: make old button hotplug rules work until all packages are migrated]] | 
 +| FIXME | Please read the articles [[doc/howto/wifitoggle]], [[/toh/tp-link/tl-wr741nd#buttons]] and [[toh/linksys/nslu2/nslu2.hardware.button]] and eventually merge them into this one article  |
-====== Configuring buttons ====== 
===== Preliminary steps ===== ===== Preliminary steps =====
The first step is to make Hotplug execute scripts in /etc/hotplug.d/button when a button is clicked. Modify /etc/hotplug2.rules --- remove '^' before 'button' as follow: The first step is to make Hotplug execute scripts in /etc/hotplug.d/button when a button is clicked. Modify /etc/hotplug2.rules --- remove '^' before 'button' as follow:
-<code>+<code bash>
$include /etc/hotplug2-common.rules $include /etc/hotplug2-common.rules
Line 26: Line 25:
The second step is to find out the internal name of the button you want to use: some images use generic names such as ''BTN_1'', ''BTN_2'', others have more specific ones like ''reset'', ''wps'', etc. Run the following: The second step is to find out the internal name of the button you want to use: some images use generic names such as ''BTN_1'', ''BTN_2'', others have more specific ones like ''reset'', ''wps'', etc. Run the following:
-<code>+<code bash>
# mkdir -p /etc/hotplug.d/button # mkdir -p /etc/hotplug.d/button
</code> </code>
Line 32: Line 31:
Create the file ''/etc/hotplug.d/button/buttons'' with your favorite text editor, paste the following: Create the file ''/etc/hotplug.d/button/buttons'' with your favorite text editor, paste the following:
-<code>+<code bash>
#!/bin/sh #!/bin/sh
logger $BUTTON logger $BUTTON
Line 40: Line 39:
Save and exit. Now press the button you want to use, then run ''logread''. Save and exit. Now press the button you want to use, then run ''logread''.
-<code>+<code bash>
Jan 1 00:01:15 OpenWrt user.notice root: BTN_1  Jan 1 00:01:15 OpenWrt user.notice root: BTN_1 
Jan 1 00:01:15 OpenWrt user.notice root: pressed  Jan 1 00:01:15 OpenWrt user.notice root: pressed 
Line 48: Line 47:
''BTN_1'' is the name of the button you want to use. If you want or need to use another button, replace every instance of ''BTN_1'' in the rest of this document with the correct text. From now on, there are several possible approaches: the first uses the ''00-button'' script from the ''atheros'' target, the other a simpler shell script. ''BTN_1'' is the name of the button you want to use. If you want or need to use another button, replace every instance of ''BTN_1'' in the rest of this document with the correct text. From now on, there are several possible approaches: the first uses the ''00-button'' script from the ''atheros'' target, the other a simpler shell script.
 +
 +**notice**
 +
 +If you want to run programs from hotplug's scripts you need to be sure ''PATH'' 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 ''. /etc/profile'' after ''#!/bin/sh''
 +
 +<code bash>
 +#!/bin/sh
 +. /etc/profile
 +</code>
===== Using Atheros' 00-button + UCI ===== ===== Using Atheros' 00-button + UCI =====
If you've installed the full version of ''wget'', run the following: If you've installed the full version of ''wget'', run the following:
-<code> +<code bash
-# wget -O /etc/hotplug.d/button/00-button http://dev.openwrt.org/export/21216/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button +# wget -O /etc/hotplug.d/button/00-button https://dev.openwrt.org/export/36332/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button
</code> </code>
If you only have ''wget-nossl'' and don't want to or can't upgrade, create ''/etc/hotplug.d/button/00-button'' with your favorite editor, then paste the following: If you only have ''wget-nossl'' and don't want to or can't upgrade, create ''/etc/hotplug.d/button/00-button'' with your favorite editor, then paste the following:
-<code>+<code bash>
#!/bin/sh #!/bin/sh
-. /etc/functions.sh+. /lib/functions.sh
do_button () { do_button () {
        local button         local button
Line 85: Line 93:
config_foreach do_button button config_foreach do_button button
</code> </code>
 +
 +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: Save and exit, then issue these commands:
-<code>+<code bash>
uci add system button    uci add system button   
uci set system.@button[-1].button=BTN_1 uci set system.@button[-1].button=BTN_1
Line 104: Line 114:
**Example 1:** //Toggle Wi-Fi radio with a button press// **Example 1:** //Toggle Wi-Fi radio with a button press//
-<code>+<code bash>
uci add system button    uci add system button   
uci set system.@button[-1].button=wps    uci set system.@button[-1].button=wps   
Line 114: Line 124:
**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 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.//
-<code>+<code bash>
uci add system button uci add system button
uci set system.@button[-1].button=BTN_1 uci set system.@button[-1].button=BTN_1
Line 131: Line 141:
**Example 3:** //Unmount USB storage using a long-ish press// **Example 3:** //Unmount USB storage using a long-ish press//
-<code>+<code bash>
uci add system button uci add system button
uci set system.@button[-1].button=BTN_1 uci set system.@button[-1].button=BTN_1
Line 142: Line 152:
**Example 4:** //Restore defaults// **Example 4:** //Restore defaults//
-<code>+<code bash>
config button config button
        option button  reset         option button  reset
Line 152: Line 162:
**Example 5:** //Toggle Wi-Fi using a script// **Example 5:** //Toggle Wi-Fi using a script//
-<code>+<code bash>
config button config button
        option button  wps         option button  wps
Line 162: Line 172:
You'll have to create the file ''/usr/bin/wifionoff'' and paste this: You'll have to create the file ''/usr/bin/wifionoff'' and paste this:
-<code>+<code bash>
#!/bin/sh #!/bin/sh
SW=$(uci -q get wireless.@wifi-device[0].disabled) SW=$(uci -q get wireless.@wifi-device[0].disabled)
Line 172: Line 182:
Another option for wifionoff is this script (doesn't store the state in uci, so it remains what is set in the configuration) 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. You can also call this script eg. from cron, to switch off your wifi at night.
-<code>+<code bash>
#!/bin/sh #!/bin/sh
STATEFILE="/tmp/wifionoff.state" STATEFILE="/tmp/wifionoff.state"
Line 210: Line 220:
Edit your alt-speed limits from transmission-daemon , //settings.json// file.To execute script, you need to install //transmission-remote// package from opkg. Edit your alt-speed limits from transmission-daemon , //settings.json// file.To execute script, you need to install //transmission-remote// package from opkg.
-<code>+<code bash>
uci add system button    uci add system button   
uci set system.@button[-1].button=BTN_1 uci set system.@button[-1].button=BTN_1
Line 238: Line 248:
FIXME FIXME
-<code>+<code bash>
mkdir -p /etc/hotplug.d/button mkdir -p /etc/hotplug.d/button
touch /etc/hotplug.d/button/00-button touch /etc/hotplug.d/button/00-button
</code> </code>
-<code>+<code bash>
if [ "$ACTION" = "pressed" ]; then if [ "$ACTION" = "pressed" ]; then
    if [ "$BUTTON" = "BTN_0" ]; then BTN_0     if [ "$BUTTON" = "BTN_0" ]; then BTN_0
Line 251: Line 261:
</code> </code>
-<code>+<code bash>
mkdir -p /etc/hotplug.d/button mkdir -p /etc/hotplug.d/button
wget -O /etc/hotplug.d/button/00-button http://dev.openwrt.org/export/21216/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button wget -O /etc/hotplug.d/button/00-button http://dev.openwrt.org/export/21216/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button
Line 257: Line 267:
</code> </code>
-<code>+<code bash>
#!/bin/sh #!/bin/sh
[ "$BUTTON" = "BTN_1" ] && [ "$ACTION" = "pressed" ] && { [ "$BUTTON" = "BTN_1" ] && [ "$ACTION" = "pressed" ] && {
Line 270: Line 280:
If you decide to use the ''wifitoggle'' 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: If you decide to use the ''wifitoggle'' 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:
-<code>+<code bash>
uci show wifitoggle uci show wifitoggle
uci set wifitoggle.@wifitoggle[0]=wifitoggle uci set wifitoggle.@wifitoggle[0]=wifitoggle
Line 289: Line 299:
First list your available buttons: First list your available buttons:
-<code>thd --dump /dev/input/event*</code>+<code bash>thd --dump /dev/input/event*</code>
press your buttons \\ press your buttons \\
''EV_KEY  KEY_WPS_BUTTON  1      /dev/input/event0 ''EV_KEY  KEY_WPS_BUTTON  1      /dev/input/event0
Line 302: Line 312:
Now associate your buttons to commands or scripts \\ Now associate your buttons to commands or scripts \\
//path /etc/triggerhappy/triggers.d/example.conf// \\ //path /etc/triggerhappy/triggers.d/example.conf// \\
-<code>KEY_WPS_BUTTON 1 /etc/mywifiscript.sh+<code bash>KEY_WPS_BUTTON 1 /etc/mywifiscript.sh
KEY_VOLUMEUP 1 amixer -q set Speaker 3%+ KEY_VOLUMEUP 1 amixer -q set Speaker 3%+
KEY_VOLUMEDOWN 1 amixer -q set Speaker 3%-</code> KEY_VOLUMEDOWN 1 amixer -q set Speaker 3%-</code>
and run triggerhappy \\ and run triggerhappy \\
-<code>/etc/init.d/triggerhappy start</code>+<code bash>/etc/init.d/triggerhappy start</code>
**cmdpad** is another simpler application to manage buttons. **cmdpad** is another simpler application to manage buttons.

Back to top

doc/howto/hardware.button.1351873594.txt.bz2 · Last modified: 2012/11/02 17:26 by squonk