Dummy plot implementation

This commit is contained in:
Michał Chodzikiewicz 2020-12-18 00:23:15 +01:00
parent e74a39d396
commit 242d8eb750
3 changed files with 64 additions and 2 deletions

View file

@ -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"

View file

@ -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<Rgb565> = 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(())
}

View file

@ -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<C>
{
data: Vec<Point>,
color: C,
}
impl<C> Plot<C>
where C: PixelColor
{
pub fn new(data: Vec<Point>,color : C) -> Plot<C> {
Plot {
data,
color,
}
}
}
impl<C> Drawable<C> for Plot<C>
where C: PixelColor
{
fn draw<D: DrawTarget<C>>(self, display: &mut D) -> Result<(), <D as DrawTarget<C>>::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]