Add hamlib support for push to talk
authorshenki <shenki@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 27 May 2013 10:17:32 +0000 (10:17 +0000)
committershenki <shenki@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 27 May 2013 10:17:32 +0000 (10:17 +0000)
This removes libctb in favour of hamlib. It has been tested with 1.2.15.3 of
hamlib with a IC-7200.

The rig is configured using it's own dialog Tools -> PTT Config.  The only
options available are the rig model and serial port, the rest of the options
are obtained from the rig definition in hamlib.

FreeDV will open the configured serial port on startup. When it cannot find
the radio, an error dialog will be displayed. Spacebar can be used to toggle
TX/RX.

git-svn-id: https://svn.code.sf.net/p/freetel/code@1283 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/CMakeLists.txt
fdmdv2/src/CMakeLists.txt
fdmdv2/src/Makefile.linux
fdmdv2/src/Makefile.win32
fdmdv2/src/dlg_comports.cpp
fdmdv2/src/dlg_comports.h
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_main.h
fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp
fdmdv2/src/topFrame.cpp

index 20683c3b3b9bb76139f6b66e471b1885ecf61611..35573eff6e79505506620a9eb9a7c22be28c79ac 100644 (file)
@@ -39,7 +39,7 @@ message(STATUS "FreeDV version: ${FREEDV_VERSION}")
 #set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
 
 # Work around for not using a svn working copy.
-add_definitions(-DSVN_REVISION="1248")
+add_definitions(-DSVN_REVISION="Unversioned directory")
 add_definitions(-D_NO_AUTOTOOLS_)
 
 
@@ -224,6 +224,22 @@ if(PORTAUDIOCPP)
     list(APPEND FREEDV_LINK_LIBS ${PORTAUDIOCPP})
 endif(PORTAUDIOCPP)
 
+#
+# Hamlib library
+#
+message(STATUS "Looking for hamlib...")
+find_library(LIBHAMLIB hamlib)
+if(LIBHAMLIB)
+    list(APPEND FREEDV_LINK_LIBS ${LIBHAMLIB})
+    message(STATUS "  hamlib found: ${LIBHAMLIB}")
+else(LIBHAMLIB)
+    message(FATAL_ERROR "hamlib not found.
+On Linux systems try installing:
+    hamlib-devel  (RPM based systems)
+    libhamlib-dev (DEB based systems)"
+    )
+endif(LIBHAMLIB)
+
 #
 # Samplerate Library
 #
