mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +00:00
add more changes
This commit is contained in:
+24
-7
@@ -1,12 +1,17 @@
|
||||
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
use graphics::DisplayDimension;
|
||||
|
||||
pub struct DisplayEink4in2BlackWhite {
|
||||
width: u32,
|
||||
height: u32,
|
||||
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
}
|
||||
|
||||
impl Default for DisplayEink4in2BlackWhite {
|
||||
fn default() -> Self {
|
||||
DisplayEink4in2BlackWhite {
|
||||
width: WIDTH,
|
||||
height: HEIGHT,
|
||||
buffer: [
|
||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use epd4in2;
|
||||
use graphics::{DisplayRotation, Graphics};
|
||||
use graphics::{DisplayRotation, Display};
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::primitives::Line;
|
||||
use color::Color;
|
||||
@@ -31,7 +48,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_size() {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -39,7 +56,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_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;
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
@@ -49,7 +66,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_rotation_0() {
|
||||
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(
|
||||
Line::new(Coord::new(0, 0), Coord::new(7, 0))
|
||||
.with_stroke(Some(Color::Black))
|
||||
@@ -68,7 +85,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_rotation_90() {
|
||||
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.draw(
|
||||
Line::new(Coord::new(0, 392), Coord::new(0, 399))
|
||||
@@ -88,7 +105,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_rotation_180() {
|
||||
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.draw(
|
||||
Line::new(Coord::new(392, 299), Coord::new(399, 299))
|
||||
@@ -112,7 +129,7 @@ mod tests {
|
||||
#[test]
|
||||
fn graphics_rotation_270() {
|
||||
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.draw(
|
||||
Line::new(Coord::new(299, 0), Coord::new(299, 7))
|
||||
|
||||
Reference in New Issue
Block a user