# based on # https://dev.openwrt.org/browser/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button # https://forum.openwrt.org/viewtopic.php?pid=172110#p172110 . /lib/functions.sh do_button () { local button local action local handler local min local max config_get button $1 button config_get action $1 action config_get handler $1 handler config_get min $1 min config_get max $1 max if [ "$button" = "left" -o "$button" = "middle" -o "$button" = "right" ] ; then # fast sliding from left to right or from right to left if [ "$BUTTON" = "BTN_0" -a "$ACTION" = "pressed" ] ; then date +%s >/tmp/b0.seconds fi if [ "$BUTTON" = "BTN_1" ] && BTN_0_pressed; then if [ "$ACTION" = "released" ]; then [ $(expr $(date +%s) - $(cat /tmp/b0.seconds)) -gt 1 ] && export BUTTON=left export ACTION=pressed else export BUTTON=right export ACTION=pressed fi # to middle elif [ "$BUTTON" = "BTN_0" -a "$ACTION" = "released" ] ; then export BUTTON=middle export ACTION=pressed fi fi # work with button entries in /config/system: left, right, middle; wps; e.g.: # uci add system button; uci set system.@button[-1].button=left; uci set system.@button[-1].action=pressed # uci set system.@button[-1].handler=handler_script_in_usr_sbin; # optional: uci set system.@button[-1].min=1; uci set system.@button[-1].max=3 [ "$ACTION" = "$action" -a "$BUTTON" = "$button" -a -n "$handler" ] && { [ -z "$min" -o -z "$max" ] && eval $handler [ -n "$min" -a -n "$max" ] && { [ $min -le $SEEN -a $max -ge $SEEN ] && eval $handler } } } config_load system config_foreach do_button button