From 242d8eb75097994a89b5edda32821eabc234edbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chodzikiewicz?= Date: Fri, 18 Dec 2020 00:23:15 +0100 Subject: [PATCH] Dummy plot implementation --- Cargo.toml | 4 ++++ examples/basic-plot/main.rs | 25 +++++++++++++++++++++++-- src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d394c8..0ddc088 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +embedded-graphics = "0.6.0" +[dev-dependencies] +embedded-graphics-simulator = "0.2.1" + diff --git a/examples/basic-plot/main.rs b/examples/basic-plot/main.rs index 646fa5e..5d16134 100644 --- a/examples/basic-plot/main.rs +++ b/examples/basic-plot/main.rs @@ -1,3 +1,24 @@ -fn main() { - println!("Hello world!"); +use embedded_graphics::{ + pixelcolor::Rgb565, + prelude::*, +}; +use embedded_graphics_simulator::{SimulatorDisplay, Window, OutputSettingsBuilder}; + +use embedded_plots::Plot; + +fn main() -> Result<(), core::convert::Infallible> { + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(480, 272)); + + Plot::new( + vec![ + Point::new(100, 100), + Point::new(150, 100), + Point::new(200, 200)],RgbColor::GREEN) + .draw(&mut display)?; + + let output_settings = OutputSettingsBuilder::new() + .build(); + Window::new("Hello World", &output_settings).show_static(&display); + + Ok(()) } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 31e1bb2..8322fed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,40 @@ +use embedded_graphics::drawable::{Drawable}; +use embedded_graphics::DrawTarget; +use embedded_graphics::geometry::Point; +use embedded_graphics::pixelcolor::{PixelColor}; +use embedded_graphics::primitives::{Line, Primitive}; +use embedded_graphics::style::PrimitiveStyle; + + +pub struct Plot +{ + data: Vec, + color: C, +} + +impl Plot + where C: PixelColor +{ + pub fn new(data: Vec,color : C) -> Plot { + Plot { + data, + color, + } + } +} + +impl Drawable for Plot + where C: PixelColor +{ + fn draw>(self, display: &mut D) -> Result<(), >::Error> { + let style = PrimitiveStyle::with_stroke(self.color,2); + for i in 1..self.data.len() { + Line::new(self.data[i-1],self.data[i]).into_styled(style).draw(display)?; + } + Ok(()) + } +} + #[cfg(test)] mod tests { #[test]