Skip to content

Commit f56bb1c

Browse files
authored
Merge pull request #12 from mt-empty/feature/wind-speed-unit
Feature/wind speed unit
2 parents c308d96 + 23c82f4 commit f56bb1c

File tree

10 files changed

+226
-63
lines changed

10 files changed

+226
-63
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pi-inky-weather-epd"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition = "2021"
55
authors = ["MT"]
66
description = "A weather display application for the Raspberry Pi using an EPD (e-paper display)."

config/default.toml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
[release]
22
release_info_url = "https://api.github.com/repos/mt-empty/pi-inky-weather-epd/releases/latest"
33
download_base_url = "https://github.com/mt-empty/pi-inky-weather-epd/releases/download"
4-
# set to 0 to disable auto-updating
5-
update_interval_days = 7
4+
update_interval_days = 0 # Set to 0 to disable auto-updating
65

76
[api]
8-
provider = "open_meteo" # bom or open_meteo
9-
latitude = -37.8136
7+
# Note: The weather data reflects the selected location’s conditions, but all times are displayed
8+
# according to your device’s (local) timezone. this should be fine for almost all users.
9+
latitude = -37.8136 # Melbourne, Australia
1010
longitude = 144.9631
11+
provider = "open_meteo" # Options: bom, open_meteo
1112

12-
# supported colours for 7.3 inky display
13-
# [black, white, green, blue, red, yellow, orange]
1413
[colours]
14+
# Supported colours for 7.3" Inky Impression display:
15+
# [black, white, green, blue, red, yellow, orange]
16+
background_colour = "white"
17+
text_colour = "black"
18+
x_axis_colour = "black"
19+
y_left_axis_colour = "red" # Temperature axis
20+
y_right_axis_colour = "blue" # Rain scale
21+
actual_temp_colour = "red"
22+
feels_like_colour = "green"
23+
rain_colour = "blue"
24+
25+
## Dark Mode Example
1526
# background_colour = "black" # solid black – no dithering
1627
# text_colour = "white" # bright white for max legibility
1728

@@ -23,21 +34,12 @@ longitude = 144.9631
2334
# feels_like_colour = "green" # dashed “feels-like” line
2435
# rain_colour = "blue" # shaded rain bars
2536

26-
background_colour = "white"
27-
text_colour = "black"
28-
x_axis_colour = "black"
29-
y_left_axis_colour = "red"
30-
y_right_axis_colour = "blue"
31-
actual_temp_colour = "red"
32-
feels_like_colour = "green"
33-
rain_colour = "blue"
3437

3538
[render_options]
36-
temp_unit = "C"
37-
# When the sky is clear, the moon phase icon will be used instead of the clear night icon
38-
use_moon_phase_instead_of_clear_night = true
39-
# this controls the placement of the x-axis when the temperature is below zero
40-
x_axis_always_at_min = true
39+
temp_unit = "C" # Options: C, F
40+
wind_speed_unit = "km/h" # Options: km/h, mph, knots
41+
use_moon_phase_instead_of_clear_night = true # When the sky is clear, the moon phase icon will be used instead of the clear night icon
42+
x_axis_always_at_min = true # Controls x-axis placement when temp is below zero
4143
use_gust_instead_of_wind = false
4244

4345
[misc]
@@ -48,6 +50,6 @@ generated_png_name = "dashboard.png"
4850
svg_icons_directory = "static/fill-svg-static/"
4951

5052
[debugging]
51-
disable_weather_api_requests = false # if true, the weather data will be loaded from a cached file instead of the API, make you ran the application at least once with this set to false
53+
disable_weather_api_requests = false # Load cached data instead of making API requests (requires at least one successful run first)
5254
disable_png_output = false
5355
allow_pre_release_version = false

config/development.toml

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
[release]
22
release_info_url = "https://api.github.com/repos/mt-empty/pi-inky-weather-epd/releases/latest"
33
download_base_url = "https://github.com/mt-empty/pi-inky-weather-epd/releases/download"
4-
# set to 0 to disable auto-updating
5-
update_interval_days = 0
4+
update_interval_days = 0 # Set to 0 to disable auto-updating
65

