luanti_scripts/fabric_power_monitor.lua
2025-03-28 14:01:18 +03:00

65 lines
2.2 KiB
Lua

if event.type == "interrupt" then
digiline_send("pmw","get")
local str = "Powev MV\n" ..
"S:" .. tostring(mem.supply) .."\n" ..
"D:" .. tostring(mem.demand) .. "\n" ..
"Battery:" .. tostring(mem.bcount) .. "\n" ..
"BC:" .. tostring(mem.bc) .. "\n" .. "BCM:" .. tostring(mem.bcm)
digiline_send("monpoww", str)
digiline_send("pmhv","get")
str = "Powev HV\n" ..
"S:" .. tostring(mem.hvsupply) .. "\n" ..
"D:" .. tostring(mem.hvdemand) .. "\n" ..
"Battery:" .. tostring(mem.hvbcount) .. "\n" ..
"BC:" .. tostring(mem.hvbc) .. "\n" ..
"BCM:" .. tostring(mem.hvbcm)
digiline_send("monpowhv", str)
digiline_send("nuclear", "get")
str = "Nuclear\n" ..
"Siren:" .. tostring(mem.n_siren) .. "\n" ..
"Burn:" .. tostring(mem.n_burnTime) .. "\n" ..
"Rods:\n"
if type(mem.n_rods) == "table" then
str = str .. tostring(mem.n_rods[1] or 0) .. " " ..
tostring(mem.n_rods[2] or 0) .. " " ..
tostring(mem.n_rods[3] or 0) .. "\n" ..
tostring(mem.n_rods[4] or 0) .. " " ..
tostring(mem.n_rods[5] or 0) .. " " ..
tostring(mem.n_rods[6] or 0)
end
digiline_send("monnuclear", str )
interrupt(10)
end
if event.type == "program" then
mem.nrods = {0, 0, 0, 0, 0, 0, 0}
digiline_send("pmw", "get")
digiline_send("pmhv", "get")
digiline_send("nuclear", "get")
interrupt(1)
end
if event.type == "digiline" then
if event.channel == "pmw" then
mem.supply = event.msg.supply
mem.demand = event.msg.demand
mem.bc = event.msg.battery_charge
mem.bcm = event.msg.battery_charge_max
mem.bcount = event.msg.battery_count
end
if event.channel == "pmhv" then
mem.hvsupply = event.msg.supply
mem.hvdemand = event.msg.demand
mem.hvbc = event.msg.battery_charge
mem.hvbcm = event.msg.battery_charge_max
mem.hvbcount = event.msg.battery_count
end
if event.channel == "nuclear" then
mem.n_burnTime = event.msg.burn_time
mem.n_siren = event.msg.siren
mem.n_rods = event.msg.rods
end
end