diff --git a/USER_MANUAL.md b/USER_MANUAL.md index f707d4664..fef36a720 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -860,6 +860,8 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes 3. Enhancements: * Add last received SNR to callsign list. (PR #389, #391) * Add support for FreeDV Reporter web-based tool. (PR #390) + * Defer sound device checking until Start is pushed. (PR #393) + * Add ability for Hamlib to use RTS/DTR instead of CAT for PTT. (PR #394) ## V1.8.9 April 2023 diff --git a/src/dlg_easy_setup.cpp b/src/dlg_easy_setup.cpp index 98d48afda..ce4fcd7ba 100644 --- a/src/dlg_easy_setup.cpp +++ b/src/dlg_easy_setup.cpp @@ -118,7 +118,7 @@ EasySetupDialog::EasySetupDialog(wxWindow* parent, wxWindowID id, const wxString m_hamlibBox = new wxStaticBox(setupCatControlBox, wxID_ANY, _("Hamlib CAT Control")); m_hamlibBox->Hide(); wxStaticBoxSizer* hamlibBoxSizer = new wxStaticBoxSizer(m_hamlibBox, wxVERTICAL); - wxGridSizer* gridSizerhl = new wxGridSizer(4, 2, 0, 0); + wxGridSizer* gridSizerhl = new wxGridSizer(5, 2, 0, 0); hamlibBoxSizer->Add(gridSizerhl); setupCatControlBoxSizer->Add(hamlibBoxSizer); @@ -152,6 +152,19 @@ EasySetupDialog::EasySetupDialog(wxWindow* parent, wxWindowID id, const wxString m_cbSerialRate = new wxComboBox(m_hamlibBox, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140, -1), 0, NULL, wxCB_DROPDOWN); gridSizerhl->Add(m_cbSerialRate, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + /* Hamlib PTT Method combobox. */ + + gridSizerhl->Add(new wxStaticText(m_hamlibBox, wxID_ANY, _("PTT uses:"), wxDefaultPosition, wxDefaultSize, 0), + 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 20); + m_cbPttMethod = new wxComboBox(m_hamlibBox, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); + m_cbPttMethod->SetSize(wxSize(140, -1)); + gridSizerhl->Add(m_cbPttMethod, 0, wxALIGN_CENTER_VERTICAL, 0); + + // Add valid PTT options to combo box. + m_cbPttMethod->Append(wxT("CAT")); + m_cbPttMethod->Append(wxT("RTS")); + m_cbPttMethod->Append(wxT("DTR")); + /* Serial port box */ m_serialBox = new wxStaticBox(setupCatControlBox, wxID_ANY, _("Serial PTT")); m_serialBox->Hide(); @@ -514,6 +527,8 @@ void EasySetupDialog::ExchangePttDeviceData(int inout) } m_tcIcomCIVHex->SetValue(wxString::Format(wxT("%02X"), wxGetApp().m_intHamlibIcomCIVHex)); + + m_cbPttMethod->SetSelection((int)wxGetApp().m_hamlibPttType); } else if (wxGetApp().m_boolUseSerialPTT) { @@ -570,6 +585,9 @@ void EasySetupDialog::ExchangePttDeviceData(int inout) pConfig->Write(wxT("/Hamlib/RigNameStr"), wxGetApp().m_strHamlibRigName); pConfig->Write(wxT("/Hamlib/SerialPort"), wxGetApp().m_strHamlibSerialPort); pConfig->Write(wxT("/Hamlib/SerialRate"), wxGetApp().m_intHamlibSerialRate); + + wxGetApp().m_hamlibPttType = (Hamlib::PttType)m_cbPttMethod->GetSelection(); + pConfig->Write(wxT("/Hamlib/PttType"), (long)wxGetApp().m_hamlibPttType); } else if (m_ckUseSerialPTT->GetValue()) { @@ -813,7 +831,9 @@ void EasySetupDialog::OnTest(wxCommandEvent& event) return; } - if (!hamlibTestObject_->connect(rig, (const char*)serialPort.ToUTF8(), rate, civHexAddress)) + auto pttType = (Hamlib::PttType)m_cbPttMethod->GetSelection(); + + if (!hamlibTestObject_->connect(rig, (const char*)serialPort.ToUTF8(), rate, civHexAddress, pttType)) { wxMessageBox( "Couldn't connect to Radio with Hamlib. Make sure the Hamlib serial Device, Rate, and Params match your radio", diff --git a/src/dlg_easy_setup.h b/src/dlg_easy_setup.h index 16c544855..123ef706d 100644 --- a/src/dlg_easy_setup.h +++ b/src/dlg_easy_setup.h @@ -82,6 +82,7 @@ class EasySetupDialog : public wxDialog wxStaticText *m_cbSerialParams; wxStaticText *m_stIcomCIVHex; wxTextCtrl *m_tcIcomCIVHex; + wxComboBox *m_cbPttMethod; // Step 2b: Serial PTT wxStaticBox* m_serialBox; diff --git a/src/dlg_ptt.cpp b/src/dlg_ptt.cpp index 4367418c5..73b8da7a9 100644 --- a/src/dlg_ptt.cpp +++ b/src/dlg_ptt.cpp @@ -59,7 +59,7 @@ ComPortsDlg::ComPortsDlg(wxWindow* parent, wxWindowID id, const wxString& title, wxStaticBox* hamlibBox = new wxStaticBox(panel, wxID_ANY, _("Hamlib Settings")); wxStaticBoxSizer* staticBoxSizer18 = new wxStaticBoxSizer( hamlibBox, wxHORIZONTAL); - wxGridSizer* gridSizerhl = new wxGridSizer(6, 2, 0, 0); + wxGridSizer* gridSizerhl = new wxGridSizer(7, 2, 0, 0); staticBoxSizer18->Add(gridSizerhl, 1, wxEXPAND|wxALIGN_LEFT, 5); /* Use Hamlib for PTT checkbox. */ @@ -100,7 +100,20 @@ ComPortsDlg::ComPortsDlg(wxWindow* parent, wxWindowID id, const wxString& title, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 20); m_cbSerialRate = new wxComboBox(hamlibBox, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140, -1), 0, NULL, wxCB_DROPDOWN); gridSizerhl->Add(m_cbSerialRate, 0, wxALIGN_CENTER_VERTICAL, 0); + + /* Hamlib PTT Method combobox. */ + gridSizerhl->Add(new wxStaticText(hamlibBox, wxID_ANY, _("PTT uses:"), wxDefaultPosition, wxDefaultSize, 0), + 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 20); + m_cbPttMethod = new wxComboBox(hamlibBox, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); + m_cbPttMethod->SetSize(wxSize(140, -1)); + gridSizerhl->Add(m_cbPttMethod, 0, wxALIGN_CENTER_VERTICAL, 0); + + // Add valid PTT options to combo box. + m_cbPttMethod->Append(wxT("CAT")); + m_cbPttMethod->Append(wxT("RTS")); + m_cbPttMethod->Append(wxT("DTR")); + gridSizerhl->Add(new wxStaticText(hamlibBox, wxID_ANY, _("Serial Params:"), wxDefaultPosition, wxDefaultSize, 0), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 20); m_cbSerialParams = new wxStaticText(hamlibBox, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, 0); @@ -437,6 +450,8 @@ void ComPortsDlg::ExchangeData(int inout) m_tcIcomCIVHex->SetValue(wxString::Format(wxT("%02X"), wxGetApp().m_intHamlibIcomCIVHex)); + m_cbPttMethod->SetSelection((int)wxGetApp().m_hamlibPttType); + /* Serial PTT */ m_ckUseSerialPTT->SetValue(wxGetApp().m_boolUseSerialPTT); @@ -484,11 +499,14 @@ void ComPortsDlg::ExchangeData(int inout) } if (g_verbose) fprintf(stderr, "serial rate: %d\n", wxGetApp().m_intHamlibSerialRate); + wxGetApp().m_hamlibPttType = (Hamlib::PttType)m_cbPttMethod->GetSelection(); + pConfig->Write(wxT("/Hamlib/UseForPTT"), wxGetApp().m_boolHamlibUseForPTT); pConfig->Write(wxT("/Hamlib/RigNameStr"), wxGetApp().m_strHamlibRigName); pConfig->Write(wxT("/Hamlib/SerialPort"), wxGetApp().m_strHamlibSerialPort); pConfig->Write(wxT("/Hamlib/SerialRate"), wxGetApp().m_intHamlibSerialRate); - + pConfig->Write(wxT("/Hamlib/PttType"), (long)wxGetApp().m_hamlibPttType); + /* Serial settings */ wxGetApp().m_boolUseSerialPTT = m_ckUseSerialPTT->IsChecked(); @@ -560,6 +578,8 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { long hexAddress = 0; m_tcIcomCIVHex->GetValue().ToLong(&hexAddress, 16); + auto pttType = (Hamlib::PttType)m_cbPttMethod->GetSelection(); + // display serial params if (g_verbose) fprintf(stderr, "serial rate: %d\n", serial_rate); @@ -568,7 +588,7 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { { // try to open rig Hamlib *hamlib = wxGetApp().m_hamlib; - bool status = hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, hexAddress); + bool status = hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, hexAddress, pttType); if (status == false) { wxMessageBox("Couldn't connect to Radio with Hamlib. Make sure the Hamlib serial Device, Rate, and Params match your radio", wxT("Error"), wxOK | wxICON_ERROR, this); @@ -725,6 +745,7 @@ void ComPortsDlg::updateControlState() m_cbSerialPort->Enable(m_ckUseHamlibPTT->GetValue()); m_cbSerialRate->Enable(m_ckUseHamlibPTT->GetValue()); m_tcIcomCIVHex->Enable(m_ckUseHamlibPTT->GetValue()); + m_cbPttMethod->Enable(m_ckUseHamlibPTT->GetValue()); m_cbCtlDevicePath->Enable(m_ckUseSerialPTT->GetValue()); m_rbUseDTR->Enable(m_ckUseSerialPTT->GetValue()); diff --git a/src/dlg_ptt.h b/src/dlg_ptt.h index 9bd392be8..4e021c265 100644 --- a/src/dlg_ptt.h +++ b/src/dlg_ptt.h @@ -61,6 +61,7 @@ class ComPortsDlg : public wxDialog wxStaticText *m_cbSerialParams; wxStaticText *m_stIcomCIVHex; wxTextCtrl *m_tcIcomCIVHex; + wxComboBox *m_cbPttMethod; Hamlib *m_hamlib; /* Serial Settings */ diff --git a/src/hamlib.cpp b/src/hamlib.cpp index 5472469d1..3e9f2b9b9 100644 --- a/src/hamlib.cpp +++ b/src/hamlib.cpp @@ -131,7 +131,7 @@ void Hamlib::populateComboBox(wxComboBox *cb) { } } -bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int serial_rate, const int civ_hex) { +bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int serial_rate, const int civ_hex, const PttType pttType) { /* Look up model from index. */ @@ -187,6 +187,20 @@ bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int if (g_verbose) fprintf(stderr, "hamlib: data_bits..: %d\n", get_data_bits()); if (g_verbose) fprintf(stderr, "hamlib: stop_bits..: %d\n", get_stop_bits()); + // Set PTT type as needed. + switch(pttType) + { + case PTT_VIA_RTS: + rig_set_conf(m_rig, rig_token_lookup(m_rig, "ptt_type"), "RTS"); + break; + case PTT_VIA_DTR: + rig_set_conf(m_rig, rig_token_lookup(m_rig, "ptt_type"), "DTR"); + break; + case PTT_VIA_CAT: + default: + break; + } + if (rig_open(m_rig) == RIG_OK) { if (g_verbose) fprintf(stderr, "hamlib: rig_open() OK\n"); diff --git a/src/hamlib.h b/src/hamlib.h index 1c4bf8985..581ea3150 100644 --- a/src/hamlib.h +++ b/src/hamlib.h @@ -15,6 +15,13 @@ extern "C" { class Hamlib { public: + enum PttType + { + PTT_VIA_CAT = 0, + PTT_VIA_RTS, + PTT_VIA_DTR + }; + Hamlib(); ~Hamlib(); @@ -23,7 +30,7 @@ class Hamlib { std::string rigIndexToName(unsigned int rigIndex); void populateComboBox(wxComboBox *cb); - bool connect(unsigned int rig_index, const char *serial_port, const int serial_rate, const int civ_hex = 0); + bool connect(unsigned int rig_index, const char *serial_port, const int serial_rate, const int civ_hex = 0, const PttType pttType = PTT_VIA_CAT); bool ptt(bool press, wxString &hamlibError); void enable_mode_detection(wxStaticText* statusBox, wxTextCtrl* freqBox, bool vhfUhfMode); void disable_mode_detection(); diff --git a/src/main.cpp b/src/main.cpp index 74c8fb97a..29c74447a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -462,6 +462,7 @@ void MainFrame::loadConfiguration_() wxGetApp().m_intHamlibRig = wxGetApp().m_hamlib->rigNameToIndex(std::string(wxGetApp().m_strHamlibRigName.ToUTF8())); } + wxGetApp().m_hamlibPttType = (Hamlib::PttType)pConfig->ReadLong("/Hamlib/PttType", 0); wxGetApp().m_strHamlibSerialPort = pConfig->Read("/Hamlib/SerialPort", ""); wxGetApp().m_intHamlibSerialRate = pConfig->ReadLong("/Hamlib/SerialRate", 0); @@ -741,8 +742,6 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ") m_panelTestFrameErrorsHist->setBarGraph(1); m_panelTestFrameErrorsHist->setLogY(1); - validateSoundCardSetup(); - // this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI)); m_togBtnOnOff->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnAnalog->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); @@ -840,6 +839,15 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ") pConfig->Write(wxT("/FirstTimeUse"), false); + if (wxGetApp().m_firstTimeUse) + { + // Initial setup. Display Easy Setup dialog. + CallAfter([&]() { + EasySetupDialog* dlg = new EasySetupDialog(this); + dlg->ShowModal(); + }); + } + //#define FTEST #ifdef FTEST ftest = fopen("ftest.raw", "wb"); @@ -934,7 +942,7 @@ MainFrame::~MainFrame() pConfig->Write("/Hamlib/SerialPort", wxGetApp().m_strHamlibSerialPort); pConfig->Write("/Hamlib/SerialRate", wxGetApp().m_intHamlibSerialRate); pConfig->Write("/Hamlib/IcomCIVHex", wxGetApp().m_intHamlibIcomCIVHex); - + pConfig->Write("/Hamlib/PttType", (long)wxGetApp().m_hamlibPttType); pConfig->Write(wxT("/File/playFileToMicInPath"), wxGetApp().m_playFileToMicInPath); pConfig->Write(wxT("/File/recFileFromRadioPath"), wxGetApp().m_recFileFromRadioPath); diff --git a/src/main.h b/src/main.h index f723b6049..c3ae95268 100644 --- a/src/main.h +++ b/src/main.h @@ -211,6 +211,7 @@ class MainApp : public wxApp unsigned int m_intHamlibSerialRate; unsigned int m_intHamlibIcomCIVHex; Hamlib *m_hamlib; + Hamlib::PttType m_hamlibPttType; bool m_boolUseSerialPTT; wxString m_strRigCtrlPort; diff --git a/src/ongui.cpp b/src/ongui.cpp index 7063102c1..5b37a3398 100644 --- a/src/ongui.cpp +++ b/src/ongui.cpp @@ -241,7 +241,7 @@ bool MainFrame::OpenHamlibRig() { int serial_rate = wxGetApp().m_intHamlibSerialRate; if (wxGetApp().CanAccessSerialPort((const char*)port.ToUTF8())) { - bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, wxGetApp().m_intHamlibIcomCIVHex); + bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, wxGetApp().m_intHamlibIcomCIVHex, wxGetApp().m_hamlibPttType); if (status == false) { wxMessageBox("Couldn't connect to Radio with hamlib", wxT("Error"), wxOK | wxICON_ERROR, this);