changeset 490:0d6dfcc1c957

weather: Add translation of weather direction angle.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Jan 2020 22:56:37 +0200
parents 120eb7eb7398
children f5c023538e2a
files config.weather.example weather.tcl
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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"
--- 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"]