From 202e2c394367c7903033dbae8f8e0d50dac7d75c Mon Sep 17 00:00:00 2001 From: Chris Pinkham Date: Tue, 12 Nov 2019 23:19:44 -0800 Subject: [PATCH] Allow skipping transmitter setup and using plugin for RDS only. Also fix a segfault in formatAndSendText() if plugin installed but not starting. --- plugin_setup.php | 2 +- src/FPPVastFM.cpp | 75 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/plugin_setup.php b/plugin_setup.php index bbbe71b..2c34c8e 100755 --- a/plugin_setup.php +++ b/plugin_setup.php @@ -33,7 +33,7 @@ function toggle(id) {
VAST-FMT/Si4713 Plugin Settings -

Start at: "FPPDStart", "Playlist Start"=>"PlaylistStart", "Never"=>"Never"), "fpp-vastfmt", ""); ?>
+

Start at: "FPPDStart", "Playlist Start"=>"PlaylistStart", "Never - RDS Only"=>"RDSOnly", "Never"=>"Never"), "fpp-vastfmt", ""); ?>
At Start, the hardware is reset, FM settings initialized, will broadcast any audio played, and send static RDS messages (if enabled).

Stop at: "PlaylistStop", "Never (default)"=>"Never"), "fpp-vastfmt", ""); ?>
At Stop, the hardware is reset. Listeners will hear static.

diff --git a/src/FPPVastFM.cpp b/src/FPPVastFM.cpp index de8673b..4f67816 100755 --- a/src/FPPVastFM.cpp +++ b/src/FPPVastFM.cpp @@ -41,6 +41,8 @@ class FPPVastFMPlugin : public FPPPlugin { setDefaultSettings(); if (settings["Start"] == "FPPDStart") { startVast(); + } else if (settings["Start"] == "RDSOnly") { + startVastForRDS(); } } virtual ~FPPVastFMPlugin() { @@ -50,20 +52,43 @@ class FPPVastFMPlugin : public FPPPlugin { si4713 = nullptr; } } + + bool initVast() { + if (si4713 != nullptr) { + delete si4713; + si4713 = nullptr; + } + + if (settings["Connection"] == "I2C") { + si4713 = new I2CSi4713(settings["ResetPin"]); + } else { + si4713 = new VASTFMT(); + } + if (si4713->isOk()) { + si4713->Init(); + + std::string rev = si4713->getRev(); + LogInfo(VB_PLUGIN, "VAST-FMT: %s\n", rev.c_str()); + + return true; + } + + delete si4713; + si4713 = nullptr; + + return false; + } + + void initRDS() { + LogInfo(VB_PLUGIN, "Enabling RDS\n"); + si4713->beginRDS(); + formatAndSendText(settings["StationText"], "", "", true); + formatAndSendText(settings["RDSTextText"], "", "", false); + } void startVast() { if (si4713 == nullptr) { - if (settings["Connection"] == "I2C") { - si4713 = new I2CSi4713(settings["ResetPin"]); - } else { - si4713 = new VASTFMT(); - } - if (si4713->isOk()) { - si4713->Init(); - - std::string rev = si4713->getRev(); - LogInfo(VB_PLUGIN, "VAST-FMT: %s\n", rev.c_str()); - + if (initVast()) { if (settings["Preemphasis"] == "50us") { si4713->setEUPreemphasis(); } @@ -83,17 +108,21 @@ class FPPVastFMPlugin : public FPPPlugin { std::string ts = si4713->getTuneStatus(); LogInfo(VB_PLUGIN, "VAST-FMT: %s\n", ts.c_str()); - + if (settings["EnableRDS"] == "True") { - printf("Enabling RDS\n"); - si4713->beginRDS(); - formatAndSendText(settings["StationText"], "", "", true); - formatAndSendText(settings["RDSTextText"], "", "", false); + initRDS(); } } - if (!si4713->isOk()) { - delete si4713; - si4713 = nullptr; + } + } + void startVastForRDS() { + if (si4713 == nullptr) { + if (initVast()) { + if (settings["EnableRDS"] == "True") { + initRDS(); + } else { + LogErr(VB_PLUGIN, "Tried to setup for RDS, but RDS is not enabled\n"); + } } } } @@ -110,6 +139,10 @@ class FPPVastFMPlugin : public FPPPlugin { int artistIdx = -1; int titleIdx = -1; + + if (!si4713) + return; + for (int x = 0; x < text.length(); x++) { if (text[x] == '[') { if (artist == "" && title == "") { @@ -139,7 +172,7 @@ class FPPVastFMPlugin : public FPPPlugin { } } if (station) { - LogDebug(VB_PLUGIN, "Setting RDS Station text to %s\n", output.c_str()); + LogDebug(VB_PLUGIN, "Setting RDS Station text to \"%s\"\n", output.c_str()); std::vector fragments; while (output.size()) { if (output.size() <= 8) { @@ -159,7 +192,7 @@ class FPPVastFMPlugin : public FPPPlugin { } si4713->setRDSStation(fragments); } else { - LogDebug(VB_PLUGIN, "Setting RDS text to %s\n", output.c_str()); + LogDebug(VB_PLUGIN, "Setting RDS text to \"%s\"\n", output.c_str()); si4713->setRDSBuffer(output, artistIdx, artist.length(), titleIdx, title.length()); } }