From dcaed6fb3e18a335abc3ab43e76fbe11fa5be135 Mon Sep 17 00:00:00 2001 From: Caemor <11088935+caemor@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:30:40 +0100 Subject: [PATCH] Update embedded-graphics and update epd4in2-blue-pill-exampleg --- Cargo.toml | 7 +- README.md | 2 +- examples/epd1in54_full/src/main.rs | 12 +- examples/epd2in9_full/src/main.rs | 12 +- examples/epd4in2_full/src/main.rs | 22 ++-- examples/epd4in2_full_blue_pill/Cargo.toml | 4 +- examples/epd4in2_full_blue_pill/src/main.rs | 122 +++++++----------- .../epd4in2_var_display_buffer/src/main.rs | 22 ++-- examples/epd7in5_full/src/main.rs | 22 ++-- examples/epd7in5_v2_full/src/main.rs | 22 ++-- src/color.rs | 9 +- src/epd1in54/graphics.rs | 54 ++++---- src/epd1in54/mod.rs | 2 +- src/epd1in54b/graphics.rs | 17 ++- src/epd2in9/graphics.rs | 17 ++- src/epd2in9/mod.rs | 2 +- src/epd4in2/graphics.rs | 54 ++++---- src/epd7in5/graphics.rs | 53 ++++---- src/epd7in5_v2/graphics.rs | 58 ++++----- src/graphics.rs | 101 ++++++++------- src/lib.rs | 2 +- 21 files changed, 289 insertions(+), 327 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 677ac97..9cac8b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,9 @@ edition = "2018" # `branch` is optional; default is `master` travis-ci = { repository = "caemor/epd-waveshare" } +[dependencies] +embedded-graphics = { version = "0.6.0-beta.2", optional = true} + [features] default = ["epd1in54", "epd1in54b", "epd2in9", "epd4in2", "epd7in5", "epd7in5_v2", "graphics"] @@ -30,9 +33,7 @@ epd7in5_v2 = [] # offers an alternative fast full lut for type_a displays, but the refresh isnt as clean looking type_a_alternative_faster_lut = [] -[dependencies.embedded-graphics] -optional = true -version = "0.5.2" + [dependencies.embedded-hal] features = ["unproven"] diff --git a/README.md b/README.md index 76a3cc1..2771eb9 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ display.draw( Font12x16::render_str("Hello Rust!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); diff --git a/examples/epd1in54_full/src/main.rs b/examples/epd1in54_full/src/main.rs index a308905..5742158 100644 --- a/examples/epd1in54_full/src/main.rs +++ b/examples/epd1in54_full/src/main.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing}; +use embedded_graphics::{fonts::Font6x8, prelude::*, Drawing, Point::Point}; use embedded_hal::prelude::*; use epd_waveshare::{ epd1in54::{Display1in54, EPD1in54}, @@ -82,7 +82,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -91,7 +91,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -100,7 +100,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -109,7 +109,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -134,7 +134,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 6, 50)) + .translate(Point::new(5 + i * 6, 50)) .into_iter(), ); diff --git a/examples/epd2in9_full/src/main.rs b/examples/epd2in9_full/src/main.rs index e4e25a0..a5834fe 100644 --- a/examples/epd2in9_full/src/main.rs +++ b/examples/epd2in9_full/src/main.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing}; +use embedded_graphics::{fonts::Font6x8, prelude::*, Drawing, Point::Point}; use embedded_hal::prelude::*; use epd_waveshare::{ epd2in9::{Display2in9, EPD2in9}, @@ -86,7 +86,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -95,7 +95,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -104,7 +104,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -113,7 +113,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -138,7 +138,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 6, 50)) + .translate(Point::new(5 + i * 6, 50)) .into_iter(), ); diff --git a/examples/epd4in2_full/src/main.rs b/examples/epd4in2_full/src/main.rs index b333b23..7cd880c 100644 --- a/examples/epd4in2_full/src/main.rs +++ b/examples/epd4in2_full/src/main.rs @@ -1,11 +1,11 @@ #![deny(warnings)] use embedded_graphics::{ - coord::Coord, fonts::{Font12x16, Font6x8}, prelude::*, primitives::{Circle, Line}, Drawing, + Point::Point, }; use embedded_hal::prelude::*; use epd_waveshare::{ @@ -77,7 +77,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -86,7 +86,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -95,7 +95,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -104,7 +104,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -119,17 +119,17 @@ fn run() -> Result<(), std::io::Error> { // draw a analog clock display.draw( - Circle::new(Coord::new(64, 64), 64) + Circle::new(Point::new(64, 64), 64) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(0, 64)) + let _ = Line::new(Point::new(64, 64), Point::new(0, 64)) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(80, 80)) + let _ = Line::new(Point::new(64, 64), Point::new(80, 80)) .stroke(Some(Color::Black)) .into_iter(), ); @@ -143,7 +143,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::White), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(175, 250)) + .translate(Point::new(175, 250)) .into_iter(), ); @@ -156,7 +156,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(50, 200)) + .translate(Point::new(50, 200)) .into_iter(), ); @@ -172,7 +172,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 12, 50)) + .translate(Point::new(5 + i * 12, 50)) .into_iter(), ); diff --git a/examples/epd4in2_full_blue_pill/Cargo.toml b/examples/epd4in2_full_blue_pill/Cargo.toml index b4abfbb..c759fb7 100644 --- a/examples/epd4in2_full_blue_pill/Cargo.toml +++ b/examples/epd4in2_full_blue_pill/Cargo.toml @@ -10,8 +10,8 @@ edition = "2018" #epd_waveshare = { path = "../../"} epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} -embedded-graphics = "0.5.2" -embedded-hal = { version = "0.2.2", features = ["unproven"] } +embedded-graphics = "0.6.0-beta.2" +embedded-hal = { version = "0.2.3", features = ["unproven"] } stm32f1xx-hal = { version = "0.2", features = ["rt", "stm32f103" ] } cortex-m = "0.5.0" diff --git a/examples/epd4in2_full_blue_pill/src/main.rs b/examples/epd4in2_full_blue_pill/src/main.rs index a20143b..f5becae 100644 --- a/examples/epd4in2_full_blue_pill/src/main.rs +++ b/examples/epd4in2_full_blue_pill/src/main.rs @@ -10,13 +10,15 @@ use stm32f1xx_hal::prelude::*; use stm32f1xx_hal::{delay, spi}; use embedded_graphics::{ - coord::Coord, - fonts::{Font12x16, Font6x8}, + fonts::{Font12x16, Font6x8, Text}, + pixelcolor::BinaryColor, prelude::*, primitives::{Circle, Line}, - Drawing, + style::{PrimitiveStyle, Styled}, + text_style, DrawTarget, }; use epd_waveshare::{ + color::*, epd4in2::Display4in2, graphics::{Display, DisplayRotation}, prelude::*, @@ -68,41 +70,18 @@ fn main() -> ! { //println!("Test all the rotations"); let mut display = Display4in2::default(); + display.set_rotation(DisplayRotation::Rotate0); - display.draw( - Font6x8::render_str("Rotate 0!") - .stroke(Some(Color::Black)) - .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), - ); + draw_text(&mut display, "Rotate 0!", 5, 50); display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Font6x8::render_str("Rotate 90!") - .stroke(Some(Color::Black)) - .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), - ); + draw_text(&mut display, "Rotate 90!", 5, 50); display.set_rotation(DisplayRotation::Rotate180); - display.draw( - Font6x8::render_str("Rotate 180!") - .stroke(Some(Color::Black)) - .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), - ); + draw_text(&mut display, "Rotate 180!", 5, 50); display.set_rotation(DisplayRotation::Rotate270); - display.draw( - Font6x8::render_str("Rotate 270!") - .stroke(Some(Color::Black)) - .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), - ); + draw_text(&mut display, "Rotate 270!", 5, 50); epd4in2.update_frame(&mut spi, &display.buffer()).unwrap(); epd4in2 @@ -114,47 +93,33 @@ fn main() -> ! { display.clear_buffer(Color::White); // draw a analog clock - display.draw( - Circle::new(Coord::new(64, 64), 64) - .stroke(Some(Color::Black)) - .into_iter(), - ); - display.draw( - Line::new(Coord::new(64, 64), Coord::new(0, 64)) - .stroke(Some(Color::Black)) - .into_iter(), - ); - display.draw( - Line::new(Coord::new(64, 64), Coord::new(80, 80)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + Circle::new(Point::new(64, 64), 64) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); + Line::new(Point::new(64, 64), Point::new(0, 64)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); + Line::new(Point::new(64, 64), Point::new(80, 80)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); // draw white on black background - display.draw( - Font6x8::render_str("It's working-WoB!") - // Using Style here - .style(Style { - fill_color: Some(Color::Black), - stroke_color: Some(Color::White), - stroke_width: 0u8, // Has no effect on fonts - }) - .translate(Coord::new(175, 250)) - .into_iter(), - ); + let _ = Text::new("It's working-WoB!", Point::new(175, 250)) + .into_styled(text_style!( + font = Font6x8, + text_color = White, + background_color = Black + )) + .draw(&mut display); // use bigger/different font - display.draw( - Font12x16::render_str("It's working-BoW!") - // Using Style here - .style(Style { - fill_color: Some(Color::White), - stroke_color: Some(Color::Black), - stroke_width: 0u8, // Has no effect on fonts - }) - .translate(Coord::new(50, 200)) - .into_iter(), - ); + let _ = Text::new("It's working-WoB!", Point::new(50, 200)) + .into_styled(text_style!( + font = Font12x16, + text_color = White, + background_color = Black + )) + .draw(&mut display); // a moving `Hello World!` let limit = 10; @@ -163,16 +128,7 @@ fn main() -> ! { for i in 0..limit { //println!("Moving Hello World. Loop {} from {}", (i + 1), limit); - display.draw( - Font6x8::render_str(" Hello World! ") - .style(Style { - fill_color: Some(Color::White), - stroke_color: Some(Color::Black), - stroke_width: 0u8, // Has no effect on fonts - }) - .translate(Coord::new(5 + i * 12, 50)) - .into_iter(), - ); + draw_text(&mut display, " Hello World! ", 5 + i * 12, 50); epd4in2.update_frame(&mut spi, &display.buffer()).unwrap(); epd4in2 @@ -190,3 +146,13 @@ fn main() -> ! { cortex_m::asm::wfi(); } } + +fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) { + let _ = Text::new(text, Point::new(x, y)) + .into_styled(text_style!( + font = Font6x8, + text_color = Black, + background_color = White + )) + .draw(display); +} diff --git a/examples/epd4in2_var_display_buffer/src/main.rs b/examples/epd4in2_var_display_buffer/src/main.rs index f15ab4b..ae365be 100644 --- a/examples/epd4in2_var_display_buffer/src/main.rs +++ b/examples/epd4in2_var_display_buffer/src/main.rs @@ -1,11 +1,11 @@ #![deny(warnings)] use embedded_graphics::{ - coord::Coord, fonts::{Font12x16, Font6x8}, prelude::*, primitives::{Circle, Line}, Drawing, + Point::Point, }; use embedded_hal::prelude::*; use epd_waveshare::{ @@ -81,7 +81,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -90,7 +90,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -99,7 +99,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -108,7 +108,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -125,17 +125,17 @@ fn run() -> Result<(), std::io::Error> { // draw a analog clock display.draw( - Circle::new(Coord::new(64, 64), 64) + Circle::new(Point::new(64, 64), 64) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(0, 64)) + let _ = Line::new(Point::new(64, 64), Point::new(0, 64)) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(80, 80)) + let _ = Line::new(Point::new(64, 64), Point::new(80, 80)) .stroke(Some(Color::Black)) .into_iter(), ); @@ -149,7 +149,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::White), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(175, 250)) + .translate(Point::new(175, 250)) .into_iter(), ); @@ -162,7 +162,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(50, 200)) + .translate(Point::new(50, 200)) .into_iter(), ); @@ -178,7 +178,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 12, 50)) + .translate(Point::new(5 + i * 12, 50)) .into_iter(), ); diff --git a/examples/epd7in5_full/src/main.rs b/examples/epd7in5_full/src/main.rs index 1a3ed2f..3e324da 100644 --- a/examples/epd7in5_full/src/main.rs +++ b/examples/epd7in5_full/src/main.rs @@ -1,11 +1,11 @@ #![deny(warnings)] use embedded_graphics::{ - coord::Coord, fonts::{Font12x16, Font6x8}, prelude::*, primitives::{Circle, Line}, Drawing, + Point::Point, }; use embedded_hal::prelude::*; use epd_waveshare::{ @@ -76,7 +76,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -85,7 +85,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -94,7 +94,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -103,7 +103,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -118,17 +118,17 @@ fn run() -> Result<(), std::io::Error> { // draw a analog clock display.draw( - Circle::new(Coord::new(64, 64), 64) + Circle::new(Point::new(64, 64), 64) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(0, 64)) + let _ = Line::new(Point::new(64, 64), Point::new(0, 64)) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(80, 80)) + let _ = Line::new(Point::new(64, 64), Point::new(80, 80)) .stroke(Some(Color::Black)) .into_iter(), ); @@ -142,7 +142,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::White), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(175, 250)) + .translate(Point::new(175, 250)) .into_iter(), ); @@ -155,7 +155,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(50, 200)) + .translate(Point::new(50, 200)) .into_iter(), ); @@ -171,7 +171,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 12, 50)) + .translate(Point::new(5 + i * 12, 50)) .into_iter(), ); diff --git a/examples/epd7in5_v2_full/src/main.rs b/examples/epd7in5_v2_full/src/main.rs index e7381f1..1f0dc00 100644 --- a/examples/epd7in5_v2_full/src/main.rs +++ b/examples/epd7in5_v2_full/src/main.rs @@ -1,11 +1,11 @@ #![deny(warnings)] use embedded_graphics::{ - coord::Coord, fonts::{Font12x16, Font6x8}, prelude::*, primitives::{Circle, Line}, Drawing, + Point::Point, }; use embedded_hal::prelude::*; use epd_waveshare::{ @@ -76,7 +76,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 0!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -85,7 +85,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 90!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -94,7 +94,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 180!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -103,7 +103,7 @@ fn run() -> Result<(), std::io::Error> { Font6x8::render_str("Rotate 270!") .stroke(Some(Color::Black)) .fill(Some(Color::White)) - .translate(Coord::new(5, 50)) + .translate(Point::new(5, 50)) .into_iter(), ); @@ -118,17 +118,17 @@ fn run() -> Result<(), std::io::Error> { // draw a analog clock display.draw( - Circle::new(Coord::new(64, 64), 64) + Circle::new(Point::new(64, 64), 64) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(0, 64)) + Line::new(Point::new(64, 64), Point::new(0, 64)) .stroke(Some(Color::Black)) .into_iter(), ); display.draw( - Line::new(Coord::new(64, 64), Coord::new(80, 80)) + Line::new(Point::new(64, 64), Point::new(80, 80)) .stroke(Some(Color::Black)) .into_iter(), ); @@ -142,7 +142,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::White), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(175, 250)) + .translate(Point::new(175, 250)) .into_iter(), ); @@ -155,7 +155,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(50, 200)) + .translate(Point::new(50, 200)) .into_iter(), ); @@ -171,7 +171,7 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i * 12, 50)) + .translate(Point::new(5 + i * 12, 50)) .into_iter(), ); diff --git a/src/color.rs b/src/color.rs index e9223de..b6ca8fc 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,5 +1,9 @@ //! B/W Color for EPDs +use embedded_graphics::pixelcolor::BinaryColor; + +pub use BinaryColor::Off as White; +pub use BinaryColor::On as Black; /// Only for the Black/White-Displays #[derive(Clone, Copy, PartialEq, Debug)] pub enum Color { @@ -51,11 +55,6 @@ impl Color { } } -#[cfg(feature = "graphics")] -use embedded_graphics::prelude::*; -#[cfg(feature = "graphics")] -impl PixelColor for Color {} - impl From for Color { fn from(value: u8) -> Self { Color::from_u8(value) diff --git a/src/epd1in54/graphics.rs b/src/epd1in54/graphics.rs index b63c460..2cdc1d2 100644 --- a/src/epd1in54/graphics.rs +++ b/src/epd1in54/graphics.rs @@ -1,6 +1,6 @@ use crate::epd1in54::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; /// Full size buffer for use with the 1in54 EPD @@ -22,12 +22,15 @@ impl Default for Display1in54 { } } -impl Drawing for Display1in54 { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display1in54 { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } @@ -52,10 +55,9 @@ impl Display for Display1in54 { #[cfg(test)] mod tests { use super::*; - use crate::color::Color; + use crate::color::{Black, Color}; use crate::graphics::{Display, DisplayRotation}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; + use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; // test buffer length #[test] @@ -76,11 +78,9 @@ mod tests { #[test] fn graphics_rotation_0() { let mut display = Display1in54::default(); - display.draw( - Line::new(Coord::new(0, 0), Coord::new(7, 0)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 0), Point::new(7, 0)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -95,11 +95,9 @@ mod tests { fn graphics_rotation_90() { let mut display = Display1in54::default(); display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Line::new(Coord::new(0, 192), Coord::new(0, 199)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 192), Point::new(0, 199)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -114,11 +112,9 @@ mod tests { fn graphics_rotation_180() { let mut display = Display1in54::default(); display.set_rotation(DisplayRotation::Rotate180); - display.draw( - Line::new(Coord::new(192, 199), Coord::new(199, 199)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(192, 199), Point::new(199, 199)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -136,11 +132,9 @@ mod tests { fn graphics_rotation_270() { let mut display = Display1in54::default(); display.set_rotation(DisplayRotation::Rotate270); - display.draw( - Line::new(Coord::new(199, 0), Coord::new(199, 7)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(199, 0), Point::new(199, 7)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index e66f032..8078676 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -21,7 +21,7 @@ //! Font6x8::render_str("Hello World!") //! .stroke(Some(Color::Black)) //! .fill(Some(Color::White)) -//! .translate(Coord::new(5, 50)) +//! .translate(Point::new(5, 50)) //! .into_iter(), //! ); //! diff --git a/src/epd1in54b/graphics.rs b/src/epd1in54b/graphics.rs index 536ba6a..a1e83e1 100644 --- a/src/epd1in54b/graphics.rs +++ b/src/epd1in54b/graphics.rs @@ -1,6 +1,6 @@ use crate::epd1in54b::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; pub struct Display1in54b { @@ -18,12 +18,15 @@ impl Default for Display1in54b { } } -impl Drawing for Display1in54b { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display1in54b { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } diff --git a/src/epd2in9/graphics.rs b/src/epd2in9/graphics.rs index d9b723c..fb1154e 100644 --- a/src/epd2in9/graphics.rs +++ b/src/epd2in9/graphics.rs @@ -1,6 +1,6 @@ use crate::epd2in9::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; /// Display with Fullsize buffer for use with the 2in9 EPD @@ -22,12 +22,15 @@ impl Default for Display2in9 { } } -impl Drawing for Display2in9 { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display2in9 { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 2e2665f..3bd61db 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -23,7 +23,7 @@ //! Font6x8::render_str("Hello World!") //! .stroke(Some(Color::Black)) //! .fill(Some(Color::White)) -//! .translate(Coord::new(5, 50)) +//! .translate(Point::new(5, 50)) //! .into_iter(), //! ); //! diff --git a/src/epd4in2/graphics.rs b/src/epd4in2/graphics.rs index 41332ab..101501e 100644 --- a/src/epd4in2/graphics.rs +++ b/src/epd4in2/graphics.rs @@ -1,6 +1,6 @@ use crate::epd4in2::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; /// Full size buffer for use with the 4in2 EPD @@ -22,12 +22,15 @@ impl Default for Display4in2 { } } -impl Drawing for Display4in2 { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display4in2 { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } @@ -52,11 +55,11 @@ impl Display for Display4in2 { #[cfg(test)] mod tests { use super::*; + use crate::color::Black; use crate::color::Color; use crate::epd4in2; use crate::graphics::{Display, DisplayRotation}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; + use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; // test buffer length #[test] @@ -77,11 +80,9 @@ mod tests { #[test] fn graphics_rotation_0() { let mut display = Display4in2::default(); - display.draw( - Line::new(Coord::new(0, 0), Coord::new(7, 0)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 0), Point::new(7, 0)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -96,11 +97,9 @@ mod tests { fn graphics_rotation_90() { let mut display = Display4in2::default(); display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Line::new(Coord::new(0, 392), Coord::new(0, 399)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 392), Point::new(0, 399)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -115,11 +114,10 @@ mod tests { fn graphics_rotation_180() { let mut display = Display4in2::default(); display.set_rotation(DisplayRotation::Rotate180); - display.draw( - Line::new(Coord::new(392, 299), Coord::new(399, 299)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + + let _ = Line::new(Point::new(392, 299), Point::new(399, 299)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -137,11 +135,9 @@ mod tests { fn graphics_rotation_270() { let mut display = Display4in2::default(); display.set_rotation(DisplayRotation::Rotate270); - display.draw( - Line::new(Coord::new(299, 0), Coord::new(299, 7)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(299, 0), Point::new(299, 7)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); diff --git a/src/epd7in5/graphics.rs b/src/epd7in5/graphics.rs index c7c20dd..62d1563 100644 --- a/src/epd7in5/graphics.rs +++ b/src/epd7in5/graphics.rs @@ -1,6 +1,6 @@ use crate::epd7in5::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; /// Full size buffer for use with the 7in5 EPD @@ -22,12 +22,15 @@ impl Default for Display7in5 { } } -impl Drawing for Display7in5 { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display7in5 { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } @@ -52,11 +55,11 @@ impl Display for Display7in5 { #[cfg(test)] mod tests { use super::*; + use crate::color::Black; use crate::color::Color; use crate::epd7in5; use crate::graphics::{Display, DisplayRotation}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; + use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; // test buffer length #[test] @@ -77,11 +80,9 @@ mod tests { #[test] fn graphics_rotation_0() { let mut display = Display7in5::default(); - display.draw( - Line::new(Coord::new(0, 0), Coord::new(7, 0)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 0), Point::new(7, 0)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -96,11 +97,9 @@ mod tests { fn graphics_rotation_90() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Line::new(Coord::new(0, 632), Coord::new(0, 639)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 632), Point::new(0, 639)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -115,11 +114,9 @@ mod tests { fn graphics_rotation_180() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate180); - display.draw( - Line::new(Coord::new(632, 383), Coord::new(639, 383)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(632, 383), Point::new(639, 383)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -134,11 +131,9 @@ mod tests { fn graphics_rotation_270() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate270); - display.draw( - Line::new(Coord::new(383, 0), Coord::new(383, 7)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(383, 0), Point::new(383, 7)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); diff --git a/src/epd7in5_v2/graphics.rs b/src/epd7in5_v2/graphics.rs index aa6f464..8c3211f 100644 --- a/src/epd7in5_v2/graphics.rs +++ b/src/epd7in5_v2/graphics.rs @@ -1,6 +1,6 @@ use crate::epd7in5_v2::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::graphics::{Display, DisplayRotation}; -use crate::prelude::*; +use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; /// Full size buffer for use with the 7in5 EPD @@ -22,12 +22,15 @@ impl Default for Display7in5 { } } -impl Drawing for Display7in5 { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(WIDTH, HEIGHT, item_pixels); +impl DrawTarget for Display7in5 { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(WIDTH, HEIGHT, pixel) + } + + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) } } @@ -52,11 +55,10 @@ impl Display for Display7in5 { #[cfg(test)] mod tests { use super::*; - use crate::color::Color; + use crate::color::{Black, Color}; use crate::epd7in5_v2; use crate::graphics::{Display, DisplayRotation}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; + use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; // test buffer length #[test] @@ -77,11 +79,10 @@ mod tests { #[test] fn graphics_rotation_0() { let mut display = Display7in5::default(); - display.draw( - Line::new(Coord::new(0, 0), Coord::new(7, 0)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + + let _ = Line::new(Point::new(0, 0), Point::new(7, 0)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -96,11 +97,10 @@ mod tests { fn graphics_rotation_90() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Line::new(Coord::new(0, 792), Coord::new(0, 799)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + + let _ = Line::new(Point::new(0, 792), Point::new(0, 799)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -115,11 +115,10 @@ mod tests { fn graphics_rotation_180() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate180); - display.draw( - Line::new(Coord::new(792, 479), Coord::new(799, 479)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + + let _ = Line::new(Point::new(792, 479), Point::new(799, 479)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -134,11 +133,10 @@ mod tests { fn graphics_rotation_270() { let mut display = Display7in5::default(); display.set_rotation(DisplayRotation::Rotate270); - display.draw( - Line::new(Coord::new(479, 0), Coord::new(479, 7)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + + let _ = Line::new(Point::new(479, 0), Point::new(479, 7)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); diff --git a/src/graphics.rs b/src/graphics.rs index d01ecb7..49758d3 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,7 +1,7 @@ //! Graphics Support for EPDs use crate::color::Color; -use embedded_graphics::prelude::*; +use embedded_graphics::{pixelcolor::BinaryColor, prelude::*}; /// Displayrotation #[derive(Clone, Copy)] @@ -22,7 +22,7 @@ impl Default for DisplayRotation { } } -pub trait Display: Drawing { +pub trait Display: DrawTarget { /// Clears the buffer of the display with the chosen background color fn clear_buffer(&mut self, background_color: Color) { for elem in self.get_mut_buffer().iter_mut() { @@ -45,31 +45,36 @@ pub trait Display: Drawing { /// Helperfunction for the Embedded Graphics draw trait /// /// Becomes uneccesary when const_generics become stablised - fn draw_helper(&mut self, width: u32, height: u32, item_pixels: T) - where - T: IntoIterator>, - { + fn draw_helper( + &mut self, + width: u32, + height: u32, + pixel: Pixel, + ) -> Result<(), Self::Error> { let rotation = self.rotation(); let buffer = self.get_mut_buffer(); - for Pixel(UnsignedCoord(x, y), color) in item_pixels { - if outside_display(x, y, width, height, rotation) { - continue; - } - // Give us index inside the buffer and the bit-position in that u8 which needs to be changed - let (index, bit) = find_position(x, y, width, height, rotation); - let index = index as usize; + let Pixel(point, color) = pixel; + if outside_display(point, width, height, rotation) { + return Ok(()); + } - // "Draw" the Pixel on that bit - match color { - Color::Black => { - buffer[index] &= !bit; - } - Color::White => { - buffer[index] |= bit; - } + // Give us index inside the buffer and the bit-position in that u8 which needs to be changed + let (index, bit) = find_position(point.x as u32, point.y as u32, width, height, rotation); + let index = index as usize; + + // "Draw" the Pixel on that bit + match color { + // Black + BinaryColor::On => { + buffer[index] &= !bit; + } + // White + BinaryColor::Off => { + buffer[index] |= bit; } } + Ok(()) } } @@ -83,8 +88,10 @@ pub trait Display: Drawing { /// # use epd_waveshare::epd2in9::DEFAULT_BACKGROUND_COLOR; /// # use epd_waveshare::prelude::*; /// # use epd_waveshare::graphics::VarDisplay; +/// # use epd_waveshare::color::Black; /// # use embedded_graphics::prelude::*; /// # use embedded_graphics::primitives::{Circle, Line}; +/// # use embedded_graphics::style::PrimitiveStyle; /// let width = 128; /// let height = 296; /// @@ -93,11 +100,9 @@ pub trait Display: Drawing { /// /// display.set_rotation(DisplayRotation::Rotate90); /// -/// display.draw( -/// Line::new(Coord::new(0, 120), Coord::new(0, 295)) -/// .stroke(Some(Color::Black)) -/// .into_iter(), -/// ); +/// let _ = Line::new(Point::new(0, 120), Point::new(0, 295)) +/// .into_styled(PrimitiveStyle::with_stroke(Black, 1)) +/// .draw(&mut display); /// ``` pub struct VarDisplay<'a> { width: u32, @@ -119,12 +124,15 @@ impl<'a> VarDisplay<'a> { } } -impl<'a> Drawing for VarDisplay<'a> { - fn draw(&mut self, item_pixels: T) - where - T: IntoIterator>, - { - self.draw_helper(self.width, self.height, item_pixels); +impl<'a> DrawTarget for VarDisplay<'a> { + type Error = core::convert::Infallible; + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + self.draw_helper(self.width, self.height, pixel) + } + + fn size(&self) -> Size { + Size::new(self.width, self.height) } } @@ -147,7 +155,11 @@ impl<'a> Display for VarDisplay<'a> { } // Checks if a pos is outside the defined display -fn outside_display(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> bool { +fn outside_display(p: Point, width: u32, height: u32, rotation: DisplayRotation) -> bool { + if p.x < 0 || p.y < 0 { + return true; + } + let (x, y) = (p.x as u32, p.y as u32); match rotation { DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => { if x >= width || y >= height { @@ -189,10 +201,9 @@ fn find_position(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotat #[cfg(test)] mod tests { use super::{find_position, outside_display, Display, DisplayRotation, VarDisplay}; + use crate::color::Black; use crate::color::Color; - use embedded_graphics::coord::Coord; - use embedded_graphics::prelude::*; - use embedded_graphics::primitives::Line; + use embedded_graphics::{prelude::*, primitives::Line, style::PrimitiveStyle}; #[test] fn buffer_clear() { @@ -228,7 +239,7 @@ mod tests { for x in 0..(width + height) { //limit x because it runs too long for y in 0..(u32::max_value()) { - if outside_display(x, y, width, height, rotation2) { + if outside_display(Point::new(x as i32, y as i32), width, height, rotation2) { break; } else { let (idx, _) = find_position(x, y, width, height, rotation2); @@ -247,11 +258,9 @@ mod tests { let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296]; let mut display = VarDisplay::new(width, height, &mut buffer); - display.draw( - Line::new(Coord::new(0, 0), Coord::new(7, 0)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 0), Point::new(7, 0)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); @@ -273,11 +282,9 @@ mod tests { display.set_rotation(DisplayRotation::Rotate90); - display.draw( - Line::new(Coord::new(0, 120), Coord::new(0, 295)) - .stroke(Some(Color::Black)) - .into_iter(), - ); + let _ = Line::new(Point::new(0, 120), Point::new(0, 295)) + .into_styled(PrimitiveStyle::with_stroke(Black, 1)) + .draw(&mut display); let buffer = display.buffer(); diff --git a/src/lib.rs b/src/lib.rs index 00e8183..7f31513 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ //! Font6x8::render_str("Hello World!") //! .stroke(Some(Color::Black)) //! .fill(Some(Color::White)) -//! .translate(Coord::new(5, 50)) +//! .translate(Point::new(5, 50)) //! .into_iter(), //! ); //!