mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +00:00
Remove more or less duplicate test cases for 2in9 buffer
This commit is contained in:
+4
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
|
||||
/// Only for the B/W Displays atm
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
@@ -85,6 +85,9 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
use embedded_graphics::prelude::*;
|
||||
#[cfg(feature = "graphics")]
|
||||
impl PixelColor for Color {}
|
||||
|
||||
impl From<u8> for Color {
|
||||
|
||||
@@ -12,7 +12,7 @@ impl Default for Buffer1in54BlackWhite {
|
||||
WIDTH as usize * HEIGHT as usize / 8
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -19,10 +19,10 @@
|
||||
//! epd4in2.sleep();
|
||||
//! ```
|
||||
|
||||
const WIDTH: u32 = 200;
|
||||
const HEIGHT: u32 = 200;
|
||||
pub const WIDTH: u32 = 200;
|
||||
pub const HEIGHT: u32 = 200;
|
||||
//const DPI: u16 = 184;
|
||||
const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
|
||||
use hal::{
|
||||
blocking::{delay::*, spi::Write},
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
|
||||
pub struct Buffer2in9 {
|
||||
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
}
|
||||
|
||||
impl Default for Buffer2in9 {
|
||||
fn default() -> Self {
|
||||
Buffer2in9 {
|
||||
buffer: [
|
||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
WIDTH as usize * HEIGHT as usize / 8
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use graphics::Display;
|
||||
|
||||
// test buffer length
|
||||
#[test]
|
||||
fn graphics_size() {
|
||||
let mut buffer = Buffer2in9::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut buffer.buffer);
|
||||
assert_eq!(display.buffer().len(), 4736);
|
||||
}
|
||||
|
||||
// test default background color on all bytes
|
||||
#[test]
|
||||
fn graphics_default() {
|
||||
let mut buffer = Buffer2in9::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut buffer.buffer);
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,9 @@ use traits::*;
|
||||
|
||||
use interface::DisplayInterface;
|
||||
|
||||
mod graphics;
|
||||
pub use epd2in9::graphics::Buffer2in9;
|
||||
|
||||
/// EPD2in9 driver
|
||||
///
|
||||
pub struct EPD2in9<SPI, CS, BUSY, DC, RST> {
|
||||
|
||||
@@ -131,6 +131,9 @@ fn rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation)
|
||||
mod tests {
|
||||
use super::{DisplayRotation, outside_display, rotation, Display};
|
||||
use color::Color;
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::primitives::Line;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn buffer_clear() {
|
||||
@@ -176,4 +179,59 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_0() {
|
||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR};
|
||||
let width = 128;
|
||||
let height = 296;
|
||||
|
||||
let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296];
|
||||
let mut display = Display::new(width, height, &mut buffer);
|
||||
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 0), Coord::new(7, 0))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
let buffer = display.buffer();
|
||||
|
||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||
|
||||
for &byte in buffer.iter().skip(1) {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_90() {
|
||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR};
|
||||
let width = 128;
|
||||
let height = 296;
|
||||
|
||||
let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296];
|
||||
let mut display = Display::new(width, height, &mut buffer);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 120), Coord::new(0, 295))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
let buffer = display.buffer();
|
||||
|
||||
extern crate std;
|
||||
std::println!("{:?}", buffer);
|
||||
|
||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||
|
||||
for &byte in buffer.iter().skip(1) {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -47,6 +47,9 @@ extern crate embedded_hal as hal;
|
||||
|
||||
use hal::spi::{Mode, Phase, Polarity};
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
extern crate embedded_graphics;
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
pub mod graphics;
|
||||
|
||||
@@ -74,7 +77,7 @@ pub mod epd2in9;
|
||||
#[cfg(any(feature = "epd1in54", feature = "epd2in9"))]
|
||||
pub(crate) mod type_a;
|
||||
|
||||
extern crate embedded_graphics;
|
||||
|
||||
|
||||
/// SPI mode -
|
||||
/// For more infos see [Requirements: SPI](index.html#spi)
|
||||
|
||||
Reference in New Issue
Block a user