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:58] – formatting 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 108: | 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 172: | Line 207: | ||
| } | } | ||
| EOF | EOF | ||
| + | chmod u+x / | ||
| </ | </ | ||
| Line 182: | 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 236: | Line 298: | ||
| uci commit system | uci commit system | ||
| </ | </ | ||
| - | |||
| ==== WR1043ND ==== | ==== WR1043ND ==== | ||
| If you decide to use the '' | If you decide to use the '' | ||
| Line 291: | 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** |
| < | < | ||