nicer bound check and renamed render to flush
This commit is contained in:
@@ -9,6 +9,7 @@ use std::{
|
||||
|
||||
use crossbeam_channel::{Receiver, bounded};
|
||||
use embedded_graphics_core::{
|
||||
Pixel,
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::{Dimensions, DrawTarget, Point, Size},
|
||||
primitives::Rectangle,
|
||||
@@ -250,7 +251,7 @@ impl G13 {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn flush(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let img_buffer = self.img_buffer.read().expect("Poisoned");
|
||||
|
||||
let mut buffer = [0u8; G13_LCD_BUF_SIZE as usize + 32 + 8];
|
||||
@@ -285,16 +286,17 @@ impl DrawTarget for G13 {
|
||||
where
|
||||
I: IntoIterator<Item = embedded_graphics_core::Pixel<Self::Color>>,
|
||||
{
|
||||
let bb = self.bounding_box();
|
||||
let mut img_buffer = self.img_buffer.write().expect("Poisoned");
|
||||
for p in pixels {
|
||||
if p.0.x < 0 || p.0.x > G13_LCD_COLUMNS - 1 || p.0.y < 0 || p.0.y > G13_LCD_ROWS - 1 {
|
||||
for Pixel(pos, color) in pixels {
|
||||
if !bb.contains(pos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let offset = p.0.x + (p.0.y / 8) * (G13_LCD_BYTES_PER_ROW) * 8;
|
||||
let mask = 1 << (p.0.y.rem_euclid(8));
|
||||
let offset = pos.x + (pos.y / 8) * (G13_LCD_BYTES_PER_ROW) * 8;
|
||||
let mask = 1 << (pos.y.rem_euclid(8));
|
||||
|
||||
if p.1.is_on() {
|
||||
if color.is_on() {
|
||||
img_buffer[offset as usize] |= mask;
|
||||
} else {
|
||||
img_buffer[offset as usize] &= !mask;
|
||||
|
||||
@@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
start = Instant::now();
|
||||
g13.clear(BinaryColor::Off)?;
|
||||
app.draw(&mut g13);
|
||||
g13.render()?; // 30 fps rendering
|
||||
g13.flush()?; // 30 fps rendering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
start = Instant::now();
|
||||
g13.clear(BinaryColor::Off)?;
|
||||
app.draw(&mut g13);
|
||||
g13.render()?;
|
||||
g13.flush()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ fn save_buffer_to_disk(
|
||||
.draw(&mut g13.g13)
|
||||
.expect("G13 to be connected");
|
||||
|
||||
let _ = g13.g13.render();
|
||||
let _ = g13.g13.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user