index d6f54ed2eb7987e08ed5037604bccbe87346d0a1..016526f528e32b0f61f4df0dc206ee891aaaff72 100644 (file)
@@ -1,4 +1,8 @@
 set(FREEDV_SOURCES
+    dlg_about.cpp
+    dlg_audiooptions.cpp
+    dlg_comports.cpp
+    dlg_filter.cpp
     fdmdv2_main.cpp
     fdmdv2_pa_wrapper.cpp
     fdmdv2_plot.cpp
@@ -6,14 +10,15 @@ set(FREEDV_SOURCES
     fdmdv2_plot_scatter.cpp
     fdmdv2_plot_spectrum.cpp
     fdmdv2_plot_waterfall_linux.cpp
-    dlg_about.cpp
-    dlg_audiooptions.cpp
-    dlg_comports.cpp
-    dlg_filter.cpp
-    sox_biquad.c
+    hamlib.cpp
     topFrame.cpp
+    sox_biquad.c
     varicode.c
     comp.h
+    dlg_about.h
+    dlg_audiooptions.h
+    dlg_comports.h
+    dlg_filter.h
     fdmdv2_defines.h
     fdmdv2_main.h
     fdmdv2_pa_wrapper.h
@@ -22,11 +27,9 @@ set(FREEDV_SOURCES
     fdmdv2_plot_scatter.h
     fdmdv2_plot_spectrum.h
     fdmdv2_plot_waterfall_linux.h
-    dlg_about.h dlg_audiooptions.h
-    dlg_comports.h
-    dlg_filter.h
-    sox.h
+    hamlib.h
     sox_biquad.h
+    sox.h
     topFrame.h
     varicode.h
     varicode_table.h
index 16c453a40f9c79c8318391e8a39bd6f1f8b614ef..54c0a1a344399246c3cd53b86feb16dd2defea3f 100644 (file)
@@ -11,6 +11,9 @@ SVN_REVISION=$(shell svnversion)
 # The list of required libraries, we will build this as we go
 LIBS_TO_BUILD :=
 
+SYSTEM_HAMLIB=y
+SYSTEM_PORTAUDIO=n
+
 # wxWidgets ---------------------------------------------
 
 ifneq ($(SYSTEM_WXWIDGETS),y)
@@ -56,26 +59,36 @@ CODEC2_LIB=$(CODEC2)/src/.libs/libcodec2.a
 # Sox ---------------------------------------------------
 # (libmagic is rqd or later versions of Ubuntu)
 
+SOX=sox-14.4.0
 ifeq ($(SYSTEM_SOX),y)
 SOX_INC ?= $(shell pkg-config sox --cflags)
 SOX_LIB ?= $(shell pkg-config sox --libs)
 else
-SOX=sox-14.4.0
 SOX_INC=-I$(SOX)/src/
 SOX_LIB=$(SOX)/src/.libs/libsox.a
 LIBS_TO_BUILD += $(SOX)/.built
 endif
 
-# CTB ---------------------------------------------------
+# Hamlib ---------------------------------------------------
 
-CTB=libctb-0.16
-CTB_INC=-I$(CTB)/include
-CTB_LIB=$(CTB)/lib/libctb-0.16.a
+HAMLIB=hamlib-1.2.15.3
+ifeq ($(SYSTEM_HAMLIB),y)
+HAMLIB_INC ?= $(shell pkg-config hamlib --cflags)
+HAMLIB_LIB ?= $(shell pkg-config hamlib --libs)
+else
+HAMLIB_INC=-I$(HAMLIB)/include/hamlib
+# TODO: need to include all the backends too
+HAMLIB_LIB=$(HAMLIB)/src/.libs/libhamlib.a
+LIBS_TO_BUILD += $(HAMLIB)/.built
+endif
 
 # FreeDV ------------------------------------------------
 
-CPP_FLAGS = -D_NO_AUTOTOOLS_ $(WX_CPPFLAGS) $(PORTAUDIO_INC) $(CODEC2_INC) $(SOX_INC) $(CTB_INC) -I. -g -Wall -O3 -DSVN_REVISION='"$(SVN_REVISION)"' -MMD -MP
-FREEDV_LIBS = $(WX_LIBS) $(PORTAUDIO_LIB) $(CODEC2_LIB) $(SOX_LIB) $(CTB_LIB) -lm -lpthread -lsndfile -lsamplerate $(LIBASOUND)
+CPP_FLAGS = -D_NO_AUTOTOOLS_ $(WX_CPPFLAGS) $(PORTAUDIO_INC) $(CODEC2_INC) \
+           $(HAMLIB_INC) $(SOX_INC) -I. -g -Wall -O2 \
+           -DSVN_REVISION='"$(SVN_REVISION)"' -MMD -MP
+FREEDV_LIBS = $(WX_LIBS) $(PORTAUDIO_LIB) $(CODEC2_LIB) $(SOX_LIB) $(HAMLIB_LIB) \
+            $(HAMLIB_LIB) -lm -lpthread -lsndfile -lsamplerate $(LIBASOUND)
 
 OBJS = topFrame.o \
 fdmdv2_main.o \
@@ -91,24 +104,28 @@ dlg_filter.o \
 dlg_options.o \
 varicode.o \
 sox_biquad.o \
-codec2-dev/src/golay23.c
-
-HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h dlg_options.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h codec2-dev/src/golay23.h
+codec2-dev/src/golay23.c \
+hamlib.o
 
-all: $(LIBS_TO_BUILD) $(CODEC2)/.built $(CTB)/.built freedv
+all: $(LIBS_TO_BUILD) $(CODEC2)/.built freedv
 
 freedv: $(OBJS) 
        $(CXX) -o freedv $(OBJS) $(CPP_FLAGS) $(FREEDV_LIBS)
-       
-%.o: %.cpp $(HDRS)
-       $(CXX) $(CPP_FLAGS) -c $< -o $@
-        
+
+%.o: %.cpp
+       $(CXX) -MMD -MF $(@:.o=.d) $(CPP_FLAGS) -c $< -o $@
+
+%.o: %.c
+       $(CC) -MMD -MF $(@:.o=.d) $(CPP_FLAGS) -c $< -o $@
+
+-include $(OBJ:.o=.d)
+
 clean:
-       rm -f *.d *.o fdmdv2
+       rm -f *.d *.o freedv
 
 clean-lib:
        rm -Rf $(WXWIDGETS) $(PORTAUDIO) $(CODEC2) $(SOX) $(CTB)
-       rm -f *.d *.o fdmdv2 
+       rm -f *.d *.o freedv
 
 # wxWidgets ---------------------------------------------------------
 
index 0b40aa55493f86c7a757b8673a978842021e40a5..2068e4d5b1d5ac6999eab0f326bb64dbde25fc5f 100644 (file)
@@ -16,7 +16,7 @@ CODEC2_INC=$(CODEC2_PATH)/src
 CODEC2_LIB=$(CODEC2_PATH)/src/.libs/libcodec2.a
 
 CPP_FLAGS = -D_NO_AUTOTOOLS_ -I$(INCLUDE_PATH) $(WX_CPPFLAGS) -I$(CODEC2_INC) -I../extern/include -g -Wall -DSVN_REVISION=\"$(SVN_REVISION)\"
-LIBS = $(WX_LIBS) $(CODEC2_LIB) -lm -lportaudiocpp -lportaudio -lpthread -lsndfile -lsamplerate -lctb-0.16 -lsox
+LIBS = $(WX_LIBS) $(CODEC2_LIB) -lm -lportaudiocpp -lportaudio -lpthread -lsndfile -lsamplerate -lhamlib -lsox
 
 OBJS = topFrame.o \
 fdmdv2_main.o \
@@ -31,9 +31,10 @@ dlg_comports.o \
 dlg_filter.o \
 varicode.o \
 sox_biquad.o \
+hamlib.o \
 ../../codec2-dev/src/golay23.o
 
-HDRS = ../version.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h topFrame.h varicode.h ../../codec2-dev/src/golay23.h
+HDRS = ../version.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h topFrame.h varicode.h ../../codec2-dev/src/golay23.h hamlib.h
 
 
 all: freedv
index 86aa5434d7f3fcd1653c1725855e8a8642aee81d..80b85f428ce7c7ed695eef01e14c448bdd1c05a0 100644 (file)
@@ -3,7 +3,7 @@
 // Purpose:         Subclasses dialog GUI for PTT Config. Creates simple 
 //                  wxWidgets dialog GUI to select real/virtual Comm ports.
 // Date:            May 11 2012
-// Authors:         David Rowe, David Witten
+// Authors:         David Rowe, David Witten, Joel Stanley
 // 
 // License:
 //
@@ -42,87 +42,31 @@ ComPortsDlg::ComPortsDlg(wxWindow* parent, wxWindowID id, const wxString& title,
     staticBoxSizer28->Add(m_ckHalfDuplex, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
     mainSizer->Add(staticBoxSizer28, 0, wxEXPAND, 5);
 
-/*    
-    wxStaticBoxSizer* staticBoxSizer28 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Audio Tone")), wxVERTICAL);
-    mainSizer->Add(staticBoxSizer28, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5);
-    m_ckPTTRtChan = new wxCheckBox(this, wxID_ANY, _("PTT tone on right audio channel"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckPTTRtChan->SetValue(false);
-    staticBoxSizer28->Add(m_ckPTTRtChan, 0, wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL, 5);
-*/
+    wxStaticBoxSizer* staticBoxSizer18 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Hamlib Settings")), wxVERTICAL);
+    mainSizer->Add(staticBoxSizer18, 1, wxEXPAND, 5);
 
-    wxStaticBoxSizer* staticBoxSizer17 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Hardware PTT Settings")), wxVERTICAL);
-    mainSizer->Add(staticBoxSizer17, 1, wxEXPAND, 5);
-    wxStaticBoxSizer* staticBoxSizer31 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("PTT Port")), wxVERTICAL);
-    staticBoxSizer17->Add(staticBoxSizer31, 1, wxEXPAND, 5);
+    wxGridSizer* gridSizer100 = new wxGridSizer(1, 5, 0, 0);
 
-//    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
-//    m_ckUseSerialPTT->SetValue(false);
-//    staticBoxSizer31->Add(m_ckUseSerialPTT, 0, wxALIGN_LEFT, 20);
-#ifdef __WXMSW__
-    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckUseSerialPTT->SetValue(false);
-    staticBoxSizer31->Add(m_ckUseSerialPTT, 0, wxALIGN_LEFT, 20);
-
-    wxArrayString m_listCtrlPortsArr;
-    m_listCtrlPorts = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(-1,45), m_listCtrlPortsArr, wxLB_SINGLE | wxLB_SORT);
-    staticBoxSizer31->Add(m_listCtrlPorts, 1, wxALIGN_CENTER, 0);
-#endif
-#ifdef __WXGTK__
-    wxBoxSizer* bSizer83;
-    bSizer83 = new wxBoxSizer(wxHORIZONTAL);
-
-    wxGridSizer* gridSizer200 = new wxGridSizer(1, 3, 0, 0);
-    
-    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckUseSerialPTT->SetValue(false);
-    gridSizer200->Add(m_ckUseSerialPTT, 1, wxALIGN_CENTER|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 2);
-
-    m_staticText12 = new wxStaticText(this, wxID_ANY, _("Device:  "), wxDefaultPosition, wxDefaultSize, 0);
-    m_staticText12->Wrap(-1);
-    gridSizer200->Add(m_staticText12, 1,wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 2);
-//    gridSizer200->Add(m_staticText12, 1, wxEXPAND|wxALIGN_CENTER|wxALIGN_RIGHT, 2);
+    /* Use Hamlib for PTT checkbox. */
+    m_ckUseHamlibPTT = new wxCheckBox(this, wxID_ANY, _("Use Hamlib PTT"), wxDefaultPosition, wxSize(-1, -1), 0);
+    m_ckUseHamlibPTT->SetValue(false);
+    gridSizer100->Add(m_ckUseHamlibPTT, 1, wxALIGN_LEFT, 2);
 
-    m_txtCtlDevicePath = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
-//    gridSizer200->Add(m_txtCtlDevicePath, 1, wxALIGN_CENTER|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 2);
-    gridSizer200->Add(m_txtCtlDevicePath, 1, wxEXPAND|wxALIGN_CENTER|wxALIGN_RIGHT, 2);
-    
-    bSizer83->Add(gridSizer200, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 2);
-    staticBoxSizer31->Add(bSizer83, 1, wxALIGN_CENTER_VERTICAL|wxALL, 1);
-
-#endif
-    wxBoxSizer* boxSizer19 = new wxBoxSizer(wxVERTICAL);
-    staticBoxSizer17->Add(boxSizer19, 1, wxEXPAND, 5);
-    wxStaticBoxSizer* staticBoxSizer16 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Signal polarity")), wxHORIZONTAL);
-    boxSizer19->Add(staticBoxSizer16, 1, wxEXPAND|wxALIGN_CENTER|wxALIGN_RIGHT, 5);
-
-    wxGridSizer* gridSizer17 = new wxGridSizer(2, 2, 0, 0);
-    staticBoxSizer16->Add(gridSizer17, 1, wxEXPAND|wxALIGN_RIGHT, 5);
+    /* Hamlib Rig Type combobox. */
+    gridSizer100->Add(new wxStaticText(this, wxID_ANY, _("Rig Model: "), wxDefaultPosition, wxDefaultSize, 0), 1,wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 2);
+    m_cbRigName = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140, -1), 0, NULL, wxCB_DROPDOWN);
+    /* TODO(Joel): this is a hack. At the least, need to gaurntee that m_hamLib
+     * exists. */
+    wxGetApp().m_hamlib->populateComboBox(m_cbRigName);
+    m_cbRigName->SetSelection(wxGetApp().m_intHamlibRig);
+    gridSizer100->Add(m_cbRigName, 1, wxALIGN_CENTER|wxALIGN_RIGHT, 2);
 
-/*
-    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckUseSerialPTT->SetValue(false);
-    gridSizer17->Add(m_ckUseSerialPTT, 0, wxALIGN_CENTER, 10);
-    gridSizer17->Add(0, 0, 0, 0, 5);
-*/
-    m_rbUseDTR = new wxRadioButton(this, wxID_ANY, _("Use DTR"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_rbUseDTR->SetToolTip(_("Toggle DTR line for PTT"));
-    m_rbUseDTR->SetValue(1);
-    gridSizer17->Add(m_rbUseDTR, 0, wxALIGN_CENTER|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
+    /* Hamlib Serial Port combobox. */
+    gridSizer100->Add(new wxStaticText(this, wxID_ANY, _("Serial Device: "), wxDefaultPosition, wxDefaultSize, 0), 1,wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 2);
+    m_cbSerialPort = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140, -1), 0, NULL, wxCB_DROPDOWN);
+    gridSizer100->Add(m_cbSerialPort, 1, wxALIGN_CENTER|wxALIGN_RIGHT, 2);
 
-    m_ckDTRPos = new wxCheckBox(this, wxID_ANY, _("DTR = +V"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckDTRPos->SetToolTip(_("Set Polarity of the DTR line"));
-    m_ckDTRPos->SetValue(false);
-    gridSizer17->Add(m_ckDTRPos, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
-
-    m_rbUseRTS = new wxRadioButton(this, wxID_ANY, _("Use RTS"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_rbUseRTS->SetToolTip(_("Toggle the RTS pin for PTT"));
-    m_rbUseRTS->SetValue(1);
-    gridSizer17->Add(m_rbUseRTS, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
-
-    m_ckRTSPos = new wxCheckBox(this, wxID_ANY, _("RTS = +V"), wxDefaultPosition, wxSize(-1,-1), 0);
-    m_ckRTSPos->SetValue(false);
-    m_ckRTSPos->SetToolTip(_("Set Polarity of the RTS line"));
-    gridSizer17->Add(m_ckRTSPos, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
+    staticBoxSizer18->Add(gridSizer100, 1, wxALIGN_CENTER_VERTICAL|wxALL, 1);
 
     wxBoxSizer* boxSizer12 = new wxBoxSizer(wxHORIZONTAL);
     mainSizer->Add(boxSizer12, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
@@ -146,13 +90,6 @@ ComPortsDlg::ComPortsDlg(wxWindow* parent, wxWindowID id, const wxString& title,
 
     // Connect events
     this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog), NULL, this);
-//    m_ckPTTRtChan->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTAudioClick), NULL, this);
-//    m_listCtrlPorts->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ComPortsDlg::PTTPortSlelcted), NULL, this);
-    m_ckUseSerialPTT->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTUseSerialClicked), NULL, this);
-    m_rbUseDTR->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseDTRCliched), NULL, this);
-    m_rbUseRTS->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseRTSClicked), NULL, this);
-//    m_ckRTSPos->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::DTRVPlusClicked), NULL, this);
-//    m_ckDTRPos->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::RTSVPlusClicked), NULL, this);
     m_buttonOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
     m_buttonCancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
     m_buttonApply->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
@@ -165,13 +102,6 @@ ComPortsDlg::~ComPortsDlg()
 {
     // Disconnect Events
     this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog), NULL, this);
-//    m_ckPTTRtChan->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTAudioClick), NULL, this);
-//    m_listCtrlPorts->Disconnect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ComPortsDlg::PTTPortSlelcted), NULL, this);
-    m_ckUseSerialPTT->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTUseSerialClicked), NULL, this);
-    m_rbUseDTR->Disconnect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseDTRCliched), NULL, this);
-    m_rbUseRTS->Disconnect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseRTSClicked), NULL, this);
-//    m_ckRTSPos->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::DTRVPlusClicked), NULL, this);
-//    m_ckDTRPos->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::RTSVPlusClicked), NULL, this);
     m_buttonOK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
     m_buttonCancel->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
     m_buttonApply->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
