diff --git a/logic/cart_detector.lua b/logic/cart_detector.lua index 244e40f..99c12b6 100644 --- a/logic/cart_detector.lua +++ b/logic/cart_detector.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 @@ -151,6 +151,28 @@ techage.register_node({"techage:ta3_cartdetector_off", "techage:ta3_cartdetector return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 1 then + local node = minetest.get_node(pos) + local dir = minetest.facedir_to_dir(node.param2) + minecart.punch_cart(pos, nil, 1.6, dir) + return 0 + else + return 2 + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 142 then -- Binary State + local node = techage.get_node_lvm(pos) + if node.name == "techage:ta3_cartdetector_on" then + return 0, {1} + else + return 0, {0} + end + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) end, diff --git a/logic/collector.lua b/logic/collector.lua index d50a1e0..6083952 100644 --- a/logic/collector.lua +++ b/logic/collector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -24,6 +24,7 @@ local CYCLE_TIME = 1 local tStates = {stopped = 0, running = 0, standby = 1, blocked = 2, nopower = 3, fault = 4} local tDropdownPos = {["1 standby"] = 1, ["2 blocked"] = 2, ["3 nopower"] = 3, ["4 fault"] = 4} local lStates = {[0] = "stopped", "standby", "blocked", "nopower", "fault"} +local TaStates = {running = 1, blocked = 2, standby = 3, nopower = 4, fault = 5, stopped = 6} local function formspec(nvm, meta) nvm.poll_numbers = nvm.poll_numbers or {} @@ -200,13 +201,21 @@ minetest.register_craft({ techage.register_node({"techage:ta4_collector"}, { on_recv_message = function(pos, src, topic, payload) - if topic == "state" then + if topic == "state" then local nvm = techage.get_nvm(pos) return lStates[nvm.stored_state or 0] else return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 129 then + local nvm = techage.get_nvm(pos) + return 0, {TaStates[lStates[nvm.stored_state or 0]]} + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) end, diff --git a/logic/detector.lua b/logic/detector.lua index b0e709b..dcf432c 100644 --- a/logic/detector.lua +++ b/logic/detector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -276,4 +276,21 @@ techage.register_node({"techage:ta4_detector_off", "techage:ta4_detector_on"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 6 then -- Detector Block Reset + local nvm = techage.get_nvm(pos) + nvm.counter = 0 + return 0 + else + return 2 + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 139 then + local nvm = techage.get_nvm(pos) + return 0, {nvm.counter or 0} + else + return 2, "" + end + end, }) diff --git a/logic/light_detector.lua b/logic/light_detector.lua index 41daa2e..3719311 100755 --- a/logic/light_detector.lua +++ b/logic/light_detector.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 @@ -168,6 +168,21 @@ techage.register_node({"techage:ta3_lightdetector_off", "techage:ta3_lightdetect return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 142 then -- Binary State + local node = techage.get_node_lvm(pos) + if node.name == "techage:ta3_lightdetector_on" then + return 0, {1} + else + return 0, {0} + end + elseif topic == 143 then -- Allow finding the specific light level + local pos_above = {x = pos.x, y = pos.y + 1, z = pos.z} + return 0, {minetest.get_node_light(pos_above, nil)} + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) end, diff --git a/logic/logic_block.lua b/logic/logic_block.lua index 0b83272..e15d652 100644 --- a/logic/logic_block.lua +++ b/logic/logic_block.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2021 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -407,4 +407,29 @@ techage.register_node({"techage:ta3_logic2"}, { mem.ttl = techage.SystemTime + (nvm.blocking_time or 0) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + local mem = techage.get_mem(pos) + nvm.own_num = nvm.own_num or M(pos):get_string("node_number") + nvm.blocking_time = nvm.blocking_time or M(pos):get_float("blocking_time") + nvm.inp_tbl = nvm.inp_tbl or {} + + if src ~= nvm.own_num then + if topic == 1 and payload[1] == 1 then + debug(mem, "(inp) " .. src .. " = on") + nvm.inp_tbl[src] = "on" + return 0 + elseif topic == 1 and payload[1] == 0 then + debug(mem, "(inp) " .. src .. " = off") + nvm.inp_tbl[src] = "off" + return 0 + else + debug(mem, "(inp) invalid command") + return 2 + end + local t = math.max((mem.ttl or 0) - techage.SystemTime, 0.1) + minetest.get_node_timer(pos):start(t) + mem.ttl = techage.SystemTime + (nvm.blocking_time or 0) + end + end, }) diff --git a/logic/lua_logic.lua b/logic/lua_logic.lua index 57cc629..48e3418 100644 --- a/logic/lua_logic.lua +++ b/logic/lua_logic.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -246,7 +246,19 @@ techage.register_node({"techage:ta3_logic"}, { end minetest.get_node_timer(pos):start(0.1) end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 1 and payload[1] == 1 then + nvm.inp_tbl.inp = true + nvm.inp_tbl["n"..src] = true + return 0 + elseif topic == 1 and payload[1] == 0 then + nvm.inp_tbl.inp = false + nvm.inp_tbl["n"..src] = false + return 0 + else + return 2 + end + end, on_node_load = function(pos) - end, }) diff --git a/logic/mba_detector.lua b/logic/mba_detector.lua index 96cdd17..ab5d744 100644 --- a/logic/mba_detector.lua +++ b/logic/mba_detector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -92,6 +92,23 @@ techage.register_node({"techage:ta4_mbadetector"}, { return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 142 then -- Binary State + if minetest.compare_block_status then + if minetest.compare_block_status(pos, "active") then + return 0, {1} + else + return 0, {0} + end + else + local mem = techage.get_mem(pos) + local res = mem.gametime and mem.gametime > (minetest.get_gametime() - 2) + return 0, {res and 1 or 0} + end + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(1) end, diff --git a/logic/node_detector.lua b/logic/node_detector.lua index 7d3c89c..25f0db0 100644 --- a/logic/node_detector.lua +++ b/logic/node_detector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -189,20 +189,29 @@ minetest.register_craft({ techage.register_node({"techage:ta3_nodedetector_off", "techage:ta3_nodedetector_on"}, { on_recv_message = function(pos, src, topic, payload) - if topic == "name" then - local nvm = techage.get_nvm(pos) - return nvm.player_name or "" - elseif topic == "state" then + if topic == "state" then local node = techage.get_node_lvm(pos) if node.name == "techage:ta3_nodedetector_off" then - return "on" - else return "off" + else + return "on" end else return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 142 then + local node = techage.get_node_lvm(pos) + if node.name == "techage:ta3_nodedetector_off" then + return 0, {0} + else + return 0, {1} + end + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) end, diff --git a/logic/player_detector.lua b/logic/player_detector.lua index 791eb8d..7aeb828 100644 --- a/logic/player_detector.lua +++ b/logic/player_detector.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -323,6 +323,22 @@ techage.register_node({ return "unsupported" end end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 144 then -- Player Name + local nvm = techage.get_nvm(pos) + return 0, {nvm.player_name or ""} + elseif topic == 142 then -- Binary State + local node = techage.get_node_lvm(pos) + if node.name == "techage:ta3_playerdetector_on" or + node.name == "techage:ta4_playerdetector_on" then + return 0, {1} + else + return 0, {0} + end + else + return 2, "" + end + end, on_node_load = function(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) end, diff --git a/logic/sequencer.lua b/logic/sequencer.lua index e2c6005..1d5d936 100644 --- a/logic/sequencer.lua +++ b/logic/sequencer.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2020 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -278,6 +278,28 @@ techage.register_node({"techage:ta3_sequencer"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 7 then -- TA3 Sequenzer + if payload[1] == 1 then + start_the_sequencer(pos) + return 0 + elseif payload[1] == 0 then + -- do not stop immediately + local nvm = techage.get_nvm(pos) + if not nvm.running then + nvm.endless = not (nvm.endless or false) + else + nvm.endless = false + end + return 0 + elseif payload[1] == 2 then + stop_the_sequencer(pos) + return 0 + end + end + return 2 + end, on_node_load = function(pos) local nvm = techage.get_nvm(pos) if nvm.running then diff --git a/logic/sequencer2.lua b/logic/sequencer2.lua index 40ae341..a4db881 100644 --- a/logic/sequencer2.lua +++ b/logic/sequencer2.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2021 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -311,4 +311,23 @@ techage.register_node({"techage:ta4_sequencer"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == 13 then + if payload[1] ~= 0 and not nvm.running then + local mem = techage.get_mem(pos) + nvm.running = true + mem.idx = tonumber(payload or 1) or 1 + restart_timer(pos, 0.1) + logic.infotext(M(pos), S("TA4 Sequencer"), S("running")) + return 0 + elseif payload[1] == 0 then + nvm.running = false + minetest.get_node_timer(pos):stop() + logic.infotext(M(pos), S("TA4 Sequencer"), S("stopped")) + return 0 + end + end + return 2 + end, }) diff --git a/logic/signallamp.lua b/logic/signallamp.lua index 0a7ae1c..982bde2 100644 --- a/logic/signallamp.lua +++ b/logic/signallamp.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2020 Joachim Stolberg + Copyright (C) 2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -121,6 +121,19 @@ techage.register_node({"techage:signal_lamp_off", "techage:signal_lamp_on"}, { return "unsupported" end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 1 and payload[1] == 1 then + local node = techage.get_node_lvm(pos) + switch_on(pos, node) + return 0 + elseif topic == 1 and payload[1] == 0 then + local node = techage.get_node_lvm(pos) + switch_off(pos, node) + return 0 + else + return 2 + end + end, }) minetest.register_craft({ diff --git a/logic/signallamp_2x.lua b/logic/signallamp_2x.lua index 793cca9..3692b30 100644 --- a/logic/signallamp_2x.lua +++ b/logic/signallamp_2x.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2021 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -17,9 +17,9 @@ local M = minetest.get_meta local S = techage.S local OFF = 0 -local RED = 1 -local GREEN = 2 -local AMBER = 3 +local GREEN = 1 +local AMBER = 2 +local RED = 3 local WRENCH_MENU = { { @@ -139,6 +139,19 @@ techage.register_node({"techage:ta4_signallamp_2x"}, { lcdlib.update_entities(pos) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + nvm.lamp = nvm.lamp or {} + if topic == 3 then -- Signal Lamp + local num = math.min(payload[1] or 1, 2) + local color = math.min(payload[2] or 0, 3) + nvm.lamp[num] = color + lcdlib.update_entities(pos) + return 0 + else + return 2 + end + end, }) minetest.register_craft({ diff --git a/logic/signallamp_4x.lua b/logic/signallamp_4x.lua index 6482785..a098ba6 100644 --- a/logic/signallamp_4x.lua +++ b/logic/signallamp_4x.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2017-2021 Joachim Stolberg + Copyright (C) 2017-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -17,9 +17,9 @@ local M = minetest.get_meta local S = techage.S local OFF = 0 -local RED = 1 -local GREEN = 2 -local AMBER = 3 +local GREEN = 1 +local AMBER = 2 +local RED = 3 local WRENCH_MENU = { { @@ -170,6 +170,19 @@ techage.register_node({"techage:ta4_signallamp_4x"}, { lcdlib.update_entities(pos) end end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + nvm.lamp = nvm.lamp or {} + if topic == 3 then -- Signal Lamp + local num = math.min(payload[1] or 1, 4) + local color = math.min(payload[2] or 0, 3) + nvm.lamp[num] = color + lcdlib.update_entities(pos) + return 0 + else + return 2 + end + end, }) minetest.register_craft({