diff options
author | Alberto Bursi <alberto.bursi@outlook.it> | 2017-03-30 11:47:32 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2017-05-14 21:45:50 +0200 |
commit | b06a286a4861d2a15f0372aabcf643d4b49cd262 (patch) | |
tree | bcb66491684a27c3a31b3f0b1ed4fd1f52cf28e5 | |
parent | aa8e91a1e4d96a5a2bfe4437b61086c6c505edc1 (diff) | |
download | upstream-b06a286a4861d2a15f0372aabcf643d4b49cd262.tar.gz upstream-b06a286a4861d2a15f0372aabcf643d4b49cd262.tar.bz2 upstream-b06a286a4861d2a15f0372aabcf643d4b49cd262.zip |
base-files: cleanup led functions in uci-defaults.sh
create a function with code common to all led functions,
create another function with code common to functions setting
a simple led trigger, restore alphabetical order in function names.
Signed-off-by: Alberto Bursi <alberto.bursi@outlook.it>
[Jo-Philipp Wich: use a single underscore to denote private functions]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rwxr-xr-x | package/base-files/files/lib/functions/uci-defaults.sh | 236 |
1 files changed, 91 insertions, 145 deletions
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index f5e8ebefbd..07e42c6491 100755 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -358,236 +358,183 @@ ucidef_add_vdsl_modem() { json_select .. } -ucidef_set_led_netdev() { +_ucidef_set_led_common() { local cfg="led_$1" local name="$2" local sysfs="$3" - local dev="$4" - local mode="${5:-link tx rx}" json_select_object led json_select_object "$1" json_add_string name "$name" - json_add_string type netdev json_add_string sysfs "$sysfs" - json_add_string device "$dev" - json_add_string mode "$mode" - json_select .. - - json_select .. } -ucidef_set_led_usbdev() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local dev="$4" +ucidef_set_led_default() { + local default="$4" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" - json_add_string name "$name" - json_add_string type usb - json_add_string sysfs "$sysfs" - json_add_string device "$dev" + json_add_string default "$default" json_select .. json_select .. } -ucidef_set_led_usbport() { - local obj="$1" - local name="$2" - local sysfs="$3" - shift - shift - shift +ucidef_set_led_gpio() { + local gpio="$4" + local inverted="$5" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$obj" - json_add_string name "$name" - json_add_string type usbport - json_add_string sysfs "$sysfs" - json_select_array ports - for port in "$@"; do - json_add_string port "$port" - done - json_select .. + json_add_string trigger "$trigger" + json_add_string type gpio + json_add_int gpio "$gpio" + json_add_boolean inverted "$inverted" json_select .. json_select .. } -ucidef_set_led_wlan() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local trigger="$4" - - json_select_object led - - json_select_object "$1" - json_add_string name "$name" - json_add_string type trigger - json_add_string sysfs "$sysfs" - json_add_string trigger "$trigger" - json_select .. - - json_select .. +ucidef_set_led_ide() { + _ucidef_set_led_trigger "$1" "$2" "$3" ide-disk } -ucidef_set_led_switch() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local trigger="$4" - local port_mask="$5" - local speed_mask="$6" +ucidef_set_led_netdev() { + local dev="$4" + local mode="${5:-link tx rx}" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" - json_add_string name "$name" - json_add_string type switch - json_add_string sysfs "$sysfs" - json_add_string trigger "$trigger" - json_add_string port_mask "$port_mask" - json_add_string speed_mask "$speed_mask" + json_add_string type netdev + json_add_string device "$dev" + json_add_string mode "$mode" json_select .. json_select .. } +ucidef_set_led_oneshot() { + _ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5 +} + ucidef_set_led_portstate() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" local port_state="$4" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" - json_add_string name "$name" - json_add_string type portstate - json_add_string sysfs "$sysfs" json_add_string trigger port_state + json_add_string type portstate json_add_string port_state "$port_state" json_select .. json_select .. } -ucidef_set_led_default() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local default="$4" +ucidef_set_led_rssi() { + local iface="$4" + local minq="$5" + local maxq="$6" + local offset="$7" + local factor="$8" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" + json_add_string type rssi json_add_string name "$name" - json_add_string sysfs "$sysfs" - json_add_string default "$default" + json_add_string iface "$iface" + json_add_string minq "$minq" + json_add_string maxq "$maxq" + json_add_string offset "$offset" + json_add_string factor "$factor" json_select .. json_select .. } -ucidef_set_led_gpio() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local gpio="$4" - local inverted="$5" +ucidef_set_led_switch() { + local trigger_name="$4" + local port_mask="$5" + local speed_mask="$6" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" - json_add_string type gpio - json_add_string name "$name" - json_add_string sysfs "$sysfs" - json_add_string trigger "$trigger" - json_add_int gpio "$gpio" - json_add_boolean inverted "$inverted" + json_add_string trigger "$trigger_name" + json_add_string type switch + json_add_string port_mask "$port_mask" + json_add_string speed_mask "$speed_mask" json_select .. json_select .. } -ucidef_set_led_ide() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" +_ucidef_set_led_timer() { + local trigger_name="$4" + local delayon="$5" + local delayoff="$6" - json_select_object led + _ucidef_set_led_common "$1" "$2" "$3" - json_select_object "$1" - json_add_string name "$name" - json_add_string sysfs "$sysfs" - json_add_string trigger ide-disk + json_add_string trigger "$trigger_name" + json_add_int delayon "$delayon" + json_add_int delayoff "$delayoff" json_select .. json_select .. } -__ucidef_set_led_timer() { - local cfg="led_$1" - local name="$2" - local sysfs="$3" - local trigger="$4" - local delayon="$5" - local delayoff="$6" +ucidef_set_led_timer() { + _ucidef_set_led_timer $1 $2 $3 "timer" $4 $5 +} - json_select_object led +_ucidef_set_led_trigger() { + local trigger_name="$4" - json_select_object "$1" - json_add_string type "$trigger" - json_add_string name "$name" - json_add_string sysfs "$sysfs" - json_add_int delayon "$delayon" - json_add_int delayoff "$delayoff" + _ucidef_set_led_common "$1" "$2" "$3" + + json_add_string trigger "$trigger_name" json_select .. json_select .. } -ucidef_set_led_oneshot() { - __ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5 -} +ucidef_set_led_usbdev() { + local dev="$4" -ucidef_set_led_timer() { - __ucidef_set_led_timer $1 $2 $3 "timer" $4 $5 + _ucidef_set_led_common "$1" "$2" "$3" + + json_add_string type usb + json_add_string device "$dev" + json_select .. + + json_select .. } -ucidef_set_led_rssi() { - local cfg="led_$1" +ucidef_set_led_usbport() { + local obj="$1" local name="$2" local sysfs="$3" - local iface="$4" - local minq="$5" - local maxq="$6" - local offset="$7" - local factor="$8" + shift + shift + shift - json_select_object led + _ucidef_set_led_common "$obj" "$name" "$sysfs" - json_select_object "$1" - json_add_string type rssi - json_add_string name "$name" - json_add_string iface "$iface" - json_add_string sysfs "$sysfs" - json_add_string minq "$minq" - json_add_string maxq "$maxq" - json_add_string offset "$offset" - json_add_string factor "$factor" + json_add_string type usbport + json_select_array ports + for port in "$@"; do + json_add_string port "$port" + done + json_select .. json_select .. json_select .. } +ucidef_set_led_wlan() { + _ucidef_set_led_trigger "$1" "$2" "$3" "$4" +} + ucidef_set_rssimon() { local dev="$1" local refresh="$2" @@ -601,7 +548,6 @@ ucidef_set_rssimon() { json_select .. json_select .. - } ucidef_add_gpio_switch() { |