From 0804a166396e1129cd70f8b7b5e988e844e0721e Mon Sep 17 00:00:00 2001 From: Zac Wilson Date: Sun, 21 Dec 2025 13:36:32 +0000 Subject: [PATCH] Fixed draw_pixel --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f0376f9..124fd38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,17 +217,20 @@ impl DoubleFrame { impl DoubleFrame { 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); - let x_i = x / 8; - let x_shift = x % 8; - let i = y * (EPD_WIDTH as u16 / 8) + x_i; + let x_i = x as usize / 8; + let x_shift = 7 - (x % 8); + let i = y as usize * (EPD_WIDTH / 8) + x_i; match colour { PixelColour::Black => { self.new.0[i as usize] &= !(1 << x_shift); - }, + } PixelColour::White => { self.new.0[i as usize] |= 1 << x_shift; - }, + } } } }