From c5bef1e9498ac5d805ffbeb007e91dc5b00b2667 Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Fri, 3 Apr 2026 19:02:44 +0300 Subject: [PATCH] disk total mem --- Makefile | 2 +- index.mjs | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 0bbc933..eac3cd3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -HOST=i2c@10.0.0.11 +HOST=i2c@192.168.1.200 build: dist/index.mjs diff --git a/index.mjs b/index.mjs index 673ab09..992ff69 100644 --- a/index.mjs +++ b/index.mjs @@ -4,35 +4,47 @@ import si from 'systeminformation' const lcd = new LCD(1, 0x27) await lcd.open() +function BtoGB(bytes) { + return (bytes / 1024 ** 3).toFixed(1) +} + async function showSystemStats() { - const [cpu, mem, temp] = await Promise.all([ + const [cpu, mem, disks] = await Promise.all([ si.currentLoad(), si.mem(), - si.cpuTemperature(), + si.fsSize(), ]); - const cpuLoad = cpu.currentLoad.toFixed(1); - const totalMem = (mem.total / 1024 ** 2).toFixed(0); - const usedMem = ((mem.total - mem.available) / 1024 ** 2).toFixed(0); - const tempC = temp.main?.toFixed(1) ?? 'N/A'; + const cpuLoad = cpu.currentLoad.toFixed(1).padStart(4, ' ') + const totalMem = BtoGB(mem.total) + const usedMem = BtoGB(mem.total - mem.available) + + let diskTotalMem = 0 + let diskUsedMem = 0 + + for (const disk of disks) { + diskTotalMem += disk.size + diskUsedMem += disk.used + } + diskTotalMem = BtoGB(diskTotalMem) + diskUsedMem = BtoGB(diskUsedMem) await lcd.send(LCD.ClearDisplay()) const hours = new Date().getHours() - if (hours >= 23 || hours <= 7) { + if (hours >= 23 || hours < 7) { lcd.backlight = false } else { lcd.backlight = true } + await lcd.jump(0, 0) + await lcd.sendString(`${diskUsedMem}/${diskTotalMem}GB`) - await lcd.jump(0, 0); - await lcd.sendString(`${cpuLoad}%`); + await lcd.jump(0, 1) + await lcd.sendString(`${usedMem}/${totalMem}GB`) - await lcd.jump(8, 0); - await lcd.sendString(`${tempC}C`) - - await lcd.jump(0, 1); - await lcd.sendString(`${usedMem}/${totalMem} MB`); + await lcd.jump(11, 1) + await lcd.sendString(`${cpuLoad}%`) } await showSystemStats()