@@ -224,14 +154,18 @@ void ComPortsDlg::populatePortList()
         for(unsigned int i = 0; i < values; i++)
         {
             key.QueryValue(key_name, key_data);
-            wxPrintf("Value:  %s Data: %s\n", key_name, key_data);
+//            wxPrintf("Value:  %s Data: %s\n", key_name, key_data);
             aStr.Add(key_data, 1);
             key.GetNextValue(key_name, el);
         }
     }
-    m_listCtrlPorts->Append(aStr);
+    m_cbSerialPort->Append(aStr);
 #endif
 #ifdef __WXGTK__
+    /* TODO(Joel): http://stackoverflow.com/questions/2530096/how-to-find-all-serial-devices-ttys-ttyusb-on-linux-without-opening-them */
+    m_cbSerialPort->Clear();
+    m_cbSerialPort->Append("/dev/ttyUSB0");
+    m_cbSerialPort->Append("/dev/ttyS0");
 #endif
 }
 
@@ -245,109 +179,29 @@ void ComPortsDlg::ExchangeData(int inout)
     
     if(inout == EXCHANGE_DATA_IN)
     {
-//        m_ckUsePTTRtChan->SetValue(wxGetApp().m_boolUseTonePTT);
         m_ckHalfDuplex->SetValue(wxGetApp().m_boolHalfDuplex);
-        m_ckUseSerialPTT->SetValue(wxGetApp().m_boolUseSerialPTT);
-        str = wxGetApp().m_strRigCtrlPort;
-#ifdef __WXMSW__
-        m_listCtrlPorts->SetStringSelection(str);
-#endif
-#ifdef __WXGTK__
-        m_txtCtlDevicePath->SetValue(str);
-#endif
-        str = wxGetApp().m_strRigCtrlBaud;
-
-//        m_listCtrlBaudrates->SetStringSelection(str);
-//        m_textRigCtrlDatabits->SetValue(wxGetApp().m_strRigCtrlDatabits);
-//        m_textRigCtrlStopbits->SetValue(wxGetApp().m_strRigCtrlStopbits);
-//        m_textRigCtrlParity->SetValue(wxGetApp().m_strRigCtrlParity);
-
-        m_rbUseRTS->SetValue(wxGetApp().m_boolUseRTS);
-        m_ckRTSPos->SetValue(wxGetApp().m_boolRTSPos);
-        m_rbUseDTR->SetValue(wxGetApp().m_boolUseDTR);
-        m_ckDTRPos->SetValue(wxGetApp().m_boolDTRPos);
+        m_ckUseHamlibPTT->SetValue(wxGetApp().m_boolHamlibUseForPTT);
+        m_cbRigName->SetSelection(wxGetApp().m_intHamlibRig);
+        m_cbSerialPort->SetValue(wxGetApp().m_strHamlibSerialPort);
     }
     if(inout == EXCHANGE_DATA_OUT)
     {
-        wxGetApp().m_boolHalfDuplex             = m_ckHalfDuplex->GetValue();
-        wxGetApp().m_boolUseSerialPTT           = m_ckUseSerialPTT->IsChecked();
-//        wxGetApp().m_boolUseTonePTT             = m_ckUsePTTRtChan->IsChecked();
-#ifdef __WXMSW__
-        wxGetApp().m_strRigCtrlPort             = m_listCtrlPorts->GetStringSelection();
-#endif
-#ifdef __WXGTK__
-        wxGetApp().m_strRigCtrlPort             = m_txtCtlDevicePath->GetValue();
-#endif
-        wxGetApp().m_boolUseRTS                 = m_rbUseRTS->GetValue();
-        wxGetApp().m_boolRTSPos                 = m_ckRTSPos->IsChecked();
-        wxGetApp().m_boolUseDTR                 = m_rbUseDTR->GetValue();
-        wxGetApp().m_boolDTRPos                 = m_ckDTRPos->IsChecked();
-        
-        pConfig->Write(wxT("/Rig/UseRTS"),          wxGetApp().m_boolUseRTS);
-        pConfig->Write(wxT("/Rig/RTSPolarity"),     wxGetApp().m_boolRTSPos);
-        pConfig->Write(wxT("/Rig/UseDTR"),          wxGetApp().m_boolUseDTR);
-        pConfig->Write(wxT("/Rig/DTRPolarity"),     wxGetApp().m_boolDTRPos);
-        pConfig->Write(wxT("/Rig/UseTonePTT"),      wxGetApp().m_boolUseTonePTT);
-        pConfig->Write(wxT("/Rig/UseSerialPTT"),    wxGetApp().m_boolUseSerialPTT);
-
-//        wxGetApp().m_strRigCtrlBaud             = m_listCtrlBaudrates->GetStringSelection();
-//        wxGetApp().m_strRigCtrlDatabits         = m_textRigCtrlDatabits->GetValue();
-//        wxGetApp().m_strRigCtrlStopbits         = m_textRigCtrlStopbits->GetValue();
-//        wxGetApp().m_strRigCtrlParity           = m_textRigCtrlParity->GetValue();
-
-//        pConfig->Write(wxT("/Rig/Port"),        wxGetApp().m_strRigCtrlPort);
-//        pConfig->Write(wxT("/Rig/Baud"),        wxGetApp().m_strRigCtrlBaud);
-//        pConfig->Write(wxT("/Rig/DataBits"),    wxGetApp().m_strRigCtrlDatabits);
-//        pConfig->Write(wxT("/Rig/StopBits"),    wxGetApp().m_strRigCtrlStopbits);
-//        pConfig->Write(wxT("/Rig/Parity"),      wxGetApp().m_strRigCtrlParity);
-       pConfig->Flush();
+        wxGetApp().m_boolHalfDuplex = m_ckHalfDuplex->GetValue();
+        pConfig->Write(wxT("/Rig/HalfDuplex"), wxGetApp().m_boolHalfDuplex);
+
+        /* Hamlib settings. */
+        wxGetApp().m_boolHamlibUseForPTT = m_ckUseHamlibPTT->GetValue();
+        wxGetApp().m_intHamlibRig = m_cbRigName->GetSelection();
+        wxGetApp().m_strHamlibSerialPort = m_cbSerialPort->GetValue();
+
+        pConfig->Write(wxT("/Hamlib/UseForPTT"), wxGetApp().m_boolHamlibUseForPTT);
+        pConfig->Write(wxT("/Hamlib/RigName"), wxGetApp().m_intHamlibRig);
+        pConfig->Write(wxT("/Hamlib/SerialPort"), wxGetApp().m_strHamlibSerialPort);
+        pConfig->Flush();
     }
     delete wxConfigBase::Set((wxConfigBase *) NULL);
 }
 