76
[api]
8-
provider = "open_meteo" # bom or open_meteo
9-
latitude = -37.8136
7+
# Note: The weather data reflects the selected location’s conditions, but all times are displayed
8+
# according to your device’s (local) timezone. this should be fine for almost all users.
9+
latitude = -37.8136 # Melbourne, Australia
1010
longitude = 144.9631
11+
provider = "open_meteo" # Options: bom, open_meteo
1112

12-
# supported colours for 7.3 inky display
13-
# [black, white, green, blue, red, yellow, orange]
1413
[colours]
14+
# Supported colours for 7.3" Inky Impression display:
15+
# [black, white, green, blue, red, yellow, orange]
16+
background_colour = "white"
17+
text_colour = "black"
18+
x_axis_colour = "black"
19+
y_left_axis_colour = "red" # Temperature axis
20+
y_right_axis_colour = "blue" # Rain scale
21+
actual_temp_colour = "red"
22+
feels_like_colour = "green"
23+
rain_colour = "blue"
24+
25+
## Dark Mode Example
1526
# background_colour = "black" # solid black – no dithering
1627
# text_colour = "white" # bright white for max legibility
1728

@@ -23,21 +34,12 @@ longitude = 144.9631
2334
# feels_like_colour = "green" # dashed “feels-like” line
2435
# rain_colour = "blue" # shaded rain bars
2536

26-
background_colour = "white"
27-
text_colour = "black"
28-
x_axis_colour = "black"
29-
y_left_axis_colour = "red"
30-
y_right_axis_colour = "blue"
31-
actual_temp_colour = "red"
32-
feels_like_colour = "green"
33-
rain_colour = "blue"
3437

3538
[render_options]
36-
temp_unit = "C"
37-
# When the sky is clear, the moon phase icon will be used instead of the clear night icon
38-
use_moon_phase_instead_of_clear_night = true
39-
# this controls the placement of the x-axis when the temperature is below zero
40-
x_axis_always_at_min = true
39+
temp_unit = "C" # Options: C, F
40+
wind_speed_unit = "km/h" # Options: km/h, mph, knots
41+
use_moon_phase_instead_of_clear_night = true # When the sky is clear, the moon phase icon will be used instead of the clear night icon
42+
x_axis_always_at_min = true # Controls x-axis placement when temp is below zero
4143
use_gust_instead_of_wind = false
4244

4345
[misc]
@@ -48,53 +50,58 @@ generated_png_name = "dashboard.png"
4850
svg_icons_directory = "static/fill-svg-static/"
4951

5052
[debugging]
51-
disable_weather_api_requests = false # if true, the weather data will be loaded from a cached file instead of the API, make you ran the application at least once with this set to false
53+
disable_weather_api_requests = false # Load cached data instead of making API requests (requires at least one successful run first)
5254
disable_png_output = false
5355
allow_pre_release_version = true
5456

57+
# ============================================================================
58+
# Alternative Locations (for testing)
59+
# ============================================================================
5560

56-
### Extreme
57-
## Babinda, QLD
61+
# Extreme Weather Locations
62+
# -------------------------
63+
# Babinda, QLD (high rainfall)
5864
# latitude = -17.3447
5965
# longitude = 145.9259
6066

61-
## Marble Bar, NSW
62-
# latitude = -27.2983
63-
# longitude = 133.6212
67+
# Marble Bar, WA (extreme heat)
68+
# latitude = -21.1767
69+
# longitude = 119.7491
6470

65-
## Tasmanian heights, TAS
71+
# Tasmanian Highlands (cold)
6672
# latitude = -41.9101
6773
# longitude = 146.8158
6874

69-
## Major Cities
70-
## Darwin
75+
# Major Australian Cities
76+
# -----------------------
77+
# Darwin
7178
# latitude = -12.4612
7279
# longitude = 130.8417
7380

