Updated algorithm to allow full speed tasks while pushing graphics at intervals

This commit is contained in:
JP Stringham
2026-01-05 09:13:12 -05:00
parent 871ec35847
commit 271069504e
3 changed files with 27 additions and 14 deletions

1
Cargo.lock generated
View File

@@ -334,7 +334,6 @@ dependencies = [
"cortex-m-rt",
"defmt",
"defmt-rtt",
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
"panic-probe",
"rp2040-boot2",

View File

@@ -9,7 +9,6 @@ cortex-m-rt = "0.7.5"
defmt = "1.0.1"
defmt-rtt = "1.0.0"
embedded-hal = "1.0.0"
embedded_hal_0_2 = {package = "embedded-hal", version = "0.2.5", features = ["unproven"]}
panic-probe = { version = "1.0.0", features = [ "print-rtt" ]}
rp2040-boot2 = "0.3.0"
rp2040-hal = "0.11.0"

View File

@@ -27,7 +27,6 @@ use sh1106_pico_rs::{sh1106::SH1106Dev, graphics::GraphicsBuf};
// Some traits we need
use embedded_hal::digital::OutputPin;
use embedded_hal_0_2::{adc::OneShot, digital::v2::ToggleableOutputPin};
/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
@@ -114,16 +113,23 @@ fn main() -> ! {
&clocks.system_clock,
);
let sh1106_dev = SH1106Dev::new(&mut delay, &mut i2c);
let mut sh1106_dev = SH1106Dev::new(&mut delay, &mut i2c);
sh1106_dev.set_vertical_flip(&mut i2c, true);
let sh1106_dev = sh1106_dev;
let mut gfx_buf = GraphicsBuf::new();
println!("Graphics ready");
led_pin.set_low().unwrap();
loop {
gfx_buf.clear();
// for tracking graphics frame timing
let mut tick = 0u32;
let mut last_gfx_push = 0u32;
println!("{} samples", adc_fifo.len());
loop {
let samples = adc_fifo.len();
if samples > 4 {
// println!("{} samples", adc_fifo.len());
for _ in 0..adc_fifo.len() {
adc_samps[adc_samp_i] = adc_fifo.read();
adc_samp_i += 1;
@@ -131,6 +137,15 @@ fn main() -> ! {
adc_samp_i = 0;
}
}
}
tick = tick.wrapping_add(1);
// tweak this magic number for lower/higher fps
if tick.abs_diff(last_gfx_push) < 100_000 {
continue;
}
last_gfx_push = tick;
gfx_buf.clear();
let mut adc_hi = 0u16;
let mut adc_lo = 0xFFFFu16;
@@ -191,10 +206,11 @@ fn main() -> ! {
deg_buf[9] = b'.';
itoa_result.len += 1;
gfx_buf.draw_string(10, 10, "Probe temp");
let deg_str = itoa_result.as_str();
println!("tenths of a deg {}, deg {}", deg, deg_str);
gfx_buf.draw_textfield(10, 10, 100, 60, deg_str);
gfx_buf.draw_textfield(10, 22, 100, 60, deg_str);
gfx_buf.sprites[0].y = 40 + ((test_val as i32) / 4) % 2;
@@ -202,7 +218,6 @@ fn main() -> ! {
sh1106_dev.blit_framebuffer(&mut i2c, &mut gfx_buf);
test_val = test_val.wrapping_add(1);
delay.delay_ms(30);
}
}