board.d: add support for gpio_switch sections
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 4 Dec 2015 15:02:32 +0000 (15:02 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 4 Dec 2015 15:02:32 +0000 (15:02 +0000)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
SVN-Revision: 47762

package/base-files/files/bin/config_generate
package/base-files/files/lib/functions/uci-defaults-new.sh

index 49784ebfaec6b0bc7d4852b1ac8ae2bfdcdcd963..9218788b5e8f24483b3262bd2d23c3cc43a64b9f 100755 (executable)
@@ -312,6 +312,24 @@ generate_led() {
        json_select ..
 }
 
+generate_gpioswitch() {
+       local cfg="$1"
+
+       json_select gpioswitch
+               json_select "$cfg"
+                       local name pin default
+                       json_get_vars name pin default
+                       uci -q batch <<-EOF
+                               delete system.$cfg
+                               set system.$cfg='gpio_switch'
+                               set system.$cfg.name='$name'
+                               set system.$cfg.gpio_pin='$pin'
+                               set system.$cfg.default='$default'
+                       EOF
+               json_select ..
+       json_select ..
+}
+
 json_init
 json_load "$(cat ${CFG})"
 
@@ -326,6 +344,9 @@ for key in $keys; do generate_switch $key; done
 json_get_keys keys rssimon
 for key in $keys; do generate_rssimon $key; done
 
+json_get_keys keys gpioswitch
+for key in $keys; do generate_gpioswitch $key; done
+
 json_get_keys keys led
 for key in $keys; do generate_led $key; done
 
index 61aa6e168e2e46b5bf7e7067144b4b053acfd311..de3f180cbb75b9d7f44ed716c518107421f367a1 100755 (executable)
@@ -540,6 +540,21 @@ ucidef_set_rssimon() {
 
 }
 
+ucidef_add_gpio_switch() {
+       local cfg="$1"
+       local name="$2"
+       local pin="$3"
+       local default="${4:-0}"
+
+       json_select_object gpioswitch
+               json_select_object "$cfg"
+                       json_add_string name "$name"
+                       json_add_int pin "$pin"
+                       json_add_int default "$default"
+               json_select ..
+       json_select ..
+}
+
 board_config_update() {
        json_init
        [ -f ${CFG} ] && json_load "$(cat ${CFG})"