add more changes
parent
f6a894c5a3
commit
a832ab9fed
|
|
@ -7,7 +7,7 @@ extern crate eink_waveshare_rs;
|
|||
|
||||
use eink_waveshare_rs::{
|
||||
EPD1in54,
|
||||
DisplayEink1in54BlackWhite,
|
||||
Buffer1in54,
|
||||
graphics::{Display, DisplayRotation},
|
||||
color::Color,
|
||||
WaveshareDisplay,
|
||||
|
|
@ -125,7 +125,8 @@ fn run() -> Result<(), std::io::Error> {
|
|||
epd.display_frame(&mut spi).expect("disp 1");
|
||||
|
||||
println!("Test all the rotations");
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
let mut buffer = Buffer1in54::default();
|
||||
let mut display = Display::new(buffer.width, buffer.height, &mut buffer.buffer);
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
use graphics::DisplayDimension;
|
||||
|
||||
pub struct DisplayEink1in54BlackWhite {
|
||||
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
width: u32,
|
||||
height: u32,
|
||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Default for DisplayEink1in54BlackWhite {
|
||||
fn default() -> Self {
|
||||
DisplayEink1in54BlackWhite {
|
||||
width: WIDTH,
|
||||
height: HEIGHT,
|
||||
buffer: [
|
||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
WIDTH as usize * HEIGHT as usize / 8
|
||||
|
|
@ -15,11 +22,23 @@ impl Default for DisplayEink1in54BlackWhite {
|
|||
}
|
||||
}
|
||||
|
||||
impl DisplayDimension for DisplayEink1in54BlackWhite {
|
||||
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 graphics::{DisplayRotation, Graphics};
|
||||
use graphics::{DisplayRotation, Display};
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::primitives::Line;
|
||||
use color::Color;
|
||||
|
|
@ -29,7 +48,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_size() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
assert_eq!(display.buffer().len(), 5000);
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +56,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_default() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
|
|
@ -46,7 +65,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_rotation_0() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 0), Coord::new(7, 0))
|
||||
.with_stroke(Some(Color::Black))
|
||||
|
|
@ -65,7 +84,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_rotation_90() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 192), Coord::new(0, 199))
|
||||
|
|
@ -85,7 +104,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_rotation_180() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Line::new(Coord::new(192, 199), Coord::new(199, 199))
|
||||
|
|
@ -109,7 +128,7 @@ mod tests {
|
|||
#[test]
|
||||
fn graphics_rotation_270() {
|
||||
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Line::new(Coord::new(199, 0), Coord::new(199, 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))
|
||||
|
|
|
|||
|
|
@ -19,26 +19,26 @@ impl Default for DisplayRotation {
|
|||
DisplayRotation::Rotate0
|
||||
}
|
||||
}
|
||||
//use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
|
||||
pub trait Display {
|
||||
pub trait DisplayDimension {
|
||||
fn buffer(&self) -> &[u8];
|
||||
fn set_rotation(&mut self, rotation: DisplayRotation);
|
||||
fn rotation(&self) -> DisplayRotation;
|
||||
fn width(&self) -> u32;
|
||||
fn height(&self) -> u32;
|
||||
}
|
||||
|
||||
pub struct Graphics<'a> {
|
||||
|
||||
pub struct Display<'a> {
|
||||
width: u32,
|
||||
height: u32,
|
||||
rotation: DisplayRotation,
|
||||
buffer: &'a mut [u8], //buffer: Box<u8>//[u8; 15000]
|
||||
}
|
||||
|
||||
impl<'a> Graphics<'a> {
|
||||
pub fn new(width: u32, height: u32, buffer: &'a mut [u8]) -> Graphics<'a> {
|
||||
impl<'a> Display<'a> {
|
||||
pub fn new(width: u32, height: u32, buffer: &'a mut [u8]) -> Display<'a> {
|
||||
let len = buffer.len() as u32;
|
||||
assert!(width / 8 * height >= len);
|
||||
Graphics {
|
||||
Display {
|
||||
width,
|
||||
height,
|
||||
rotation: DisplayRotation::default(),
|
||||
|
|
@ -58,7 +58,7 @@ impl<'a> Graphics<'a> {
|
|||
}
|
||||
|
||||
|
||||
impl<'a> Drawing<Color> for Graphics<'a> {
|
||||
impl<'a> Drawing<Color> for Display<'a> {
|
||||
fn draw<T>(&mut self, item_pixels: T)
|
||||
where
|
||||
T: Iterator<Item = Pixel<Color>>
|
||||
|
|
|
|||
Loading…
Reference in New Issue