From 54a2f51d385bdfaf01e51937b51eaebd5344c185 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 14 May 2014 12:00:11 +0000 Subject: [PATCH] Allow for HRD on rigs where more than one mode maps to Tranceiver::MODE. Some rigs like the FT-857(D) have multiple modes that only have one representation in the Transceiver class, e.g. FM, FM(N) and WFM. The HRDTransceiver class now allows multiple modes to be mapped to one Transceiver::MODE, the last match in the HRD mode dropdown is used when mapping a Tranceiver::MODE to a HRD mode setting which is normally the most suitable mode. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4135 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- HRDTransceiver.cpp | 33 +++++++++++++++++++++++++-------- HRDTransceiver.hpp | 8 ++++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/HRDTransceiver.cpp b/HRDTransceiver.cpp index 19e8ae3db..44a3fb4fd 100644 --- a/HRDTransceiver.cpp +++ b/HRDTransceiver.cpp @@ -303,9 +303,22 @@ int HRDTransceiver::find_dropdown (QRegExp const& re) const return dropdown_names_.indexOf (re); } -int HRDTransceiver::find_dropdown_selection (int dropdown, QRegExp const& re) const +std::vector HRDTransceiver::find_dropdown_selection (int dropdown, QRegExp const& re) const { - return dropdowns_.value (dropdown_names_.value (dropdown)).lastIndexOf (re); // backwards because more specialised modes tend to be later in list + std::vector indices; + auto list = dropdowns_.value (dropdown_names_.value (dropdown)); + int index {0}; + while (-1 != (index = list.lastIndexOf (re, index - 1))) + { + // search backwards because more specialized modes tend to be later in + // list + indices.push_back (index); + if (!index) + { + break; + } + } + return indices; } int HRDTransceiver::lookup_dropdown_selection (int dropdown, QString const& selection) const @@ -335,8 +348,8 @@ void HRDTransceiver::map_modes (int dropdown, ModeMap *map) std::for_each (map->begin (), map->end (), [this, dropdown] (ModeMap::value_type const& item) { - auto rhs = std::get<1> (item); - qDebug () << '\t' << std::get<0> (item) << "<->" << (rhs >= 0 ? dropdowns_[dropdown_names_[dropdown]][rhs] : "None"); + auto const& rhs = std::get<1> (item); + qDebug () << '\t' << std::get<0> (item) << "<->" << (rhs.size () ? dropdowns_[dropdown_names_[dropdown]][rhs.front ()] : "None"); }); #endif } @@ -348,12 +361,16 @@ int HRDTransceiver::lookup_mode (MODE mode, ModeMap const& map) const { throw error {tr ("Ham Radio Deluxe: rig doesn't support mode")}; } - return std::get<1> (*it); + return std::get<1> (*it).front (); } auto HRDTransceiver::lookup_mode (int mode, ModeMap const& map) const -> MODE { - auto it = std::find_if (map.begin (), map.end (), [mode] (ModeMap::value_type const& item) {return std::get<1> (item) == mode;}); + auto it = std::find_if (map.begin (), map.end (), [mode] (ModeMap::value_type const& item) + { + auto const& indices = std::get<1> (item); + return indices.cend () != std::find (indices.cbegin (), indices.cend (), mode); + }); if (map.end () == it) { throw error {tr ("Ham Radio Deluxe: sent an unrecognised mode")}; @@ -503,7 +520,7 @@ void HRDTransceiver::do_tx_frequency (Frequency tx, bool rationalise_mode) } else if (split_mode_dropdown_ >= 0) { - set_dropdown (split_mode_dropdown_, split ? split_mode_dropdown_selection_on_ : split_mode_dropdown_selection_off_); + set_dropdown (split_mode_dropdown_, split ? split_mode_dropdown_selection_on_.front () : split_mode_dropdown_selection_off_.front ()); } else if (vfo_A_button_ >= 0 && vfo_B_button_ >= 0 && tx_A_button_ >= 0 && tx_B_button_ >= 0) { @@ -586,7 +603,7 @@ void HRDTransceiver::poll () { try { - update_split (get_dropdown (split_mode_dropdown_, quiet) == split_mode_dropdown_selection_on_); + update_split (get_dropdown (split_mode_dropdown_, quiet) == split_mode_dropdown_selection_on_.front ()); } catch (error const&) { diff --git a/HRDTransceiver.hpp b/HRDTransceiver.hpp index ebb0154e0..a86f75629 100644 --- a/HRDTransceiver.hpp +++ b/HRDTransceiver.hpp @@ -50,14 +50,14 @@ private: void sync_impl (); int find_button (QRegExp const&) const; int find_dropdown (QRegExp const&) const; - int find_dropdown_selection (int dropdown, QRegExp const&) const; + std::vector find_dropdown_selection (int dropdown, QRegExp const&) const; int lookup_dropdown_selection (int dropdown, QString const&) const; int get_dropdown (int, bool no_debug = false); void set_dropdown (int, int); void set_button (int button_index, bool checked = true); bool is_button_checked (int button_index, bool no_debug = false); - using ModeMap = std::vector >; + using ModeMap = std::vector > >; void map_modes (int dropdown, ModeMap *); int lookup_mode (MODE, ModeMap const&) const; MODE lookup_mode (int, ModeMap const&) const; @@ -84,8 +84,8 @@ private: int split_mode_button_; int split_mode_dropdown_; bool split_mode_dropdown_write_only_; - int split_mode_dropdown_selection_on_; - int split_mode_dropdown_selection_off_; + std::vector split_mode_dropdown_selection_on_; + std::vector split_mode_dropdown_selection_off_; int split_off_button_; int tx_A_button_; int tx_B_button_;