[LEDE-DEV] [RFC 02/12] base-files: support button actions through board.d

Jo-Philipp Wich jo at mein.io
Tue May 31 07:24:48 PDT 2016


Add support for specifying button actions via /etc/board.d/ scripts to utilize
the generic button config framework ported from the ath25 target.

Signed-off-by: Jo-Philipp Wich <jo at mein.io>

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 345393c..aaaac59 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -343,6 +343,27 @@ generate_gpioswitch() {
 	json_select ..
 }
 
+generate_button() {
+	local key="$1"
+	local cfg="btn_$key"
+
+	json_select button
+		json_select "$key"
+			local button action handler min max
+			json_get_vars button action handler min max
+			uci -q batch <<-EOF
+				delete system.$cfg
+				set system.$cfg='button'
+				set system.$cfg.button='$button'
+				set system.$cfg.action='$action'
+				set system.$cfg.handler='$handler'
+				set system.$cfg.min='$min'
+				set system.$cfg.max='$max'
+			EOF
+		json_select ..
+	json_select ..
+}
+
 json_init
 json_load "$(cat ${CFG})"
 
@@ -363,4 +384,7 @@ for key in $keys; do generate_gpioswitch $key; done
 json_get_keys keys led
 for key in $keys; do generate_led $key; done
 
+json_get_keys keys button
+for key in $keys; do generate_button $key; done
+
 uci commit
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index b097fba..c51a6da 100755
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -572,6 +572,25 @@ ucidef_add_gpio_switch() {
 	json_select ..
 }
 
+ucidef_add_button() {
+	local cfg="$1"
+	local button="$2"
+	local action="$3"
+	local handler="$4"
+	local min="$5"
+	local max="$6"
+
+	json_select_object button
+		json_select_object "$cfg"
+			json_add_string button "$button"
+			json_add_string action "$action"
+			json_add_string handler "$handler"
+			json_add_int min "$min"
+			json_add_int max "$max"
+		json_select ..
+	json_select ..
+}
+
 board_config_update() {
 	json_init
 	[ -f ${CFG} ] && json_load "$(cat ${CFG})"
-- 
2.1.4




More information about the Lede-dev mailing list