| 1 | /^Controller / { |
| 2 | controller = $2 |
| 3 | controllers[++ctrl_count] = controller |
| 4 | } |
| 5 | |
| 6 | /^\t[A-Z][A-Za-z]+:/ { |
| 7 | key = $1 |
| 8 | sub(":$", "", key) |
| 9 | sub("^\t" $1 " *", "") |
| 10 | val = $0 |
| 11 | data[controller, key] = val |
| 12 | } |
| 13 | |
| 14 | END { |
| 15 | # Using the 1st seen controller. Should we select specific instead? |
| 16 | power_status = data[controllers[1], "Powered"] |
| 17 | if (ctrl_count > 0) { |
| 18 | if (power_status == "no") { |
| 19 | show = "off" |
| 20 | } else if (power_status == "yes") { |
| 21 | show = "on" |
| 22 | } else { |
| 23 | print_error("Unexpected bluetooth power status: " power_status) |
| 24 | show = "ERROR" |
| 25 | } |
| 26 | } else { |
| 27 | show = "n/a" |
| 28 | } |
| 29 | print("power_status", show) |
| 30 | } |
| 31 | |
| 32 | function print_error(msg) { |
| 33 | print(msg) > "/dev/stderr" |
| 34 | } |