Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:hardware:hardware.button [2019/07/16 13:03] – content updated and optimized vgaetera | docs:guide-user:hardware:hardware.button [2022/04/27 15:48] – [Attach functions to a push button] some1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| There several ways for controlling buttons in OpenWrt. | There several ways for controlling buttons in OpenWrt. | ||
| * [[# | * [[# | ||
| - | * [[# | + | * [[# |
| * [[# | * [[# | ||
| Line 8: | Line 8: | ||
| ===== procd buttons ===== | ===== procd buttons ===== | ||
| - | native | + | Native |
| + | |||
| + | These scripts receive the **same** environment as older style [[docs: | ||
| + | |||
| + | To get the button name you can try: | ||
| + | * ''cat / | ||
| + | * or use hotplug compatible scripts with procd | ||
| - | These scripts receive the **same** environment as older style hotplug buttons received. | ||
| ^ Button Action ^ Script Environment ^ Script return value ^ | ^ Button Action ^ Script Environment ^ Script return value ^ | ||
| | Press | ACTION=" | | Press | ACTION=" | ||
| | Held " | | Held " | ||
| - | | Release< | + | | Release | ACTION=" |
| + | |||
| + | :!: " | ||
| + | |||
| + | <WRAP round box 60%> | ||
| + | Please consider using these kernel codes when adding support for new devices, they' | ||
| + | ^ Kernel code ^ event ^ | ||
| + | | BTN_0 | BTN_0 | | ||
| + | | BTN_1 | BTN_1 | | ||
| + | | BTN_2 | BTN_2 | | ||
| + | | BTN_3 | BTN_3 | | ||
| + | | BTN_4 | BTN_4 | | ||
| + | | BTN_5 | BTN_5 | | ||
| + | | BTN_6 | BTN_6 | | ||
| + | | BTN_7 | BTN_7 | | ||
| + | | BTN_8 | BTN_8 | | ||
| + | | BTN_9 | BTN_9 | | ||
| + | | KEY_BRIGHTNESS_ZERO | brightness_zero | | ||
| + | | KEY_CONFIG | config | | ||
| + | | KEY_COPY | copy | | ||
| + | | KEY_EJECTCD | eject | | ||
| + | | KEY_HELP | help | | ||
| + | | KEY_LIGHTS_TOGGLE | lights_toggle | | ||
| + | | KEY_PHONE | phone | | ||
| + | | **KEY_POWER** | **power** | | ||
| + | | **KEY_POWER2** | **reboot** | | ||
| + | | **KEY_RESTART** | **reset** | | ||
| + | | **KEY_RFKILL** | **rfkill** | | ||
| + | | KEY_VIDEO | video | | ||
| + | | KEY_VOLUMEDOWN | volume_down | | ||
| + | | KEY_VOLUMEUP | volume_up | | ||
| + | | KEY_WIMAX | wwan | | ||
| + | | KEY_WLAN | wlan | | ||
| + | | KEY_WPS_BUTTON | wps | | ||
| + | |||
| + | </ | ||
| - | 1 - " | ||
| ===== Hotplug Buttons ===== | ===== Hotplug Buttons ===== | ||
| - | | {{: | + | | {{: |
| - | | FIXME | Please read the articles [[docs: | + | | FIXME | Please read the articles [[docs: |
| ==== Preliminary steps ==== | ==== Preliminary steps ==== | ||
| - | + | The first step is to find out the internal name of the button you want to use: some images use generic names such as '' | |
| - | The first step is to find out the internal name of the button you want to use: some images use generic names such as '' | + | Run the following: |
| <code bash> | <code bash> | ||
| mkdir -p / | mkdir -p / | ||
| - | </ | ||
| - | Create the file '' | + | cat << " |
| - | + | logger | |
| - | <code bash> | + | EOF |
| - | #!/bin/sh | + | |
| - | logger the button was $BUTTON and the action was $ACTION | + | |
| </ | </ | ||
| - | Save and exit. Now press the button you want to use, then run '' | + | Now press the button you want to use, then run '' |
| <code bash> | <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 |
| - | Jan 1 00:01:16 OpenWrt user.notice root: BTN_1 | + | Jan 1 00:01:16 OpenWrt user.notice root: BTN_1 |
| - | Jan 1 00:01:16 OpenWrt user.notice root: released | + | Jan 1 00:01:16 OpenWrt user.notice root: released |
| </ | </ | ||
| - | '' | + | '' |
| + | If you want or need to use another button, replace every instance of '' | ||
| + | From now on, there are several possible approaches: the first uses the '' | ||
| - | **notice** | + | If you want to run programs from hotplug' |
| - | + | Especially if you install stuff into nonstandard locations like / | |
| - | If you want to run programs from hotplug' | + | |
| <code bash> | <code bash> | ||
| - | #!/bin/sh | + | source |
| - | . / | + | |
| </ | </ | ||
| ==== Using Atheros' | ==== Using Atheros' | ||
| - | If you've installed the full version of '' | ||
| - | |||
| <code bash> | <code bash> | ||
| - | # wget -O / | + | cat << " |
| - | </ | + | source |
| - | If you only have '' | ||
| - | |||
| - | <code bash> | ||
| - | cat << " | ||
| - | #!/bin/sh | ||
| - | . / | ||
| do_button () { | do_button () { | ||
| - | | + | |
| - | local action | + | local action |
| - | local handler | + | local handler |
| - | local min | + | local min |
| - | local max | + | local max |
| - | | + | |
| - | config_get action $1 action | + | config_get action |
| - | config_get handler $1 handler | + | config_get handler |
| - | config_get min $1 min | + | config_get min "${1}" |
| - | config_get max $1 max | + | config_get max "${1}" |
| - | | + | |
| - | [ -z " | + | [ -z "${min}" -o -z "${max}" ] && eval ${handler} |
| - | [ -n " | + | [ -n "${min}" -a -n "${max}" ] && { |
| - | [ $min -le $SEEN -a $max -ge $SEEN ] && eval $handler | + | [ "${min}" |
| - | | + | |
| } | } | ||
| + | } | ||
| } | } | ||
| Line 94: | Line 122: | ||
| config_foreach do_button button | config_foreach do_button button | ||
| EOF | EOF | ||
| - | </ | ||
| - | Please note that after r34793 / | + | uci add system button |
| - | + | ||
| - | Save and exit, then issue these commands: | + | |
| - | + | ||
| - | <code bash> | + | |
| - | uci add system button | + | |
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| uci set system.@button[-1].action=" | uci set system.@button[-1].action=" | ||
| Line 110: | Line 132: | ||
| '' | '' | ||
| - | You may need to reboot the router the make the change effective (mine would work with the simple shell script just fine but wouldn' | + | You may need to reboot the router the make the change effective (mine would work with the simple shell script just fine but wouldn' |
| - | + | If this works, you can change the handler to something more useful, and add more button handlers. | |
| - | === Examples === | + | |
| + | ==== Examples ==== | ||
| **Example 1:** //Toggle Wi-Fi radio with a button press// | **Example 1:** //Toggle Wi-Fi radio with a button press// | ||
| <code bash> | <code bash> | ||
| - | uci add system button | + | uci add system button |
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| uci set system.@button[-1].action=" | uci set system.@button[-1].action=" | ||
| uci set system.@button[-1].handler=" | uci set system.@button[-1].handler=" | ||
| - | uci commit system | + | uci commit system |
| </ | </ | ||
| - | **Example 2:** //Assign two different functions to the same button: short press VS long press. This relies on tracking the // | + | **Example 2:** //Assign two different functions to the same button: short press VS long press. |
| + | This relies on tracking the // | ||
| <code bash> | <code bash> | ||
| Line 139: | Line 162: | ||
| uci set system.@button[-1].min=" | uci set system.@button[-1].min=" | ||
| uci set system.@button[-1].max=" | uci set system.@button[-1].max=" | ||
| - | uci commit system | + | uci commit system |
| </ | </ | ||
| Line 147: | Line 170: | ||
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| uci set system.@button[-1].action=" | uci set system.@button[-1].action=" | ||
| - | uci set system.@button[-1].handler=" | + | uci set system.@button[-1].handler=" |
| uci set system.@button[-1].min=" | uci set system.@button[-1].min=" | ||
| uci set system.@button[-1].max=" | uci set system.@button[-1].max=" | ||
| - | uci commit system | + | uci commit system |
| </ | </ | ||
| Line 161: | Line 184: | ||
| uci set system.@button[-1].min=" | uci set system.@button[-1].min=" | ||
| uci set system.@button[-1].max=" | uci set system.@button[-1].max=" | ||
| - | uci commit system | + | uci commit system |
| </ | </ | ||
| Line 176: | Line 199: | ||
| cat << " | cat << " | ||
| #!/bin/sh | #!/bin/sh | ||
| - | SW=" | + | [ " |
| - | [ " | + | |
| - | [ " | + | [ "${SW}" = " |
| - | wifi | + | |
| + | || uci set wireless.@wifi-device[0].disabled=" | ||
| + | wifi | ||
| + | } | ||
| EOF | EOF | ||
| + | chmod u+x / | ||
| </ | </ | ||
| Another option for wifionoff is this script (doesn' | Another option for wifionoff is this script (doesn' | ||
| - | You can also call this script | + | You can also call this script |
| <code bash> | <code bash> | ||
| Line 191: | Line 218: | ||
| STATEFILE="/ | STATEFILE="/ | ||
| - | if [ $# -eq 1 ]; then | + | if [ "${#}" |
| - | case $1 in | + | case "${1}" |
| - | " | + | " |
| - | STATE=off | + | " |
| - | | + | esac |
| - | " | + | |
| - | STATE=on | + | |
| - | | + | |
| - | esac | + | |
| else | else | ||
| - | | + | |
| - | STATE=on | + | GOAL="on" |
| - | else | + | else |
| - | | + | # if the statefile doesn' |
| - | | + | GOAL=" |
| + | fi | ||
| fi | fi | ||
| - | if [ -z ${STATE} ]; then | + | |
| - | STATE=on | + | if [ "${GOAL}" |
| - | fi | + | /sbin/wifi down |
| - | + | touch " | |
| - | if [ ${STATE} == "on" ]; then | + | |
| - | /sbin/wifi down | + | |
| - | | + | |
| else | else | ||
| - | | + | |
| - | | + | # file may not exist if we're given args |
| + | rm " | ||
| fi | fi | ||
| - | | ||
| - | echo " | ||
| EOF | EOF | ||
| + | chmod u+x / | ||
| + | </ | ||
| + | |||
| + | **Example 5-bis:** //Toggle only a Wireless Network using a script without disabling the entire Wi-Fi module// | ||
| + | |||
| + | This solution is heavily based on example 5. You need to figure out the name of your Wi-Fi Network configuration to make it work and replace the 3 occurrences of " | ||
| + | |||
| + | One way to find out your Wireless Network configuration name in LuCi is to navigate to the " | ||
| + | |||
| + | <code bash> | ||
| + | uci add system button | ||
| + | uci set system.@button[-1].button=" | ||
| + | uci set system.@button[-1].action=" | ||
| + | uci set system.@button[-1].handler="/ | ||
| + | uci set system.@button[-1].min=" | ||
| + | uci set system.@button[-1].max=" | ||
| + | uci commit system | ||
| + | |||
| + | cat << " | ||
| + | #!/bin/sh | ||
| + | { | ||
| + | SW=" | ||
| + | [ " | ||
| + | && uci del wireless.default_radio0.disabled \ | ||
| + | || uci set wireless.default_radio0.disabled=' | ||
| + | wifi | ||
| + | } | ||
| + | EOF | ||
| + | chmod u+x / | ||
| </ | </ | ||
| Line 227: | Line 276: | ||
| Edit your alt-speed limits from transmission-daemon , // | Edit your alt-speed limits from transmission-daemon , // | ||
| <code bash> | <code bash> | ||
| - | uci add system button | + | uci add system button |
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| uci set system.@button[-1].action=" | uci set system.@button[-1].action=" | ||
| uci set system.@button[-1].handler=" | uci set system.@button[-1].handler=" | ||
| - | uci add system button | + | uci add system button |
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| uci set system.@button[-1].action=" | uci set system.@button[-1].action=" | ||
| Line 249: | Line 298: | ||
| uci commit system | uci commit system | ||
| </ | </ | ||
| - | |||
| - | ==== Leftovers from a previous version ==== | ||
| - | |||
| - | FIXME | ||
| - | |||
| - | <code bash> | ||
| - | if [ " | ||
| - | if [ " | ||
| - | elif [ " | ||
| - | fi | ||
| - | fi | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | mkdir -p / | ||
| - | wget -O / | ||
| - | wget -O http:// | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | #!/bin/sh | ||
| - | [ " | ||
| - | SW=$(uci get wireless.@wifi-device[0].disabled) | ||
| - | [ $SW == ' | ||
| - | [ $SW == ' | ||
| - | wifi | ||
| - | } | ||
| - | </ | ||
| - | |||
| ==== WR1043ND ==== | ==== WR1043ND ==== | ||
| - | If you decide to use the '' | + | If you decide to use the '' |
| + | The following will work and make the QSS led blink " | ||
| <code bash> | <code bash> | ||
| Line 298: | Line 319: | ||
| ===== HID buttons ===== | ===== HID buttons ===== | ||
| ==== triggerhappy ==== | ==== triggerhappy ==== | ||
| - | 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. | + | 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. |
| - | === Installation === | ||
| <code bash> | <code bash> | ||
| # Install packages | # Install packages | ||
| Line 330: | Line 350: | ||
| </ | </ | ||
| - | ==== Notes ==== | + | Notes: |
| * triggerhappy repeats commands twice: see bug https:// | * triggerhappy repeats commands twice: see bug https:// | ||
| - | * kernel modules: | + | * kernel modules: **kmod-hid** and **kmod-hid-generic** both should be installed\\ The **kmod-hid-generic** and supposedly also **kmod-usb-hid** |
| < | < | ||
| Line 347: | Line 367: | ||
| ===== Sliding switches ===== | ===== Sliding switches ===== | ||
| - | Some routers, for example the [[toh: | + | Some routers, for example the [[toh: |
| + | These are usually implemented using two GPIOs, meaning OpenWrt interprets a switch like this as two separate push buttons. | ||
| - | The '' | + | The '' |
| + | Buttons scripts, in either procd or hotplug format, can be written for switch positions directly. | ||
| + | See the package' | ||