#!/bin/sh

EXTRA_COMMANDS="$EXTRA_COMMANDS standby normal"

standby() {
    #if on and enabled
    [ $DISABLED = '1' ] && return
    [ $STANDBY = '0' ] && return

    case "$board" in
    dlan2-2400-ac)
        echo 0 > /sys/class/gpio/gpio63/value
        ;;
    dlan-1000-ac)
        echo 0 > /sys/class/gpio/gpio2/value
        ;;
    dlan-pro-1200-ac|\
    dlan-pro-1200-n)
        echo 0 > /sys/class/gpio/gpio13/value
        ;;
    dlan-550-wifi)
        echo 0 > /sys/class/gpio/gpio16/value
        ;;
    esac

    # LED scheme 2014
    [ "$LED_SCHEME" = "on" ] && {
        led_timer "$(uci_get system led_plcw sysfs)" 500 59500
        led_off "$(uci_get system led_plcr sysfs)"
    }
    led_set_attr "devolo:status:dlan" inverted 0
}

normal() {
    #if on and enabled
    [ $DISABLED = '1' ] && return
    [ $STANDBY = '0' ] && return

    case "$board" in
    dlan2-2400-ac)
        echo 1 > /sys/class/gpio/gpio63/value
        ;;
    dlan-1000-ac)
        echo 1 > /sys/class/gpio/gpio2/value
        ;;
    dlan-pro-1200-ac|\
    dlan-pro-1200-n)
        echo 1 > /sys/class/gpio/gpio13/value
        ;;
    dlan-550-wifi)
        echo 1 > /sys/class/gpio/gpio16/value
        ;;
    esac

    # LED scheme 2014
    [ "$LED_SCHEME" = "on" ] && {
        ( . /etc/init.d/led && config_load system && load_led led_plcw && load_led led_plcr )
    }
    led_set_attr "devolo:status:dlan" inverted 1
}
