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:47] – code 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 10: | Line 10: | ||
| Native button handling in procd is handled by scripts in ''/ | Native button handling in procd is handled by scripts in ''/ | ||
| - | These scripts receive the **same** environment as older style [[docs: | + | These scripts receive the **same** environment as older style [[docs: |
| - | However, the script files have to be named after the button. | + | |
| - | I am unaware of a way of getting | + | To get the button name you can try: |
| - | (Other than using hotplug compatible scripts with procd ;) | + | * '' |
| + | * or use hotplug compatible scripts with procd | ||
| ^ Button Action ^ Script Environment ^ Script return value ^ | ^ Button Action ^ Script Environment ^ Script return value ^ | ||
| Line 20: | Line 22: | ||
| | Release | ACTION=" | | Release | ACTION=" | ||
| - | Note that " | + | :!: " |
| + | |||
| + | <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 | | ||
| + | |||
| + | </ | ||
| ===== Hotplug Buttons ===== | ===== Hotplug Buttons ===== | ||
| Line 34: | Line 69: | ||
| cat << " | cat << " | ||
| - | logger "the button was $BUTTON and the action was $ACTION" | + | logger "the button was ${BUTTON} and the action was ${ACTION}" |
| EOF | EOF | ||
| </ | </ | ||
| Line 59: | Line 94: | ||
| ==== Using Atheros' | ==== Using Atheros' | ||
| - | If you've installed the full version of '' | ||
| - | |||
| - | <code bash> | ||
| - | wget -O / | ||
| - | </ | ||
| - | |||
| - | If you only have '' | ||
| - | |||
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| source / | source / | ||
| + | |||
| do_button () { | do_button () { | ||
| local button | local button | ||
| Line 77: | Line 105: | ||
| local max | local max | ||
| - | config_get button $1 button | + | config_get button |
| - | 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}" |
| - | [ " | + | [ "${ACTION}" = "${action}" -a "${BUTTON}" = "${button}" -a -n "${handler}" ] && { |
| - | [ -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 / | ||
| - | |||
| - | Save and exit, then issue these commands: | ||
| - | |||
| - | <code bash> | ||
| uci add system button | uci add system button | ||
| uci set system.@button[-1].button=" | uci set system.@button[-1].button=" | ||
| Line 121: | Line 143: | ||
| 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 |
| </ | </ | ||
| Line 140: | 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 148: | 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 162: | 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 177: | Line 199: | ||
| cat << " | cat << " | ||
| #!/bin/sh | #!/bin/sh | ||
| - | [ " | + | [ "${BUTTON}" = " |
| SW=" | SW=" | ||
| [ " | [ " | ||
| Line 185: | Line 207: | ||
| } | } | ||
| EOF | EOF | ||
| + | chmod u+x / | ||
| </ | </ | ||
| Line 195: | Line 218: | ||
| STATEFILE="/ | STATEFILE="/ | ||
| - | if [ " | + | if [ " |
| case " | case " | ||
| - | " | + | " |
| - | " | + | " |
| esac | esac | ||
| else | else | ||
| - | if [ ! -e " | + | if [ -e " |
| - | STATE=" | + | GOAL=" |
| else | else | ||
| - | | + | |
| + | GOAL="off" | ||
| fi | fi | ||
| fi | fi | ||
| - | if [ -z " | + | |
| - | STATE=" | + | if [ "${GOAL}" = "off" ]; then |
| - | fi | + | |
| - | + | ||
| - | if [ "${STATE}" = "on" ]; then | + | |
| /sbin/wifi down | /sbin/wifi down | ||
| - | | + | |
| else | else | ||
| /sbin/wifi up | /sbin/wifi up | ||
| - | | + | |
| + | rm "${STATEFILE}" | ||
| fi | fi | ||
| + | EOF | ||
| + | chmod u+x / | ||
| + | </ | ||
| - | echo "STATE=${STATE}" > "${STATEFILE}" | + | **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 "default_radio0" | ||
| + | |||
| + | 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=" | ||
| + | [ "${SW}" | ||
| + | && uci del wireless.default_radio0.disabled \ | ||
| + | || uci set wireless.default_radio0.disabled=' | ||
| + | wifi | ||
| + | } | ||
| EOF | EOF | ||
| + | chmod u+x / | ||
| </ | </ | ||
| Line 249: | Line 298: | ||
| uci commit system | uci commit system | ||
| </ | </ | ||
| - | |||
| ==== WR1043ND ==== | ==== WR1043ND ==== | ||
| If you decide to use the '' | If you decide to use the '' | ||
| Line 304: | Line 352: | ||
| Notes: | Notes: | ||
| * triggerhappy repeats commands twice: see bug https:// | * triggerhappy repeats commands twice: see bug https:// | ||
| - | * 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 / | + | * kernel modules: **kmod-hid** and **kmod-hid-generic** both should be installed\\ The **kmod-hid-generic** and supposedly also **kmod-usb-hid** |
| < | < | ||