|
|
|
|
@ -19,29 +19,18 @@ impl Default for DisplayRotation {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub enum Display { |
|
|
|
|
Eink42BlackWhite, |
|
|
|
|
} |
|
|
|
|
impl Display { |
|
|
|
|
/// 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 { |
|
|
|
|
pub trait Display { |
|
|
|
|
fn get_buffer(&self) -> &[u8]; |
|
|
|
|
fn set_rotation(&mut self, rotation: DisplayRotation); |
|
|
|
|
fn rotation(&self) -> DisplayRotation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct DisplayEink42BlackWhite { |
|
|
|
|
buffer: [u8; 400 * 300 / 8], |
|
|
|
|
rotation: DisplayRotation, //TODO: check embedded_graphics for orientation
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for DisplayEink42BlackWhite { |
|
|
|
|
fn default() -> Self { |
|
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
|
@ -54,42 +43,16 @@ impl Default for DisplayEink42BlackWhite {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
impl Buffer for DisplayEink42BlackWhite { |
|
|
|
|
|
|
|
|
|
impl Display for DisplayEink42BlackWhite { |
|
|
|
|
fn get_buffer(&self) -> &[u8] { |
|
|
|
|
&self.buffer |
|
|
|
|
} |
|
|
|
|
fn set_rotation(&mut self, rotation: DisplayRotation) { |
|
|
|
|
self.rotation = rotation; |
|
|
|
|
} |
|
|
|
|
impl Drawing<u8> for DisplayEink42BlackWhite { |
|
|
|
|
fn draw<T>(&mut self, item_pixels: T) |
|
|
|
|
where |
|
|
|
|
T: Iterator<Item = Pixel<u8>> |
|
|
|
|
{ |
|
|
|
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; |
|
|
|
|
for Pixel(UnsignedCoord(x,y), color) in item_pixels { |
|
|
|
|
let (idx, bit) = match self.rotation { |
|
|
|
|
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => ( |
|
|
|
|
(x as usize / 8 + (WIDTH as usize / 8) * y as usize), |
|
|
|
|
0x80 >> (x % 8), |
|
|
|
|
), |
|
|
|
|
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => ( |
|
|
|
|
y as usize / 8 * WIDTH as usize + x as usize, |
|
|
|
|
0x80 >> (y % 8), |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if idx >= self.buffer.len() { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
match Color::from(color) { |
|
|
|
|
Color::Black => { |
|
|
|
|
self.buffer[idx] &= !bit; |
|
|
|
|
} |
|
|
|
|
Color::White => { |
|
|
|
|
self.buffer[idx] |= bit; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
fn rotation(&self) -> DisplayRotation { |
|
|
|
|
self.rotation |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -127,83 +90,4 @@ impl Drawing<Color> for DisplayEink42BlackWhite {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// impl Drawing<u8> for DisplayRibbonLeft {
|
|
|
|
|
// fn draw<T>(&mut self, item_pixels: T)
|
|
|
|
|
// where
|
|
|
|
|
// T: Iterator<Item = Pixel<u8>>,
|
|
|
|
|
// {
|
|
|
|
|
// for Pixel(UnsignedCoord(x, y), color) in item_pixels {
|
|
|
|
|
// if y > 127 || x > 295 {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// let cell = &mut self.0[y as usize / 8 + (295 - x as usize) * 128 / 8];
|
|
|
|
|
// let bit = 7 - y % 8;
|
|
|
|
|
// if color != 0 {
|
|
|
|
|
// *cell &= !(1 << bit);
|
|
|
|
|
// } else {
|
|
|
|
|
// *cell |= 1 << bit;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /// 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) {
|
|
|
|
|
// let (idx, bit) = match self.rotation {
|
|
|
|
|
// Displayorientation::Rotate0 | Displayorientation::Rotate180 => (
|
|
|
|
|
// (x as usize / 8 + (self.width as usize / 8) * y as usize),
|
|
|
|
|
// 0x80 >> (x % 8),
|
|
|
|
|
// ),
|
|
|
|
|
// Displayorientation::Rotate90 | Displayorientation::Rotate270 => (
|
|
|
|
|
// y as usize / 8 * self.width as usize + x as usize,
|
|
|
|
|
// 0x80 >> (y % 8),
|
|
|
|
|
// ),
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// if idx >= self.buffer.len() {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// match color {
|
|
|
|
|
// Color::Black => {
|
|
|
|
|
// self.buffer[idx] &= !bit;
|
|
|
|
|
// }
|
|
|
|
|
// Color::White => {
|
|
|
|
|
// self.buffer[idx] |= bit;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /// Draw a single Pixel with `color`
|
|
|
|
|
// ///
|
|
|
|
|
// /// limited to i16::max images (buffer_size) at the moment
|
|
|
|
|
// #[allow(dead_code)]
|
|
|
|
|
// fn draw_byte(&mut self, x: u16, y: u16, filling: u8, color: &Color) {
|
|
|
|
|
// let idx = match self.rotation {
|
|
|
|
|
// Displayorientation::Rotate0 | Displayorientation::Rotate180 => {
|
|
|
|
|
// x as usize / 8 + (self.width as usize / 8) * y as usize
|
|
|
|
|
// },
|
|
|
|
|
// Displayorientation::Rotate90 | Displayorientation::Rotate270 => {
|
|
|
|
|
// y as usize / 8 + (self.width as usize / 8) * x as usize
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// if idx >= self.buffer.len() {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// match color {
|
|
|
|
|
// Color::Black => {
|
|
|
|
|
// self.buffer[idx] = !filling;
|
|
|
|
|
// },
|
|
|
|
|
// Color::White => {
|
|
|
|
|
// self.buffer[idx] = filling;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//TODO: write tests
|