From ff21d6e611e9617bb6abbbf1e54981ef0aded171 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 16 Oct 2018 18:33:06 +0200 Subject: [PATCH] add impl Drawing for DisplayEink42BlackWhite fix error by using option for style --- examples/embedded_linux_epd4in2/src/main.rs | 8 ++--- src/drawing.rs | 34 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/examples/embedded_linux_epd4in2/src/main.rs b/examples/embedded_linux_epd4in2/src/main.rs index 2f30b63..3097018 100644 --- a/examples/embedded_linux_epd4in2/src/main.rs +++ b/examples/embedded_linux_epd4in2/src/main.rs @@ -193,22 +193,22 @@ fn run() -> Result<(), std::io::Error> { let mut display = DisplayEink42BlackWhite::default(); display.draw( Circle::new(Coord::new(64, 64), 64) - .with_stroke(Color::Black) + .with_stroke(Some(Color::Black)) .into_iter(), ); display.draw( Line::new(Coord::new(64, 64), Coord::new(0, 64)) - .with_stroke(Color::Black) + .with_stroke(Some(Color::Black)) .into_iter(), ); display.draw( Line::new(Coord::new(64, 64), Coord::new(80, 80)) - .with_stroke(Color::Black) + .with_stroke(Some(Color::Black)) .into_iter(), ); display.draw( Font6x8::render_str("Hello World!") - .with_stroke(Color::Black) + .with_stroke(Some(Color::Black)) .translate(Coord::new(5 + i*10, 50)) .into_iter(), ); diff --git a/src/drawing.rs b/src/drawing.rs index 97c3ef7..28b81e5 100644 --- a/src/drawing.rs +++ b/src/drawing.rs @@ -93,6 +93,40 @@ impl Drawing for DisplayEink42BlackWhite { } } +impl Drawing for DisplayEink42BlackWhite { + fn draw(&mut self, item_pixels: T) + where + T: Iterator> + { + use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; + for Pixel(UnsignedCoord(x,y), color) in item_pixels { + let (idx, bit) = match self.rotation { + DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => ( + (x as usize / 8 + (WIDTH as usize / 8) * y as usize), + 0x80 >> (x % 8), + ), + DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => ( + y as usize / 8 * WIDTH as usize + x as usize, + 0x80 >> (y % 8), + ), + }; + + if idx >= self.buffer.len() { + return; + } + + match color { + Color::Black => { + self.buffer[idx] &= !bit; + } + Color::White => { + self.buffer[idx] |= bit; + } + } + } + } +} + // impl Drawing for DisplayRibbonLeft { // fn draw(&mut self, item_pixels: T) // where