Add support for beduino commands

This commit is contained in:
Joachim Stolberg 2022-06-06 15:59:12 +02:00
parent abac1cce98
commit a0b637e4e9
14 changed files with 250 additions and 28 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,
})

View File

@ -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,

View File

@ -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,
})

View File

@ -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,
})

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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,
})

View File

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

View File

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

View File

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