use generalised graphics with new specialised buffers
parent
1baf35c1a4
commit
f6a894c5a3
|
|
@ -1,17 +1,7 @@
|
||||||
use graphics::{
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||||
outside_display,
|
|
||||||
rotation,
|
|
||||||
DisplayRotation,
|
|
||||||
Display
|
|
||||||
};
|
|
||||||
use color::Color;
|
|
||||||
use embedded_graphics::prelude::*;
|
|
||||||
|
|
||||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
|
||||||
|
|
||||||
pub struct DisplayEink1in54BlackWhite {
|
pub struct DisplayEink1in54BlackWhite {
|
||||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||||
rotation: DisplayRotation,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DisplayEink1in54BlackWhite {
|
impl Default for DisplayEink1in54BlackWhite {
|
||||||
|
|
@ -20,71 +10,34 @@ impl Default for DisplayEink1in54BlackWhite {
|
||||||
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
|
||||||
],
|
]
|
||||||
rotation: DisplayRotation::default()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for DisplayEink1in54BlackWhite {
|
|
||||||
fn buffer(&self) -> &[u8] {
|
|
||||||
&self.buffer
|
|
||||||
}
|
|
||||||
fn set_rotation(&mut self, rotation: DisplayRotation) {
|
|
||||||
self.rotation = rotation;
|
|
||||||
}
|
|
||||||
fn rotation(&self) -> DisplayRotation {
|
|
||||||
self.rotation
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Drawing<Color> for DisplayEink1in54BlackWhite {
|
|
||||||
fn draw<T>(&mut self, item_pixels: T)
|
|
||||||
where
|
|
||||||
T: Iterator<Item = Pixel<Color>>
|
|
||||||
{
|
|
||||||
let width = WIDTH as u32;
|
|
||||||
let height = HEIGHT as u32;
|
|
||||||
|
|
||||||
for Pixel(UnsignedCoord(x,y), color) in item_pixels {
|
|
||||||
if outside_display(x, y, width, height, self.rotation) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (idx, bit) = rotation(x, y, width, height, self.rotation);
|
|
||||||
|
|
||||||
let idx = idx as usize;
|
|
||||||
match color {
|
|
||||||
Color::Black => {
|
|
||||||
self.buffer[idx] &= !bit;
|
|
||||||
}
|
|
||||||
Color::White => {
|
|
||||||
self.buffer[idx] |= bit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR};
|
use graphics::{DisplayRotation, Graphics};
|
||||||
use embedded_graphics::coord::Coord;
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::primitives::Line;
|
use embedded_graphics::primitives::Line;
|
||||||
|
use color::Color;
|
||||||
|
use embedded_graphics::prelude::*;
|
||||||
|
|
||||||
// test buffer length
|
// test buffer length
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_size() {
|
fn graphics_size() {
|
||||||
let display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let display = Graphics::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||||
assert_eq!(display.buffer().len(), 5000);
|
assert_eq!(display.buffer().len(), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test default background color on all bytes
|
// test default background color on all bytes
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_default() {
|
fn graphics_default() {
|
||||||
let display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let display = Graphics::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());
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +45,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_0() {
|
fn graphics_rotation_0() {
|
||||||
let mut display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let mut display = Graphics::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))
|
||||||
|
|
@ -110,7 +64,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_90() {
|
fn graphics_rotation_90() {
|
||||||
let mut display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let mut display = Graphics::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))
|
||||||
|
|
@ -129,7 +84,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_180() {
|
fn graphics_rotation_180() {
|
||||||
let mut display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let mut display = Graphics::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))
|
||||||
|
|
@ -152,7 +108,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_270() {
|
fn graphics_rotation_270() {
|
||||||
let mut display = DisplayEink1in54BlackWhite::default();
|
let mut display1in54 = DisplayEink1in54BlackWhite::default();
|
||||||
|
let mut display = Graphics::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,14 +1,3 @@
|
||||||
use graphics::{
|
|
||||||
outside_display,
|
|
||||||
rotation,
|
|
||||||
DisplayRotation,
|
|
||||||
Display
|
|
||||||
};
|
|
||||||
use color::Color;
|
|
||||||
use embedded_graphics::prelude::*;
|
|
||||||
|
|
||||||
use graphics::Graphics;
|
|
||||||
|
|
||||||
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||||
|
|
||||||
pub struct DisplayEink4in2BlackWhite {
|
pub struct DisplayEink4in2BlackWhite {
|
||||||
|
|
@ -32,9 +21,11 @@ impl Default for DisplayEink4in2BlackWhite {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use epd4in2;
|
use epd4in2;
|
||||||
use graphics::Graphics;
|
use graphics::{DisplayRotation, Graphics};
|
||||||
use embedded_graphics::coord::Coord;
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::primitives::Line;
|
use embedded_graphics::primitives::Line;
|
||||||
|
use color::Color;
|
||||||
|
use embedded_graphics::prelude::*;
|
||||||
|
|
||||||
// test buffer length
|
// test buffer length
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -48,7 +39,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_default() {
|
fn graphics_default() {
|
||||||
let mut display4in2 = DisplayEink4in2BlackWhite::default();
|
let mut display4in2 = DisplayEink4in2BlackWhite::default();
|
||||||
let mut display = Graphics::new(WIDTH, HEIGHT, &mut display4in2.buffer);
|
let display = Graphics::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());
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ impl Default for DisplayRotation {
|
||||||
DisplayRotation::Rotate0
|
DisplayRotation::Rotate0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
//use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||||
|
|
||||||
pub trait Display {
|
pub trait Display {
|
||||||
fn buffer(&self) -> &[u8];
|
fn buffer(&self) -> &[u8];
|
||||||
|
|
@ -63,15 +63,12 @@ impl<'a> Drawing<Color> for Graphics<'a> {
|
||||||
where
|
where
|
||||||
T: Iterator<Item = Pixel<Color>>
|
T: Iterator<Item = Pixel<Color>>
|
||||||
{
|
{
|
||||||
let width = WIDTH as u32;
|
|
||||||
let height = HEIGHT as u32;
|
|
||||||
|
|
||||||
for Pixel(UnsignedCoord(x,y), color) in item_pixels {
|
for Pixel(UnsignedCoord(x,y), color) in item_pixels {
|
||||||
if outside_display(x, y, width, height, self.rotation) {
|
if outside_display(x, y, self.width, self.height, self.rotation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (idx, bit) = rotation(x, y, width, height, self.rotation);
|
let (idx, bit) = rotation(x, y, self.width, self.height, self.rotation);
|
||||||
|
|
||||||
let idx = idx as usize;
|
let idx = idx as usize;
|
||||||
match color {
|
match color {
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,14 @@ mod epd4in2;
|
||||||
#[cfg(feature = "epd4in2")]
|
#[cfg(feature = "epd4in2")]
|
||||||
pub use epd4in2::EPD4in2;
|
pub use epd4in2::EPD4in2;
|
||||||
#[cfg(feature = "epd4in2")]
|
#[cfg(feature = "epd4in2")]
|
||||||
pub use epd4in2::graphics::DisplayEink4in2BlackWhite;
|
pub use epd4in2::graphics::DisplayEink4in2BlackWhite as Buffer4in2;
|
||||||
|
|
||||||
#[cfg(feature = "epd1in54")]
|
#[cfg(feature = "epd1in54")]
|
||||||
mod epd1in54;
|
mod epd1in54;
|
||||||
#[cfg(feature = "epd1in54")]
|
#[cfg(feature = "epd1in54")]
|
||||||
pub use epd1in54::EPD1in54;
|
pub use epd1in54::EPD1in54;
|
||||||
#[cfg(feature = "epd1in54")]
|
#[cfg(feature = "epd1in54")]
|
||||||
pub use epd1in54::graphics::DisplayEink1in54BlackWhite;
|
pub use epd1in54::graphics::DisplayEink1in54BlackWhite as Buffer1in54;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "epd2in9")]
|
#[cfg(feature = "epd2in9")]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue