diff --git a/src/display.rs b/src/display.rs index 301ade2..78f2c7d 100644 --- a/src/display.rs +++ b/src/display.rs @@ -83,6 +83,7 @@ fn initialize_display(i2c: I2cdev) -> Result .into_buffered_graphics_mode(); disp.init().map_err(|e| format!("Display initialization error: {:?}", e))?; + disp.set_brightness(Brightness::DIMMEST)?; Ok(disp) } diff --git a/src/main.rs b/src/main.rs index 5f6831d..9dd4b55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,15 +51,25 @@ fn main() -> Result<(), Box> { .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()?; @@ -68,11 +78,11 @@ fn main() -> Result<(), Box> { 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); @@ -91,7 +101,12 @@ fn main() -> Result<(), Box> { 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)); } } @@ -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(), - } -}