From 2826423e5b899c6af1f63ec82d4c413ece38735c Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 19 Feb 2023 21:29:07 +0100 Subject: [PATCH] Add command 'load' to the TA4 power terminal --- basis/liquid_lib.lua | 3 ++- energy_storage/heatexchanger2.lua | 3 ++- init.lua | 4 ++-- manuals/ta4_lua_controller_EN.md | 4 +++- power/power_terminal2.lua | 31 +++++++++++++++++++++++++++++-- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/basis/liquid_lib.lua b/basis/liquid_lib.lua index 12f911a..1075e1a 100644 --- a/basis/liquid_lib.lua +++ b/basis/liquid_lib.lua @@ -84,7 +84,8 @@ techage.liquid.recv_message = { nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 if payload[1] == 1 then - return 0, {techage.power.percent(LQD(pos).capa, nvm.liquid.amount)} + local value = techage.power.percent(LQD(pos).capa, nvm.liquid.amount) + return 0, {math.floor(value + 0.5)} else return 0, {nvm.liquid.amount} end diff --git a/energy_storage/heatexchanger2.lua b/energy_storage/heatexchanger2.lua index 551a9b3..938f9f2 100644 --- a/energy_storage/heatexchanger2.lua +++ b/energy_storage/heatexchanger2.lua @@ -382,7 +382,8 @@ techage.register_node({"techage:heatexchanger2"}, { local data = power.get_network_data(pos, Cable, DOWN) return 0, {data.consumed - data.provided} elseif topic == 134 then -- Tank Load Percent - return 0, {techage.power.percent(nvm.capa_max, nvm.capa)} + local value = techage.power.percent(nvm.capa_max, nvm.capa) + return 0, {math.floor(value + 0.5)} else return 2, "" end diff --git a/init.lua b/init.lua index 1c03091..fb9cae4 100644 --- a/init.lua +++ b/init.lua @@ -36,8 +36,8 @@ elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.01 then elseif minetest.global_exists("safer_lua") and safer_lua.version < 1.01 then minetest.log("error", "[techage] Techage requires safer_lua version 1.01 or newer!") return -elseif minetest.global_exists("networks") and networks.version < 0.12 then - minetest.log("error", "[techage] Techage requires networks version 0.12 or newer!") +elseif minetest.global_exists("networks") and networks.version < 0.13 then + minetest.log("error", "[techage] Techage requires networks version 0.13 or newer!") return elseif minetest.global_exists("hyperloop") and hyperloop.version < 2.07 then minetest.log("error", "[techage] Techage requires hyperloop version 2.07 or newer!") diff --git a/manuals/ta4_lua_controller_EN.md b/manuals/ta4_lua_controller_EN.md index 2c937b3..59f9a5c 100644 --- a/manuals/ta4_lua_controller_EN.md +++ b/manuals/ta4_lua_controller_EN.md @@ -366,7 +366,9 @@ Please note, that this is not a technical distinction, only a logical. | "state" | one of: "on", "off" | State of a TA4 Button | | "fuel" | number | fuel value of a fuel consuming block | | "depth" | number | Read the current depth value of a quarry block (1..80) | -| "load" | number | Read the load value in percent (0..100) of a tank, silo, accu, or battery block, or from the Signs Bot Box. Silo and tank return two values: The percentage value and the absolute value in units.
Example: percent, absolute = $send_cmnd("223", "load") | +| "load" | number | Read the load value in percent (0..100) of a accu, or battery block. | +| "load" | number | Read the load value in percent (0..100) of a tank or silo.
Silo and tank return two values:
The percentage value and the absolute value in units.
Example: percent, absolute = $send_cmnd("223", "load") | +| "load" | number | Read the grid storage amount in percent (0..100) from a TA3 Power Terminal. | | "delivered" | number | Read the current delivered power value of a generator block. A power consuming block (accu) provides a negative value | | "flowrate" | Total flow rate in liquid units | Only for TA4 Pumps | | "action" | player-name, action-string | Only for Sensor Chests | diff --git a/power/power_terminal2.lua b/power/power_terminal2.lua index c7e39de..b8bcd58 100644 --- a/power/power_terminal2.lua +++ b/power/power_terminal2.lua @@ -238,13 +238,18 @@ minetest.register_node("techage:ta3_power_terminal", { }, }, - after_place_node = function(pos) + after_place_node = function(pos, placer) M(pos):set_int("outdir", networks.side_to_outdir(pos, "B")) Cable:after_place_node(pos) M(pos):set_string("formspec", formspec1(pos)) + local number = techage.add_node(pos, "techage:ta3_power_terminal") + M(pos):set_string("node_number", number) + M(pos):set_string("owner", placer:get_player_name()) + M(pos):set_string("infotext", S("TA3 Power Terminal").." "..number) end, - after_dig_node = function(pos) + after_dig_node = function(pos, oldnode, oldmetadata, digger) Cable:after_dig_node(pos) + techage.remove_node(pos, oldnode, oldmetadata) techage.del_mem(pos) end, on_rightclick = function(pos, node, clicker) @@ -305,6 +310,28 @@ minetest.register_node("techage:ta3_power_terminal", { power.register_nodes({"techage:ta3_power_terminal"}, Cable, "con", {"B"}) +techage.register_node({"techage:ta3_power_terminal"}, { + on_recv_message = function(pos, src, topic, payload) + if topic == "load" then + local outdir = M(pos):get_int("outdir") + local value = networks.power.get_storage_percent(pos, Cable, outdir) + return techage.round(value) + else + return "unsupported" + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 134 then + local outdir = M(pos):get_int("outdir") + local value = networks.power.get_storage_percent(pos, Cable, outdir) + return 0, {math.floor(value + 0.5)} + else + return 2, "" + end + end, +}) + minetest.register_craft({ output = "techage:ta3_power_terminal", recipe = {