Skip to content

Commit

Permalink
Merge pull request #685 from drowe67/ms-cardinal-directions
Browse files Browse the repository at this point in the history
Add support for displaying cardinal directions instead of headings.
  • Loading branch information
tmiw committed Feb 5, 2024
2 parents a6427b5 + 91965cf commit c2656ba
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Move TX Mode column to left of Status in FreeDV Reporter window. (PR #670)
* Add heading column to FreeDV Reporter window. (PR #672, #675)
* Prevent FreeDV Reporter window from being above the main window. (PR #679)
* Add support for displaying cardinal directions instead of headings. (PR #685)
3. Code cleanup:
* Move FreeDV Reporter dialog code to dialogs section of codebase. (PR #664)

Expand Down
5 changes: 5 additions & 0 deletions src/config/ReportingConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ReportingConfiguration::ReportingConfiguration()
, freedvReporterMsgRowForegroundColor("/Reporting/FreeDV/MsgRowForegroundColor", "#000000")

, reportingFrequencyAsKhz("/Reporting/FrequencyAsKHz", false)
, reportingDirectionAsCardinal("/Reporting/DirectionAsCardinal", false)
{
// Special handling for the frequency list to properly handle locales
reportingFrequencyList.setLoadProcessor([this](std::vector<wxString> list) {
Expand Down Expand Up @@ -196,6 +197,8 @@ void ReportingConfiguration::load(wxConfigBase* config)
load_(config, freedvReporterMsgRowBackgroundColor);
load_(config, freedvReporterMsgRowForegroundColor);

load_(config, reportingDirectionAsCardinal);

// Special load handling for reporting below.
wxString freqStr = config->Read(reportingFrequency.getElementName(), oldFreqStr);
reportingFrequency.setWithoutProcessing(atoll(freqStr.ToUTF8()));
Expand Down Expand Up @@ -235,6 +238,8 @@ void ReportingConfiguration::save(wxConfigBase* config)
save_(config, freedvReporterRxRowForegroundColor);
save_(config, freedvReporterMsgRowBackgroundColor);
save_(config, freedvReporterMsgRowForegroundColor);

save_(config, reportingDirectionAsCardinal);

// Special save handling for reporting below.
wxString tempFreqStr = wxString::Format(wxT("%" PRIu64), reportingFrequency.getWithoutProcessing());
Expand Down
1 change: 1 addition & 0 deletions src/config/ReportingConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ReportingConfiguration : public WxWidgetsConfigStore
ConfigurationDataElement<wxString> freedvReporterMsgRowForegroundColor;

ConfigurationDataElement<bool> reportingFrequencyAsKhz;
ConfigurationDataElement<bool> reportingDirectionAsCardinal;

virtual void load(wxConfigBase* config) override;
virtual void save(wxConfigBase* config) override;
Expand Down
8 changes: 8 additions & 0 deletions src/gui/dialogs/dlg_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c
m_useMetricDistances = new wxCheckBox(m_reportingTab, wxID_ANY, _("Distances in km"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
sbSizerReportingFreeDVNoCall->Add(m_useMetricDistances, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);

m_useCardinalDirections = new wxCheckBox(m_reportingTab, wxID_ANY, _("Show cardinal directions"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
sbSizerReportingFreeDVNoCall->Add(m_useCardinalDirections, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);

m_ckboxFreeDVReporterForceReceiveOnly = new wxCheckBox(m_reportingTab, wxID_ANY, _("Force RX Only reporting"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
sbSizerReportingFreeDVNoCall->Add(m_ckboxFreeDVReporterForceReceiveOnly, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);

Expand Down Expand Up @@ -880,6 +883,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
m_ckboxFreeDVReporterEnable->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterEnabled);
m_freedvReporterHostname->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterHostname);
m_useMetricDistances->SetValue(wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances);
m_useCardinalDirections->SetValue(wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal);
m_ckboxFreeDVReporterForceReceiveOnly->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterForceReceiveOnly);

// Callsign list config
Expand Down Expand Up @@ -1052,6 +1056,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
wxGetApp().appConfiguration.reportingConfiguration.freedvReporterHostname = m_freedvReporterHostname->GetValue();
wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances = m_useMetricDistances->GetValue();
wxGetApp().appConfiguration.reportingConfiguration.freedvReporterForceReceiveOnly = m_ckboxFreeDVReporterForceReceiveOnly->GetValue();
wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal = m_useCardinalDirections->GetValue();

// Callsign list config
wxGetApp().appConfiguration.reportingConfiguration.useUTCForReporting = m_ckbox_use_utc_time->GetValue();
Expand Down Expand Up @@ -1286,6 +1291,7 @@ void OptionsDlg::updateReportingState()
m_ckboxPskReporterEnable->Enable(true);
m_ckboxFreeDVReporterEnable->Enable(true);
m_ckboxFreeDVReporterForceReceiveOnly->Enable(true);
m_useCardinalDirections->Enable(true);
}
else
{
Expand All @@ -1296,6 +1302,7 @@ void OptionsDlg::updateReportingState()
m_ckboxFreeDVReporterEnable->Enable(false);
m_ckboxManualFrequencyReporting->Enable(false);
m_ckboxFreeDVReporterForceReceiveOnly->Enable(true);
m_useCardinalDirections->Enable(true);
}
}
else
Expand All @@ -1311,6 +1318,7 @@ void OptionsDlg::updateReportingState()
m_useMetricDistances->Enable(false);
m_freedvReporterHostname->Enable(false);
m_ckboxFreeDVReporterForceReceiveOnly->Enable(false);
m_useCardinalDirections->Enable(false);

m_ckbox_use_utc_time->Enable(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/dlg_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class OptionsDlg : public wxDialog
wxCheckBox *m_ckboxFreeDVReporterEnable;
wxTextCtrl *m_freedvReporterHostname;
wxCheckBox *m_useMetricDistances;
wxCheckBox *m_useCardinalDirections;
wxCheckBox *m_ckboxFreeDVReporterForceReceiveOnly;

wxButton* m_BtnFifoReset;
Expand Down
51 changes: 46 additions & 5 deletions src/gui/dialogs/freedv_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void FreeDVReporterDialog::refreshLayout()
#endif // defined(WIN32)

wxListItem item;
m_listSpots->GetColumn(2 + colOffset, item);
m_listSpots->GetColumn(DISTANCE_COL + colOffset, item);

if (wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances)
{
Expand All @@ -436,10 +436,10 @@ void FreeDVReporterDialog::refreshLayout()
item.SetText("Miles");
}

m_listSpots->SetColumn(2 + colOffset, item);
m_listSpots->SetColumn(DISTANCE_COL + colOffset, item);

// Refresh frequency units as appropriate.
m_listSpots->GetColumn(5 + colOffset, item);
m_listSpots->GetColumn(FREQUENCY_COL + colOffset, item);
if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz)
{
item.SetText("kHz");
Expand All @@ -448,7 +448,21 @@ void FreeDVReporterDialog::refreshLayout()
{
item.SetText("MHz");
}
m_listSpots->SetColumn(5 + colOffset, item);
m_listSpots->SetColumn(FREQUENCY_COL + colOffset, item);

// Change direction/heading column label based on preferences
m_listSpots->GetColumn(HEADING_COL + colOffset, item);
if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal)
{
item.SetText("Dir");
item.SetAlign(wxLIST_FORMAT_LEFT);
}
else
{
item.SetText("Hdg");
item.SetAlign(wxLIST_FORMAT_RIGHT);
}
m_listSpots->SetColumn(HEADING_COL + colOffset, item);

std::map<int, int> colResizeList;
for (auto& kvp : allReporterData_)
Expand All @@ -467,6 +481,19 @@ void FreeDVReporterDialog::refreshLayout()
}

kvp.second->freqString = frequencyString;

// Refresh cardinal vs. degree directions.
if (wxGetApp().appConfiguration.reportingConfiguration.reportingGridSquare != kvp.second->gridSquare)
{
if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal)
{
kvp.second->heading = GetCardinalDirection_(kvp.second->headingVal);
}
else
{
kvp.second->heading = wxString::Format("%.0f", kvp.second->headingVal);
}
}

addOrUpdateListIfNotFiltered_(kvp.second, colResizeList);
}
Expand Down Expand Up @@ -1328,7 +1355,14 @@ void FreeDVReporterDialog::onUserConnectFn_(std::string sid, std::string lastUpd
else
{
temp->headingVal = calculateBearingInDegrees_(wxGetApp().appConfiguration.reportingConfiguration.reportingGridSquare, gridSquareWxString);
temp->heading = wxString::Format("%.0f", temp->headingVal);
if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal)
{
temp->heading = GetCardinalDirection_(temp->headingVal);
}
else
{
temp->heading = wxString::Format("%.0f", temp->headingVal);
}
}
}

Expand Down Expand Up @@ -1897,3 +1931,10 @@ bool FreeDVReporterDialog::isFiltered_(uint64_t freq)
freq != filteredFrequency_);
}
}

wxString FreeDVReporterDialog::GetCardinalDirection_(int degrees)
{
int cardinalDirectionNumber( static_cast<int>( ( ( degrees / 360.0 ) * 16 ) + 0.5 ) % 16 );
const char* const cardinalDirectionTexts[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "SW", "WNW", "NW", "NNW" };
return cardinalDirectionTexts[cardinalDirectionNumber];
}
1 change: 1 addition & 0 deletions src/gui/dialogs/freedv_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class FreeDVReporterDialog : public wxFrame
static wxCALLBACK int ListCompareFn_(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData);
static double DegreesToRadians_(double degrees);
static double RadiansToDegrees_(double radians);
static wxString GetCardinalDirection_(int degrees);
};

#endif // __FREEDV_REPORTER_DIALOG__

0 comments on commit c2656ba

Please sign in to comment.