Add support for beduino commands

This commit is contained in:
Joachim Stolberg 2022-06-06 20:39:55 +02:00
parent a0b637e4e9
commit 24e91edc7e
21 changed files with 368 additions and 29 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
@ -654,4 +654,27 @@ techage.register_node({"techage:ta4_lua_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")
if topic == 1 and payload[1] == 1 then
set_input(pos, number, src, "on")
elseif topic == 1 and payload[1] == 0 then
set_input(pos, number, src, "off")
else
return 2
end
return 0
end,
on_beduino_request_data = function(pos, src, topic, payload)
local meta = minetest.get_meta(pos)
if topic == 129 then
local running = meta:get_int("running") or STATE_STOPPED
return 0, running
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
@ -46,6 +46,13 @@ local function send_command(pos)
end
end
local function get_stack(pos, idx)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack("main", idx)
return stack:get_name(), stack:get_count()
end
local function get_stacks(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -215,7 +222,7 @@ techage.register_node({"techage:ta4_sensor_chest"}, {
elseif topic == "action" then
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
return PlayerActions[number][1], PlayerActions[number][2]
return (PlayerActions[number] or {})[1], (PlayerActions[number] or {})[2]
elseif topic == "stacks" then
return get_stacks(pos)
elseif topic == "text" then
@ -226,6 +233,40 @@ techage.register_node({"techage:ta4_sensor_chest"}, {
return "unsupported"
end
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
if topic == 66 then
local meta = minetest.get_meta(pos)
meta:set_string("text", tostring(payload))
meta:set_string("formspec", formspec2(pos))
return 0
else
return 2
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")}
elseif topic == 138 and payload[1] == 1 then -- Sensor Chests State (action)
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
local action = (PlayerActions[number] or {})[2] or "None"
return 0, {({put = 1, get = 2})[action] or 0}
elseif topic == 138 and payload[1] == 2 then -- Sensor Chests State (player name)
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
return 0, {(PlayerActions[number] or {})[1]}
elseif topic == 138 and payload[1] == 3 then -- Sensor Chests State (stack item name)
local name, _ = get_stack(pos, payload[2] or 1)
return 0, {name}
elseif topic == 138 and payload[1] == 4 then -- Sensor Chests State (stack item count)
local _, count = get_stack(pos, payload[2] or 1)
return 0, {count}
else
return 2, ""
end
end,
})
minetest.register_craft({

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
@ -124,6 +124,17 @@ techage.register_node({"techage:ta3_doorcontroller"}, {
swap_door_nodes(pos, false)
end
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
if topic == 1 and payload[1] == 1 then
swap_door_nodes(pos, true)
return 0
elseif topic == 1 and payload[1] == 0 then
swap_door_nodes(pos, false)
return 0
else
return 2
end
end,
})
minetest.register_craft({

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2020-2021 Joachim Stolberg
Copyright (C) 2020-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -345,6 +345,17 @@ techage.register_node({"techage:ta3_doorcontroller2"}, {
end
return false
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
if topic == 1 and payload[1] == 1 then
return hide_nodes(pos) and 0 or 3
elseif topic == 1 and payload[1] == 0 then
return show_nodes(pos) and 0 or 3
elseif topic == 9 then -- Exchange Block
local nvm = techage.get_nvm(pos)
return exchange_nodes(pos, nvm, payload[1] or 1) and 0 or 3
end
return 2
end,
on_node_load = function(pos)
local meta = M(pos)
local nvm = techage.get_nvm(pos)

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2020-2021 Joachim Stolberg
Copyright (C) 2020-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -228,6 +228,33 @@ techage.register_node({"techage:ta5_flycontroller"}, {
end
return false
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 11 then
if payload[1] == 1 then
nvm.moveBA = true
nvm.running = true
return fly.move_to_other_pos(pos, false) and 0 or 3
elseif payload[1] == 2 then
nvm.moveBA = false
nvm.running = true
return fly.move_to_other_pos(pos, true) and 0 or 3
elseif payload[1] == 3 then
nvm.moveBA = nvm.moveBA == false
nvm.running = true
return fly.move_to_other_pos(pos, nvm.moveBA == false) and 0 or 3
end
else
return 2
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 129 then
return 0, {nvm.running and 1 or 6}
end
return 2, ""
end,
})
minetest.register_craft({

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2020-2021 Joachim Stolberg
Copyright (C) 2020-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -204,6 +204,33 @@ techage.register_node({"techage:ta4_movecontroller"}, {
end
return false
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 11 then
if payload[1] == 1 then
nvm.moveBA = true
nvm.running = true
return fly.move_to_other_pos(pos, false) and 0 or 3
elseif payload[1] == 2 then
nvm.moveBA = false
nvm.running = true
return fly.move_to_other_pos(pos, true) and 0 or 3
elseif payload[1] == 3 then
nvm.moveBA = nvm.moveBA == false
nvm.running = true
return fly.move_to_other_pos(pos, nvm.moveBA == false) and 0 or 3
end
else
return 2
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 129 then
return 0, {nvm.running and 1 or 6}
end
return 2, ""
end,
})
minetest.register_craft({

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2020-2021 Joachim Stolberg
Copyright (C) 2020-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -156,6 +156,43 @@ techage.register_node({"techage:ta4_turncontroller"}, {
end
return false
end,
on_beduino_receive_cmnd = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 12 then
if payload[1] == 1 then
local nvm = techage.get_nvm(pos)
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "l")
if new_posses then
nvm.lpos = new_posses
return 0
end
return 3
elseif payload[1] == 2 then
local nvm = techage.get_nvm(pos)
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
if new_posses then
nvm.lpos = new_posses
return 0
end
return 3
elseif payload[1] == 3 then
local nvm = techage.get_nvm(pos)
local new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
if new_posses then
nvm.lpos = new_posses
new_posses = fly.rotate_nodes(pos, nvm.lpos, "r")
if new_posses then
nvm.lpos = new_posses
return 0
end
end
return 3
end
return 2
else
return 2
end
end,
})
minetest.register_craft({

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
@ -255,6 +255,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, node)
CRD(pos).State:on_node_load(pos)
local nvm = techage.get_nvm(pos)

View File

@ -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
@ -186,6 +186,24 @@ local tubing = {
return CRD(pos).State:on_receive_message(pos, topic, payload)
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 134 then -- Load
local storage_pos = M(pos):get_string("storage_pos")
if storage_pos ~= "" then
local amount, capa = techage.explore.get_oil_amount(P(storage_pos))
if amount and capa and capa > 0 then
if payload[1] == 1 then
return 0, {techage.power.percent(capa or 0, amount or 0)}
else
return 0, {math.min(amount or 0, 65535)}
end
end
end
return 2
else
return CRD(pos).State:on_beduino_request_data(pos, topic, payload)
end
end,
on_node_load = function(pos, node)
CRD(pos).State:on_node_load(pos)
if node.name == "techage:ta3_pumpjack_act" then

View File

@ -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
@ -254,15 +254,6 @@ liquid.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Pipe,
power.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Cable, "con")
techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "state" then
nvm.state = nvm.state or techage.STOPPED
return techage.StateStrings[nvm.state]
else
return "unsupported"
end
end,
on_node_load = function(pos, node)
if node.name == "techage:ta3_reboiler_on" then
play_sound(pos)

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
@ -255,6 +255,36 @@ techage.register_node({"techage:powerswitch", "techage:powerswitch_on",
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:powerswitch" then
switch_on(pos, node, nil, "techage:powerswitch_on")
return 0
elseif topic == 1 and payload[1] == 1 and node.name == "techage:powerswitchsmall" then
switch_on(pos, node, nil, "techage:powerswitchsmall_on")
return 0
elseif topic == 1 and payload[1] == 0 and node.name == "techage:powerswitch_on" then
switch_off(pos, node, nil, "techage:powerswitch")
return 0
elseif topic == 1 and payload[1] == 0 and node.name == "techage:powerswitchsmall_on" then
switch_off(pos, node, nil, "techage:powerswitchsmall")
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 == 142 then
if node.name == "techage:powerswitch_on" or
node.name == "techage:powerswitchsmall_on" then
return 0, {1}
end
return 0, {0}
else
return 2, ""
end
end,
})
minetest.register_craft({

View File

@ -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
@ -218,6 +218,17 @@ techage.register_node({"techage:ta4_solar_inverter"}, {
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,
})
control.register_nodes({"techage:ta4_solar_inverter"}, {

View File

@ -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
@ -120,6 +120,20 @@ techage.register_node({"techage:ta4_solar_minicell"}, {
return "unsupported"
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 145 then -- Solar Cell State
if nvm.providing then
return 0, {2}
elseif (nvm.capa or 0) > 0 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) 2019-2020 Joachim Stolberg
Copyright (C) 2019-2022 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -172,6 +172,17 @@ techage.register_node({"techage:ta3_akku"}, {
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 then -- load
return 0, {math.floor(techage.power.percent(PWR_CAPA, nvm.capa) + 0.5)}
else
return State:on_beduino_request_data(pos, topic, payload)
end
end,
})
control.register_nodes({"techage:ta3_akku"}, {

View File

@ -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
@ -338,6 +338,19 @@ techage.register_node({"techage:tiny_generator", "techage:tiny_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
return 0, {nvm.provided or 0}
elseif topic == 132 then
return 0, {techage.fuel.get_fuel_amount(nvm)}
else
return State:on_beduino_request_data(pos, topic, payload)
end
end,
on_node_load = function(pos, node)
State:on_node_load(pos)
if node.name == "techage:tiny_generator_on" then

View File

@ -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
@ -160,6 +160,17 @@ techage.register_node({"techage:ta4_electricmeter"}, {
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 == 146 then -- Consumption
return 0, {math.floor((nvm.units or 0) / techage.CYCLES_PER_DAY)}
else
return State:on_beduino_request_data(pos, topic, payload)
end
end,
})
control.register_nodes({"techage:ta4_electricmeter"}, {

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
Copyright (C) 2019-2022 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -135,6 +135,14 @@ techage.register_node({"techage:ta4_laser_emitter"}, {
return "unsupported"
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 142 then -- Binary State
local nvm = techage.get_nvm(pos)
return 0, {nvm.running and 1 or 0}
else
return 2, ""
end
end,
})
power.register_nodes({"techage:ta4_laser_emitter", "techage:ta4_laser_receiver"}, Cable, "special", {"F"})

View File

@ -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
@ -150,6 +150,12 @@ techage.register_node({"techage:ta4_transformer"}, {
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,
})
control.register_nodes({"techage:ta4_transformer"}, {

View File

@ -186,6 +186,12 @@ techage.register_node({"techage:ta5_tele_pipe"}, {
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_tele_pipe"}, Cable, "con", {"B", "R", "F", "D", "U"})

View File

@ -175,6 +175,12 @@ techage.register_node({"techage:ta5_tele_tube"}, {
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_tele_tube"}, Cable, "con", {"B", "R", "F", "D", "U"})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2021 DS-Minetest, Joachim Stolberg
Copyright (C) 2019-2022 DS-Minetest, Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -307,6 +307,37 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
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
State:start(pos, nvm)
elseif topic == 1 and payload[1] == 0 then
State:stop(pos, nvm)
else
return 2
end
return 0
end,
on_beduino_request_data = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == 129 then
local node = minetest.get_node(pos)
if node.name == "ignore" then -- unloaded node?
return 0, {7} -- unloaded
end
if nvm.error then
return 0, {5} -- fault
elseif techage.is_running(nvm) then
return 0, {1} -- running
else
return 0, {6} -- stopped
end
elseif topic == 135 then -- Delivered Power
return 0, {nvm.delivered or 0}
else
return 2, ""
end
end,
on_node_load = function(pos)
local nvm = techage.get_nvm(pos)
add_rotor(pos, nvm, true)