|
|
|
@ -19,29 +19,18 @@ impl Default for DisplayRotation { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub enum Display { |
|
|
|
pub trait Display { |
|
|
|
Eink42BlackWhite, |
|
|
|
fn buffer(&self) -> &[u8]; |
|
|
|
} |
|
|
|
fn set_rotation(&mut self, rotation: DisplayRotation); |
|
|
|
impl Display { |
|
|
|
fn rotation(&self) -> DisplayRotation; |
|
|
|
/// Gets the Dimensions of a dipslay in the following order:
|
|
|
|
|
|
|
|
/// - Width
|
|
|
|
|
|
|
|
/// - Height
|
|
|
|
|
|
|
|
/// - Neccessary Buffersize
|
|
|
|
|
|
|
|
pub fn get_dimensions(&self) -> (u16, u16, u16) { |
|
|
|
|
|
|
|
match self { |
|
|
|
|
|
|
|
Display::Eink42BlackWhite => (400, 300, 15000), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub trait Buffer { |
|
|
|
|
|
|
|
fn get_buffer(&self) -> &[u8]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct DisplayEink42BlackWhite { |
|
|
|
pub struct DisplayEink42BlackWhite { |
|
|
|
buffer: [u8; 400 * 300 / 8], |
|
|
|
buffer: [u8; 400 * 300 / 8], |
|
|
|
rotation: DisplayRotation, //TODO: check embedded_graphics for orientation
|
|
|
|
rotation: DisplayRotation, //TODO: check embedded_graphics for orientation
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Default for DisplayEink42BlackWhite { |
|
|
|
impl Default for DisplayEink42BlackWhite { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
@ -54,15 +43,23 @@ impl Default for DisplayEink42BlackWhite { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
impl Buffer for DisplayEink42BlackWhite { |
|
|
|
|
|
|
|
fn get_buffer(&self) -> &[u8] { |
|
|
|
impl Display for DisplayEink42BlackWhite { |
|
|
|
|
|
|
|
fn buffer(&self) -> &[u8] { |
|
|
|
&self.buffer |
|
|
|
&self.buffer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn set_rotation(&mut self, rotation: DisplayRotation) { |
|
|
|
|
|
|
|
self.rotation = rotation; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fn rotation(&self) -> DisplayRotation { |
|
|
|
|
|
|
|
self.rotation |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
impl Drawing<u8> for DisplayEink42BlackWhite { |
|
|
|
|
|
|
|
|
|
|
|
impl Drawing<Color> for DisplayEink42BlackWhite { |
|
|
|
fn draw<T>(&mut self, item_pixels: T) |
|
|
|
fn draw<T>(&mut self, item_pixels: T) |
|
|
|
where |
|
|
|
where |
|
|
|
T: Iterator<Item = Pixel<u8>> |
|
|
|
T: Iterator<Item = Pixel<Color>> |
|
|
|
{ |
|
|
|
{ |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
for Pixel(UnsignedCoord(x,y), color) in item_pixels { |
|
|
|
for Pixel(UnsignedCoord(x,y), color) in item_pixels { |
|
|
|
@ -81,7 +78,7 @@ impl Drawing<u8> for DisplayEink42BlackWhite { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
match Color::from(color) { |
|
|
|
match color { |
|
|
|
Color::Black => { |
|
|
|
Color::Black => { |
|
|
|
self.buffer[idx] &= !bit; |
|
|
|
self.buffer[idx] &= !bit; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -93,83 +90,122 @@ impl Drawing<u8> for DisplayEink42BlackWhite { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// impl Drawing<u8> for DisplayRibbonLeft {
|
|
|
|
//TODO: write tests
|
|
|
|
// fn draw<T>(&mut self, item_pixels: T)
|
|
|
|
#[cfg(test)] |
|
|
|
// where
|
|
|
|
mod tests { |
|
|
|
// T: Iterator<Item = Pixel<u8>>,
|
|
|
|
use super::*; |
|
|
|
// {
|
|
|
|
use epd4in2; |
|
|
|
// for Pixel(UnsignedCoord(x, y), color) in item_pixels {
|
|
|
|
use embedded_graphics::coord::Coord; |
|
|
|
// if y > 127 || x > 295 {
|
|
|
|
use embedded_graphics::fonts::Font6x8; |
|
|
|
// continue;
|
|
|
|
use embedded_graphics::prelude::*; |
|
|
|
// }
|
|
|
|
use embedded_graphics::primitives::{Circle, Line}; |
|
|
|
// let cell = &mut self.0[y as usize / 8 + (295 - x as usize) * 128 / 8];
|
|
|
|
|
|
|
|
// let bit = 7 - y % 8;
|
|
|
|
#[test] |
|
|
|
// if color != 0 {
|
|
|
|
fn from_u8() { |
|
|
|
// *cell &= !(1 << bit);
|
|
|
|
assert_eq!(Color::Black, Color::from(0u8)); |
|
|
|
// } else {
|
|
|
|
assert_eq!(Color::White, Color::from(1u8)); |
|
|
|
// *cell |= 1 << bit;
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
// test all values aside from 0 and 1 which all should panic
|
|
|
|
// }
|
|
|
|
#[test] |
|
|
|
// }
|
|
|
|
fn from_u8_panic() { |
|
|
|
|
|
|
|
for val in 2..=u8::max_value() { |
|
|
|
|
|
|
|
let result = std::panic::catch_unwind(|| Color::from(val)); |
|
|
|
|
|
|
|
assert!(result.is_err()); |
|
|
|
// /// Draw a single Pixel with `color`
|
|
|
|
}
|
|
|
|
// ///
|
|
|
|
} |
|
|
|
// /// limited to i16::max images (buffer_size) at the moment
|
|
|
|
|
|
|
|
// pub fn draw_pixel(&mut self, x: u16, y: u16, color: &Color) {
|
|
|
|
// test buffer length
|
|
|
|
// let (idx, bit) = match self.rotation {
|
|
|
|
#[test] |
|
|
|
// Displayorientation::Rotate0 | Displayorientation::Rotate180 => (
|
|
|
|
fn graphics_4in2_size() { |
|
|
|
// (x as usize / 8 + (self.width as usize / 8) * y as usize),
|
|
|
|
let display = DisplayEink42BlackWhite::default(); |
|
|
|
// 0x80 >> (x % 8),
|
|
|
|
assert_eq!(display.buffer().len(), 15000); |
|
|
|
// ),
|
|
|
|
} |
|
|
|
// Displayorientation::Rotate90 | Displayorientation::Rotate270 => (
|
|
|
|
|
|
|
|
// y as usize / 8 * self.width as usize + x as usize,
|
|
|
|
// test default background color on all bytes
|
|
|
|
// 0x80 >> (y % 8),
|
|
|
|
#[test] |
|
|
|
// ),
|
|
|
|
fn graphics_4in2_default() { |
|
|
|
// };
|
|
|
|
let display = DisplayEink42BlackWhite::default(); |
|
|
|
|
|
|
|
use epd4in2; |
|
|
|
// if idx >= self.buffer.len() {
|
|
|
|
for &byte in display.buffer() { |
|
|
|
// return;
|
|
|
|
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// match color {
|
|
|
|
|
|
|
|
// Color::Black => {
|
|
|
|
#[test] |
|
|
|
// self.buffer[idx] &= !bit;
|
|
|
|
fn graphics_4in2_rotation_0() { |
|
|
|
// }
|
|
|
|
let mut display = DisplayEink42BlackWhite::default(); |
|
|
|
// Color::White => {
|
|
|
|
display.draw( |
|
|
|
// self.buffer[idx] |= bit;
|
|
|
|
Line::new(Coord::new(0, 0), Coord::new(7, 0)) |
|
|
|
// }
|
|
|
|
.with_stroke(Some(Color::Black)) |
|
|
|
// }
|
|
|
|
.into_iter(), |
|
|
|
// }
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// /// Draw a single Pixel with `color`
|
|
|
|
let buffer = display.buffer(); |
|
|
|
// ///
|
|
|
|
|
|
|
|
// /// limited to i16::max images (buffer_size) at the moment
|
|
|
|
assert_eq!(buffer[0], Color::Black.get_byte_value()); |
|
|
|
// #[allow(dead_code)]
|
|
|
|
|
|
|
|
// fn draw_byte(&mut self, x: u16, y: u16, filling: u8, color: &Color) {
|
|
|
|
for &byte in buffer.iter().skip(1) { |
|
|
|
// let idx = match self.rotation {
|
|
|
|
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
// Displayorientation::Rotate0 | Displayorientation::Rotate180 => {
|
|
|
|
} |
|
|
|
// x as usize / 8 + (self.width as usize / 8) * y as usize
|
|
|
|
} |
|
|
|
// },
|
|
|
|
|
|
|
|
// Displayorientation::Rotate90 | Displayorientation::Rotate270 => {
|
|
|
|
#[test] |
|
|
|
// y as usize / 8 + (self.width as usize / 8) * x as usize
|
|
|
|
fn graphics_4in2_rotation_90() { |
|
|
|
// },
|
|
|
|
let mut display = DisplayEink42BlackWhite::default(); |
|
|
|
// };
|
|
|
|
display.set_rotation(DisplayRotation::Rotate90); |
|
|
|
|
|
|
|
display.draw( |
|
|
|
// if idx >= self.buffer.len() {
|
|
|
|
Line::new(Coord::new(0, 392), Coord::new(0, 399)) |
|
|
|
// return;
|
|
|
|
.with_stroke(Some(Color::Black)) |
|
|
|
// }
|
|
|
|
.into_iter(), |
|
|
|
|
|
|
|
); |
|
|
|
// match color {
|
|
|
|
|
|
|
|
// Color::Black => {
|
|
|
|
let buffer = display.buffer(); |
|
|
|
// self.buffer[idx] = !filling;
|
|
|
|
|
|
|
|
// },
|
|
|
|
assert_eq!(buffer[0], Color::Black.get_byte_value()); |
|
|
|
// Color::White => {
|
|
|
|
|
|
|
|
// self.buffer[idx] = filling;
|
|
|
|
for &byte in buffer.iter().skip(1) { |
|
|
|
// }
|
|
|
|
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: write tests
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn graphics_4in2_rotation_180() { |
|
|
|
|
|
|
|
let mut display = DisplayEink42BlackWhite::default(); |
|
|
|
|
|
|
|
display.set_rotation(DisplayRotation::Rotate180); |
|
|
|
|
|
|
|
display.draw( |
|
|
|
|
|
|
|
Line::new(Coord::new(392, 299), Coord::new(399, 299)) |
|
|
|
|
|
|
|
.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, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn graphics_4in2_rotation_270() { |
|
|
|
|
|
|
|
let mut display = DisplayEink42BlackWhite::default(); |
|
|
|
|
|
|
|
display.set_rotation(DisplayRotation::Rotate270); |
|
|
|
|
|
|
|
display.draw( |
|
|
|
|
|
|
|
Line::new(Coord::new(299, 0), Coord::new(299, 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, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |