Browse Source

Cargo fmt

main
Mitch Souders 5 years ago
parent
commit
e225464b62
  1. 2
      src/color.rs
  2. 70
      src/epd5in65f/graphics.rs
  3. 1
      src/epd5in65f/mod.rs
  4. 13
      src/graphics.rs
  5. 6
      src/lib.rs

2
src/color.rs

@ -83,7 +83,7 @@ impl OctColor {
0x05 => Ok(OctColor::Yellow), 0x05 => Ok(OctColor::Yellow),
0x06 => Ok(OctColor::Orange), 0x06 => Ok(OctColor::Orange),
0x07 => Ok(OctColor::HiZ), 0x07 => Ok(OctColor::HiZ),
_ => Err(()) _ => Err(()),
} }
} }
///Split the nibbles of a single byte and convert both to an OctColor if possible ///Split the nibbles of a single byte and convert both to an OctColor if possible

70
src/epd5in65f/graphics.rs

@ -1,7 +1,7 @@
use crate::color::OctColor;
use crate::epd5in65f::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; use crate::epd5in65f::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{OctDisplay, DisplayRotation}; use crate::graphics::{DisplayRotation, OctDisplay};
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
use crate::color::OctColor;
/// Full size buffer for use with the 5in65f EPD /// Full size buffer for use with the 5in65f EPD
/// ///
@ -56,7 +56,7 @@ impl OctDisplay for Display5in65f {
mod tests { mod tests {
use super::*; use super::*;
use crate::epd5in65f; use crate::epd5in65f;
use crate::graphics::{OctDisplay, DisplayRotation}; use crate::graphics::{DisplayRotation, OctDisplay};
use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; use embedded_graphics::{primitives::Line, style::PrimitiveStyle};
// test buffer length // test buffer length
@ -71,10 +71,13 @@ mod tests {
fn graphics_default() { fn graphics_default() {
let display = Display5in65f::default(); let display = Display5in65f::default();
for &byte in display.buffer() { for &byte in display.buffer() {
assert_eq!(byte, OctColor::colors_byte( assert_eq!(
byte,
OctColor::colors_byte(
epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR,
epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR,
)); )
);
} }
} }
@ -89,13 +92,19 @@ mod tests {
let buffer = display.buffer(); let buffer = display.buffer();
for &byte in buffer.iter().take(1) { for &byte in buffer.iter().take(1) {
assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); assert_eq!(
OctColor::split_byte(byte),
Ok((OctColor::Black, OctColor::Black))
);
} }
for &byte in buffer.iter().skip(1) { for &byte in buffer.iter().skip(1) {
assert_eq!( assert_eq!(
OctColor::split_byte(byte), OctColor::split_byte(byte),
Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) Ok((
epd5in65f::DEFAULT_BACKGROUND_COLOR,
epd5in65f::DEFAULT_BACKGROUND_COLOR
))
); );
} }
} }
@ -105,20 +114,29 @@ mod tests {
let mut display = Display5in65f::default(); let mut display = Display5in65f::default();
display.set_rotation(DisplayRotation::Rotate90); display.set_rotation(DisplayRotation::Rotate90);
let _ = Line::new(Point::new(0, WIDTH as i32 - 2), Point::new(0, WIDTH as i32- 1)) let _ = Line::new(
Point::new(0, WIDTH as i32 - 2),
Point::new(0, WIDTH as i32 - 1),
)
.into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1))
.draw(&mut display); .draw(&mut display);
let buffer = display.buffer(); let buffer = display.buffer();
for &byte in buffer.iter().take(1) { for &byte in buffer.iter().take(1) {
assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); assert_eq!(
OctColor::split_byte(byte),
Ok((OctColor::Black, OctColor::Black))
);
} }
for &byte in buffer.iter().skip(1) { for &byte in buffer.iter().skip(1) {
assert_eq!( assert_eq!(
OctColor::split_byte(byte), OctColor::split_byte(byte),
Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) Ok((
epd5in65f::DEFAULT_BACKGROUND_COLOR,
epd5in65f::DEFAULT_BACKGROUND_COLOR
))
); );
} }
} }
@ -128,21 +146,29 @@ mod tests {
let mut display = Display5in65f::default(); let mut display = Display5in65f::default();
display.set_rotation(DisplayRotation::Rotate180); display.set_rotation(DisplayRotation::Rotate180);
let _ = Line::new(Point::new(WIDTH as i32 - 2, HEIGHT as i32 - 1), let _ = Line::new(
Point::new(WIDTH as i32 - 1, HEIGHT as i32 - 1)) Point::new(WIDTH as i32 - 2, HEIGHT as i32 - 1),
Point::new(WIDTH as i32 - 1, HEIGHT as i32 - 1),
)
.into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1))
.draw(&mut display); .draw(&mut display);
let buffer = display.buffer(); let buffer = display.buffer();
for &byte in buffer.iter().take(1) { for &byte in buffer.iter().take(1) {
assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); assert_eq!(
OctColor::split_byte(byte),
Ok((OctColor::Black, OctColor::Black))
);
} }
for &byte in buffer.iter().skip(1) { for &byte in buffer.iter().skip(1) {
assert_eq!( assert_eq!(
OctColor::split_byte(byte), OctColor::split_byte(byte),
Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) Ok((
epd5in65f::DEFAULT_BACKGROUND_COLOR,
epd5in65f::DEFAULT_BACKGROUND_COLOR
))
); );
} }
} }
@ -152,21 +178,29 @@ mod tests {
let mut display = Display5in65f::default(); let mut display = Display5in65f::default();
display.set_rotation(DisplayRotation::Rotate270); display.set_rotation(DisplayRotation::Rotate270);
let _ = Line::new(Point::new(HEIGHT as i32 -1, 0), let _ = Line::new(
Point::new(HEIGHT as i32 -1, 1)) Point::new(HEIGHT as i32 - 1, 0),
Point::new(HEIGHT as i32 - 1, 1),
)
.into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1))
.draw(&mut display); .draw(&mut display);
let buffer = display.buffer(); let buffer = display.buffer();
for &byte in buffer.iter().take(1) { for &byte in buffer.iter().take(1) {
assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); assert_eq!(
OctColor::split_byte(byte),
Ok((OctColor::Black, OctColor::Black))
);
} }
for &byte in buffer.iter().skip(1) { for &byte in buffer.iter().skip(1) {
assert_eq!( assert_eq!(
OctColor::split_byte(byte), OctColor::split_byte(byte),
Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) Ok((
epd5in65f::DEFAULT_BACKGROUND_COLOR,
epd5in65f::DEFAULT_BACKGROUND_COLOR
))
); );
} }
} }

