Skip to content

Commit

Permalink
Fix: #8 partial buffered screen update
Browse files Browse the repository at this point in the history
  • Loading branch information
IniterWorker committed Sep 25, 2024
1 parent 00d85cc commit 74dc913
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ where
start: (u16, u16),
end: (u16, u16),
) -> Result<(), DisplayError> {
Command::ColumnAddressSet(start.0, end.0.saturating_sub(1)).send(&mut self.interface)?;
Command::RowAddressSet(start.1, end.1.saturating_sub(1)).send(&mut self.interface)?;
Command::ColumnAddressSet(start.0, end.0).send(&mut self.interface)?;
Command::RowAddressSet(start.1, end.1).send(&mut self.interface)?;

Ok(())
}
Expand Down Expand Up @@ -268,15 +268,17 @@ where
) -> Result<(), DisplayError> {
Command::MemoryWrite.send(interface)?;

let num_pages = (lower_right.1 - upper_left.1) as usize + 1;
// Number of rows to process (Y range)
let num_pages = (lower_right.1 - upper_left.1 + 1) as usize;

let starting_page = (upper_left.1) as usize;
// Starting row (Y coordinate)
let starting_page = upper_left.1 as usize;

// Calculate start and end X coordinates for each page
// X coordinates (columns) for the rectangle
let page_lower = upper_left.0 as usize;
let page_upper = lower_right.0 as usize;
let page_upper = ((lower_right.0 + 1) as usize).min(disp_width); // +1 to include the last column

// TODO: improve this
// Process the buffer in rows (chunks of disp_width)
buffer
.chunks(disp_width)
.skip(starting_page)
Expand Down
2 changes: 1 addition & 1 deletion src/mode/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
///
/// This method may return an error if there are communication issues with the display.
pub fn clear(&mut self) -> Result<(), DisplayError> {
self.set_draw_area((0, 0), self.dimensions())?;
self.set_draw_area((0, 0), self.bounds())?;
self.clear_fit()
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/mode/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ where
return Ok(());
}

let (width, height) = self.dimensions();
let (bound_width, bound_height) = self.bounds();
let (screen_width, screen_height) = self.dimensions();

// Determine witch bytes need to be sent
let disp_min_x = self.mode.min_x;
let disp_min_y = self.mode.min_y;

let (disp_max_x, disp_max_y) =
((self.mode.max_x).min(width), (self.mode.max_y).min(height));
let (disp_max_x, disp_max_y) = (
(self.mode.max_x).min(bound_width),
(self.mode.max_y).min(bound_height),
);

// reset idle state
self.mode.min_x = u16::MAX;
Expand All @@ -138,7 +141,7 @@ where
Self::flush_buffer_chunks(
&mut self.interface,
self.mode.buffer.as_mut(),
width as usize,
screen_width as usize,
(disp_min_x, disp_min_y),
(disp_max_x, disp_max_y),
)
Expand All @@ -152,7 +155,7 @@ where
Self::flush_buffer_chunks(
&mut self.interface,
self.mode.buffer.as_mut(),
height as usize,
screen_height as usize,
(disp_min_y, disp_min_x),
(disp_max_y, disp_max_x),
)
Expand Down

0 comments on commit 74dc913

Please sign in to comment.