Separate digiline handling for receiver

This commit is contained in:
Serhii Mozhaiskyi 2019-12-24 13:25:50 +02:00
parent 1441b6fe35
commit b47ecc6f6a
5 changed files with 46 additions and 4 deletions

@ -59,6 +59,14 @@ digiline.send('ham_radio', { command = 'set_frequency', value = '12345' })
-- set RDS message
digiline.send('ham_radio', { command = 'set_rds_message', value = 'new RDS message' })
-- returns { update = 'rds_message', success = true }
-- get receiver info
digiline.send('ham_radio_receiver', { command = 'get' })
-- returns { frequency = 12345, rds_message = 'text' }
-- set receiver frequency
digiline.send('ham_radio_receiver', { command = 'set_frequency', value = '12345' })
-- returns { update = 'frequency', success = true/false, message = errorMessage }
```
## Config

@ -28,4 +28,5 @@ ham_radio.settings = {
-- digiline config
digiline_channel = "ham_radio",
digiline_rds_channel = "ham_radio_rds",
digiline_receiver_channel = "ham_radio_receiver",
}

@ -1,5 +1,6 @@
ham_radio.digiline_effector = function(pos, _, channel, msg)
local command_channel = ham_radio.settings.digiline_channel -- static channel
ham_radio.digiline_effector_transmitter = function(pos, _, channel, msg)
-- static channels for transmitter
local command_channel = ham_radio.settings.digiline_channel
local rds_channel = ham_radio.settings.digiline_rds_channel
if channel ~= command_channel and channel ~= rds_channel then
@ -53,4 +54,36 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
success = true
})
end
end
ham_radio.digiline_effector_receiver = function(pos, _, channel, msg)
-- static channel for receiver
local command_channel = ham_radio.settings.digiline_receiver_channel
if channel ~= command_channel or type(msg) ~= "table" then
return
end
local meta = minetest.get_meta(pos)
if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
frequency = meta:get_string("frequency"),
rds_message = meta:get_string("rds_message"),
})
elseif msg.command == "frequency" or msg.command == "set_frequency" then
local new_frequency = msg.value
local validate = ham_radio.validate_frequency(new_frequency, true)
if validate.result then
meta:set_string("frequency", new_frequency)
end
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
update = 'frequency',
success = validate.result,
message = validate.message
})
end
end

@ -79,7 +79,7 @@ minetest.register_node("ham_radio:receiver", {
digiline = {
receptor = {action = function() end},
effector = {
action = ham_radio.digiline_effector
action = ham_radio.digiline_effector_receiver
},
},
});

@ -103,7 +103,7 @@ minetest.register_node("ham_radio:transmitter", {
digiline = {
receptor = {action = function() end},
effector = {
action = ham_radio.digiline_effector
action = ham_radio.digiline_effector_transmitter
},
},
});