<div dir="ltr"><div><div>I have configured button definition in the mach-file as below:<br> .desc = "LAN WIFI button",<br> .type = EV_KEY,<br> .code = KEY_LAN_WIFI_BUTTON,<br> .debounce_interval = DB120_KEYS_DEBOUNCE_INTERVAL,<br> .gpio = DB120_GPIO_BTN_LAN_WIFI,<br> .active_low = 1,<br><br></div>and add script under file : etc/hotplug.d/button/50-buttonpress<br><br>if [ "$ACTION" = "pressed" -a "$BUTTON" = "lanwifi" ]; then <br> echo "255" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness <br></div>else<br> echo "0" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness<div>fi<br><div><br></div><div>In this case if i move the slide switch, it works fine but one issue is there. When i do reset the status LED always ON. If we move slide switch only it works i mean to say suppose now slide switch in low state means Status LED is OFF then if i do reset the device then also the Status LED becomes ON. <br><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 18, 2015 at 6:07 AM, Hartmut Knaack <span dir="ltr"><<a href="mailto:knaack.h@gmx.de" target="_blank">knaack.h@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Afkar Rafique schrieb am 16.10.2015 um 03:47:<br>
> Thanks for the reply.<br>
><br>
> I have change the script as below:<br>
><br>
> #!/bin/sh /etc/rc.common<br>
><br>
> START=19<br>
> start() {<br>
> echo in > /sys/class/gpio/gpio16/direction 2> /dev/null<br>
> echo 16 > /sys/class/gpio/export 2> /dev/null<br>
<br>
</span>Still, you can only set the direction AFTER exporting the GPIO (otherwise the gpioXX<br>
directory with its contents like direction don't exist).<br>
<span class=""><br>
> if [ "$(cat /sys/class/gpio/gpio16/value)" == "1" ] ; then<br>
> echo "255" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness<br>
> else<br>
> echo "0" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness<br>
> fi<br>
> }<br>
><br>
> I need to monitor the LED on/off all the time during runtime.<br>
><br>
> During start of this script its working, but not getting how to make it work run time.<br>
><br>
> Could you please explain how i can do it in gpio-button.<br>
<br>
</span>That would require you to add a custom button definition in the mach-file of your<br>
specific device and compile your own firmware image.<br>
You could however use a small script which infinitely loops through your poll and sleeps<br>
for a second, so the CPU can work on other tasks, too (while true; do if...then...else<br>
sleep 1; done). Downside is, that you can only react to "button press events", which are<br>
long enough (one second, as this is the low limit of sleep time). Also, don't forget to<br>
let it run in background, so you don't block your init process.<br>
<div><div class="h5"><br>
><br>
> On Fri, Oct 16, 2015 at 3:38 AM, Hartmut Knaack <<a href="mailto:knaack.h@gmx.de">knaack.h@gmx.de</a> <mailto:<a href="mailto:knaack.h@gmx.de">knaack.h@gmx.de</a>>> wrote:<br>
><br>
> Afkar Rafique schrieb am 15.10.2015 um 04:07:<br>
> > Thanks for the reply.<br>
> ><br>
> > i have Create /etc/init.d/buttons and written below script:<br>
> ><br>
> > #!/bin/sh /etc/rc.common<br>
> > START=19<br>
> > start() {<br>
> > /bin/umount /etc/config 2>/dev/null<br>
> > echo out > /sys/class/gpio/gpio16/direction 2> /dev/null<br>
> > echo 16 > /sys/class/gpio/export 2> /dev/null<br>
> > if [ "$(cat /sys/class/gpio/gpio16/value)" == "1" ] ; then<br>
> > echo "255" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness<br>
> > else<br>
> > echo "0" > /sys/devices/platform/leds-gpio/leds/db120:green:status/brightness<br>
> > fi<br>
> > }<br>
> ><br>
> > and restart .<br>
> ><br>
> > chmod +x /etc/init.d/buttons<br>
> > /etc/init.d/buttons enable<br>
> > /etc/init.d/buttons start<br>
> ><br>
> > Now i am able to read the GPIO 16 value 1/0 based on GPIO state, but as above script i have written to ON/OFF the Status LED based on GPIO value, Status LED is not getting OFF even if GPIO16 value is "0".<br>
> ><br>
> > Can anyone please help on this<br>
> ><br>
><br>
> Quite a mess you've got there. No idea why you need to umount /etc/config,<br>
> but anyway: First thing in GPIO setup is exporting, then you set its direction.<br>
> If you intend to read the GPIO status, then better use "in" as direction.<br>
> Now, do you just want to do an action (LED on/off) just during start of this<br>
> script, or all the time during runtime, when the GPIO status changes? In the<br>
> latter case, you should look into gpio-button.<br>
><br>
> ><br>
> ><br>
</div></div>> > On Thu, Oct 15, 2015 at 12:37 AM, Martin Blumenstingl <<a href="mailto:martin.blumenstingl@googlemail.com">martin.blumenstingl@googlemail.com</a> <mailto:<a href="mailto:martin.blumenstingl@googlemail.com">martin.blumenstingl@googlemail.com</a>> <mailto:<a href="mailto:martin.blumenstingl@googlemail.com">martin.blumenstingl@googlemail.com</a> <mailto:<a href="mailto:martin.blumenstingl@googlemail.com">martin.blumenstingl@googlemail.com</a>>>> wrote:<br>
<span class="">> ><br>
> > On Wed, Oct 14, 2015 at 12:19 PM, Afkar Rafique <<a href="mailto:afkar.ec@gmail.com">afkar.ec@gmail.com</a> <mailto:<a href="mailto:afkar.ec@gmail.com">afkar.ec@gmail.com</a>> <mailto:<a href="mailto:afkar.ec@gmail.com">afkar.ec@gmail.com</a> <mailto:<a href="mailto:afkar.ec@gmail.com">afkar.ec@gmail.com</a>>>> wrote:<br>
> > > Could anyone please explain how i can configure and read GPIO value.<br>
> > There's an article on the wiki which explains how to set a GPIO to a<br>
> > specific value: [0]<br>
> > If you want to read a GPIO value then you use direction "in" and then<br>
> > simply cat to read the "value".<br>
> ><br>
> > The only thing that you might have to do is doing a bit of maths to<br>
> > get the correct GPIO number.<br>
> > When you are trying to read GPIO #16 then it's GPIO #16 of a specific<br>
> > chip -> /sys/class/gpio/ should contain a file gpiochipNNN.<br>
> > What you do is take NNN (let's assume it's 456) and add your GPIO<br>
> > number to it: 456 + 16 = 472 -> this is the number needef to "export"<br>
> > the GPIO.<br>
> ><br>
> ><br>
> > [0] <a href="http://wiki.openwrt.org/doc/hardware/port.gpio#software" rel="noreferrer" target="_blank">http://wiki.openwrt.org/doc/hardware/port.gpio#software</a><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > openwrt-devel mailing list<br>
</span>> > <a href="mailto:openwrt-devel@lists.openwrt.org">openwrt-devel@lists.openwrt.org</a> <mailto:<a href="mailto:openwrt-devel@lists.openwrt.org">openwrt-devel@lists.openwrt.org</a>><br>
> > <a href="https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel" rel="noreferrer" target="_blank">https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel</a><br>
> ><br>
><br>
><br>
<br>
</blockquote></div><br></div>