-//-------------------------------------------------------------------------
-// PTTAudioClick()
-//-------------------------------------------------------------------------
-void ComPortsDlg::PTTAudioClick(wxCommandEvent& event)
-{
-}
-
-//-------------------------------------------------------------------------
-// PTTUseSerialClicked()
-//-------------------------------------------------------------------------
-void ComPortsDlg::PTTUseSerialClicked(wxCommandEvent& event)
-{
-}
-/*
-//-------------------------------------------------------------------------
-// DTRVPlusClicked()
-//-------------------------------------------------------------------------
-void ComPortsDlg::DTRVPlusClicked(wxCommandEvent& event)
-{
-}
-
-//-------------------------------------------------------------------------
-// RTSVPlusClicked()
-//-------------------------------------------------------------------------
-void ComPortsDlg::RTSVPlusClicked(wxCommandEvent& event)
-{
-}
-*/
-
-//-------------------------------------------------------------------------
-// OnCancel()
-//-------------------------------------------------------------------------
-void ComPortsDlg::UseDTRCliched(wxCommandEvent& event)
-{
-}
-
-//-------------------------------------------------------------------------
-// UseRTSClicked()
-//-------------------------------------------------------------------------
-void ComPortsDlg::UseRTSClicked(wxCommandEvent& event)
-{
-}
-
 //-------------------------------------------------------------------------
 // OnApply()
 //-------------------------------------------------------------------------
@@ -372,4 +226,3 @@ void ComPortsDlg::OnOK(wxCommandEvent& event)
     ExchangeData(EXCHANGE_DATA_OUT);
     this->EndModal(wxID_OK);
 }
-
index 70eb4c3c008cc7e154a4a4d694aa9e384eb3cc52..808b7a65fe55a7f2932517f4865c5e1a93a37380 100644 (file)
@@ -23,6 +23,7 @@
 #define __COMPORTS_DIALOG__
 
 #include "fdmdv2_main.h"
+#include "hamlib.h"
 #include <wx/settings.h>
 #include <wx/xrc/xmlres.h>
 #include <wx/xrc/xh_bmp.h>
@@ -33,6 +34,7 @@
 #include <wx/listbox.h>
 #include <wx/radiobut.h>
 #include <wx/button.h>
+#include <wx/spinctrl.h>
 
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
 // Class ComPortsDlg
@@ -46,30 +48,21 @@ class ComPortsDlg : public wxDialog
 
     protected:
         wxCheckBox* m_ckHalfDuplex;
-        wxCheckBox* m_ckUsePTTRtChan;
-        wxListBox* m_listCtrlPorts;
-        wxCheckBox* m_ckUseSerialPTT;
-        wxStaticText* m_staticText12;
-        wxTextCtrl *m_txtCtlDevicePath;
-        wxRadioButton* m_rbUseDTR;
-        wxCheckBox* m_ckRTSPos;
-        wxRadioButton* m_rbUseRTS;
-        wxCheckBox* m_ckDTRPos;
+
         wxButton* m_buttonOK;
         wxButton* m_buttonCancel;
         wxButton* m_buttonApply;
 
+        /* Hamlib settings. */
+        wxCheckBox *m_ckUseHamlibPTT;
+        wxComboBox *m_cbRigName;
+        wxComboBox *m_cbSerialPort;
+
+        Hamlib *m_hamlib;
+
 protected:
-        void ListAllPorts();
+        void populatePortList();
 
-        void populatePortList(void);
-        void PTTAudioClick(wxCommandEvent& event);
-//        void PTTPortSlelcted(wxCommandEvent& event);
-        void PTTUseSerialClicked(wxCommandEvent& event);
-        void UseDTRCliched(wxCommandEvent& event);
-        //void DTRVPlusClicked(wxCommandEvent& event);
-        void UseRTSClicked(wxCommandEvent& event);
-        //void RTSVPlusClicked(wxCommandEvent& event);
         void OnOK(wxCommandEvent& event);
         void OnCancel(wxCommandEvent& event);
         void OnApply(wxCommandEvent& event);
index 2dea7956c7fe0184deb3e3e823f0768fbfcced2f..6ebf58eed902168310e9b9f2105d05364e244de8 100644 (file)
@@ -155,10 +155,8 @@ bool MainApp::OnInit()
     m_textVoiceOutput.Empty();
     m_strSampleRate.Empty();
     m_strBitrate.Empty();
-    m_boolUseTonePTT   = false;
-    m_boolUseSerialPTT = true;
     // Create the main application window
-    MainFrame *frame = new MainFrame(NULL);
+    frame = new MainFrame(NULL);
     SetTopWindow(frame);
     // Should guarantee that the first plot tab defined is the one
     // displayed. But it doesn't when built from command line.  Why?
@@ -183,8 +181,9 @@ int MainApp::OnExit()
 MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
 {
     m_zoom              = 1.;
-    m_serialPort        = NULL;
-    m_device            = NULL;
+
+    /* TODO(Joel): Try making hamlib owned by MainFrame. */ 
+    wxGetApp().m_hamlib = new Hamlib();
 
     tools->AppendSeparator();
     wxMenuItem* m_menuItemToolsConfigDelete;
@@ -304,23 +303,16 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
             g_nSoundCards = 2;
     }
 
-    wxGetApp().m_strRigCtrlPort     = pConfig->Read(wxT("/Rig/Port"),               wxT("COM3"));
-    wxGetApp().m_strRigCtrlBaud     = pConfig->Read(wxT("/Rig/Baud"),               wxT("9600"));
-    wxGetApp().m_strRigCtrlDatabits = pConfig->Read(wxT("/Rig/DataBits"),           wxT("8"));
-    wxGetApp().m_strRigCtrlStopbits = pConfig->Read(wxT("/Rig/StopBits"),           wxT("1"));
-    wxGetApp().m_strRigCtrlParity   = pConfig->Read(wxT("/Rig/Parity"),             wxT("n"));
-    wxGetApp().m_boolUseTonePTT     = pConfig->ReadBool(wxT("/Rig/UseTonePTT"),     false);
     wxGetApp().m_boolHalfDuplex     = pConfig->ReadBool(wxT("/Rig/HalfDuplex"),     true);
