OpenWrt for Zyxel WSM20 (Multy M1) development discussion

I've two hotplug scripts which are shuting down all leds by setting each brightness to 0 and otherwise reload the led deamon with the values from (l)uci when an event is triggered.
Since the only triggers defined in my configuration are for WiFi devices, the second script is in the network hotplug folder.

My LED configuration (/etc/config/system):

config led
        option sysfs 'white:system'
        option trigger 'none'
        option default '0'

config led
        option name 'WiFi 2.4GHz'
        option sysfs 'green:led3'
        option trigger 'netdev'
        option dev 'phy0-ap0'
        list mode 'link'

config led
        option name 'WiFi 2.4GHz'
        option sysfs 'white:led5'
        option trigger 'netdev'
        option dev 'phy0-ap0'
        list mode 'link'

config led
        option name 'WiFi 5GHz'
        option sysfs 'green:led1'
        option trigger 'netdev'
        option dev 'phy1-ap0'
        list mode 'link'

config led
        option name 'WiFi 5GHz'
        option sysfs 'red:system'
        option trigger 'netdev'
        option dev 'phy1-ap0'
        list mode 'link'

The script for using the hotplug event for the button is not a big deal, /etc/hotplug.d/button/99-led:

#!/bin/sh

if [ "$BUTTON" = "BTN_0" ]; then
        if [ "$ACTION" = "released" ]; then
                for brightness in /sys/class/leds/*/brightness ; do
                        echo 0 > $brightness
                done
        elif [ "$ACTION" = "pressed" ]; then
                /etc/init.d/led restart
        fi
fi

The tricky part is reading the status of the button after a reboot or when a trigger has been fired, /etc/hotplug.d/net/99-led-off-button:

#!/bin/sh

if grep -E '^ gpio-496 .*) in  hi' /sys/kernel/debug/gpio ; then
        #Button led !pressed
        for brightness in /sys/class/leds/*/brightness ; do
                echo 0 > $brightness
        done
else
        #Button led pressed
        :
fi

I don't know if this is the most elegant solution for this task but it works. Maybe someone has an idea for a more generic solution.

3 Likes