From 652183d2531fcc5a1d0a90e181bbb8f981b757a1 Mon Sep 17 00:00:00 2001 From: Serhii Mozhaiskyi Date: Fri, 13 Dec 2019 13:11:59 +0200 Subject: [PATCH] improve digiline --- README.md | 14 ++++++++------ digiline.lua | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4e3771b..c672fa9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Craft recipes depend of the mods installed. Craft a transmitter and place it in the world. Right click on transmitter to open configuration dialog, then set frequency and RDS message. - Empty frequency turns transmitter off. - Transmitter information is displayed as info text when player points at it. +- RDS message can be multiline. However, it is transmitted line by line. - RDS message and frequency can be set via digiline. Also, you can read transmitter configuration via digiline too. ## Beacon @@ -39,22 +40,25 @@ If RDS reception is toggled on, the RDS messages from all transmitters on this f ## Stationary Receiver Right click on receiver opens configuration window to set frequency. Receiver displays RDS messages as infotext in the same way as handheld receiver. It does not have signal power meter. +- You can operate the receiver in the same way as the transmitter. ## Digiline ```lua --- this channel accepts plain text -digiline.send('ham_radio_rds', 'new RDS message') +-- channel "ham_radio_rds" accepts plain text +digiline.send('ham_radio_rds', 'new RDS message') -- get transmitter info digiline.send('ham_radio', { command = 'get' }) -- returns { frequency = 12345, rds_message = 'text' } -- set frequency -digiline.send('ham_radio', { command = 'frequency', value = '12345' }) +digiline.send('ham_radio', { command = 'set_frequency', value = '12345' }) +-- returns { update = 'frequency', success = true/false, message = errorMessage } -- set RDS message -digiline.send('ham_radio', { command = 'rds_message', value = 'new RDS message' }) +digiline.send('ham_radio', { command = 'set_rds_message', value = 'new RDS message' }) +-- returns { update = 'rds_message', success = true } ``` ## What's next? @@ -74,5 +78,3 @@ Source code: MIT Textures: CC BY-SA 3.0 Sounds: cut from "G32-20-Tuning Radio" by craigsmith, CC 0 - - diff --git a/digiline.lua b/digiline.lua index b8ec8c5..3f1ab27 100644 --- a/digiline.lua +++ b/digiline.lua @@ -25,23 +25,32 @@ ham_radio.digiline_effector = function(pos, _, channel, msg) end if msg.command == "get" then - digilines.receptor_send(pos, digilines.rules.default, digiline_channel, { + 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" then + elseif msg.command == "frequency" or msg.command == "set_frequency" then local new_frequency = msg.value - if ham_radio.validate_frequency(new_frequency).result then + local validate = ham_radio.validate_frequency(new_frequency) + if validate.result then meta:set_string("frequency", new_frequency) ham_radio.transmitter_update_infotext(meta) ham_radio.save_transmitter(pos, meta) end + digilines.receptor_send(pos, digilines.rules.default, command_channel, { + update = 'frequency', + success = validate.result, + message = validate.message + }) - elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" then + elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" or msg.command == "set_rds_message" then meta:set_string("rds_message", msg.value) ham_radio.transmitter_update_infotext(meta) ham_radio.save_transmitter(pos, meta) - + digilines.receptor_send(pos, digilines.rules.default, command_channel, { + update = 'rds_message', + success = true + }) end end \ No newline at end of file