Fixed examples and more small improvements

digi-v2-tests
Chris 5 years ago
parent 3b0b5962ec
commit 520317f351

@ -6,8 +6,10 @@ extern crate eink_waveshare_rs;
use eink_waveshare_rs::{
EPD1in54,
Buffer1in54,
epd1in54::{
EPD1in54,
Buffer1in54,
},
graphics::{Display, DisplayRotation},
color::Color,
WaveshareDisplay,

@ -6,8 +6,10 @@ extern crate eink_waveshare_rs;
use eink_waveshare_rs::{
EPD4in2,
Buffer4in2,
epd4in2::{
EPD4in2,
Buffer4in2,
},
graphics::{Display, DisplayRotation},
color::Color,
WaveshareDisplay,
@ -162,7 +164,7 @@ fn run() -> Result<(), std::io::Error> {
println!("Now test new graphics with default rotation and some special stuff:");
let mut display = DisplayEink42BlackWhite::default();
display.clear_buffer(Color::White);
// draw a analog clock
display.draw(

@ -48,7 +48,7 @@ impl Color {
}
// Inverses the given color from Black to White or from White to Black
fn inverse_color(color: &Color) -> Color {
pub(crate) fn inverse_color(color: &Color) -> Color {
match color {
Color::White => Color::Black,
Color::Black => Color::White,

@ -40,7 +40,8 @@ use traits::{WaveshareDisplay};
use interface::DisplayInterface;
pub mod graphics;
mod graphics;
pub use epd1in54::graphics::Buffer1in54BlackWhite as Buffer1in54;
/// EPD1in54 driver
///

@ -19,9 +19,9 @@
//! epd4in2.sleep();
//! ```
const WIDTH: u32 = 128;
const HEIGHT: u32 = 296;
const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
pub const WIDTH: u32 = 128;
pub const HEIGHT: u32 = 296;
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
use hal::{
blocking::{delay::*, spi::Write},

@ -1,8 +1,8 @@
use color::Color;
pub(crate) const WIDTH: u32 = 400;
pub(crate) const HEIGHT: u32 = 300;
pub(crate) const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
pub const WIDTH: u32 = 400;
pub const HEIGHT: u32 = 300;
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
pub(crate) const LUT_VCOM0: [u8; 44] = [
0x00, 0x17, 0x00, 0x00, 0x00, 0x02,

@ -56,14 +56,15 @@ use interface::DisplayInterface;
//The Lookup Tables for the Display
pub(crate) mod constants; //TODO: Limit to crate::drawing
use self::constants::*;
pub use self::constants::*;
use color::Color;
pub(crate) mod command;
use self::command::Command;
pub mod graphics;
mod graphics;
pub use self::graphics::Buffer4in2;
/// EPD4in2 driver

@ -43,10 +43,16 @@ impl<'a> Display<'a> {
&self.buffer
}
pub fn clear_buffer(&mut self, background_color: Color) {
for elem in &mut self.buffer.iter_mut() {
*elem = background_color.get_byte_value();
}
}
pub fn set_rotation(&mut self, rotation: DisplayRotation) {
self.rotation = rotation;
}
pub fn rotation(&self) -> DisplayRotation {
self.rotation
}
@ -120,7 +126,27 @@ pub(crate) fn rotation(x: u32, y: u32, width: u32, height: u32, rotation: Displa
#[cfg(test)]
mod tests {
use super::{DisplayRotation, outside_display, rotation};
use super::{DisplayRotation, outside_display, rotation, Display};
use color::Color;
#[test]
fn buffer_clear() {
use epd4in2::constants::{WIDTH, HEIGHT};
let mut buffer = [Color::Black.get_byte_value(); WIDTH as usize / 8 * HEIGHT as usize];
let mut display = Display::new(WIDTH, HEIGHT, &mut buffer);
for &byte in display.buffer.iter() {
assert_eq!(byte, Color::Black.get_byte_value());
}
display.clear_buffer(Color::White);
for &byte in display.buffer.iter() {
assert_eq!(byte, Color::White.get_byte_value());
}
}
#[test]
fn rotation_overflow() {

@ -63,26 +63,13 @@ pub mod color;
mod interface;
#[cfg(feature = "epd4in2")]
mod epd4in2;
#[cfg(feature = "epd4in2")]
pub use epd4in2::EPD4in2;
#[cfg(feature = "epd4in2")]
pub use epd4in2::graphics::Buffer4in2;
pub mod epd4in2;
#[cfg(feature = "epd1in54")]
mod epd1in54;
#[cfg(feature = "epd1in54")]
pub use epd1in54::EPD1in54;
#[cfg(feature = "epd1in54")]
pub use epd1in54::graphics::Buffer1in54BlackWhite as Buffer1in54;
pub mod epd1in54;
#[cfg(feature = "epd2in9")]
mod epd2in9;
///2in9 eink
#[cfg(feature = "epd2in9")]
///2in9 eink
pub use epd2in9::EPD2in9;
pub mod epd2in9;
#[cfg(any(feature = "epd1in54", feature = "epd2in9"))]
pub(crate) mod type_a;

Loading…
Cancel
Save