From bb693ac02605d318e641f929cc2abc956c19e51b Mon Sep 17 00:00:00 2001 From: Felix Wittwer Date: Sat, 6 Aug 2022 01:52:25 +0200 Subject: [PATCH] Add layout draft for weather --- src/lib.rs | 11 ++++++ src/weather/data.rs | 0 src/weather/mod.rs | 92 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/weather/data.rs create mode 100644 src/weather/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 0e6f48b..3dd090b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,18 @@ use std::process::Command; use std::{fs, io}; use tinybmp::Bmp; +mod weather; + pub fn populate(display: &mut D) +where + D: DrawTarget, + D::Error: Debug, +{ + weather::get_weather(display) +} + + +pub fn populate_default(display: &mut D) where D: DrawTarget, D::Error: Debug, diff --git a/src/weather/data.rs b/src/weather/data.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/weather/mod.rs b/src/weather/mod.rs new file mode 100644 index 0000000..81ce681 --- /dev/null +++ b/src/weather/mod.rs @@ -0,0 +1,92 @@ +use embedded_graphics::{ + draw_target::DrawTarget, + image::Image, + mono_font::MonoTextStyle, + prelude::*, + text::Text +}; +use profont::{PROFONT_12_POINT, PROFONT_14_POINT, PROFONT_24_POINT, PROFONT_9_POINT, PROFONT_7_POINT}; +use ssd1675::Color; +use std::fmt::Debug; +use tinybmp::Bmp; + +mod data; + + +pub fn get_weather(display: &mut D) +where + D: DrawTarget, + D::Error: Debug, +{ + // draw image + let bmp_data = include_bytes!("../../rain2.bmp"); + let bmp = Bmp::::from_slice(bmp_data).unwrap(); + Image::new(&bmp, Point::new(10, 10)) + .draw(display) + .expect("Failed to draw image"); + + Text::new( + &format!("{:.1}°C", -28.1), + Point::new(75, 28), + MonoTextStyle::new(&PROFONT_24_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + "gefühlt: 12°C", + Point::new(75, 39), + MonoTextStyle::new(&PROFONT_9_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("{:2.0}%", 32), + Point::new(10, 62), + MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("Regen\nWahrsch."), + Point::new(44, 55), + MonoTextStyle::new(&PROFONT_7_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("{:2.0}%", 2.0), + Point::new(10, 81), + MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("Luft\nfeuchte"), + Point::new(44, 74), + MonoTextStyle::new(&PROFONT_7_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("{:2.0}", 3), + Point::new(20, 100), + MonoTextStyle::new(&PROFONT_14_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + + Text::new( + &format!("UV\nIdx"), + Point::new(44, 93), + MonoTextStyle::new(&PROFONT_7_POINT, Color::Black), + ) + .draw(display) + .expect("error drawing text"); + +}