Skip to content

Commit

Permalink
Allow skipping transmitter setup and using plugin for RDS only.
Browse files Browse the repository at this point in the history
Also fix a segfault in formatAndSendText() if plugin installed
but not starting.
  • Loading branch information
cpinkham committed Nov 13, 2019
1 parent c472a54 commit 202e2c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion plugin_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function toggle(id) {
<div id="VASTFMTPluginsettings" class="settings">
<fieldset>
<legend>VAST-FMT/Si4713 Plugin Settings</legend>
<p>Start at: <?php PrintSettingSelect("Start", "Start", 1, 0, "FPPDStart", Array("FPPD Start (default)"=>"FPPDStart", "Playlist Start"=>"PlaylistStart", "Never"=>"Never"), "fpp-vastfmt", ""); ?><br />
<p>Start at: <?php PrintSettingSelect("Start", "Start", 1, 0, "FPPDStart", Array("FPPD Start (default)"=>"FPPDStart", "Playlist Start"=>"PlaylistStart", "Never - RDS Only"=>"RDSOnly", "Never"=>"Never"), "fpp-vastfmt", ""); ?><br />
At Start, the hardware is reset, FM settings initialized, will broadcast any audio played, and send static RDS messages (if enabled).</p>
<p>Stop at: <?php PrintSettingSelect("Stop", "Stop", 1, 0, "Never", Array("Playlist Stop"=>"PlaylistStop", "Never (default)"=>"Never"), "fpp-vastfmt", ""); ?><br />
At Stop, the hardware is reset. Listeners will hear static.</p>
Expand Down
75 changes: 54 additions & 21 deletions src/FPPVastFM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class FPPVastFMPlugin : public FPPPlugin {
setDefaultSettings();
if (settings["Start"] == "FPPDStart") {
startVast();
} else if (settings["Start"] == "RDSOnly") {
startVastForRDS();
}
}
virtual ~FPPVastFMPlugin() {
Expand All @@ -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();
}
Expand All @@ -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");
}
}
}
}
Expand All @@ -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 == "") {
Expand Down Expand Up @@ -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<std::string> fragments;
while (output.size()) {
if (output.size() <= 8) {
Expand All @@ -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());
}
}
Expand Down

0 comments on commit 202e2c3

Please sign in to comment.