Skip to content

Commit

Permalink
Add option to add a delay after starting TX and before ending TX.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Dec 10, 2023
1 parent 87588d0 commit 4fd707c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/config/FreeDVConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ FreeDVConfiguration::FreeDVConfiguration()

, monitorVoiceKeyerAudio("/Monitor/VoiceKeyerAudio", false)
, monitorTxAudio("/Monitor/TransmitAudio", false)

, txRxDelayMilliseconds("/Audio/TxRxDelayMilliseconds", 0)
{
// empty
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/FreeDVConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class FreeDVConfiguration : public WxWidgetsConfigStore

ConfigurationDataElement<bool> monitorVoiceKeyerAudio;
ConfigurationDataElement<bool> monitorTxAudio;

ConfigurationDataElement<int> txRxDelayMilliseconds;

virtual void load(wxConfigBase* config) override;
virtual void save(wxConfigBase* config) override;
Expand Down
15 changes: 15 additions & 0 deletions src/dlg_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c

m_ckboxEnableSpacebarForPTT = new wxCheckBox(m_rigControlTab, wxID_ANY, _("Enable Space key for PTT"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
sbSizer_ptt->Add(m_ckboxEnableSpacebarForPTT, 0, wxALL | wxALIGN_LEFT, 5);

wxSizer* txRxDelaySizer = new wxBoxSizer(wxHORIZONTAL);

auto txRxDelayLabel = new wxStaticText(m_rigControlTab, wxID_ANY, _("TX/RX Delay (milliseconds): "));
txRxDelaySizer->Add(txRxDelayLabel, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);

m_txtTxRxDelayMilliseconds = new wxTextCtrl(m_rigControlTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(40,-1), 0, wxTextValidator(wxFILTER_DIGITS));
m_txtTxRxDelayMilliseconds->SetToolTip(_("The amount of time to wait between toggling PTT and stopping/starting TX audio in milliseconds."));
txRxDelaySizer->Add(m_txtTxRxDelayMilliseconds, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);

sbSizer_ptt->Add(txRxDelaySizer, 0, wxALL, 0);
sizerRigControl->Add(sbSizer_ptt,0, wxALL | wxEXPAND, 5);

wxStaticBoxSizer* sbSizer_hamlib;
Expand Down Expand Up @@ -781,6 +791,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
m_txtCtrlCallSign->SetValue(wxGetApp().appConfiguration.reportingConfiguration.reportingFreeTextString);

m_ckboxEnableSpacebarForPTT->SetValue(wxGetApp().appConfiguration.enableSpaceBarForPTT);
m_txtTxRxDelayMilliseconds->SetValue(wxString::Format("%d", wxGetApp().appConfiguration.txRxDelayMilliseconds.get()));
m_ckboxUseAnalogModes->SetValue(wxGetApp().appConfiguration.rigControlConfiguration.hamlibUseAnalogModes);
m_ckboxEnableFreqModeChanges->SetValue(wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges);

Expand Down Expand Up @@ -915,6 +926,8 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyList = tmpList;

wxGetApp().appConfiguration.enableSpaceBarForPTT = m_ckboxEnableSpacebarForPTT->GetValue();

wxGetApp().appConfiguration.txRxDelayMilliseconds = wxAtoi(m_txtTxRxDelayMilliseconds->GetValue());

wxGetApp().appConfiguration.rigControlConfiguration.hamlibUseAnalogModes = m_ckboxUseAnalogModes->GetValue();

Expand Down Expand Up @@ -1258,6 +1271,7 @@ void OptionsDlg::updateRigControlState()
{
m_ckboxEnableFreqModeChanges->Enable(true);
m_ckboxEnableSpacebarForPTT->Enable(true);
m_txtTxRxDelayMilliseconds->Enable(true);
m_ckboxUseAnalogModes->Enable(m_ckboxEnableFreqModeChanges->GetValue());
}
else
Expand All @@ -1266,6 +1280,7 @@ void OptionsDlg::updateRigControlState()
m_ckboxUseAnalogModes->Enable(false);
m_ckboxEnableFreqModeChanges->Enable(false);
m_ckboxEnableSpacebarForPTT->Enable(false);
m_txtTxRxDelayMilliseconds->Enable(false);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/dlg_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class OptionsDlg : public wxDialog
wxCheckBox *m_ckboxUseAnalogModes;
wxCheckBox *m_ckboxEnableFreqModeChanges;
wxCheckBox *m_ckboxEnableSpacebarForPTT;
wxTextCtrl *m_txtTxRxDelayMilliseconds;

/* Waterfall color */
wxRadioButton *m_waterfallColorScheme1; // Multicolored
Expand Down
32 changes: 26 additions & 6 deletions src/ongui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,14 @@ void MainFrame::togglePTT(void) {
wxThread::Sleep(50);
}

// Wait an additional configured timeframe before actually clearing PTT (below)
if (wxGetApp().appConfiguration.txRxDelayMilliseconds > 0)
{
// Delay outbound TX audio if going into TX.
std::this_thread::sleep_for(std::chrono::milliseconds(wxGetApp().appConfiguration.txRxDelayMilliseconds.get()));
}
g_tx = false;

// tx-> rx transition, swap to the page we were on for last rx
m_auiNbookCtrl->ChangeSelection(wxGetApp().appConfiguration.currentNotebookTab);

Expand Down Expand Up @@ -837,18 +845,17 @@ void MainFrame::togglePTT(void) {
m_togBtnOnOff->Enable(false);
}

g_tx = m_btnTogPTT->GetValue();

if (wxGetApp().appConfiguration.rigControlConfiguration.hamlibUseForPTT) {
if (wxGetApp().rigFrequencyController != nullptr && wxGetApp().rigFrequencyController->isConnected()) {
// Update mode display on the bottom of the main UI.
wxGetApp().rigFrequencyController->requestCurrentFrequencyMode();
}
}

auto newTx = m_btnTogPTT->GetValue();
if (wxGetApp().rigPttController != nullptr && wxGetApp().rigPttController->isConnected())
{
wxGetApp().rigPttController->ptt(g_tx);
wxGetApp().rigPttController->ptt(newTx);
}

// reset level gauge
Expand All @@ -861,16 +868,16 @@ void MainFrame::togglePTT(void) {
// Report TX change to registered reporters
for (auto& obj : wxGetApp().m_reporters)
{
obj->transmit(freedvInterface.getCurrentTxModeStr(), g_tx);
obj->transmit(freedvInterface.getCurrentTxModeStr(), newTx);
}

// Change button color depending on TX status.
m_btnTogPTT->SetBackgroundColour(g_tx ? *wxRED : wxNullColour);
m_btnTogPTT->SetBackgroundColour(newTx ? *wxRED : wxNullColour);

// If we're recording, switch to/from modulator and radio.
if (g_sfRecFile != nullptr)
{
if (!g_tx)
if (!newTx)
{
g_recFileFromModulator = false;
g_recFileFromRadio = true;
Expand All @@ -881,6 +888,19 @@ void MainFrame::togglePTT(void) {
g_recFileFromModulator = true;
}
}

if (newTx)
{
if (wxGetApp().appConfiguration.txRxDelayMilliseconds > 0)
{
// Delay outbound TX audio if going into TX.
std::this_thread::sleep_for(std::chrono::milliseconds(wxGetApp().appConfiguration.txRxDelayMilliseconds.get()));
}

// g_tx governs when audio actually goes out during TX, so don't set to true until
// after the delay occurs.
g_tx = true;
}
}

HamlibRigController::Mode MainFrame::getCurrentMode_()
Expand Down

0 comments on commit 4fd707c

Please sign in to comment.