Skip to content

Commit

Permalink
Try reduce cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Nov 16, 2023
1 parent 1c00693 commit 9d6a71d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ use embedded_graphics::{
use std::error::Error;
use std::fs;
use std::thread;
use std::time::Duration;
use std::time::{Duration, Instant};
use sysinfo::{System, SystemExt, CpuExt, DiskExt};
use machine_ip;

fn main() -> Result<(), Box<dyn Error>> {
let mut disp = initialize_display()?;
let mut sys: System = SystemExt::new_all();

let mut last_disk_update = Instant::now();
let disk_update_interval = Duration::from_secs(60);

loop {
sys.refresh_all();
sys.refresh_cpu();
sys.refresh_memory();

let temp = get_cpu_temperature()?;
let temp = get_cpu_temperature();
let ip_address = get_local_ip();
let cpu_usage = get_cpu_usage(&sys);
let ram_usage = get_ram_usage(&sys);

if last_disk_update.elapsed() >= disk_update_interval {
sys.refresh_disks();
last_disk_update = Instant::now();
}
let disk_usage = get_disk_usage(&sys);

update_display(&mut disp, &ip_address, &cpu_usage, temp, ram_usage, disk_usage)?;
Expand Down

0 comments on commit 9d6a71d

Please sign in to comment.