5 produce_screen_brightness
() {
6 screen_brightness_device_path
="$1"
8 $(cat $screen_brightness_device_path/max_brightness) \
9 $(cat $screen_brightness_device_path/brightness)\
20 for (i=2; i<=NF; i++) printf(" %s", $i);
23 /^[ \t]*Mute:/ {mute = $2}
24 /^[ \t]*front-left:/ {left = $4}
25 /^[ \t]*front-right:/ {right = $4}
30 printf("%s %s", left, right)
44 /^time: +[0-9]+:[0-9]+$/ {
46 seconds_current = time[1]
47 seconds_total = time[2]
49 hours = int(seconds_current / 60 / 60);
50 secs_beyond_hours = seconds_current - (hours * 60 * 60);
51 mins = int(secs_beyond_hours / 60);
52 secs = secs_beyond_hours - (mins * 60);
54 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
56 current_time = sprintf("%.2d:%.2d", mins, secs)
59 if (seconds_total > 0) {
60 time_percentage = (seconds_current / seconds_total) * 100
61 current_percentage = sprintf("%d%%", time_percentage)
63 current_percentage = "~"
68 state = status["state:"]
70 if (state == "play") {
72 } else if (state == "pause") {
74 } else if (state == "stop") {
82 status["state:"], current_time, current_percentage\
105 title = data["Title:"]
113 last = split(file, parts, "/")
124 weather_station_id
="$1"
125 metar
-d "$weather_station_id" 2>&1 \
127 /METAR pattern not found in NOAA data/ {
133 fahrenheit = (celsius * (9 / 5)) + 32;
134 temperature = fahrenheit
141 print temperature "°F"
146 date +'%a %b %d %H:%M:%S'
154 -v opt_mpd_song_max_chars
=10 \
156 /^in:SCREEN_BRIGHTNESS/\
159 set_screen_brightness()
165 db["volume"] = msg_body
172 db["mpd_curr_song_time"] = $2
173 db["mpd_curr_song_percent"] = $3
179 db["mpd_curr_song_name"] = msg_body
185 db["weather_temperature"] = msg_body
191 db["datetime"] = msg_body
201 function set_screen_brightness( max, cur) {
204 db["screen_brightness"] = (cur / max) * 100
207 function split_msg_parts() {
209 sub("^" msg_head " +", "")
211 debug(msg_head, msg_body)
214 function make_bar( position, bar, sep, i, j) {
215 position[++i] = sprintf("*%d%%", db["screen_brightness"])
216 position[++i] = sprintf("(%s)", db["volume"])
217 position[++i] = make_status_mpd()
218 position[++i] = db["weather_temperature"]
219 position[++i] = db["datetime"]
222 for (j = 1; j <= i; j++) {
223 bar = bar sep position[j]
229 function make_status_mpd( state, status) {
230 state = db["mpd_state"]
232 if (state == "play") {
233 status = make_status_mpd_state_known("▶")
234 } else if (state == "pause") {
235 status = make_status_mpd_state_known("❚❚")
236 } else if (state == "stop") {
237 status = make_status_mpd_state_known("⬛")
239 status = make_status_mpd_state_unknown("--")
242 return sprintf("[%s]", status)
245 function make_status_mpd_state_known(symbol) {
249 db["mpd_curr_song_time"],
250 db["mpd_curr_song_percent"],
251 substr(db["mpd_curr_song_name"], 1, opt_mpd_song_max_chars)\
255 function make_status_mpd_state_unknown(symbol) {
256 return sprintf("%s", symbol)
259 function debug(location, msg) {
261 print_error(location, msg)
265 function print_error(location, msg) {
266 print(location " ==> " msg) > "/dev/stderr"
281 echo "${msg_head} $($cmd)" > "$pipe"
288 dir_data
="$HOME/.khatus"
289 weather_station_id
='KJFK'
290 screen_brightness_device_name
='acpi_video0'
296 -l data-dir
:,weather-station
:screen-device
: \
308 weather_station_id
="$2"
312 screen_brightness_device_name
="$2"
322 pipe
="$dir_data/khatus_data_pipe"
323 screen_brightness_device_path
='/sys/class/backlight'
324 screen_brightness_device_path
+="/$screen_brightness_device_name"
326 ( echo "Khatus starting with the following parameters:"
327 ( echo " dir_data|= $dir_data"
329 echo " screen_brightness_device_name|=$screen_brightness_device_name"
330 echo " screen_brightness_device_path|=$screen_brightness_device_path"
331 echo " weather_station_id|= $weather_station_id"
340 cmd_produce_screen_brightness
='produce_screen_brightness'
341 cmd_produce_screen_brightness
+=" $screen_brightness_device_path"
342 cmd_produce_weather
="produce_weather $weather_station_id"
344 # TODO: Redirect each worker's stderr to a dedicated log file
345 spawn produce_datetime
"$pipe" 'in:DATE_TIME' 1
346 spawn
"$cmd_produce_screen_brightness" "$pipe" 'in:SCREEN_BRIGHTNESS' 1
347 spawn
"$cmd_produce_weather" "$pipe" 'in:WEATHER' $
(( 30 * 60 ))
348 spawn produce_mpd_state
"$pipe" 'in:MPD_STATE' 1
349 spawn produce_mpd_song
"$pipe" 'in:MPD_SONG' 1
350 spawn produce_volume
"$pipe" 'in:VOLUME' 1
351 spawn produce_bar_req
"$pipe" 'out:BAR' 1