Is it possible to configure the actions of the mode switch button for the GL-AR750s router without the manufacturer's interface?
It should be available as a switch:
keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&jtag_disable_pins>;
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
};
mode {
label = "mode";
linux,code = <BTN_0>;
linux,input-type = <EV_SW>;
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
};
I don't know if hotplug events are sent for a switch transition -- https://openwrt.org/docs/guide-user/hardware/hardware.button
I unfortunately don't know how to read a Linux button's state with a script.
From my experience, if it exists, the script at /etc/rc.button/BTN_0
is called on slider action.
From the script you can poll the status of the slider switch by doing grep -q 'gpio-0.*sw1.*hi' /sys/kernel/debug/gpio
.
I don't remember the reason why I wasn't processing the action right in the /etc/rc.button/BTN_0
script, just telling you what ended up working for me.
root@OpenWrt:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/18040000.gpio, 18040000.gpio:
gpio-1 ( |gl-ar750s:green:powe) out lo
gpio-2 ( |reset ) in hi IRQ
gpio-7 ( |usb-vbus ) out hi
gpio-8 ( |mode ) in lo IRQ
gpio-19 ( |gl-ar750s:green:wlan) out hi
gpio-20 ( |gl-ar750s:green:wlan) out lo
Useful in a start-up script, as you probably want to check the current state of the button to make decisions:
if grep -E '^ gpio-8 .*) in hi' /sys/kernel/debug/gpio ; then
echo "Switch is on"
else
echo "Switch is off"
fi
"hi" is with the slider near the dot on my device running master
With the script on the linked page generated with
mkdir -p /etc/hotplug.d/button
cat << "EOF" > /etc/hotplug.d/button/buttons
logger "the button was ${BUTTON} and the action was ${ACTION}"
EOF
I get
Sun Dec 8 00:19:14 2019 user.notice root: the button was BTN_0 and the action was released
Sun Dec 8 00:19:17 2019 user.notice root: the button was BTN_0 and the action was pressed
Sun Dec 8 00:19:19 2019 user.notice root: the button was BTN_0 and the action was released
Sun Dec 8 00:19:20 2019 user.notice root: the button was BTN_0 and the action was pressed
Double check that the transition "makes sense to you" when you script it. It looks like moving toward the dot is a "released" event the way things are presently defined.
Probably why I was polling the state instead of relying on the action, good catch!
Thanks! Will be trying that to see if I can get the Wifi on/off.
Thanks for the info. I am able to get 4 usable states using these 2 buttons in alternative states.
Here is my /etc/hotplug.d/BTN_0
file
if grep -E '^ gpio-8 .*) in hi' /sys/kernel/debug/gpio ; then
/etc/buttonon
else
/etc/buttonoff
fi
I have a few different buttonon and buttonoff profiles so i copy over which 2 profiles i want to the appropriate button file.
my /etc/buttonon
file looks like this
kill `ps | grep [b]uttonoff | awk '{ print $1 }'`
echo -n 1 >> /tmp/switcheroo
if cat /tmp/switcheroo | grep 11; then
rm /tmp/switcheroo
/etc/button3on
exit
fi
if [ -f /etc/hotplug.d/button/off.status ] || [ -f /etc/hotplug.d/button/3.status ]; then
touch /etc/hotplug.d/button/on.status
rm /etc/hotplug.d/button/3.status
rm /etc/hotplug.d/button/off.status
#Insert your buttonon commands here
fi
sleep 20 && rm /tmp/switcheroo &
and my /etc/buttonoff
file
kill `ps | grep [b]uttonon | awk '{ print $1 }'`
echo -n 1 >> /tmp/switcheroo
if cat /tmp/switcheroo | grep 11; then
rm /tmp/switcheroo
/etc/button3off
exit
fi
if [ -f /etc/hotplug.d/button/on.status ] || [ -f /etc/hotplug.d/button/3.status ]; then
touch /etc/hotplug.d/button/off.status
rm /etc/hotplug.d/button/3.status
rm /etc/hotplug.d/button/on.status
#Insert your buttonoff commands here
fi
sleep 20 && rm /tmp/switcheroo &
Now using the code above, if you switch the button from and back to its original state within 20 seconds it will give you that buttons alternative state.
My alternative-on or /etc/button3on
file
if [ -f /etc/hotplug.d/button/off.status ]; then
touch /etc/hotplug.d/button/3.status
touch /etc/hotplug.d/button/on.status
rm /tmp/switcheroo
rm /etc/hotplug.d/button/off.status
#Insert your Alternative-on commands here
fi
Alternative-off /etc/button3off
code
if [ -f /etc/hotplug.d/button/on.status ]; then
touch /etc/hotplug.d/button/3.status
touch /etc/hotplug.d/button/off.status
rm /tmp/switcheroo
rm /etc/hotplug.d/button/on.status
#Insert your alternative-off commands here
fi
I use Button off and button on as VPN1 and VPN2 with my alternative modes being no VPN so I don't accidentally go online without a VPN. To ensure I don't accidentally boot without a VPN I put /etc/hotplug.d/button/BTN_0
as an entry in the /etc/rc.local
startup file so that it will take the button out of alternative state upon reboot.
Be sure to chmod +x
all of your button files as well.
If it's any help, check out the sources for the slider-support package.