From b47ecc6f6aa8fa5b4d8257a86ede32642e48d317 Mon Sep 17 00:00:00 2001 From: Serhii Mozhaiskyi Date: Tue, 24 Dec 2019 13:25:50 +0200 Subject: [PATCH] Separate digiline handling for receiver --- README.md | 8 ++++++++ config.lua | 1 + digiline.lua | 37 +++++++++++++++++++++++++++++++++++-- receiver_station.lua | 2 +- transmitter.lua | 2 +- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1df2664..37e508b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.lua b/config.lua index cef696c..7db8ab8 100644 --- a/config.lua +++ b/config.lua @@ -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", } diff --git a/digiline.lua b/digiline.lua index 3f1ab27..4c2baf4 100644 --- a/digiline.lua +++ b/digiline.lua @@ -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 \ No newline at end of file diff --git a/receiver_station.lua b/receiver_station.lua index 28e5e43..c6cb35b 100644 --- a/receiver_station.lua +++ b/receiver_station.lua @@ -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 }, }, }); diff --git a/transmitter.lua b/transmitter.lua index 26b5144..3f1e0bf 100644 --- a/transmitter.lua +++ b/transmitter.lua @@ -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 }, }, });