mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +00:00
add impl Drawing<Color> for DisplayEink42BlackWhite
fix error by using option for style
This commit is contained in:
@@ -93,6 +93,40 @@ impl Drawing<u8> for DisplayEink42BlackWhite {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawing<Color> for DisplayEink42BlackWhite {
|
||||
fn draw<T>(&mut self, item_pixels: T)
|
||||
where
|
||||
T: Iterator<Item = Pixel<Color>>
|
||||
{
|
||||
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 {
|
||||
Color::Black => {
|
||||
self.buffer[idx] &= !bit;
|
||||
}
|
||||
Color::White => {
|
||||
self.buffer[idx] |= bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl Drawing<u8> for DisplayRibbonLeft {
|
||||
// fn draw<T>(&mut self, item_pixels: T)
|
||||
// where
|
||||
|
||||
Reference in New Issue
Block a user