74-
## Sydney
81+
# Sydney
7582
# latitude = -33.8681
7683
# longitude = 151.2103
7784

78-
## Melbourne
85+
# Melbourne
7986
# latitude = -37.8122
8087
# longitude = 144.9591
8188

82-
## Brisbane
89+
# Brisbane
8390
# latitude = -27.4960
8491
# longitude = 153.0341
8592

86-
## Perth
87-
# latitude = -41.5750
88-
# longitude = 147.1674
93+
# Perth
94+
# latitude = -31.9523
95+
# longitude = 115.8614
8996

90-
## Adelaide
97+
# Adelaide
9198
# latitude = -34.9283
9299
# longitude = 138.5980
93100

94-
## Hobart
101+
# Hobart
95102
# latitude = -42.8769
96103
# longitude = 147.3322
97104

98-
## Canberra
105+
# Canberra
99106
# latitude = -35.2853
100107
# longitude = 149.1229

dashboard-template-min.svg

Lines changed: 1 addition & 1 deletion
Loading

pi-inky-weather-epd.code-workspace

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"[rust]": {
1313
"editor.defaultFormatter": "rust-lang.rust-analyzer"
1414
},
15+
"[svg]": {
16+
"editor.formatOnSave": false
17+
},
18+
"workbench.editorAssociations": {
19+
"*.svg": "default"
20+
},
1521
"files.trimTrailingWhitespace": true,
1622
"files.insertFinalNewline": true,
1723
"files.trimFinalNewlines": true,
@@ -25,6 +31,7 @@
2531
"rust-analyzer.check.command": "clippy",
2632
"rust-analyzer.cargo.features": "all",
2733
// Spell Check
34+
"cSpell.language": "en-au",
2835
"cSpell.words": [
2936
"meteo",
3037
"aarch",

readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Note, the gif and images are a bit outdated, specifically UV icon colour changes
4747
mkdir -p ~/.config
4848
cat > ~/.config/pi-inky-weather-epd.toml << EOF
4949
[api]
50-
provider = "open_meteo" # "open_meteo" (worldwide) or "bom" (Australia only)
5150
latitude = YOUR_LATITUDE # e.g., -33.8727 # Sydney
5251
longitude = YOUR_LONGITUDE # e.g., 151.2057
52+
provider = "open_meteo" # "open_meteo" (worldwide) or "bom" (Australia only)
5353
EOF
5454
```
5555
@@ -89,6 +89,13 @@ Here are example configurations. Note: some of these images are slightly outdate
8989
9090
<img src="./misc/dashboard-default.png" alt="Default configuration" width="600"/>
9191
92+
### Imperial Units
93+
```toml
94+
[render_options]
95+
temp_unit = "F"
96+
wind_speed_unit = "mph"
97+
```
98+
9299
### Use Clear night Icon instead of Moon Phase icon when Time=night and Weather=clear
93100
94101
<img src="./misc/dashboard-without-moon-phase.png" alt="Moon phase configuration" width="600"/>

src/configs/settings.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ pub enum TemperatureUnit {
2525
F,
2626
}
2727

28+
#[derive(Debug, Deserialize, PartialOrd, PartialEq, Clone, Copy, Display)]
29+
pub enum WindSpeedUnit {
30+
#[serde(rename = "km/h")]
31+
#[strum(serialize = "km/h")]
32+
KmH,
33+
#[serde(rename = "mph")]
34+
#[strum(serialize = "mph")]
35+
Mph,
36+
#[serde(rename = "knots")]
37+
#[strum(serialize = "knots")]
38+
Knots,
39+
}
40+
2841
#[nutype(
2942
sanitize(trim),
3043
validate(with = is_valid_colour, error = ValidationError),
@@ -129,6 +142,7 @@ pub struct Misc {
129142
#[derive(Debug, Deserialize, Clone)]
130143
pub struct RenderOptions {
131144
pub temp_unit: TemperatureUnit,
145+
pub wind_speed_unit: WindSpeedUnit,
132146
pub use_moon_phase_instead_of_clear_night: bool,
133147
pub x_axis_always_at_min: bool,
134148
pub use_gust_instead_of_wind: bool,

src/dashboard/context.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Context {
3333
pub max_relative_humidity_font_style: String,
3434
pub total_rain_today: String,
3535
pub temp_unit: String,
36+
pub current_wind_speed_unit: String,
3637
pub current_hour_actual_temp: String,
3738
pub current_hour_weather_icon: String,
3839
pub current_hour_feels_like: String,
@@ -121,6 +122,7 @@ impl Default for Context {
121122
max_relative_humidity_font_style: FontStyle::Normal.to_string(),
122123
total_rain_today: na.clone(),
123124
temp_unit: render_options.temp_unit.to_string(),
125+
current_wind_speed_unit: render_options.wind_speed_unit.to_string(),
124126
current_hour_actual_temp: na.clone(),
125127
current_hour_weather_icon: not_available_icon_path.clone(),
126128
current_hour_feels_like: na.clone(),
@@ -567,7 +569,10 @@ impl ContextBuilder {
567569
fn set_now_values_for_table(&mut self, current_hour: &HourlyForecast) {
568570
self.context.current_hour_wind_speed = current_hour
569571
.wind
570-
.get_speed(CONFIG.render_options.use_gust_instead_of_wind)
572+
.get_speed_in_unit(
573+
CONFIG.render_options.use_gust_instead_of_wind,
574+
CONFIG.render_options.wind_speed_unit,
575+
)
571576
.to_string();
572577
self.context.current_hour_wind_icon = current_hour.wind.get_icon_path();
573578
self.context.current_hour_uv_index = current_hour.uv_index.to_string();
@@ -625,10 +630,20 @@ impl ContextBuilder {
625630
.wind
626631
.get_speed(CONFIG.render_options.use_gust_instead_of_wind));
627632

633+
// Convert wind speed to configured unit
634+
let max_wind_today_converted = crate::domain::models::Wind::convert_speed(
635+
max_wind_today,
636+
CONFIG.render_options.wind_speed_unit,
637+
);
638+
let max_wind_tomorrow_converted = crate::domain::models::Wind::convert_speed(
639+
max_wind_tomorrow,
640+
CONFIG.render_options.wind_speed_unit,
641+
);
642+
628643
if max_wind_today > max_wind_tomorrow {
629-
self.context.max_gust_speed = max_wind_today.to_string();
644+
self.context.max_gust_speed = max_wind_today_converted.to_string();
630645
} else {
631-
self.context.max_gust_speed = max_wind_tomorrow.to_string();
646+
self.context.max_gust_speed = max_wind_tomorrow_converted.to_string();
632647
self.context.max_gust_speed_font_style = FontStyle::Italic.to_string();
633648
}
634649

src/domain/models.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ impl Wind {
106106
self.speed_kmh
107107
}
108108
}
109+
110+
/// Convert wind speed from km/h to the specified unit
111+
pub fn convert_speed(speed_kmh: u16, unit: crate::configs::settings::WindSpeedUnit) -> u16 {
112+
use crate::configs::settings::WindSpeedUnit;
113+
match unit {
114+
WindSpeedUnit::KmH => speed_kmh,
115+
WindSpeedUnit::Mph => (speed_kmh as f64 * 0.621371).round() as u16,
116+
WindSpeedUnit::Knots => (speed_kmh as f64 * 0.539957).round() as u16,
117+
}
118+
}
119+
120+
/// Get the wind speed in the configured unit
121+
pub fn get_speed_in_unit(
122+
&self,
123+
use_gust: bool,
124+
unit: crate::configs::settings::WindSpeedUnit,
125+
) -> u16 {
126+
let speed_kmh = self.get_speed(use_gust);
127+
Self::convert_speed(speed_kmh, unit)
128+
}
109129
}
110130

111131
/// Domain model for precipitation information

0 commit comments

Comments
 (0)