X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_parse_bluetoothctl_show;fp=bin%2Fkhatus_parse_bluetoothctl_show;h=08a8708a50e04da4744043092b1f47e2f5963f76;hb=fd22859bbb95b488a17e439e9e64de2eef00a04d;hp=0000000000000000000000000000000000000000;hpb=f03e88c6896157abd5517394024162aedebff829;p=khatus.git diff --git a/bin/khatus_parse_bluetoothctl_show b/bin/khatus_parse_bluetoothctl_show new file mode 100755 index 0000000..08a8708 --- /dev/null +++ b/bin/khatus_parse_bluetoothctl_show @@ -0,0 +1,36 @@ +#! /usr/bin/awk -f + +/^Controller / { + controller = $2 + controllers[++ctrl_count] = controller +} + +/^\t[A-Z][A-Za-z]+:/ { + key = $1 + sub(":$", "", key) + sub("^" $1, "") + val = $0 + data[controller, key] = val +} + +END { + # Using the 1st seen controller. Should we select specific instead? + power_status = data[controllers[1], "Powered"] + if (ctrl_count > 0) { + if (power_status == "no") { + show = "off" + } else if (power_status == "yes") { + show = "on" + } else { + print_error("Unexpected bluetooth power status: " power_status) + show = "ERROR" + } + } else { + show = "off" # TODO: Perhaps use differentiated marker? + } + print(show) +} + +function print_error(msg) { + print(msg) > "/dev/stderr" +}