Skip to content

Commit

Permalink
start using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanBall committed Nov 3, 2023
1 parent 6b56aae commit 441e5be
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 291 deletions.
13 changes: 5 additions & 8 deletions display_themes/examples/simulate_theme_1.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use airquamon_domain::Data;
use display_themes::{Theme, Theme1};
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{SimulatorDisplay, Window, OutputSettingsBuilder};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use epd_waveshare::color::TriColor;
use display_themes::{Theme, Theme1};
use airquamon_domain::Data;


fn main() -> Result<(), core::convert::Infallible> {
let mut display = SimulatorDisplay::<TriColor>::new(Size::new(296, 128));

let data = Data{
let data = Data {
co2: 459,
temperature: 20.59,
humidity: 57.42,
Expand All @@ -17,9 +16,7 @@ fn main() -> Result<(), core::convert::Infallible> {
let mut theme1 = Theme1::new();
theme1.draw(&data, &mut display).unwrap();

let output_settings = OutputSettingsBuilder::new()
.scale(2)
.build();
let output_settings = OutputSettingsBuilder::new().scale(2).build();
Window::new("Airquamon Simulator", &output_settings).show_static(&display);

Ok(())
Expand Down
13 changes: 5 additions & 8 deletions display_themes/examples/simulate_theme_2.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use airquamon_domain::Data;
use display_themes::{Theme, Theme2};
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{SimulatorDisplay, Window, OutputSettingsBuilder};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use epd_waveshare::color::TriColor;
use display_themes::{Theme, Theme2};
use airquamon_domain::Data;


fn main() -> Result<(), core::convert::Infallible> {
let mut display = SimulatorDisplay::<TriColor>::new(Size::new(296, 128));

let data = Data{
let data = Data {
co2: 900,
temperature: 20.59,
humidity: 57.42,
Expand All @@ -17,9 +16,7 @@ fn main() -> Result<(), core::convert::Infallible> {
let mut theme = Theme2::new();
theme.draw(&data, &mut display).unwrap();

let output_settings = OutputSettingsBuilder::new()
.scale(2)
.build();
let output_settings = OutputSettingsBuilder::new().scale(2).build();
Window::new("Airquamon Simulator", &output_settings).show_static(&display);

Ok(())
Expand Down
20 changes: 12 additions & 8 deletions display_themes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![no_std]

use airquamon_domain::Data;
use embedded_graphics::prelude::*;
use core::fmt;
use embedded_graphics::prelude::*;

mod theme_1;
pub use theme_1::Theme1;
Expand All @@ -11,11 +11,15 @@ mod theme_2;
pub use theme_2::Theme2;

pub trait Theme<COLOR>
where
COLOR: PixelColor,
where
COLOR: PixelColor,
{
fn draw<DRAWTARGET>(&mut self, data: &Data, display: &mut DRAWTARGET) -> Result<(), DRAWTARGET::Error>
where
DRAWTARGET: DrawTarget<Color = COLOR> + OriginDimensions,
DRAWTARGET::Error: fmt::Debug;
}
fn draw<DRAWTARGET>(
&mut self,
data: &Data,
display: &mut DRAWTARGET,
) -> Result<(), DRAWTARGET::Error>
where
DRAWTARGET: DrawTarget<Color = COLOR> + OriginDimensions,
DRAWTARGET::Error: fmt::Debug;
}
55 changes: 36 additions & 19 deletions display_themes/src/theme_1.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
use crate::Theme;
use airquamon_domain::Data;
use core::fmt;
use core::fmt::Write;
use embedded_graphics::{
mono_font::{MonoTextStyleBuilder, iso_8859_1::FONT_8X13_BOLD},
mono_font::{iso_8859_1::FONT_8X13_BOLD, MonoTextStyleBuilder},
prelude::*,
primitives::{Line, PrimitiveStyle},
text::{Baseline, Text, TextStyleBuilder},
};
use epd_waveshare::color::TriColor;
use heapless::String;
use core::fmt::Write;
use core::fmt;

pub struct Theme1 {
display_text: String<60>,
}

impl Theme1 {
pub fn new() -> Self {
Theme1 {
Theme1 {
display_text: String::new(),
}
}
}

impl Theme<TriColor> for Theme1
{
fn draw<DRAWTARGET>(&mut self, data: &Data, display: &mut DRAWTARGET) -> Result<(), DRAWTARGET::Error>
where
DRAWTARGET: DrawTarget<Color = TriColor> + OriginDimensions,
DRAWTARGET::Error: fmt::Debug
impl Theme<TriColor> for Theme1 {
fn draw<DRAWTARGET>(
&mut self,
data: &Data,
display: &mut DRAWTARGET,
) -> Result<(), DRAWTARGET::Error>
where
DRAWTARGET: DrawTarget<Color = TriColor> + OriginDimensions,
DRAWTARGET::Error: fmt::Debug,
{
self.display_text.clear();
write!(self.display_text, "CO2: {0} ppm | {1:#.2} °C | {2:#.2} %", data.co2, data.temperature, data.humidity).expect("Error occurred while trying to write in String");
write!(
self.display_text,
"CO2: {0} ppm | {1:#.2} °C | {2:#.2} %",
data.co2, data.temperature, data.humidity
)
.expect("Error occurred while trying to write in String");
let _ = Line::new(
Point::new(5, display.size().height as i32 / 2),
Point::new(display.size().width as i32 - 5, display.size().height as i32 / 2)
)
.into_styled(PrimitiveStyle::with_stroke(TriColor::Chromatic, 4))
.draw(display);
Point::new(5, display.size().height as i32 / 2),
Point::new(
display.size().width as i32 - 5,
display.size().height as i32 / 2,
),
)
.into_styled(PrimitiveStyle::with_stroke(TriColor::Chromatic, 4))
.draw(display);
draw_text(display, &self.display_text, 5, 10)?;
Ok(())
}
}

fn draw_text<DRAWTARGET>(display: &mut DRAWTARGET, text: &str, x: i32, y: i32) -> Result<(), DRAWTARGET::Error>
fn draw_text<DRAWTARGET>(
display: &mut DRAWTARGET,
text: &str,
x: i32,
y: i32,
) -> Result<(), DRAWTARGET::Error>
where
DRAWTARGET: DrawTarget<Color = TriColor> {
DRAWTARGET: DrawTarget<Color = TriColor>,
{
let style = MonoTextStyleBuilder::new()
.font(&FONT_8X13_BOLD)
.text_color(TriColor::Black)
Expand All @@ -56,4 +73,4 @@ where

Text::with_text_style(text, Point::new(x, y), style, text_style).draw(display)?;
Ok(())
}
}
Loading

0 comments on commit 441e5be

Please sign in to comment.