-    wxGetApp().m_boolUseSerialPTT   = pConfig->ReadBool(wxT("/Rig/UseSerialPTT"),   false);
-    wxGetApp().m_boolUseRTS         = pConfig->ReadBool(wxT("/Rig/UseRTS"),         true);
-    wxGetApp().m_boolRTSPos         = pConfig->ReadBool(wxT("/Rig/RTSPolarity"),    false);
-    wxGetApp().m_boolUseDTR         = pConfig->ReadBool(wxT("/Rig/UseDTR"),         false);
-    wxGetApp().m_boolDTRPos         = pConfig->ReadBool(wxT("/Rig/DTRPolarity"),    false);
     wxGetApp().m_playFileToMicInPath = pConfig->Read("/File/playFileToMicInPath",   wxT(""));
     wxGetApp().m_recFileFromRadioPath = pConfig->Read("/File/recFileFromRadioPath", wxT(""));
     wxGetApp().m_recFileFromRadioSecs = pConfig->Read("/File/recFileFromRadioSecs", 30);
     wxGetApp().m_playFileFromRadioPath = pConfig->Read("/File/playFileFromRadioPath", wxT(""));
 
+    wxGetApp().m_boolHamlibUseForPTT = pConfig->ReadBool("/Hamlib/UseForPTT", false);
+    wxGetApp().m_intHamlibRig = pConfig->ReadLong("/Hamlib/RigName", 0);
+    wxGetApp().m_strHamlibSerialPort = pConfig->Read("/Hamlib/SerialPort", "");
+    
     bool slow = false; // prevents compile error when using default bool
     wxGetApp().m_snrSlow = pConfig->Read("/Audio/snrSlow", slow);
 
@@ -369,9 +361,10 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     //m_togRxID->Disable();
     //m_togTxID->Disable();
     m_togBtnAnalog->Disable();
+    m_btnTogPTT->Disable();
     //m_togBtnALC->Disable();
 
-    SetupSerialPort();
+    OpenHamlibRig(); 
 
     // squelch settings
     char sqsnr[15];
@@ -453,6 +446,9 @@ MainFrame::~MainFrame()
     int w;
     int h;
 
+    /* TOOD(Joel): the ownership of m_hamlib is probably wrong. */
+    if (wxGetApp().m_hamlib) delete wxGetApp().m_hamlib;
+
     //MainApp *pApp = wxGetApp();
     wxConfigBase *pConfig = wxConfigBase::Get();
     if(pConfig)
@@ -489,18 +485,11 @@ MainFrame::~MainFrame()
         pConfig->Write(wxT("/Audio/soundCard2OutDeviceNum"),  g_soundCard2OutDeviceNum);
         pConfig->Write(wxT("/Audio/soundCard2SampleRate"),    g_soundCard2SampleRate );
 
-        pConfig->Write(wxT("/Rig/Port"),                    wxGetApp().m_strRigCtrlPort);
-        pConfig->Write(wxT("/Rig/Baud"),                    wxGetApp().m_strRigCtrlBaud);
-        pConfig->Write(wxT("/Rig/DataBits"),                wxGetApp().m_strRigCtrlDatabits);
-        pConfig->Write(wxT("/Rig/StopBits"),                wxGetApp().m_strRigCtrlStopbits);
-        pConfig->Write(wxT("/Rig/Parity"),                  wxGetApp().m_strRigCtrlParity);
-        pConfig->Write(wxT("/Rig/UseRTS"),                  wxGetApp().m_boolUseRTS);
-        pConfig->Write(wxT("/Rig/RTSPolarity"),             wxGetApp().m_boolRTSPos);
-        pConfig->Write(wxT("/Rig/UseDTR"),                  wxGetApp().m_boolUseDTR);
-        pConfig->Write(wxT("/Rig/DTRPolarity"),             wxGetApp().m_boolDTRPos);
-        pConfig->Write(wxT("/Rig/UseTonePTT"),              wxGetApp().m_boolUseTonePTT);
-        pConfig->Write(wxT("/Rig/UseSerialPTT"),            wxGetApp().m_boolUseSerialPTT);
         pConfig->Write(wxT("/Rig/HalfDuplex"),              wxGetApp().m_boolHalfDuplex);
+        pConfig->Write("/Hamlib/UseForPTT", wxGetApp().m_boolHamlibUseForPTT);
+        pConfig->Write("/Hamlib/RigName", wxGetApp().m_intHamlibRig);
+        pConfig->Write("/Hamlib/SerialPort", wxGetApp().m_strHamlibSerialPort);
+
 
         pConfig->Write(wxT("/File/playFileToMicInPath"),    wxGetApp().m_playFileToMicInPath);
         pConfig->Write(wxT("/File/recFileFromRadioPath"),   wxGetApp().m_recFileFromRadioPath);
@@ -523,7 +512,6 @@ MainFrame::~MainFrame()
     //m_togBtnALC->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnALCClickUI), NULL, this);
     //m_btnTogPTT->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this);
 
-    CloseSerialPort();
     sox_biquad_finish();
 
     if (m_RxRunning)
@@ -900,11 +888,39 @@ void MainFrame::OnCheckSNRClick(wxCommandEvent& event)
     //printf("m_snrSlow: %d\n", (int)wxGetApp().m_snrSlow);
 }
 
