OpenWrt Forum Archive

Topic: use buttons in OpenWrt - 50% success

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I want to use my buttons in owrt, so i edited to file /etc/hotplug2-init.rules:

...
         SUBSYSTEM ~~ button {
                 exec kill -USR1 1 ;
         }

to

...
         SUBSYSTEM ~~ button {
                 exec /usr/bin/toggle.sh;
         }

the file /usr/bin/toggle.sh contains this:

#!/bin/sh

tmpfile="/tmp/toggletmp"

if [ -f $tmpfile ] ; then
    echo 1 > /proc/gpio/2_dir
    echo 1 > /proc/gpio/2_out
    rm $tmpfile

else
    echo 1 > /proc/gpio/2_dir
    echo 0 > /proc/gpio/2_out
    echo 1 > $tmpfile

this means this script toggles only the wlan led on my atheros router. The problem is, while the button is pressed the script gets called all the time. I would prefer a message when the key is pressed and when the key is released. Is there a variable available i could use?

michu

complete bullshit... I found an entry in the wiki and documented it also here: http://www.neophob.com/serendipity/inde … event.html.

what is the purpose of the variable SEEN, as in the atheros build this variable is allways zero...

(Last edited by michu on 30 Nov 2007, 02:28)

BTW, I don't know about Atheros boards, but for Broadcom (like Linksys) there is specific support for this. Just create a script /etc/hotplug.d/button/[button-name] and it will be run when the button is pressed, and again when it's released (test $ACTION to see which)

Of course you have to work out the names of the available buttons, but you can see their names in https://svn.openwrt.org/openwrt/trunk/p … src/diag.c

Unfortunately it doesn't properly support slide switches like the 'bridge' switch on the WHR-G54S, as which polarity you get depends on where the switch was when the unit powered up :-(

candlerb wrote:

BTW, I don't know about Atheros boards, but for Broadcom (like Linksys) there is specific support for this. Just create a script /etc/hotplug.d/button/[button-name] and it will be run when the button is pressed, and again when it's released (test $ACTION to see which)

Of course you have to work out the names of the available buttons, but you can see their names in https://svn.openwrt.org/openwrt/trunk/p … src/diag.c

Unfortunately it doesn't properly support slide switches like the 'bridge' switch on the WHR-G54S, as which polarity you get depends on where the switch was when the unit powered up :-(

yes i know that, i also checked the file /target/linux/atheros/files/arch/mips/atheros/reset.c which handles the button stuff for atheros... those files sets an env variable called SEEN and I dont really know what for this variable is... I created a custom version of reset to trace it a bit and saw that the variables

        /* copy keys to our continuous event payload buffer */
        add_msg(skb, "HOME=/");
        add_msg(skb, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
        add_msg(skb, "SUBSYSTEM=button");
        add_msg(skb, "BUTTON=reset");
        add_msg(skb, (event->set ? "ACTION=pressed" : "ACTION=released"));
        sprintf(buf, "SEEN=%ld", (event->jiffies - seen)/HZ);

jiffies  and seen are negative. I checked those variables with the broadcom build, there they are defined as unsigned long where those variables in the ateros build are defined as int... Ill check this

The discussion might have continued from here.