Skip to content

Commit e1835c5

Browse files
author
cogwheel886
committed
fix: implement three-state partial refresh for epd2in13_v4_status
Run 1: full refresh (establishes clean display state) Run 2: display_part_base_image (writes both RAM banks, one full refresh) Run 3+: display_partial only (true partial waveform, no color inversion) State tracked via /tmp files cleared on reboot. Eliminates 4-5 cycle full waveform on every status update. Confirmed working on Pi Zero 2W with Waveshare 2.13 V4 hardware.
1 parent 9f332b4 commit e1835c5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

examples/epd2in13_v4_status.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
//! Reads real system data via sysinfo + pisugar socket and renders to e-paper.
33
//!
44
//! Uses partial refresh on subsequent runs to minimize e-paper wear.
5-
//! State file `/tmp/epd_status_initialized` tracks whether a full refresh
6-
//! has been performed since boot.
5+
//! Two state files in `/tmp` (cleared on reboot) control the sequence:
6+
//!
7+
//! 1. First run — full refresh, creates `epd_status_initialized`
8+
//! 2. Second run — `display_part_base_image` (establishes base in both RAM
9+
//! banks with one full refresh), creates `epd_status_base_set`
10+
//! 3. Third+ runs — `display_partial` only (true partial waveform, no flashing)
711
812
use embedded_graphics::{
913
mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
@@ -27,6 +31,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
2731
use sysinfo::{Components, Disks, System};
2832

2933
const STATE_FILE: &str = "/tmp/epd_status_initialized";
34+
const BASE_FILE: &str = "/tmp/epd_status_base_set";
3035

3136
// ---- Data collection ----
3237

@@ -404,16 +409,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
404409

405410
let buf = display.buffer();
406411
let initialized = Path::new(STATE_FILE).exists();
412+
let base_set = Path::new(BASE_FILE).exists();
407413

408414
if !initialized {
409-
// First run since boot — full refresh establishes clean base image
415+
// First run since boot — full refresh
410416
epd.update_frame(&mut spi, buf, &mut delay)?;
411417
epd.display_frame(&mut spi, &mut delay)?;
412418
std::fs::write(STATE_FILE, "")?;
413419
println!("full | {}", data.summary());
414-
} else {
415-
// Subsequent runs — partial refresh minimizes wear
420+
} else if !base_set {
421+
// Second runestablish partial base (writes both RAM banks, one full refresh)
416422
epd.display_part_base_image(&mut spi, buf, &mut delay)?;
423+
std::fs::write(BASE_FILE, "")?;
424+
println!("base | {}", data.summary());
425+
} else {
426+
// All subsequent runs — true partial refresh only
417427
epd.display_partial(&mut spi, buf, &mut delay)?;
418428
println!("partial | {}", data.summary());
419429
}

0 commit comments

Comments
 (0)