feat: use different bitmaps for weather condition encoding
BIN
assets/cloudsun.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/cloudy.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/drizzle.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/rain.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/snow.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/sunny.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/thunder.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
rain2.bmp
Before Width: | Height: | Size: 402 B |
|
@ -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.
|
||||
|
|
|
@ -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<PlotPoint> {
|
||||
let data: Vec<f32> = 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<u16> 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<Bmp<'_, Color>> 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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
25
src/weather/icons.rs
Normal file
|
@ -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");
|
|
@ -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<D>(display: &mut D)
|
||||
where
|
||||
|
@ -32,8 +32,7 @@ where
|
|||
};
|
||||
|
||||
// draw image
|
||||
let bmp_data = include_bytes!("../../rain2.bmp");
|
||||
let bmp = Bmp::<Color>::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");
|
||||
|
|