From 7a00e51dc657b7cee3007b97083c9fb6a5aaa24b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 3 Aug 2021 23:12:13 +0200 Subject: [PATCH] Spectrum markers: implemented histogram markers max power hold --- sdrgui/gui/glspectrum.cpp | 51 +++++++++++++++++++++++----- sdrgui/gui/spectrummarkers.h | 11 +++++- sdrgui/gui/spectrummarkersdialog.cpp | 9 +++++ sdrgui/gui/spectrummarkersdialog.h | 1 + sdrgui/gui/spectrummarkersdialog.ui | 29 +++++++++++++--- 5 files changed, 88 insertions(+), 13 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index 621ef092f..388fe6845 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -1180,13 +1180,36 @@ void GLSpectrum::drawMarkers() if (m_histogramMarkers.at(i).m_markerType == SpectrumHistogramMarkerTypePower) { + float power = m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin]; ypoint.ry() = - (m_powerScale.getRangeMax() - m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin]) / m_powerScale.getRange(); + (m_powerScale.getRangeMax() - power) / m_powerScale.getRange(); ypoint.ry() = ypoint.ry() < 0 ? 0 : ypoint.ry() > 1 ? 1 : ypoint.ry(); powerStr = displayScaledF( - m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin], + power, + m_linear ? 'e' : 'f', + m_linear ? 3 : 1, + false + ); + } + else if (m_histogramMarkers.at(i).m_markerType == SpectrumHistogramMarkerTypePowerMax) + { + float power = m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin]; + + if ((m_histogramMarkers.at(i).m_holdReset) || (power > m_histogramMarkers[i].m_powerMax)) + { + m_histogramMarkers[i].m_powerMax = power; + m_histogramMarkers[i].m_holdReset = false; + } + + ypoint.ry() = + (m_powerScale.getRangeMax() - m_histogramMarkers[i].m_powerMax) / m_powerScale.getRange(); + ypoint.ry() = ypoint.ry() < 0 ? + 0 : ypoint.ry() > 1 ? + 1 : ypoint.ry(); + powerStr = displayScaledF( + m_histogramMarkers[i].m_powerMax, m_linear ? 'e' : 'f', m_linear ? 3 : 1, false @@ -1230,12 +1253,24 @@ void GLSpectrum::drawMarkers() else { textColor.setAlpha(192); - float power0 = m_histogramMarkers.at(0).m_markerType == SpectrumHistogramMarkerTypePower ? - m_currentSpectrum[m_histogramMarkers.at(0).m_fftBin] : - m_linear ? m_histogramMarkers.at(0).m_power : CalcDb::dbPower(m_histogramMarkers.at(0).m_power); - float poweri = m_histogramMarkers.at(i).m_markerType == SpectrumHistogramMarkerTypePower ? - m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin] : - m_linear ? m_histogramMarkers.at(i).m_power : CalcDb::dbPower(m_histogramMarkers.at(i).m_power); + float power0, poweri; + + if (m_histogramMarkers.at(0).m_markerType == SpectrumHistogramMarkerTypePower) { + power0 = m_currentSpectrum[m_histogramMarkers.at(0).m_fftBin]; + } else if (m_histogramMarkers.at(0).m_markerType == SpectrumHistogramMarkerTypePowerMax) { + power0 = m_histogramMarkers.at(0).m_powerMax; + } else { + power0 = m_linear ? m_histogramMarkers.at(0).m_power : CalcDb::dbPower(m_histogramMarkers.at(0).m_power); + } + + if (m_histogramMarkers.at(i).m_markerType == SpectrumHistogramMarkerTypePower) { + poweri = m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin]; + } else if (m_histogramMarkers.at(i).m_markerType == SpectrumHistogramMarkerTypePowerMax) { + poweri = m_histogramMarkers.at(i).m_powerMax; + } else { + poweri = m_linear ? m_histogramMarkers.at(i).m_power : CalcDb::dbPower(m_histogramMarkers.at(i).m_power); + } + QString deltaPowerStr; if (m_linear) { diff --git a/sdrgui/gui/spectrummarkers.h b/sdrgui/gui/spectrummarkers.h index e3f08f3aa..c55734404 100644 --- a/sdrgui/gui/spectrummarkers.h +++ b/sdrgui/gui/spectrummarkers.h @@ -27,7 +27,8 @@ enum SpectrumHistogramMarkerType { SpectrumHistogramMarkerTypeManual, - SpectrumHistogramMarkerTypePower + SpectrumHistogramMarkerTypePower, + SpectrumHistogramMarkerTypePowerMax }; struct SpectrumHistogramMarker @@ -36,6 +37,8 @@ struct SpectrumHistogramMarker float m_frequency; int m_fftBin; float m_power; + bool m_holdReset; + float m_powerMax; SpectrumHistogramMarkerType m_markerType; QColor m_markerColor; QString m_frequencyStr; @@ -49,6 +52,8 @@ struct SpectrumHistogramMarker m_frequency(0), m_fftBin(0), m_power(0), + m_holdReset(true), + m_powerMax(0), m_markerType(SpectrumHistogramMarkerTypeManual), m_markerColor(QColorConstants::White), m_frequencyStr(), @@ -62,6 +67,8 @@ struct SpectrumHistogramMarker float frequency, int fftBin, float power, + bool holdReset, + float powerMax, SpectrumHistogramMarkerType markerType, QColor markerColor, const QString& frequencyStr, @@ -73,6 +80,8 @@ struct SpectrumHistogramMarker m_frequency(frequency), m_fftBin(fftBin), m_power(power), + m_holdReset(holdReset), + m_powerMax(powerMax), m_markerType(markerType), m_markerColor(markerColor), m_frequencyStr(frequencyStr), diff --git a/sdrgui/gui/spectrummarkersdialog.cpp b/sdrgui/gui/spectrummarkersdialog.cpp index a53b57255..cc749ef5d 100644 --- a/sdrgui/gui/spectrummarkersdialog.cpp +++ b/sdrgui/gui/spectrummarkersdialog.cpp @@ -250,6 +250,15 @@ void SpectrumMarkersDialog::on_powerMode_currentIndexChanged(int index) m_histogramMarkers[m_histogramMarkerIndex].m_markerType = (SpectrumHistogramMarkerType) index; } +void SpectrumMarkersDialog::on_powerHoldReset_clicked() +{ + if (m_histogramMarkers.size() == 0) { + return; + } + + m_histogramMarkers[m_histogramMarkerIndex].m_holdReset = true; +} + void SpectrumMarkersDialog::on_wMarkerFrequency_changed(qint64 value) { if (m_waterfallMarkers.size() == 0) { diff --git a/sdrgui/gui/spectrummarkersdialog.h b/sdrgui/gui/spectrummarkersdialog.h index e6c48f53c..d4c0d3622 100644 --- a/sdrgui/gui/spectrummarkersdialog.h +++ b/sdrgui/gui/spectrummarkersdialog.h @@ -68,6 +68,7 @@ private slots: void on_markerAdd_clicked(); void on_markerDel_clicked(); void on_powerMode_currentIndexChanged(int index); + void on_powerHoldReset_clicked(); void on_wMarkerFrequency_changed(qint64 value); void on_timeCoarse_valueChanged(int value); void on_timeFine_valueChanged(int value); diff --git a/sdrgui/gui/spectrummarkersdialog.ui b/sdrgui/gui/spectrummarkersdialog.ui index 3d35da8df..ba041adac 100644 --- a/sdrgui/gui/spectrummarkersdialog.ui +++ b/sdrgui/gui/spectrummarkersdialog.ui @@ -6,7 +6,7 @@ 0 0 - 390 + 418 201 @@ -34,7 +34,7 @@ 0 10 - 361 + 391 74 @@ -367,6 +367,22 @@ + + + + + 24 + 24 + + + + Reset power max hold + + + R + + + @@ -382,7 +398,12 @@ - Pow + Cur + + + + + Max @@ -449,7 +470,7 @@ 0 10 - 361 + 391 93