diff --git a/assets/cloudsun.bmp b/assets/cloudsun.bmp new file mode 100644 index 0000000..f7be29d Binary files /dev/null and b/assets/cloudsun.bmp differ diff --git a/assets/cloudy.bmp b/assets/cloudy.bmp new file mode 100644 index 0000000..8f32980 Binary files /dev/null and b/assets/cloudy.bmp differ diff --git a/assets/drizzle.bmp b/assets/drizzle.bmp new file mode 100644 index 0000000..dfa7f21 Binary files /dev/null and b/assets/drizzle.bmp differ diff --git a/assets/rain.bmp b/assets/rain.bmp new file mode 100644 index 0000000..12cc500 Binary files /dev/null and b/assets/rain.bmp differ diff --git a/assets/snow.bmp b/assets/snow.bmp new file mode 100644 index 0000000..e157c06 Binary files /dev/null and b/assets/snow.bmp differ diff --git a/assets/sunny.bmp b/assets/sunny.bmp new file mode 100644 index 0000000..2072ffd Binary files /dev/null and b/assets/sunny.bmp differ diff --git a/assets/thunder.bmp b/assets/thunder.bmp new file mode 100644 index 0000000..a442dc3 Binary files /dev/null and b/assets/thunder.bmp differ diff --git a/rain2.bmp b/rain2.bmp deleted file mode 100644 index 223b185..0000000 Binary files a/rain2.bmp and /dev/null differ diff --git a/src/lib.rs b/src/lib.rs index 3dd090b..1e0d548 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ where .expect("error drawing text"); } - let bmp_data = include_bytes!("../rain2.bmp"); + let bmp_data = include_bytes!("../assets/rain.bmp"); // Load 16 BPP 8x8px image. // Note: The color type is specified explicitly to match the format used by the BMP image. diff --git a/src/weather/data.rs b/src/weather/data.rs index 3d189b4..57506b5 100644 --- a/src/weather/data.rs +++ b/src/weather/data.rs @@ -7,6 +7,9 @@ use embedded_plots::curve::PlotPoint; use serde::Deserialize; +use ssd1675::Color; +use tinybmp::Bmp; +use super::icons; /// Response from the OpenWeather API with both current and forecast data for a given location. #[derive(Deserialize)] @@ -55,6 +58,10 @@ impl WeatherData { self.current.data.uvi.round() as u8 } + pub fn current_condition(&self) -> Bmp<'static, Color> { + unimplemented!() + } + pub fn forecast_plot_data(&self) -> Vec { let data: Vec = self.hourly.iter().take(24).map(|h| h.data.temp).collect(); @@ -186,6 +193,7 @@ pub enum WeatherCondition { Squall, Tornado, Clear, + SunClouds, Clouds, } @@ -207,9 +215,39 @@ impl From for WeatherCondition { 771 => Self::Squall, 781 => Self::Tornado, 800 => Self::Clear, - 801..=804 => Self::Clouds, + 801|802 => Self::SunClouds, + 803|804 => Self::Clouds, // NOTE(feliix42): There's no `Error` mapping or something like that. _ => Self::Clear, } } } + +impl Into> for WeatherCondition { + /// gets a bitmap for each current weather condition. + fn into(self) -> Bmp<'static, Color> { + let bmp = match self { + Self::Thunderstorm => icons::THUNDER, + Self::Drizzle => icons::DRIZZLE, + Self::Rain => icons::RAIN, + Self::Snow => icons::SNOW, + Self::Mist => icons::MIST, + Self::Smoke => icons::SMOKE, + Self::Haze => icons::HAZE, + Self::SandDust => icons::SANDDUST, + Self::Fog => icons::FOG, + Self::Sand => icons::SAND, + Self::Dust => icons::DUST, + Self::Ash => icons::ASH, + Self::Squall => icons::SQUALL, + Self::Tornado => icons::TORNADO, + // TODO(feliix42): Show Moon(phases) here after sundown + Self::Clear => icons::CLEAR, + Self::Clouds => icons::CLOUDS, + Self::SunClouds => icons::SUNCLOUDS, + }; + + Bmp::from_slice(bmp).unwrap() + } +} + diff --git a/src/weather/icons.rs b/src/weather/icons.rs new file mode 100644 index 0000000..f063051 --- /dev/null +++ b/src/weather/icons.rs @@ -0,0 +1,25 @@ +//! Icons for different weather conditions. +//! +//! This module contains raw byte arrays for different weather conditions supported by the +//! OpenWeather API v3. They are loaded and parsed by the `WeatherCondition::into` function. + +pub static THUNDER: &'static [u8] = include_bytes!("../../assets/thunder.bmp"); +pub static DRIZZLE: &'static [u8] = include_bytes!("../../assets/drizzle.bmp"); +pub static RAIN: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static SNOW: &'static [u8] = include_bytes!("../../assets/snow.bmp"); + +// TODO(feliix42): replace assets +pub static MIST: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static SMOKE: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static HAZE: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static SANDDUST: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static FOG: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static SAND: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static DUST: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static ASH: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static SQUALL: &'static [u8] = include_bytes!("../../assets/rain.bmp"); +pub static TORNADO: &'static [u8] = include_bytes!("../../assets/rain.bmp"); + +pub static CLEAR: &'static [u8] = include_bytes!("../../assets/sunny.bmp"); +pub static CLOUDS: &'static [u8] = include_bytes!("../../assets/cloudy.bmp"); +pub static SUNCLOUDS: &'static [u8] = include_bytes!("../../assets/cloudsun.bmp"); diff --git a/src/weather/mod.rs b/src/weather/mod.rs index ac1c447..e1baf32 100644 --- a/src/weather/mod.rs +++ b/src/weather/mod.rs @@ -12,11 +12,11 @@ use profont::{ use ssd1675::Color; use std::error::Error; use std::fmt::Debug; -use tinybmp::Bmp; mod api; mod data; mod secret; +mod icons; pub fn get_weather(display: &mut D) where @@ -32,8 +32,7 @@ where }; // draw image - let bmp_data = include_bytes!("../../rain2.bmp"); - let bmp = Bmp::::from_slice(bmp_data).unwrap(); + let bmp = weather_data.current_condition(); Image::new(&bmp, Point::new(10, 10)) .draw(display) .expect("Failed to draw image");