# HG changeset patch # User Matti Hamalainen # Date 1579640197 -7200 # Node ID 0d6dfcc1c9578b17ef54736cb3b60b20de200664 # Parent 120eb7eb7398ad49ce83d36d6be8473a908ea65e weather: Add translation of weather direction angle. diff -r 120eb7eb7398 -r 0d6dfcc1c957 config.weather.example --- a/config.weather.example Tue Jan 21 22:34:15 2020 +0200 +++ b/config.weather.example Tue Jan 21 22:56:37 2020 +0200 @@ -37,6 +37,8 @@ ### set weather_msg_list_station [list "\002@station@\002 ( http://www.google.fi/maps/@@c_lat@,@c_lng@,18z )"] +set weather_msg_wind_directions [list "pohjoinen" "koillinen" "itä" "kaakko" "etelä" "lounas" "länsi" "luode" ] + set weather_msg_result [list "\002@station@\002, mitattu klo @ctime@: \002@temp@°C\002"] lappend weather_msg_result ", tien pinta @rv_2@°C" diff -r 120eb7eb7398 -r 0d6dfcc1c957 weather.tcl --- a/weather.tcl Tue Jan 21 22:34:15 2020 +0200 +++ b/weather.tcl Tue Jan 21 22:56:37 2020 +0200 @@ -126,6 +126,19 @@ } +# Translate wind direction compass degree to name +proc weather_get_wind_direction {udegree} { + global weather_msg_wind_directions + + set udir [expr int(floor((fmod($udegree, 360.0) + 45.0/2) / 45.0))] + if {$udir < [llength $weather_msg_wind_directions]} { + return [lindex $weather_msg_wind_directions $udir] + } else { + return "ERROR" + } +} + + #------------------------------------------------------------------------- # Produce one location of weather data as a string proc weather_get_str {udata umsg} { @@ -140,7 +153,8 @@ set uvals(temp) [lindex $udata 6] set uvals(humidity) [lindex $udata 7] set uvals(wind_speed) [lindex $udata 8] - set uvals(wind_direction) [lindex $udata 9] + set wdeg [lindex $udata 9] + set uvals(wind_direction) "[weather_get_wind_direction $wdeg] ($wdeg)" if {[expr [clock seconds] - $uvals(vtime)] < 3600} { set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"]