5 produce_net_wifi_status
() {
7 -f ACTIVE
,SSID
,SIGNAL \
13 BEGIN {wifi_status = "--"}
14 $1 == "yes" {wifi_status = $2 ":" $3 "%"}
15 END {print wifi_status}
19 produce_bluetooth_power
() {
20 echo -e 'show \n quit' \
25 controllers[++ctrl_count] = controller;
27 /^\t[A-Z][A-Za-z]+:/ {
31 for (i=3; i<=NF; i++) {
33 data[controller, key] = val;
36 # Using the 1st seen controller. Should we select specific instead?
37 power_status = data[controllers[1], "Powered"];
39 if (power_status == "no") {
41 } else if (power_status == "yes") {
44 printf("Unexpected bluetooth power status: %s\n", power_status)\
46 power_status = "ERROR"
49 power_status = "off" # TODO: Perhaps use differentiated marker?
51 printf("%s", power_status);
55 produce_screen_brightness
() {
56 screen_brightness_device_path
="$1"
58 $(cat $screen_brightness_device_path/max_brightness) \
59 $(cat $screen_brightness_device_path/brightness)\
70 for (i=2; i<=NF; i++) printf(" %s", $i);
73 /^[ \t]*Mute:/ {mute = $2}
74 /^[ \t]*front-left:/ {left = $4}
75 /^[ \t]*front-right:/ {right = $4}
80 printf("%s %s", left, right)
94 /^time: +[0-9]+:[0-9]+$/ {
96 seconds_current = time[1]
97 seconds_total = time[2]
99 hours = int(seconds_current / 60 / 60);
100 secs_beyond_hours = seconds_current - (hours * 60 * 60);
101 mins = int(secs_beyond_hours / 60);
102 secs = secs_beyond_hours - (mins * 60);
104 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
106 current_time = sprintf("%.2d:%.2d", mins, secs)
109 if (seconds_total > 0) {
110 time_percentage = (seconds_current / seconds_total) * 100
111 current_percentage = sprintf("%d%%", time_percentage)
113 current_percentage = "~"
118 state = status["state:"]
120 if (state == "play") {
122 } else if (state == "pause") {
124 } else if (state == "stop") {
132 status["state:"], current_time, current_percentage\
140 | nc
127.0.0.1 6600 \
148 sub("^" key " +", "")
155 title = data["Title:"]
163 last = split(file, parts, "/")
174 weather_station_id
="$1"
175 metar
-d "$weather_station_id" 2>&1 \
177 /METAR pattern not found in NOAA data/ {
183 fahrenheit = (celsius * (9 / 5)) + 32;
184 temperature = fahrenheit
191 print temperature "°F"
196 date +'%a %b %d %H:%M:%S'
204 -v opt_mpd_song_max_chars
=10 \
206 /^in:NET_WIFI_STATUS/\
209 db["net_wifi_status"] = msg_body
212 /^in:BLUETOOTH_POWER/\
215 db["bluetooth_power"] = msg_body
218 /^in:SCREEN_BRIGHTNESS/\
221 set_screen_brightness()
227 db["volume"] = msg_body
234 db["mpd_curr_song_time"] = $2
235 db["mpd_curr_song_percent"] = $3
241 db["mpd_curr_song_name"] = msg_body
247 db["weather_temperature"] = msg_body
253 db["datetime"] = msg_body
263 function set_screen_brightness( max, cur) {
266 db["screen_brightness"] = (cur / max) * 100
269 function split_msg_parts() {
271 sub("^" msg_head " +", "")
273 debug(msg_head, msg_body)
276 function make_bar( position, bar, sep, i, j) {
277 position[++i] = make_status_net()
278 position[++i] = sprintf("B=%s", db["bluetooth_power"])
279 position[++i] = sprintf("*%d%%", db["screen_brightness"])
280 position[++i] = sprintf("(%s)", db["volume"])
281 position[++i] = make_status_mpd()
282 position[++i] = db["weather_temperature"]
283 position[++i] = db["datetime"]
286 for (j = 1; j <= i; j++) {
287 bar = bar sep position[j]
293 function make_status_net() {
294 return sprintf("N[w:%s]", db["net_wifi_status"])
297 function make_status_mpd( state, status) {
298 state = db["mpd_state"]
300 if (state == "play") {
301 status = make_status_mpd_state_known("▶")
302 } else if (state == "pause") {
303 status = make_status_mpd_state_known("❚❚")
304 } else if (state == "stop") {
305 status = make_status_mpd_state_known("⬛")
307 status = make_status_mpd_state_unknown("--")
310 return sprintf("[%s]", status)
313 function make_status_mpd_state_known(symbol) {
317 db["mpd_curr_song_time"],
318 db["mpd_curr_song_percent"],
319 substr(db["mpd_curr_song_name"], 1, opt_mpd_song_max_chars)\
323 function make_status_mpd_state_unknown(symbol) {
324 return sprintf("%s", symbol)
327 function debug(location, msg) {
329 print_error(location, msg)
333 function print_error(location, msg) {
334 print(location " ==> " msg) > "/dev/stderr"
349 echo "${msg_head} $($cmd)" > "$pipe"
356 dir_data
="$HOME/.khatus"
357 weather_station_id
='KJFK'
358 screen_brightness_device_name
='acpi_video0'
364 -l data-dir
:,weather-station
:screen-device
: \
376 weather_station_id
="$2"
380 screen_brightness_device_name
="$2"
390 pipe
="$dir_data/khatus_data_pipe"
391 screen_brightness_device_path
='/sys/class/backlight'
392 screen_brightness_device_path
+="/$screen_brightness_device_name"
394 ( echo "Khatus starting with the following parameters:"
395 ( echo " dir_data|= $dir_data"
397 echo " screen_brightness_device_name|=$screen_brightness_device_name"
398 echo " screen_brightness_device_path|=$screen_brightness_device_path"
399 echo " weather_station_id|= $weather_station_id"
408 cmd_produce_screen_brightness
='produce_screen_brightness'
409 cmd_produce_screen_brightness
+=" $screen_brightness_device_path"
410 cmd_produce_weather
="produce_weather $weather_station_id"
412 # TODO: Redirect each worker's stderr to a dedicated log file
413 spawn produce_datetime
"$pipe" 'in:DATE_TIME' 1
414 spawn
"$cmd_produce_screen_brightness" "$pipe" 'in:SCREEN_BRIGHTNESS' 1
415 spawn
"$cmd_produce_weather" "$pipe" 'in:WEATHER' $
(( 30 * 60 ))
416 spawn produce_mpd_state
"$pipe" 'in:MPD_STATE' 1
417 spawn produce_mpd_song
"$pipe" 'in:MPD_SONG' 1
418 spawn produce_volume
"$pipe" 'in:VOLUME' 1
419 spawn produce_bluetooth_power
"$pipe" 'in:BLUETOOTH_POWER' 5
420 spawn produce_net_wifi_status
"$pipe" 'in:NET_WIFI_STATUS' 5
421 spawn produce_bar_req
"$pipe" 'out:BAR' 1