Compare commits
2 commits
b8c2dea685
...
0381b8d14c
Author | SHA1 | Date | |
---|---|---|---|
0381b8d14c | |||
2d2ca44ef5 |
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/fog.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/thick-fog.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/thunder.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
assets/wind.bmp
Normal file
After Width: | Height: | Size: 402 B |
BIN
rain2.bmp
Before Width: | Height: | Size: 402 B |
|
@ -18,6 +18,7 @@ where
|
||||||
weather::get_weather(display)
|
weather::get_weather(display)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(feliix42): Remove dead code here
|
||||||
|
|
||||||
pub fn populate_default<D>(display: &mut D)
|
pub fn populate_default<D>(display: &mut D)
|
||||||
where
|
where
|
||||||
|
@ -69,7 +70,7 @@ where
|
||||||
.expect("error drawing text");
|
.expect("error drawing text");
|
||||||
}
|
}
|
||||||
|
|
||||||
let bmp_data = include_bytes!("../rain2.bmp");
|
let bmp_data = include_bytes!("../assets/rain.bmp");
|
||||||
|
|
||||||
// Load 16 BPP 8x8px image.
|
// Load 16 BPP 8x8px image.
|
||||||
// Note: The color type is specified explicitly to match the format used by the BMP 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 embedded_plots::curve::PlotPoint;
|
||||||
use serde::Deserialize;
|
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.
|
/// Response from the OpenWeather API with both current and forecast data for a given location.
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -55,6 +58,10 @@ impl WeatherData {
|
||||||
self.current.data.uvi.round() as u8
|
self.current.data.uvi.round() as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn current_condition(&self) -> Bmp<'static, Color> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn forecast_plot_data(&self) -> Vec<PlotPoint> {
|
pub fn forecast_plot_data(&self) -> Vec<PlotPoint> {
|
||||||
let data: Vec<f32> = self.hourly.iter().take(24).map(|h| h.data.temp).collect();
|
let data: Vec<f32> = self.hourly.iter().take(24).map(|h| h.data.temp).collect();
|
||||||
|
|
||||||
|
@ -186,6 +193,7 @@ pub enum WeatherCondition {
|
||||||
Squall,
|
Squall,
|
||||||
Tornado,
|
Tornado,
|
||||||
Clear,
|
Clear,
|
||||||
|
SunClouds,
|
||||||
Clouds,
|
Clouds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,9 +215,39 @@ impl From<u16> for WeatherCondition {
|
||||||
771 => Self::Squall,
|
771 => Self::Squall,
|
||||||
781 => Self::Tornado,
|
781 => Self::Tornado,
|
||||||
800 => Self::Clear,
|
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.
|
// NOTE(feliix42): There's no `Error` mapping or something like that.
|
||||||
_ => Self::Clear,
|
_ => 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
24
src/weather/icons.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//! 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");
|
||||||
|
|
||||||
|
pub static MIST: &'static [u8] = include_bytes!("../../assets/fog.bmp");
|
||||||
|
pub static SMOKE: &'static [u8] = include_bytes!("../../assets/thick-fog.bmp");
|
||||||
|
pub static HAZE: &'static [u8] = include_bytes!("../../assets/fog.bmp");
|
||||||
|
pub static SANDDUST: &'static [u8] = include_bytes!("../../assets/thick-fog.bmp");
|
||||||
|
pub static FOG: &'static [u8] = include_bytes!("../../assets/fog.bmp");
|
||||||
|
pub static SAND: &'static [u8] = include_bytes!("../../assets/thick-fog.bmp");
|
||||||
|
pub static DUST: &'static [u8] = include_bytes!("../../assets/thick-fog.bmp");
|
||||||
|
pub static ASH: &'static [u8] = include_bytes!("../../assets/thick-fog.bmp");
|
||||||
|
pub static SQUALL: &'static [u8] = include_bytes!("../../assets/wind.bmp");
|
||||||
|
pub static TORNADO: &'static [u8] = include_bytes!("../../assets/wind.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 ssd1675::Color;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use tinybmp::Bmp;
|
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod data;
|
mod data;
|
||||||
mod secret;
|
mod secret;
|
||||||
|
mod icons;
|
||||||
|
|
||||||
pub fn get_weather<D>(display: &mut D)
|
pub fn get_weather<D>(display: &mut D)
|
||||||
where
|
where
|
||||||
|
@ -32,8 +32,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
// draw image
|
// draw image
|
||||||
let bmp_data = include_bytes!("../../rain2.bmp");
|
let bmp = weather_data.current_condition();
|
||||||
let bmp = Bmp::<Color>::from_slice(bmp_data).unwrap();
|
|
||||||
Image::new(&bmp, Point::new(10, 10))
|
Image::new(&bmp, Point::new(10, 10))
|
||||||
.draw(display)
|
.draw(display)
|
||||||
.expect("Failed to draw image");
|
.expect("Failed to draw image");
|
||||||
|
|