Fix epd1in54 example, test if old bugs are fixed
parent
8922707bac
commit
9289d689b7
|
|
@ -7,8 +7,10 @@ authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
|||
|
||||
#eink_waveshare_rs = { git = "https://github.com/Caemor/eink-waveshare-rs"}
|
||||
#eink_waveshare_rs = { path = "../../"}
|
||||
eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd1in54"]}
|
||||
eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]}
|
||||
|
||||
linux-embedded-hal = "0.2.0"
|
||||
|
||||
embedded-graphics = "0.4.3"
|
||||
|
||||
embedded-hal = { version = "0.2.1", features = ["unproven"] }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ extern crate eink_waveshare_rs;
|
|||
|
||||
use eink_waveshare_rs::{
|
||||
EPD1in54,
|
||||
//drawing_old::{Graphics},
|
||||
DisplayEink1in54BlackWhite,
|
||||
graphics::{Display, DisplayRotation},
|
||||
color::Color,
|
||||
WaveshareDisplay,
|
||||
};
|
||||
|
|
@ -17,6 +18,16 @@ use lin_hal::{Pin, Spidev};
|
|||
use lin_hal::sysfs_gpio::Direction;
|
||||
use lin_hal::Delay;
|
||||
|
||||
extern crate embedded_graphics;
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::fonts::{Font6x8};
|
||||
use embedded_graphics::prelude::*;
|
||||
//use embedded_graphics::primitives::{Circle, Line};
|
||||
use embedded_graphics::Drawing;
|
||||
|
||||
extern crate embedded_hal;
|
||||
use embedded_hal::prelude::*;
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
|
||||
|
|
@ -25,7 +36,6 @@ use lin_hal::Delay;
|
|||
// DigitalIn Hack as long as it's not in the linux_embedded_hal
|
||||
// from https://github.com/rudihorn/max31865/blob/extra_examples/examples/rpi.rs
|
||||
// (slightly changed now as OutputPin doesn't provide is_high and is_low anymore)
|
||||
extern crate embedded_hal;
|
||||
use embedded_hal::digital::{InputPin};
|
||||
|
||||
//TODO: Remove when linux_embedded_hal implements InputPin
|
||||
|
|
@ -114,31 +124,48 @@ fn run() -> Result<(), std::io::Error> {
|
|||
epd.clear_frame(&mut spi).expect("clear frame 1");
|
||||
epd.display_frame(&mut spi).expect("disp 1");
|
||||
|
||||
// Speeddemo
|
||||
let small_buffer = [Color::Black.get_byte_value(); 32];//16x16
|
||||
let number_of_runs = 1;
|
||||
for i in 0..number_of_runs {
|
||||
let offset = i * 8 % 150;
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 25 + offset, 25 + offset, 16, 16).expect("partial frame");
|
||||
epd.display_frame(&mut spi).expect("disp 2");
|
||||
}
|
||||
println!("Test all the rotations");
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// Clear the full screen
|
||||
epd.clear_frame(&mut spi).expect("clear frame 2");
|
||||
epd.display_frame(&mut spi).expect("disp 3");
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 90!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// Draw some squares
|
||||
let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 20, 20, 160, 160)?;
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 180!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
let small_buffer = [Color::White.get_byte_value(); 800]; //80x80
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 60, 60, 80, 80)?;
|
||||
|
||||
let small_buffer = [Color::Black.get_byte_value(); 8]; //8x8
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8).expect("partial frame 2");
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 270!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// Display updated frame
|
||||
epd.display_frame(&mut spi).expect("disp 4");
|
||||
epd.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
epd.display_frame(&mut spi).expect("display frame new graphics");
|
||||
delay.delay_ms(5000u16);
|
||||
|
||||
// Set the EPD to sleep
|
||||
epd.sleep(&mut spi).expect("sleep");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
use graphics::{
|
||||
outside_display,
|
||||
rotation,
|
||||
DisplayRotation,
|
||||
Display
|
||||
};
|
||||
use color::Color;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
||||
|
||||
pub struct DisplayEink1in54BlackWhite {
|
||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation,
|
||||
}
|
||||
|
||||
impl Default for DisplayEink1in54BlackWhite {
|
||||
fn default() -> Self {
|
||||
DisplayEink1in54BlackWhite {
|
||||
buffer: [
|
||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR};
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::primitives::Line;
|
||||
|
||||
// test buffer length
|
||||
#[test]
|
||||
fn graphics_size() {
|
||||
let display = DisplayEink1in54BlackWhite::default();
|
||||
assert_eq!(display.buffer().len(), 5000);
|
||||
}
|
||||
|
||||
// test default background color on all bytes
|
||||
#[test]
|
||||
fn graphics_default() {
|
||||
let display = DisplayEink1in54BlackWhite::default();
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_0() {
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 0), Coord::new(7, 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, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_90() {
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 192), Coord::new(0, 199))
|
||||
.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, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_180() {
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Line::new(Coord::new(192, 199), Coord::new(199, 199))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
let buffer = display.buffer();
|
||||
|
||||
extern crate std;
|
||||
std::println!("{:?}", buffer);
|
||||
|
||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||
|
||||
for &byte in buffer.iter().skip(1) {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_270() {
|
||||
let mut display = DisplayEink1in54BlackWhite::default();
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Line::new(Coord::new(199, 0), Coord::new(199, 7))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
let buffer = display.buffer();
|
||||
|
||||
extern crate std;
|
||||
std::println!("{:?}", buffer);
|
||||
|
||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||
|
||||
for &byte in buffer.iter().skip(1) {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,8 @@ use traits::{WaveshareDisplay};
|
|||
|
||||
use interface::DisplayInterface;
|
||||
|
||||
pub mod graphics;
|
||||
|
||||
/// EPD1in54 driver
|
||||
///
|
||||
pub struct EPD1in54<SPI, CS, BUSY, DC, RST> {
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@ pub use epd4in2::graphics::DisplayEink42BlackWhite;
|
|||
mod epd1in54;
|
||||
#[cfg(feature = "epd1in54")]
|
||||
pub use epd1in54::EPD1in54;
|
||||
#[cfg(feature = "epd1in54")]
|
||||
pub use epd1in54::graphics::DisplayEink1in54BlackWhite;
|
||||
|
||||
|
||||
#[cfg(feature = "epd2in9")]
|
||||
mod epd2in9;
|
||||
|
|
|
|||
Loading…
Reference in New Issue