5 produce_bluetooth_power
() {
6 echo -e 'show \n quit' \
11 controllers[++ctrl_count] = controller;
13 /^\t[A-Z][A-Za-z]+:/ {
17 for (i=3; i<=NF; i++) {
19 data[controller, key] = val;
22 # Using the 1st seen controller. Should we select specific instead?
23 power_status = data[controllers[1], "Powered"];
25 if (power_status == "no") {
27 } else if (power_status == "yes") {
30 printf("Unexpected bluetooth power status: %s\n", power_status)\
32 power_status = "ERROR"
35 power_status = "off" # TODO: Perhaps use differentiated marker?
37 printf("%s", power_status);
41 produce_screen_brightness
() {
42 screen_brightness_device_path
="$1"
44 $(cat $screen_brightness_device_path/max_brightness) \
45 $(cat $screen_brightness_device_path/brightness)\
56 for (i=2; i<=NF; i++) printf(" %s", $i);
59 /^[ \t]*Mute:/ {mute = $2}
60 /^[ \t]*front-left:/ {left = $4}
61 /^[ \t]*front-right:/ {right = $4}
66 printf("%s %s", left, right)
80 /^time: +[0-9]+:[0-9]+$/ {
82 seconds_current = time[1]
83 seconds_total = time[2]
85 hours = int(seconds_current / 60 / 60);
86 secs_beyond_hours = seconds_current - (hours * 60 * 60);
87 mins = int(secs_beyond_hours / 60);
88 secs = secs_beyond_hours - (mins * 60);
90 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
92 current_time = sprintf("%.2d:%.2d", mins, secs)
95 if (seconds_total > 0) {
96 time_percentage = (seconds_current / seconds_total) * 100
97 current_percentage = sprintf("%d%%", time_percentage)
99 current_percentage = "~"
104 state = status["state:"]
106 if (state == "play") {
108 } else if (state == "pause") {
110 } else if (state == "stop") {
118 status["state:"], current_time, current_percentage\
126 | nc
127.0.0.1 6600 \
134 sub("^" key " +", "")
141 title = data["Title:"]
149 last = split(file, parts, "/")
160 weather_station_id
="$1"
161 metar
-d "$weather_station_id" 2>&1 \
163 /METAR pattern not found in NOAA data/ {
169 fahrenheit = (celsius * (9 / 5)) + 32;
170 temperature = fahrenheit
177 print temperature "°F"
182 date +'%a %b %d %H:%M:%S'
190 -v opt_mpd_song_max_chars
=10 \
192 /^in:BLUETOOTH_POWER/\
195 db["bluetooth_power"] = msg_body
198 /^in:SCREEN_BRIGHTNESS/\
201 set_screen_brightness()
207 db["volume"] = msg_body
214 db["mpd_curr_song_time"] = $2
215 db["mpd_curr_song_percent"] = $3
221 db["mpd_curr_song_name"] = msg_body
227 db["weather_temperature"] = msg_body
233 db["datetime"] = msg_body
243 function set_screen_brightness( max, cur) {
246 db["screen_brightness"] = (cur / max) * 100
249 function split_msg_parts() {
251 sub("^" msg_head " +", "")
253 debug(msg_head, msg_body)
256 function make_bar( position, bar, sep, i, j) {
257 position[++i] = sprintf("B=%s", db["bluetooth_power"])
258 position[++i] = sprintf("*%d%%", db["screen_brightness"])
259 position[++i] = sprintf("(%s)", db["volume"])
260 position[++i] = make_status_mpd()
261 position[++i] = db["weather_temperature"]
262 position[++i] = db["datetime"]
265 for (j = 1; j <= i; j++) {
266 bar = bar sep position[j]
272 function make_status_mpd( state, status) {
273 state = db["mpd_state"]
275 if (state == "play") {
276 status = make_status_mpd_state_known("▶")
277 } else if (state == "pause") {
278 status = make_status_mpd_state_known("❚❚")
279 } else if (state == "stop") {
280 status = make_status_mpd_state_known("⬛")
282 status = make_status_mpd_state_unknown("--")
285 return sprintf("[%s]", status)
288 function make_status_mpd_state_known(symbol) {
292 db["mpd_curr_song_time"],
293 db["mpd_curr_song_percent"],
294 substr(db["mpd_curr_song_name"], 1, opt_mpd_song_max_chars)\
298 function make_status_mpd_state_unknown(symbol) {
299 return sprintf("%s", symbol)
302 function debug(location, msg) {
304 print_error(location, msg)
308 function print_error(location, msg) {
309 print(location " ==> " msg) > "/dev/stderr"
324 echo "${msg_head} $($cmd)" > "$pipe"
331 dir_data
="$HOME/.khatus"
332 weather_station_id
='KJFK'
333 screen_brightness_device_name
='acpi_video0'
339 -l data-dir
:,weather-station
:screen-device
: \
351 weather_station_id
="$2"
355 screen_brightness_device_name
="$2"
365 pipe
="$dir_data/khatus_data_pipe"
366 screen_brightness_device_path
='/sys/class/backlight'
367 screen_brightness_device_path
+="/$screen_brightness_device_name"
369 ( echo "Khatus starting with the following parameters:"
370 ( echo " dir_data|= $dir_data"
372 echo " screen_brightness_device_name|=$screen_brightness_device_name"
373 echo " screen_brightness_device_path|=$screen_brightness_device_path"
374 echo " weather_station_id|= $weather_station_id"
383 cmd_produce_screen_brightness
='produce_screen_brightness'
384 cmd_produce_screen_brightness
+=" $screen_brightness_device_path"
385 cmd_produce_weather
="produce_weather $weather_station_id"
387 # TODO: Redirect each worker's stderr to a dedicated log file
388 spawn produce_datetime
"$pipe" 'in:DATE_TIME' 1
389 spawn
"$cmd_produce_screen_brightness" "$pipe" 'in:SCREEN_BRIGHTNESS' 1
390 spawn
"$cmd_produce_weather" "$pipe" 'in:WEATHER' $
(( 30 * 60 ))
391 spawn produce_mpd_state
"$pipe" 'in:MPD_STATE' 1
392 spawn produce_mpd_song
"$pipe" 'in:MPD_SONG' 1
393 spawn produce_volume
"$pipe" 'in:VOLUME' 1
394 spawn produce_bluetooth_power
"$pipe" 'in:BLUETOOTH_POWER' 5
395 spawn produce_bar_req
"$pipe" 'out:BAR' 1