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