add impl Drawing<Color> for DisplayEink42BlackWhite
fix error by using option for styleembedded-hal-1.0
parent
e92af2198a
commit
ff21d6e611
|
|
@ -193,22 +193,22 @@ fn run() -> Result<(), std::io::Error> {
|
||||||
let mut display = DisplayEink42BlackWhite::default();
|
let mut display = DisplayEink42BlackWhite::default();
|
||||||
display.draw(
|
display.draw(
|
||||||
Circle::new(Coord::new(64, 64), 64)
|
Circle::new(Coord::new(64, 64), 64)
|
||||||
.with_stroke(Color::Black)
|
.with_stroke(Some(Color::Black))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
display.draw(
|
display.draw(
|
||||||
Line::new(Coord::new(64, 64), Coord::new(0, 64))
|
Line::new(Coord::new(64, 64), Coord::new(0, 64))
|
||||||
.with_stroke(Color::Black)
|
.with_stroke(Some(Color::Black))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
display.draw(
|
display.draw(
|
||||||
Line::new(Coord::new(64, 64), Coord::new(80, 80))
|
Line::new(Coord::new(64, 64), Coord::new(80, 80))
|
||||||
.with_stroke(Color::Black)
|
.with_stroke(Some(Color::Black))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str("Hello World!")
|
Font6x8::render_str("Hello World!")
|
||||||
.with_stroke(Color::Black)
|
.with_stroke(Some(Color::Black))
|
||||||
.translate(Coord::new(5 + i*10, 50))
|
.translate(Coord::new(5 + i*10, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
// impl Drawing<u8> for DisplayRibbonLeft {
|
||||||
// fn draw<T>(&mut self, item_pixels: T)
|
// fn draw<T>(&mut self, item_pixels: T)
|
||||||
// where
|
// where
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue