|
|
|
@ -1,12 +1,17 @@ |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
|
|
|
|
use graphics::DisplayDimension; |
|
|
|
|
|
|
|
|
|
|
|
pub struct DisplayEink4in2BlackWhite { |
|
|
|
pub struct DisplayEink4in2BlackWhite { |
|
|
|
|
|
|
|
width: u32, |
|
|
|
|
|
|
|
height: u32, |
|
|
|
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], |
|
|
|
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Default for DisplayEink4in2BlackWhite { |
|
|
|
impl Default for DisplayEink4in2BlackWhite { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
DisplayEink4in2BlackWhite { |
|
|
|
DisplayEink4in2BlackWhite { |
|
|
|
|
|
|
|
width: WIDTH, |
|
|
|
|
|
|
|
height: HEIGHT,
|
|
|
|
buffer: [ |
|
|
|
buffer: [ |
|
|
|
DEFAULT_BACKGROUND_COLOR.get_byte_value(); |
|
|
|
DEFAULT_BACKGROUND_COLOR.get_byte_value(); |
|
|
|
WIDTH as usize * HEIGHT as usize / 8
|
|
|
|
WIDTH as usize * HEIGHT as usize / 8
|
|
|
|
@ -15,13 +20,25 @@ impl Default for DisplayEink4in2BlackWhite { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl DisplayDimension for DisplayEink4in2BlackWhite { |
|
|
|
|
|
|
|
fn buffer(&self) -> &[u8] { |
|
|
|
|
|
|
|
&self.buffer |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fn width(&self) -> u32 { |
|
|
|
|
|
|
|
self.width |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fn height(&self) -> u32 { |
|
|
|
|
|
|
|
self.height |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod tests { |
|
|
|
mod tests { |
|
|
|
use super::*; |
|
|
|
use super::*; |
|
|
|
use epd4in2; |
|
|
|
use epd4in2; |
|
|
|
use graphics::{DisplayRotation, Graphics}; |
|
|
|
use graphics::{DisplayRotation, Display}; |
|
|
|
use embedded_graphics::coord::Coord; |
|
|
|
use embedded_graphics::coord::Coord; |
|
|
|
use embedded_graphics::primitives::Line; |
|
|
|
use embedded_graphics::primitives::Line; |
|
|
|
use color::Color; |
|
|
|
use color::Color; |
|
|
|
@ -31,7 +48,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_size() { |
|
|
|
fn graphics_size() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
assert_eq!(display.buffer().len(), 15000); |
|
|
|
assert_eq!(display.buffer().len(), 15000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -39,7 +56,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_default() { |
|
|
|
fn graphics_default() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
use epd4in2; |
|
|
|
use epd4in2; |
|
|
|
for &byte in display.buffer() { |
|
|
|
for &byte in display.buffer() { |
|
|
|
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
@ -49,7 +66,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_rotation_0() { |
|
|
|
fn graphics_rotation_0() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let mut display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
display.draw( |
|
|
|
display.draw( |
|
|
|
Line::new(Coord::new(0, 0), Coord::new(7, 0)) |
|
|
|
Line::new(Coord::new(0, 0), Coord::new(7, 0)) |
|
|
|
.with_stroke(Some(Color::Black)) |
|
|
|
.with_stroke(Some(Color::Black)) |
|
|
|
@ -68,7 +85,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_rotation_90() { |
|
|
|
fn graphics_rotation_90() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let mut display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
display.set_rotation(DisplayRotation::Rotate90); |
|
|
|
display.set_rotation(DisplayRotation::Rotate90); |
|
|
|
display.draw( |
|
|
|
display.draw( |
|
|
|
Line::new(Coord::new(0, 392), Coord::new(0, 399)) |
|
|
|
Line::new(Coord::new(0, 392), Coord::new(0, 399)) |
|
|
|
@ -88,7 +105,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_rotation_180() { |
|
|
|
fn graphics_rotation_180() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let mut display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
display.set_rotation(DisplayRotation::Rotate180); |
|
|
|
display.set_rotation(DisplayRotation::Rotate180); |
|
|
|
display.draw( |
|
|
|
display.draw( |
|
|
|
Line::new(Coord::new(392, 299), Coord::new(399, 299)) |
|
|
|
Line::new(Coord::new(392, 299), Coord::new(399, 299)) |
|
|
|
@ -112,7 +129,7 @@ mod tests { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn graphics_rotation_270() { |
|
|
|
fn graphics_rotation_270() { |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display4in2 = DisplayEink4in2BlackWhite::default(); |
|
|
|
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
let mut display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); |
|
|
|
display.set_rotation(DisplayRotation::Rotate270); |
|
|
|
display.set_rotation(DisplayRotation::Rotate270); |
|
|
|
display.draw( |
|
|
|
display.draw( |
|
|
|
Line::new(Coord::new(299, 0), Coord::new(299, 7)) |
|
|
|
Line::new(Coord::new(299, 0), Coord::new(299, 7)) |
|
|
|
|