Fixed draw_pixel

This commit is contained in:
Zac Wilson 2025-12-21 13:36:32 +00:00
parent 16d8071a03
commit 0804a16639

View file

@ -217,17 +217,20 @@ impl DoubleFrame<AutomaticPartialWindow> {
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> { impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) { pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
if x >= EPD_WIDTH as u16 || y >= EPD_HEIGHT as u16 {
return; // pixel is offscreen so can be skipped
}
self.partial_window.update_partial_window(x, x, y, y); self.partial_window.update_partial_window(x, x, y, y);
let x_i = x / 8; let x_i = x as usize / 8;
let x_shift = x % 8; let x_shift = 7 - (x % 8);
let i = y * (EPD_WIDTH as u16 / 8) + x_i; let i = y as usize * (EPD_WIDTH / 8) + x_i;
match colour { match colour {
PixelColour::Black => { PixelColour::Black => {
self.new.0[i as usize] &= !(1 << x_shift); self.new.0[i as usize] &= !(1 << x_shift);
}, }
PixelColour::White => { PixelColour::White => {
self.new.0[i as usize] |= 1 << x_shift; self.new.0[i as usize] |= 1 << x_shift;
}, }
} }
} }
} }