Digiline receiver: load new RDS immediately

This commit is contained in:
Serhii Mozhaiskyi 2019-12-24 14:03:08 +02:00
parent 007614adce
commit 6d19c5c302
2 changed files with 15 additions and 11 deletions

@ -78,8 +78,10 @@ ham_radio.digiline_effector_receiver = function(pos, _, channel, msg)
local validate = ham_radio.validate_frequency(new_frequency, true)
if validate.result then
meta:set_string("frequency", new_frequency)
ham_radio.reset_receiver(pos)
ham_radio.receiver_update_infotext(meta)
-- load new RDS messages
local poshash = minetest.pos_to_string(pos, 0)
ham_radio.receiver_rds[poshash] = ham_radio.get_rds_messages(new_frequency, true)
ham_radio.get_next_rds_message(poshash, meta)
end
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
update = 'frequency',

@ -99,23 +99,25 @@ minetest.register_abm(
action = function(pos, node)
local meta = minetest.get_meta(pos)
local frequency = meta:get_string("frequency")
if frequency == "" then
return
end
local poshash = minetest.pos_to_string(pos, 0)
if ham_radio.receiver_rds[poshash] == nil or not next(ham_radio.receiver_rds[poshash]) then
-- when all RDS messages are shown, reload them again
ham_radio.receiver_rds[poshash] = ham_radio.get_rds_messages(frequency, true)
end
local message = table.remove(ham_radio.receiver_rds[poshash])
if message ~= nil then
meta:set_string('rds_message', message)
ham_radio.receiver_update_infotext(meta)
end
ham_radio.get_next_rds_message(poshash, meta)
end
}
);
ham_radio.get_next_rds_message = function (poshash, meta)
local message = table.remove(ham_radio.receiver_rds[poshash])
if message ~= nil then
meta:set_string('rds_message', message)
ham_radio.receiver_update_infotext(meta)
end
end