Skip to content

Commit

Permalink
Set display to dimmest, only display first 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Nov 21, 2024
1 parent 63f6a61 commit 3a96550
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn initialize_display(i2c: I2cdev) -> Result<Display, Box<dyn std::error::Error>
.into_buffered_graphics_mode();

disp.init().map_err(|e| format!("Display initialization error: {:?}", e))?;
disp.set_brightness(Brightness::DIMMEST)?;
Ok(disp)
}

28 changes: 18 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,25 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_memory(MemoryRefreshKind::new().with_ram()),
);

let mut networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
println!("Ip Networks: {:?}", network.ip_networks());
}

debug!("System initialized. System info:");
debug!("================================");
debug!("System name: {}", System::name().unwrap_or_default());
debug!("System kernel version: {}", System::kernel_version().unwrap_or_default());
debug!("System OS version: {}", System::os_version().unwrap_or_default());

const SCREEN_TIMEOUT: Duration = Duration::from_secs(300);
const DISPLAY_ON_DURATION: Duration = Duration::from_secs(10);
const DISPLAY_OFF_DURATION: Duration = Duration::from_secs(20);

let mut disk_usage = String::new();
let disk_update_interval = Duration::from_secs(60);
let mut last_disk_update = Instant::now() - disk_update_interval;
let start_time = Instant::now();
info!("Starting main loop");

fan_controller.fan_off()?;
Expand All @@ -68,11 +78,11 @@ fn main() -> Result<(), Box<dyn Error>> {
sys.refresh_cpu_usage();
sys.refresh_memory();

let ip_address = get_local_ip();
let ip_address = "replace me";
let temp = get_cpu_temperature();

let temp_str = format!("{:.1}", temp);
let cpu_usage = format!("{:.1}", sys.global_cpu_info().cpu_usage());
let cpu_usage = format!("{:.1}", sys.global_cpu_usage());
let ram_usage = format!("{:.1}", get_ram_usage(&sys));

trace!("Checking fan controller. Fan running: {}", fan_controller.is_running);
Expand All @@ -91,7 +101,12 @@ fn main() -> Result<(), Box<dyn Error>> {
disk_usage = format!("{:.1}", get_disk_usage());
}

poe_disp.update(&ip_address, cpu_usage, temp_str, ram_usage, &disk_usage).unwrap();
let elapsed_time = start_time.elapsed();
if elapsed_time < SCREEN_TIMEOUT || (elapsed_time - SCREEN_TIMEOUT) % DISPLAY_OFF_DURATION < DISPLAY_ON_DURATION {
poe_disp.update(&ip_address, cpu_usage, temp_str, ram_usage, &disk_usage).unwrap();
} else {
poe_disp.clear(BinaryColor::Off)?;
}
thread::sleep(Duration::from_secs(1));
}
}
Expand Down Expand Up @@ -122,10 +137,3 @@ fn get_disk_usage() -> f64 {
0.0
}
}

fn get_local_ip() -> String {
match machine_ip::get() {
Some(ip) => ip.to_string(),
None => "No IP".to_string(),
}
}

0 comments on commit 3a96550

Please sign in to comment.