disk total mem

This commit is contained in:
2026-04-03 19:02:44 +03:00
parent f8f295f476
commit c5bef1e949
2 changed files with 27 additions and 15 deletions

View File

@ -1,4 +1,4 @@
HOST=i2c@10.0.0.11
HOST=i2c@192.168.1.200
build: dist/index.mjs

View File

@ -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()