1
src/epd5in65f/mod.rs

@ -6,7 +6,6 @@
//! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_5in65f.c) //! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_5in65f.c)
//! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd5in65f.py) //! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd5in65f.py)
use embedded_hal::{ use embedded_hal::{
blocking::{delay::*, spi::Write}, blocking::{delay::*, spi::Write},
digital::v2::{InputPin, OutputPin}, digital::v2::{InputPin, OutputPin},

13
src/graphics.rs

@ -1,7 +1,7 @@
//! Graphics Support for EPDs //! Graphics Support for EPDs
use crate::buffer_len; use crate::buffer_len;
use crate::color::{OctColor, Color}; use crate::color::{Color, OctColor};
use embedded_graphics::{pixelcolor::BinaryColor, prelude::*}; use embedded_graphics::{pixelcolor::BinaryColor, prelude::*};
/// Displayrotation /// Displayrotation
@ -129,7 +129,8 @@ pub trait OctDisplay: DrawTarget<OctColor> {
} }
// Give us index inside the buffer and the bit-position in that u8 which needs to be changed // Give us index inside the buffer and the bit-position in that u8 which needs to be changed
let (index, upper) = find_oct_position(point.x as u32, point.y as u32, width, height, rotation); let (index, upper) =
find_oct_position(point.x as u32, point.y as u32, width, height, rotation);
let index = index as usize; let index = index as usize;
// "Draw" the Pixel on that bit // "Draw" the Pixel on that bit
@ -251,19 +252,19 @@ fn find_rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotat
DisplayRotation::Rotate0 => { DisplayRotation::Rotate0 => {
nx = x; nx = x;
ny = y; ny = y;
}, }
DisplayRotation::Rotate90 => { DisplayRotation::Rotate90 => {
nx = width - 1 - y; nx = width - 1 - y;
ny = x; ny = x;
} , }
DisplayRotation::Rotate180 => { DisplayRotation::Rotate180 => {
nx = width - 1 - x; nx = width - 1 - x;
ny = height - 1 - y; ny = height - 1 - y;
}, }
DisplayRotation::Rotate270 => { DisplayRotation::Rotate270 => {
nx = y; nx = y;
ny = height - 1 - x; ny = height - 1 - x;
}, }
} }
(nx, ny) (nx, ny)
} }

6
src/lib.rs

@ -78,21 +78,21 @@ pub mod epd2in13_v2;
pub mod epd2in9; pub mod epd2in9;
pub mod epd2in9bc; pub mod epd2in9bc;
pub mod epd4in2; pub mod epd4in2;
pub mod epd5in65f;
pub mod epd7in5; pub mod epd7in5;
pub mod epd7in5_v2; pub mod epd7in5_v2;
pub mod epd5in65f;
pub(crate) mod type_a; pub(crate) mod type_a;
/// Includes everything important besides the chosen Display /// Includes everything important besides the chosen Display
pub mod prelude { pub mod prelude {
pub use crate::color::{Color, TriColor, OctColor}; pub use crate::color::{Color, OctColor, TriColor};
pub use crate::traits::{RefreshLUT, WaveshareDisplay, WaveshareThreeColorDisplay}; pub use crate::traits::{RefreshLUT, WaveshareDisplay, WaveshareThreeColorDisplay};
pub use crate::SPI_MODE; pub use crate::SPI_MODE;
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
pub use crate::graphics::{OctDisplay, Display, DisplayRotation}; pub use crate::graphics::{Display, DisplayRotation, OctDisplay};
} }
/// Computes the needed buffer length. Takes care of rounding up in case width /// Computes the needed buffer length. Takes care of rounding up in case width

Loading…
Cancel
Save