diff --git a/basic_machines/chest.lua b/basic_machines/chest.lua index b07f824..8894f8a 100644 --- a/basic_machines/chest.lua +++ b/basic_machines/chest.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -180,6 +180,16 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 131 then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local state = techage.get_inv_state(inv, "main") + return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0 + else + return 2, "" + end + end, }) @@ -412,6 +422,16 @@ techage.register_node({"techage:chest_ta4"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 131 then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local state = techage.get_inv_state(inv, "main") + return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0 + else + return 2, "" + end + end, }) minetest.register_craft({ diff --git a/basic_machines/distributor.lua b/basic_machines/distributor.lua index 6df2639..bf4964c 100644 --- a/basic_machines/distributor.lua +++ b/basic_machines/distributor.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -478,6 +478,19 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 4 then + local slot = ({red = 1, green = 2, blue = 3, yellow = 4})[payload[1]] + local state = payload[2] == 1 and "on" or "off" + change_filter_settings(pos, slot, state) + return 0 + else + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/electronic_fab.lua b/basic_machines/electronic_fab.lua index c7aadca..e6a2640 100644 --- a/basic_machines/electronic_fab.lua +++ b/basic_machines/electronic_fab.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -203,6 +203,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/gravelrinser.lua b/basic_machines/gravelrinser.lua index cff4611..43ef7b9 100644 --- a/basic_machines/gravelrinser.lua +++ b/basic_machines/gravelrinser.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -249,6 +249,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) remove_objects({x=pos.x, y=pos.y+1, z=pos.z}) CRD(pos).State:on_node_load(pos) diff --git a/basic_machines/gravelsieve.lua b/basic_machines/gravelsieve.lua index 0d61593..f12c581 100644 --- a/basic_machines/gravelsieve.lua +++ b/basic_machines/gravelsieve.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -174,6 +174,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index 48a9efc..e41b2fa 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -206,6 +206,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/liquidsampler.lua b/basic_machines/liquidsampler.lua index 0a4ca84..4467a18 100644 --- a/basic_machines/liquidsampler.lua +++ b/basic_machines/liquidsampler.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -173,6 +173,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, } local node_name_ta2, node_name_ta3, _ = diff --git a/basic_machines/pusher.lua b/basic_machines/pusher.lua index fd03895..7f1a4db 100644 --- a/basic_machines/pusher.lua +++ b/basic_machines/pusher.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -181,13 +181,15 @@ local function can_start(pos, nvm, state) end local function config_item(pos, payload) - local name, count = unpack(payload:split(" ")) - if name and (minetest.registered_nodes[name] or minetest.registered_items[name] - or minetest.registered_craftitems[name]) then - count = tonumber(count) or 1 - local inv = M(pos):get_inventory() - inv:set_stack("main", 1, {name = name, count = 1}) - return count + if type(payload) == "string" then + local name, count = unpack(payload:split(" ")) + if name and (minetest.registered_nodes[name] or minetest.registered_items[name] + or minetest.registered_craftitems[name]) then + count = tonumber(count) or 1 + local inv = M(pos):get_inventory() + inv:set_stack("main", 1, {name = name, count = 1}) + return count + end end return 0 end @@ -256,6 +258,24 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 64 then -- Start pusher + local nvm = techage.get_nvm(pos) + CRD(pos).State:stop(pos, nvm) + nvm.item_count = math.min(config_item(pos, payload), 12) + nvm.rmt_num = src + CRD(pos).State:start(pos, nvm) + return 0 + elseif topic == 65 then -- Config Pusher + local nvm = techage.get_nvm(pos) + CRD(pos).State:stop(pos, nvm) + config_item(pos, payload) + CRD(pos).State:start(pos, nvm) + return 0 + else + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = diff --git a/basic_machines/quarry.lua b/basic_machines/quarry.lua index 90aaf87..33be5ec 100644 --- a/basic_machines/quarry.lua +++ b/basic_machines/quarry.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -368,6 +368,17 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 133 then -- Quarry Depth + local nvm = techage.get_nvm(pos) + return 0, {nvm.level or 0} + else + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/recycler.lua b/basic_machines/recycler.lua index e2442a2..b2d51d4 100644 --- a/basic_machines/recycler.lua +++ b/basic_machines/recycler.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -235,6 +235,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/ta4_chest.lua b/basic_machines/ta4_chest.lua index 096eaef..53ec22c 100644 --- a/basic_machines/ta4_chest.lua +++ b/basic_machines/ta4_chest.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -597,10 +597,10 @@ techage.register_node({"techage:ta4_chest"}, { on_recv_message = function(pos, src, topic, payload) if topic == "count" then local nvm = techage.get_nvm(pos) - return get_count(nvm, tonumber(payload) or 0) + return get_count(nvm, tonumber(payload or 1) or 1) elseif topic == "itemstring" then local nvm = techage.get_nvm(pos) - return get_itemstring(nvm, tonumber(payload) or 0) + return get_itemstring(nvm, tonumber(payload or 1) or 1) elseif topic == "state" then local nvm = techage.get_nvm(pos) return inv_state(nvm) @@ -608,6 +608,20 @@ techage.register_node({"techage:ta4_chest"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 140 and payload[1] == 1 then -- Inventory Item Count + local nvm = techage.get_nvm(pos) + return 0, {get_count(nvm, tonumber(payload[2] or 1) or 1)} + elseif topic == 140 and payload[1] == 2 then -- Inventory Item Name + local nvm = techage.get_nvm(pos) + return 0, {get_itemstring(nvm, tonumber(payload[2] or 1) or 1)} + elseif topic == 131 then -- Chest State + local nvm = techage.get_nvm(pos) + return 0, {inv_state(nvm)} + else + return 2, "" + end + end, }) techage.register_node({"techage:ta4_chest_dummy"}, { diff --git a/basic_machines/ta4_injector.lua b/basic_machines/ta4_injector.lua index 4332e17..e08bfd0 100644 --- a/basic_machines/ta4_injector.lua +++ b/basic_machines/ta4_injector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -242,6 +242,12 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/ta5_chest.lua b/basic_machines/ta5_chest.lua index 1d56064..7cc26a0 100644 --- a/basic_machines/ta5_chest.lua +++ b/basic_machines/ta5_chest.lua @@ -175,6 +175,15 @@ techage.register_node({"techage:ta5_hl_chest"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 131 then -- Chest State + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return 0, {techage.get_inv_state(inv, "main")} + else + return 2, "" + end + end, }) diff --git a/basis/command.lua b/basis/command.lua index f2b4362..bc7e332 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -406,6 +406,35 @@ function techage.transfer(pos, outdir, topic, payload, network, nodenames) return false end +------------------------------------------------------------------- +-- Beduino functions (see "bep-005_ta_cmnd.md") +------------------------------------------------------------------- +function techage.beduino_send_cmnd(src, number, topic, payload) + --print("beduino_send_cmnd", src, number, topic) + local ninfo = NodeInfoCache[number] or update_nodeinfo(number) + if ninfo and ninfo.name and ninfo.pos then + local ndef = NodeDef[ninfo.name] + if ndef and ndef.on_beduino_receive_cmnd then + techage_counting_hit() + return ndef.on_beduino_receive_cmnd(ninfo.pos, src, topic, payload or {}) + end + end + return 1, "" +end + +function techage.beduino_request_data(src, number, topic, payload) + --print("beduino_request_data", src, number, topic) + local ninfo = NodeInfoCache[number] or update_nodeinfo(number) + if ninfo and ninfo.name and ninfo.pos then + local ndef = NodeDef[ninfo.name] + if ndef and ndef.on_beduino_request_data then + techage_counting_hit() + return ndef.on_beduino_request_data(ninfo.pos, src, topic, payload or {}) + end + end + return 1, "" +end + ------------------------------------------------------------------- -- Client side Push/Pull item functions ------------------------------------------------------------------- diff --git a/basis/node_states.lua b/basis/node_states.lua index f866910..b681990 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -66,12 +66,14 @@ local N = techage.get_node_lvm -- TechAge machine states -- -techage.RUNNING = 1 -- in normal operation/turned on -techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory -techage.STANDBY = 3 -- nothing to do (e.g. no input items), or node (world) not loaded -techage.NOPOWER = 4 -- only for power consuming nodes, no operation -techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player -techage.STOPPED = 6 -- not operational/turned off +techage.RUNNING = 1 -- in normal operation/turned on +techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory +techage.STANDBY = 3 -- nothing to do (e.g. no input items), or node (world) not loaded +techage.NOPOWER = 4 -- only for power consuming nodes, no operation +techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player +techage.STOPPED = 6 -- not operational/turned off +techage.UNLOADED = 7 -- Map block unloaded +techage.INACTIVE = 8 -- Map block loaded but node is not actively working techage.StatesImg = { "techage_inv_button_on.png", @@ -479,6 +481,40 @@ function NodeStates:on_receive_message(pos, topic, payload) end end +function NodeStates:on_beduino_receive_cmnd(pos, topic, payload) + if topic == 1 then + if payload[1] == 0 then + self:stop(pos, techage.get_nvm(pos)) + return 0 + else + self:start(pos, techage.get_nvm(pos)) + return 0 + end + else + return 2 -- unknown or invalid topic + end +end + +function NodeStates:on_beduino_request_data(pos, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then + local node = minetest.get_node(pos) + if node.name == "ignore" then -- unloaded node? + return 0, {techage.UNLOADED} + elseif nvm.techage_state == RUNNING then + local ttl = (nvm.last_active or 0) + 2 * (self.cycle_time or 0) + if ttl < minetest.get_gametime() then + return 0, {techage.INACTIVE} + end + end + return 0, {nvm.techage_state or STOPPED} + else + return 2, "" -- topic is unknown or invalid + end +end + -- restart timer function NodeStates:on_node_load(pos) local nvm = techage.get_nvm(pos) diff --git a/carts/chest_cart.lua b/carts/chest_cart.lua index e34e874..343819f 100644 --- a/carts/chest_cart.lua +++ b/carts/chest_cart.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -159,6 +159,15 @@ techage.register_node({"techage:chest_cart"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 131 then -- Chest State + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return 0, {techage.get_inv_state(inv, "main")} + else + return 2, "" + end + end, }) Tube:set_valid_sides("techage:chest_cart", {"L", "R", "F", "B"}) diff --git a/chemistry/ta4_doser.lua b/chemistry/ta4_doser.lua index 30abf1e..316a3c6 100644 --- a/chemistry/ta4_doser.lua +++ b/chemistry/ta4_doser.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -360,6 +360,12 @@ techage.register_node({"techage:ta4_doser", "techage:ta4_doser_on"}, { on_recv_message = function(pos, src, topic, payload) return State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return State:on_beduino_request_data(pos, topic, payload) + end, }) techage.recipes.register_craft_type("ta4_doser", { diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index c8849dd..268fa93 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -207,6 +207,18 @@ techage.register_node({"techage:coalfirebox"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then + return 0, {nvm.running and "running" or "stopped"} + elseif topic == 132 then + return 0, {techage.fuel.get_fuel_amount(nvm)} + else + return 2, "" + end + end, }) minetest.register_craft({ diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index e744574..b952c21 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -231,6 +231,17 @@ techage.register_node({"techage:generator", "techage:generator_on"}, { return State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 135 then -- Delivered Power + return 0, {math.floor((nvm.provided or 0) + 0.5)} + else + return State:on_beduino_request_data(pos, topic, payload) + end + end, }) -- used by power terminal diff --git a/coal_power_station/oilfirebox.lua b/coal_power_station/oilfirebox.lua index 960d581..efcc942 100644 --- a/coal_power_station/oilfirebox.lua +++ b/coal_power_station/oilfirebox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -132,6 +132,18 @@ techage.register_node({"techage:oilfirebox"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then + return 0, {nvm.running and "running" or "stopped"} + elseif topic == 132 then + return 0, {fuel.get_fuel_amount(nvm)} + else + return 2, "" + end + end, }) minetest.register_craft({ diff --git a/energy_storage/heatexchanger2.lua b/energy_storage/heatexchanger2.lua index 2478288..2e513ea 100644 --- a/energy_storage/heatexchanger2.lua +++ b/energy_storage/heatexchanger2.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -356,6 +356,37 @@ techage.register_node({"techage:heatexchanger2"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 1 and payload[1] == 1 then + start_node(pos, techage.get_nvm(pos)) + return 0 + elseif topic == 1 and payload[1] == 0 then + stop_node(pos, techage.get_nvm(pos)) + return 0 + else + return 2, "" + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then -- State + if techage.is_running(nvm) then + return 0, {1} + else + return 0, {0} + end + elseif topic == 135 then -- Delivered Power + 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)} + else + return 2, "" + end + end, on_node_load = function(pos, node) local nvm = techage.get_nvm(pos) if techage.is_running(nvm) then diff --git a/furnace/firebox.lua b/furnace/firebox.lua index e933d08..755052b 100644 --- a/furnace/firebox.lua +++ b/furnace/firebox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -173,6 +173,18 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then -- State + return 0, {nvm.running and "running" or "stopped"} + elseif topic == 132 then -- Fuel Level + return 0, {fuel.get_fuel_amount(nvm)} + else + return 2, "" + end + end, -- called from furnace_top on_transfer = function(pos, in_dir, topic, payload) local nvm = techage.get_nvm(pos) diff --git a/furnace/furnace_top.lua b/furnace/furnace_top.lua index e49e748..28bb441 100644 --- a/furnace/furnace_top.lua +++ b/furnace/furnace_top.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -257,6 +257,17 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 141 then -- Furnace Output + local nvm = techage.get_nvm(pos) + return 0, {string.split(nvm.output or "unknown", " ")[1]} + else + return CRD(pos).State:on_beduino_request_data(pos, topic, payload) + end + end, } local _, node_name_ta3, _ = diff --git a/fusion_reactor/controller.lua b/fusion_reactor/controller.lua index 8af0bd8..653602d 100644 --- a/fusion_reactor/controller.lua +++ b/fusion_reactor/controller.lua @@ -269,6 +269,12 @@ techage.register_node({"techage:ta5_fr_controller_pas", "techage:ta5_fr_controll on_recv_message = function(pos, src, topic, payload) return State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return State:on_beduino_request_data(pos, topic, payload) + end, }) power.register_nodes({"techage:ta5_fr_controller_pas", "techage:ta5_fr_controller_act"}, Cable, "con", {"L", "R"}) diff --git a/fusion_reactor/heatexchanger2.lua b/fusion_reactor/heatexchanger2.lua index 88747f3..2190a2d 100644 --- a/fusion_reactor/heatexchanger2.lua +++ b/fusion_reactor/heatexchanger2.lua @@ -334,6 +334,35 @@ techage.register_node({"techage:ta5_heatexchanger2"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 1 and payload[1] == 1 then + start_node(pos, techage.get_nvm(pos)) + return 0 + elseif topic == 1 and payload[1] == 0 then + stop_node(pos, techage.get_nvm(pos)) + return 0 + else + return 2, "" + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 128 then + return 0, techage.get_node_lvm(pos).name + elseif topic == 129 then -- State + if techage.is_running(nvm) then + return 0, {1} + else + return 0, {0} + end + elseif topic == 135 then -- Delivered Power + local data = power.get_network_data(pos, Cable, DOWN) + return 0, {data.consumed - data.provided} + else + return 2, "" + end + end, on_node_load = function(pos, node) local nvm = techage.get_nvm(pos) if techage.is_running(nvm) then diff --git a/fusion_reactor/ta5_pump.lua b/fusion_reactor/ta5_pump.lua index fab96a0..a522bc3 100644 --- a/fusion_reactor/ta5_pump.lua +++ b/fusion_reactor/ta5_pump.lua @@ -170,6 +170,12 @@ techage.register_node({"techage:ta5_pump", "techage:ta5_pump_on"}, { on_recv_message = function(pos, src, topic, payload) return State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return State:on_beduino_request_data(pos, topic, payload) + end, }) -- Pumps have to provide one output and one input side diff --git a/hydrogen/electrolyzer.lua b/hydrogen/electrolyzer.lua index c3cc336..155091f 100644 --- a/hydrogen/electrolyzer.lua +++ b/hydrogen/electrolyzer.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -197,11 +197,11 @@ local tool_config = { }, { type = "dropdown", - choices = "0%,20%,40%,60%,80%", + choices = "0%,20%,40%,60%,80%,98%", name = "turnoff", label = S("Turnoff point"), tooltip = S("If the charge of the storage\nsystem exceeds the configured value,\nthe block switches off"), - default = "0%", + default = "98%", }, } @@ -332,11 +332,24 @@ techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on" return State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 134 and payload[1] == 1 then + return 0, {techage.power.percent(CAPACITY, (nvm.liquid and nvm.liquid.amount) or 0)} + elseif topic == 135 then + return 0, {math.floor((nvm.provided or 0) + 0.5)} + else + return State:on_beduino_request_data(pos, topic, payload) + end + end, on_node_load = function(pos, node) local meta = M(pos) if not meta:contains("reduction") then meta:set_string("reduction", "100%") - meta:set_string("turnoff", "0%") + meta:set_string("turnoff", "100%") end end, }) diff --git a/hydrogen/fuelcell.lua b/hydrogen/fuelcell.lua index 81301af..791558c 100644 --- a/hydrogen/fuelcell.lua +++ b/hydrogen/fuelcell.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -304,6 +304,19 @@ techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, { return State:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 134 and payload[1] == 1 then + return 0, {techage.power.percent(CAPACITY, (nvm.liquid and nvm.liquid.amount) or 0)} + elseif topic == 135 then + return 0, {math.floor((nvm.provided or 0) + 0.5)} + else + return State:on_beduino_request_data(pos, topic, payload) + end + end, }) control.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, { diff --git a/icta_controller/battery.lua b/icta_controller/battery.lua index 24c710c..1b4082e 100644 --- a/icta_controller/battery.lua +++ b/icta_controller/battery.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -176,4 +176,12 @@ techage.register_node({"techage:ta4_battery"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 134 then + local meta = minetest.get_meta(pos) + return 0, {calc_percent(meta:get_int("content"))} + else + return 2, "" + end + end, }) diff --git a/icta_controller/controller.lua b/icta_controller/controller.lua index 7c3292e..e1c2ae6 100644 --- a/icta_controller/controller.lua +++ b/icta_controller/controller.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -444,4 +444,30 @@ techage.register_node({"techage:ta4_icta_controller"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local meta = minetest.get_meta(pos) + local number = meta:get_string("number") + local state = meta:get_int("state") + + if state == techage.RUNNING and topic == 1 and payload[1] == 1 then + set_input(pos, number, src, topic) + elseif state == techage.RUNNING and topic == 1 and payload[1] == 0 then + set_input(pos, number, src, topic) + else + return 2 + end + return 0 + end, + on_beduino_request_data = function(pos, src, topic, payload) + local meta = minetest.get_meta(pos) + local number = meta:get_string("number") + local state = meta:get_int("state") + + if topic == 129 then + local state = meta:get_int("state") or 0 + return 0, {techage.StateStrings[state] or "stopped"} + else + return 2, "" + end + end, }) diff --git a/icta_controller/display.lua b/icta_controller/display.lua index e2a182d..5433f0e 100644 --- a/icta_controller/display.lua +++ b/icta_controller/display.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -211,14 +211,22 @@ function techage.display.add_line(pos, payload, cycle_time) table.insert(nvm.text, str) end -function techage.display.write_row(pos, payload, cycle_time) +function techage.display.write_row(pos, payload, cycle_time, beduino) local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos) + local str, row + nvm.text = nvm.text or {} mem.ticks = mem.ticks or 0 - local str = tostring(payload.get("str")) or "oops" - local row = tonumber(payload.get("row")) or 1 - + + if beduino then + row = tonumber(payload:sub(1,1) or "1") or 1 + str = payload:sub(2) or "oops" + else + str = tostring(payload.get("str")) or "oops" + row = tonumber(payload.get("row")) or 1 + end + if mem.ticks == 0 then mem.ticks = cycle_time end @@ -254,6 +262,18 @@ techage.register_node({"techage:ta4_display"}, { techage.display.clear_screen(pos, 1) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 67 then -- add one line and scroll if necessary + techage.display.add_line(pos, payload, 1) + elseif topic == 68 then -- overwrite the given row + techage.display.write_row(pos, payload, 1, true) + elseif topic == 17 then -- clear the screen + techage.display.clear_screen(pos, 1) + else + return 2 + end + return 0 + end, }) techage.register_node({"techage:ta4_displayXL"}, { @@ -266,6 +286,18 @@ techage.register_node({"techage:ta4_displayXL"}, { techage.display.clear_screen(pos, 2) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 67 then -- add one line and scroll if necessary + techage.display.add_line(pos, payload, 2) + elseif topic == 68 then -- overwrite the given row + techage.display.write_row(pos, payload, 2, true) + elseif topic == 17 then -- clear the screen + techage.display.clear_screen(pos, 2) + else + return 2 + end + return 0 + end, }) lcdlib.register_display_entity("techage:display_entity") diff --git a/icta_controller/signaltower.lua b/icta_controller/signaltower.lua index 6377494..13b0d8e 100644 --- a/icta_controller/signaltower.lua +++ b/icta_controller/signaltower.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -132,4 +132,27 @@ techage.register_node({"techage:ta4_signaltower", return meta:get_string("state") end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 2 then + local color = ({"green", "amber", "red"})[payload[1]] + local node = minetest.get_node(pos) + if color then + switch_on(pos, node, color) + else + switch_off(pos, node) + end + return 0 + else + return 2 -- unknown or invalid topic + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 130 then + local meta = minetest.get_meta(pos) + local color = ({off = 0, green = 1, amber = 2, red = 3})[meta:get_string("state")] or 1 + return 0, {color} + else + return 2, "" -- unknown or invalid topic + end + end, }) diff --git a/liquids/pump.lua b/liquids/pump.lua index 868d81a..99f0b51 100644 --- a/liquids/pump.lua +++ b/liquids/pump.lua @@ -284,6 +284,17 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, { return State4:on_receive_message(pos, topic, payload) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State4:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 137 then -- Total Flow Rate + local nvm = techage.get_nvm(pos) + return 0, {nvm.flowrate or 0} + else + return State4:on_beduino_request_data(pos, topic, payload) + end + end, }) -- Pumps have to provide one output and one input side diff --git a/liquids/silo.lua b/liquids/silo.lua index 0ef45c8..752f657 100644 --- a/liquids/silo.lua +++ b/liquids/silo.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -312,6 +312,25 @@ techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 129 then -- State + local meta = M(pos) + local inv = meta:get_inventory() + return 0, {techage.get_inv_state(inv, "main")} + elseif topic == 134 then + local inv = M(pos):get_inventory() + local nvm = techage.get_nvm(pos) + nvm.item_count = nvm.item_count or get_item_count(pos) + nvm.capa = nvm.capa or get_silo_capa(pos) + if payload[1] == 1 then + return 0, {techage.power.percent(nvm.capa, nvm.item_count)} + else + return 0, {nvm.item_count} + end + else + return 2, "" + end + end, on_node_load = function(pos) local nvm = techage.get_nvm(pos) nvm.item_count = nil diff --git a/liquids/valve.lua b/liquids/valve.lua index 8c9edd7..02c977b 100644 --- a/liquids/valve.lua +++ b/liquids/valve.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2021 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -139,6 +139,29 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local node = techage.get_node_lvm(pos) + if topic == 1 and payload[1] == 1 and node.name == "techage:ta3_valve_closed" then + liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") + return 0 + elseif topic == 1 and payload[1] == 0 and node.name == "techage:ta3_valve_open" then + liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") + return 0 + else + return 2, "" + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + local node = techage.get_node_lvm(pos) + if topic == 129 then -- State + if node.name == "techage:ta3_valve_open" then + return 0, {1} + end + return 0, {0} + else + return 2, "" + end + end, }) liquid.register_nodes({"techage:ta3_valve_closed"}, Pipe, "special", {}, {}) diff --git a/liquids/waterpump.lua b/liquids/waterpump.lua index 82ecf08..6911493 100644 --- a/liquids/waterpump.lua +++ b/liquids/waterpump.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -158,4 +158,10 @@ techage.register_node({"techage:t4_waterpump"}, { on_recv_message = function(pos, src, topic, payload) return State:on_receive_message(pos, topic, payload) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + return State:on_beduino_receive_cmnd(pos, topic, payload) + end, + on_beduino_request_data = function(pos, src, topic, payload) + return State:on_beduino_request_data(pos, topic, payload) + end, }) diff --git a/move_controller/soundblock.lua b/move_controller/soundblock.lua index 73aaa90..bafcbb2 100644 --- a/move_controller/soundblock.lua +++ b/move_controller/soundblock.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2021 Joachim Stolberg + Copyright (C) 2021-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -44,6 +44,18 @@ local function formspec(meta) "button[2.5,7.2;3,1;play;" .. S("Play") .. "]" end +local function play_predefined_sound(pos) + local mem = techage.get_mem(pos) + if not mem.blocking_time or (mem.blocking_time < minetest.get_gametime()) then + local idx = M(pos):get_int("idx") + local ogg = techage.OggFileList[idx or 1] or techage.OggFileList[1] + local gain = M(pos):get_int("gain") + play_sound(pos, ogg, gain) + mem.blocking_time = minetest.get_gametime() + 2 + return true + end +end + minetest.register_node("techage:ta3_soundblock", { description = S("TA3 Sound Block"), tiles = { @@ -94,15 +106,7 @@ techage.register_node({"techage:ta3_soundblock"}, { if topic == "info" then return INFO elseif topic == "on" then - local mem = techage.get_mem(pos) - if not mem.blocking_time or (mem.blocking_time < minetest.get_gametime()) then - local idx = M(pos):get_int("idx") - local ogg = techage.OggFileList[idx or 1] or techage.OggFileList[1] - local gain = M(pos):get_int("gain") - play_sound(pos, ogg, gain) - mem.blocking_time = minetest.get_gametime() + 2 - return true - end + play_predefined_sound(pos) elseif topic == "sound" then M(pos):set_int("idx", tonumber(payload or 1) or 1) elseif topic == "gain" then @@ -111,6 +115,23 @@ techage.register_node({"techage:ta3_soundblock"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 1 then + if payload[1] == 0 then + play_predefined_sound(pos) + return 0 + end + elseif topic == 14 then + if payload[1] == 1 then + M(pos):set_int("gain", payload[2]) + return 0 + elseif payload[1] == 2 then + M(pos):set_int("idx", payload[2]) + return 0 + end + end + return 2 -- unknown or invalid topic + end, on_node_load = function(pos) local meta = M(pos) meta:set_string("formspec", formspec(meta))