Skip to content

Commit

Permalink
AM demod channel mode: fixed some frequency display inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Nov 28, 2023
1 parent 003a04e commit ee51ffd
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions plugins/channelrx/demodam/amdemodgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ void AMDemodGUI::on_frequencyMode_currentIndexChanged(int index)
{
m_settings.m_frequencyMode = (AMDemodSettings::FrequencyMode) index;
ui->deltaFrequency->blockSignals(true);

if (m_settings.m_frequencyMode == AMDemodSettings::Offset)
{
ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999);
ui->deltaFrequency->setValue(m_settings.m_inputFrequencyOffset);
ui->deltaUnits->setText("Hz");

if (m_settings.m_snap)
{
m_settings.m_snap = false;
Expand All @@ -229,10 +231,14 @@ void AMDemodGUI::on_frequencyMode_currentIndexChanged(int index)
ui->deltaFrequency->setValue(freqToChannel(m_settings.m_frequency) / 1000);
ui->deltaUnits->setText("MHz");
}

ui->deltaFrequency->blockSignals(false);

if (m_settings.m_snap) {
applySnap();
}

updateAbsoluteCenterFrequency();
applySettings();
}

Expand All @@ -256,11 +262,14 @@ void AMDemodGUI::calcOffset()
void AMDemodGUI::channelMarkerChangedByCursor()
{
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();

if (m_settings.m_snap) {
applySnap();
}

m_settings.m_frequency = m_deviceCenterFrequency + m_settings.m_inputFrequencyOffset;
int value = 0;

if (m_settings.m_frequencyMode == AMDemodSettings::Offset) {
value = m_settings.m_inputFrequencyOffset;
} else if (m_settings.m_frequencyMode == AMDemodSettings::MediumWave) {
Expand Down Expand Up @@ -653,9 +662,32 @@ void AMDemodGUI::snapClicked()
} else {
m_settings.m_snap = !m_settings.m_snap;
}
if (m_settings.m_snap) {

if (m_settings.m_snap)
{
applySnap();

qint64 value;

if (m_settings.m_frequencyMode == AMDemodSettings::Offset) {
value = m_settings.m_inputFrequencyOffset;
} else if (m_settings.m_frequencyMode == AMDemodSettings::MediumWave) {
value = m_settings.m_frequency / 1000;
} else if (m_settings.m_frequencyMode == AMDemodSettings::Airband25k) {
value = m_settings.m_frequency / 1000;
} else if (m_settings.m_frequencyMode == AMDemodSettings::Airband8K) {
value = freqToChannel(m_settings.m_frequency) / 1000;
}

// We support finer tuning by marker than by deltaFrequency widget (unless in offset mode),
// so block signals so it doesn't truncate frequency to limit of widget
ui->deltaFrequency->blockSignals(true);
ui->deltaFrequency->setValue(value);
ui->deltaFrequency->blockSignals(false);

updateAbsoluteCenterFrequency();
}

displaySnap();
applySettings();
}
Expand All @@ -667,6 +699,7 @@ void AMDemodGUI::applySnap()
}

qint64 frequency = m_deviceCenterFrequency + m_settings.m_inputFrequencyOffset;

if (m_settings.m_frequencyMode == AMDemodSettings::MediumWave)
{
frequency = (frequency / 1000) * 1000;
Expand All @@ -677,9 +710,11 @@ void AMDemodGUI::applySnap()
}
else if (m_settings.m_frequencyMode == AMDemodSettings::Airband8K)
{
frequency = std::round((frequency / 8333) * 8333.3);
frequency = std::round((frequency / 8333) * 8333.33333333);
}

m_settings.m_inputFrequencyOffset = frequency - m_deviceCenterFrequency;
m_settings.m_frequency = frequency;
m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
}

Expand Down

0 comments on commit ee51ffd

Please sign in to comment.