+// check for space bar press
+
+int MainApp::FilterEvent(wxEvent& event)
+{
+    if ((event.GetEventType() == wxEVT_KEY_DOWN) && 
+        (((wxKeyEvent&)event).GetKeyCode() == WXK_SPACE))
+        {
+            //printf("m_rxRunnng: %d\n", frame->m_RxRunning);
+            if (frame->m_RxRunning) {
+                if (frame->m_btnTogPTT->GetValue())
+                    frame->m_btnTogPTT->SetValue(false);
+                else
+                    frame->m_btnTogPTT->SetValue(true);
+
+                frame->togglePTT();
+            }
+            return true;
+
+        }
+    return -1;
+}
+
 //-------------------------------------------------------------------------
 // OnTogBtnPTT ()
 //-------------------------------------------------------------------------
 void MainFrame::OnTogBtnPTT (wxCommandEvent& event)
 {
+    togglePTT();
+    event.Skip();
+}
+
+void MainFrame::togglePTT(void) {
     if (g_tx)
     {
         // tx-> rx transition, swap to the page we were on for last rx
@@ -917,65 +933,17 @@ void MainFrame::OnTogBtnPTT (wxCommandEvent& event)
         m_auiNbookCtrl->ChangeSelection(m_auiNbookCtrl->GetPageIndex((wxWindow *)m_panelSpeechIn));
     }
     g_tx = m_btnTogPTT->GetValue();
-    // Tortured and tortuous logic, it seems to me...
-    if(wxGetApp().m_boolUseSerialPTT && m_serialPort != NULL)
-    {
-        if(event.IsChecked())
-        {
-            if(wxGetApp().m_boolUseRTS)     // Use RTS
-            {
-                if(wxGetApp().m_boolRTSPos) // RTS asserted HIGH
-                {
-                    m_serialPort->SetLineState(ctb::LinestateRts);
-                }
-                else                        // RTS asserted LOW
-                {
-                    m_serialPort->ClrLineState(ctb::LinestateRts);
-                }
-            }
-            else                            // Use DTR
-            {
-                if(wxGetApp().m_boolDTRPos) // DTR asserted HIGH
-                {
-                    m_serialPort->SetLineState(ctb::LinestateDtr);
-                }
-                else                        // DTR asserted LOW
-                {
-                    m_serialPort->ClrLineState(ctb::LinestateDtr);
-                }
-            }
-        }
-        else  // !isChecked() - so Clear
-        {
-            if(wxGetApp().m_boolUseRTS)     // Use RTS
-            {
-                if(wxGetApp().m_boolRTSPos) // RTS cleared LOW
-                {
-                    m_serialPort->ClrLineState(ctb::LinestateRts);
-                }
-                else                        // RTS cleared HIGH
-                {
-                    m_serialPort->SetLineState(ctb::LinestateRts);
-                }
-            }
-            else                            // Use DTR
-            {
-                if(wxGetApp().m_boolDTRPos) // DTR cleared LOW
-                {
-                    m_serialPort->ClrLineState(ctb::LinestateDtr);
-                }
-                else                        // DTR cleared HIGH
-                {
-                    m_serialPort->SetLineState(ctb::LinestateDtr);
-                }
-            }
-        }
+
+    // Hamlib
+    Hamlib *rig = wxGetApp().m_hamlib; 
+    if (wxGetApp().m_boolHamlibUseForPTT && rig != NULL) {
+        rig->ptt(g_tx);
     }
+
     // reset level gauge
     m_maxLevel = 0;
     m_textLevel->SetLabel(wxT(""));
     m_gaugeLevel->SetValue(0);
-    event.Skip();
 }
 
 //-------------------------------------------------------------------------
@@ -1367,7 +1335,6 @@ void MainFrame::OnExit(wxCommandEvent& event)
     m_togBtnAnalog->Disable();
     //m_togBtnALC->Disable();
     //m_btnTogPTT->Disable();
-    CloseSerialPort();
     Pa_Terminate();
     Destroy();
 }
@@ -1432,46 +1399,15 @@ void MainFrame::OnToolsAudioUI(wxUpdateUIEvent& event)
 void MainFrame::OnToolsComCfg(wxCommandEvent& event)
 {
     wxUnusedVar(event);
-    int rv = 0;
-    int  iLineState  = 0;
-    //bool bPTTEnabled = m_btnTogPTT->IsEnabled();
-    //bool bPTTState   = m_btnTogPTT->GetValue();
 
-    if(m_serialPort != NULL)
-    {
-        CloseSerialPort();
-    }
     ComPortsDlg *dlg = new ComPortsDlg(NULL);
-    rv = dlg->ShowModal();
-    if(rv == wxID_OK)
+    if(dlg->ShowModal() == wxID_OK)
     {
         dlg->ExchangeData(EXCHANGE_DATA_OUT);
-        SetupSerialPort();
-    }
-    else if(rv == wxID_CANCEL)
-    {
-        SetupSerialPort();
-        if(m_serialPort != NULL)
-        {
-            if(iLineState | ctb::LinestateRts)
-            {
-                m_serialPort->SetLineState(ctb::LinestateRts);
-            }
-            else
-            {
-                m_serialPort->ClrLineState(ctb::LinestateRts);
-            }
-            if(iLineState | ctb::LinestateDtr)
-            {
-                m_serialPort->SetLineState(ctb::LinestateDtr);
-            }
-            else
-            {
-                m_serialPort->ClrLineState(ctb::LinestateDtr);
-            }
-        // m_btnTogPTT->Enable(bPTTEnabled);
-        // m_btnTogPTT->SetValue(bPTTState);
-        }
+        /* Opening is done on app start. If the user has just
+         * adjusted the hamlib settings, do an open when they press
+         * okay. */
+        OpenHamlibRig();
     }
     delete dlg;
 }
@@ -1567,6 +1503,23 @@ void MainFrame::OnHelpAbout(wxCommandEvent& event)
 
 //bool wxLaunchDefaultBrowser(http:("http://freedv.org/");
 
+bool MainFrame::OpenHamlibRig() {
+    if (wxGetApp().m_boolHamlibUseForPTT != true)
+       return false;
+    if (wxGetApp().m_intHamlibRig == 0)
+        return false;
+    if (wxGetApp().m_hamlib == NULL)
+        return false;
+
+    int rig = wxGetApp().m_intHamlibRig;
+    wxString port = wxGetApp().m_strHamlibSerialPort;
+    bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8));
+    if (status == false)
+        wxMessageBox("Couldn't connect to Radio with hamlib", wxT("About"), wxOK | wxICON_ERROR, this);
+
+    return status;
+} 
+
 //-------------------------------------------------------------------------
 // OnTogBtnOnOff()
 //-------------------------------------------------------------------------
@@ -1588,13 +1541,8 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         //m_togRxID->Enable();
         //m_togTxID->Enable();
         m_togBtnAnalog->Enable();
-/*
-        if(m_serialPort != NULL)
-        {
-            m_btnTogPTT->Enable();
-        }
-*/
         m_togBtnOnOff->SetLabel(wxT("Stop"));
+        m_btnTogPTT->Enable();
 
         m_rb1400old->Disable();
         m_rb1600->Disable();
@@ -1705,6 +1653,13 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         m_plotTimer.Stop();
 #endif // _USE_TIMER
 
+        // ensure we are not transmitting
+        Hamlib *rig = wxGetApp().m_hamlib; 
+        if (wxGetApp().m_boolHamlibUseForPTT && rig != NULL) {
+          rig->ptt(false);
+        }
+        m_btnTogPTT->SetValue(false);
+
         stopRxStream();
 
         free(g_error_pattern);
@@ -1718,7 +1673,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         //m_togRxID->Disable();
         //m_togTxID->Disable();
         m_togBtnAnalog->Disable();
-        //m_btnTogPTT->Disable();
+        m_btnTogPTT->Disable();
         m_togBtnOnOff->SetLabel(wxT("Start"));
         m_rb1400old->Enable();
         m_rb1600->Enable();
@@ -3032,68 +2987,3 @@ void fdmdv2_clickTune(float freq) {
         g_RxFreqOffsetHz = FDMDV_FCENTRE - freq;
     }
 }
