mirror of
https://github.com/technix/ham_radio.git
synced 2025-03-01 05:34:36 +01:00
Separate digiline handling for receiver
This commit is contained in:
@ -59,6 +59,14 @@ digiline.send('ham_radio', { command = 'set_frequency', value = '12345' })
|
|||||||
-- set RDS message
|
-- set RDS message
|
||||||
digiline.send('ham_radio', { command = 'set_rds_message', value = 'new RDS message' })
|
digiline.send('ham_radio', { command = 'set_rds_message', value = 'new RDS message' })
|
||||||
-- returns { update = 'rds_message', success = true }
|
-- 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
|
## Config
|
||||||
|
@ -28,4 +28,5 @@ ham_radio.settings = {
|
|||||||
-- digiline config
|
-- digiline config
|
||||||
digiline_channel = "ham_radio",
|
digiline_channel = "ham_radio",
|
||||||
digiline_rds_channel = "ham_radio_rds",
|
digiline_rds_channel = "ham_radio_rds",
|
||||||
|
digiline_receiver_channel = "ham_radio_receiver",
|
||||||
}
|
}
|
||||||
|
37
digiline.lua
37
digiline.lua
@ -1,5 +1,6 @@
|
|||||||
ham_radio.digiline_effector = function(pos, _, channel, msg)
|
ham_radio.digiline_effector_transmitter = function(pos, _, channel, msg)
|
||||||
local command_channel = ham_radio.settings.digiline_channel -- static channel
|
-- static channels for transmitter
|
||||||
|
local command_channel = ham_radio.settings.digiline_channel
|
||||||
local rds_channel = ham_radio.settings.digiline_rds_channel
|
local rds_channel = ham_radio.settings.digiline_rds_channel
|
||||||
|
|
||||||
if channel ~= command_channel and channel ~= rds_channel then
|
if channel ~= command_channel and channel ~= rds_channel then
|
||||||
@ -53,4 +54,36 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
|
|||||||
success = true
|
success = true
|
||||||
})
|
})
|
||||||
end
|
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
|
end
|
@ -79,7 +79,7 @@ minetest.register_node("ham_radio:receiver", {
|
|||||||
digiline = {
|
digiline = {
|
||||||
receptor = {action = function() end},
|
receptor = {action = function() end},
|
||||||
effector = {
|
effector = {
|
||||||
action = ham_radio.digiline_effector
|
action = ham_radio.digiline_effector_receiver
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -103,7 +103,7 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
digiline = {
|
digiline = {
|
||||||
receptor = {action = function() end},
|
receptor = {action = function() end},
|
||||||
effector = {
|
effector = {
|
||||||
action = ham_radio.digiline_effector
|
action = ham_radio.digiline_effector_transmitter
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user