-
-//----------------------------------------------------------------
-// SetupSerialPort()
-//----------------------------------------------------------------
-void MainFrame::SetupSerialPort(void)
-{
-    long baudrate;
-
-    wxGetApp().m_strRigCtrlBaud.ToLong(&baudrate, 10);
-    if(!wxGetApp().m_strRigCtrlPort.IsEmpty())
-    {
-        wxString protocol = wxGetApp().m_strRigCtrlDatabits + wxGetApp().m_strRigCtrlParity + wxGetApp().m_strRigCtrlStopbits;
-        m_serialPort = new ctb::SerialPort();
-        if(m_serialPort->Open(wxGetApp().m_strRigCtrlPort.c_str(), baudrate, protocol.c_str(), ctb::SerialPort::NoFlowControl ) >= 0 )
-        {
-            m_device = m_serialPort;
-            //  always start with PTT cleared
-            if(wxGetApp().m_boolRTSPos) // RTS cleared LOW
-            {
-                m_serialPort->ClrLineState(ctb::LinestateRts);
-            }
-            else                        // RTS cleared HIGH
-            {
-                m_serialPort->SetLineState(ctb::LinestateRts);
-            }
-            if(wxGetApp().m_boolDTRPos) // DTR cleared LOW
-            {
-                m_serialPort->ClrLineState(ctb::LinestateDtr);
-            }
-            else                        // DTR cleared HIGH
-            {
-                m_serialPort->SetLineState(ctb::LinestateDtr);
-            }
-            //m_btnTogPTT->Enable(true);
-            m_btnTogPTT->SetValue(false);
-        }
-        else
-        {
-            m_serialPort = NULL;
-            m_device     = NULL;
-            //m_btnTogPTT->Disable();
-        }
-    }
-/*
-    else
-    {
-        wxMessageBox(wxT("You must select a Serial port to Open!"), wxT("Error"), wxOK);
-    }
-*/
-}
-
-//----------------------------------------------------------------
-// CloseSerialPort()
-//----------------------------------------------------------------
-void MainFrame::CloseSerialPort(void)
-{
-    if((m_serialPort != NULL) && m_serialPort->IsOpen())
-    {
-        m_serialPort->Close();
-        m_serialPort = NULL;
-        m_device     = NULL;
-        //m_btnTogPTT->SetLabel(wxT("PTT"));
-        //m_btnTogPTT->Enable(false);
-    }
-}
index 334b7c5df6770f0e139b7a9eeae44d748f953439..743ecfc184fd0d0bf2fedc1573b4d5d433d01085 100644 (file)
 
 #include <samplerate.h>
 
+#include <hamlib.h> 
+
 #include "codec2.h"
 #include "codec2_fdmdv.h"
 #include "codec2_fifo.h"
 #include "golay23.h"
 
-#include "ctb-0.16/ctb.h"
-#include "ctb-0.16/portscan.h"
-#include "ctb-0.16/serportx.h"
-#include "ctb-0.16/serport.h"
-
 #include "topFrame.h"
 #include "dlg_comports.h"
 #include "fdmdv2_plot.h"
@@ -104,6 +101,8 @@ extern int                 g_soundCard2InDeviceNum;
 extern int                 g_soundCard2OutDeviceNum;
 extern int                 g_soundCard2SampleRate;
 
+class MainFrame;
+
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
 // Class MainApp
 //
@@ -133,18 +132,12 @@ class MainApp : public wxApp
         wxString            m_strSampleRate;
         wxString            m_strBitrate;
 
-        wxString            m_strRigCtrlPort;
-        wxString            m_strRigCtrlBaud;
-        wxString            m_strRigCtrlDatabits;
-        wxString            m_strRigCtrlStopbits;
-        wxString            m_strRigCtrlParity;
         bool                m_boolHalfDuplex;
-        bool                m_boolUseSerialPTT;
-        bool                m_boolUseTonePTT;
-        bool                m_boolUseRTS;
-        bool                m_boolRTSPos;
-        bool                m_boolUseDTR;
-        bool                m_boolDTRPos;
+
+        bool                m_boolHamlibUseForPTT;
+        unsigned int        m_intHamlibRig;
+        wxString            m_strHamlibSerialPort;
+        Hamlib              *m_hamlib;
 
         wxString            m_playFileToMicInPath;
         wxString            m_recFileFromRadioPath;
@@ -206,6 +199,8 @@ class MainApp : public wxApp
 
         bool        m_testFrames;
 
+        int        FilterEvent(wxEvent& event);
+        MainFrame *frame;
     protected:
 };
 
@@ -324,8 +319,7 @@ class MainFrame : public TopFrame
         
         txRxThread*             m_txRxThread;
 
-        void SetupSerialPort(void);
-        void CloseSerialPort(void);
+        bool                    OpenHamlibRig();
 
 #ifdef _USE_TIMER
         wxTimer                 m_plotTimer;
@@ -357,10 +351,9 @@ class MainFrame : public TopFrame
     void initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevice, 
                              int soundCard, int sampleRate, int inputChannels);
 
-    protected:
+    void togglePTT(void);
 
-        ctb::IOBase*            m_device;
-        ctb::SerialPort*        m_serialPort;
+    protected:
 
         void setsnrBeta(bool snrSlow);
 
index 34cd316404bdfb532244a18fe12157ef1689689a..b65c2083f290c9f4ca389535279bed0143649022 100644 (file)
@@ -366,7 +366,6 @@ void PlotWaterfall::plotPixelData()
 
     // Shift previous bit map up one row of blocks ----------------------------
     wxNativePixelData data(*m_pBmp);
-    assert(data != NULL);
     wxNativePixelData::Iterator bitMapStart(data);
     wxNativePixelData::Iterator p = bitMapStart;
 
index b277e71c403cfcf623c6fcce1e64ca9315ddf8b9..3409ac3a23d75ac7c4d4b2b04f76614f77afc046 100644 (file)
@@ -416,7 +416,7 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const
     wxBoxSizer* bSizer11;
     bSizer11 = new wxBoxSizer(wxVERTICAL);
     m_btnTogPTT = new wxToggleButton(this, wxID_ANY, _("PTT"), wxDefaultPosition, wxDefaultSize, 0);
-    m_btnTogPTT->SetToolTip(_("PTT Switch between Receive and Transmit"));
+    m_btnTogPTT->SetToolTip(_("Push to Talk - Switch between Receive and Transmit - you can also use the space bar "));
     bSizer11->Add(m_btnTogPTT, 1, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1);
     sbSizer5->Add(bSizer11, 2, wxEXPAND, 1);
     rightSizer->Add(sbSizer5, 2, wxALIGN_CENTER|wxALL|wxEXPAND, 3);