Skip to content

Commit

Permalink
Merge pull request #725 from drowe67/ms-show-rx-offset-waterfall
Browse files Browse the repository at this point in the history
Show green line indicating RX frequency.
  • Loading branch information
tmiw authored Jun 19, 2024
2 parents a5fb94a + 9ef2497 commit fb9d36a
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum OS X deployment version")

set(PROJECT_NAME FreeDV)
set(PROJECT_VERSION 1.9.9.2)
set(PROJECT_VERSION 1.9.9.3)
set(PROJECT_DESCRIPTION "HF Digital Voice for Radio Amateurs")
set(PROJECT_HOMEPAGE_URL "https://freedv.org")

Expand Down Expand Up @@ -49,7 +49,7 @@ endif(APPLE)
# Adds a tag to the end of the version string. Leave empty
# for official release builds.
if(NOT DEFINED FREEDV_VERSION_TAG)
set(FREEDV_VERSION_TAG "")
set(FREEDV_VERSION_TAG "devel")
endif(NOT DEFINED FREEDV_VERSION_TAG)

# Prevent in-source builds to protect automake/autoconf config.
Expand Down
9 changes: 7 additions & 2 deletions USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,18 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes

# Release Notes

## V1.9.9.3 TBD 2024

1. Enhancements:
* Show green line indicating RX frequency. (PR #725)
2. Build system:
* Allow overrriding the version tag when building. (PR #727)

## V1.9.9.2 June 2024

1. Bugfixes:
* Remove TX attenuation and squelch tooltips. (PR #717)
* Disable 800XA radio button when in RX Only mode. (PR #716)
2. Build system:
* Allow overrriding the version tag when building. (PR #727)

## V1.9.9.1 April 2024

Expand Down
22 changes: 21 additions & 1 deletion src/gui/controls/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
//==========================================================================
#ifndef __FDMDV2_PLOT__
#define __FDMDV2_PLOT__

#include <deque>

#include <wx/wx.h>
#include <wx/aui/auibook.h>
#include <wx/rawbmp.h>
Expand Down Expand Up @@ -73,6 +76,8 @@
#define LIGHT_YELLOW_COLOR wxColor(0xFF, 0xFF, 0xB5)
#define DARK_YELLOW_COLOR wxColor(0xFF, 0xFF, 0x08)

#define ORANGE_COLOR wxColor(0xFF, 0xA5, 0x00)

class MainFrame;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
Expand Down Expand Up @@ -111,7 +116,7 @@ class PlotPanel : public wxPanel
virtual void OnMouseLeftDown(wxMouseEvent& event);
void OnMouseLeftUp(wxMouseEvent& event);
virtual void OnMouseRightDown(wxMouseEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event);
virtual void OnMouseWheelMoved(wxMouseEvent& event);
void OnClose(wxCloseEvent& event ){ event.Skip(); }
virtual void OnSize( wxSizeEvent& event ) = 0;
void OnErase(wxEraseEvent& event);
Expand All @@ -126,6 +131,17 @@ class PlotPanel : public wxPanel
virtual void OnShow(wxShowEvent& event);
virtual double GetLabelSize();
virtual void SetLabelSize(double size);

void setSync(bool sync) { sync_ = sync; }
void addOffset(float offset)
{
rxOffsets_.push_back(offset);
if (rxOffsets_.size() >= 20)
{
// Limit to ~2 seconds worth of offsets for averaging
rxOffsets_.pop_front();
}
}

protected:
int m_x;
Expand All @@ -144,6 +160,10 @@ class PlotPanel : public wxPanel
double m_zoomFactor;
int m_greyscale;
int m_line_color;

std::deque<float> rxOffsets_;
bool sync_;

DECLARE_EVENT_TABLE()
};
#endif //__FDMDV2_PLOT__
93 changes: 89 additions & 4 deletions src/gui/controls/plot_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
#include <wx/wx.h>

#include "plot_spectrum.h"
#include "codec2_fdmdv.h" // for FDMDV_FCENTRE

void clickTune(float frequency); // callback to pass new click freq
extern float g_RxFreqOffsetHz;

BEGIN_EVENT_TABLE(PlotSpectrum, PlotPanel)
EVT_MOTION (PlotSpectrum::OnMouseMove)
EVT_LEFT_DOWN (PlotSpectrum::OnMouseLeftDown)
EVT_LEFT_DCLICK (PlotSpectrum::OnMouseLeftDoubleClick)
EVT_LEFT_UP (PlotSpectrum::OnMouseLeftUp)
EVT_MIDDLE_DOWN (PlotSpectrum::OnMouseMiddleDown)
EVT_RIGHT_DCLICK (PlotSpectrum::OnMouseRightDoubleClick)
EVT_MOUSEWHEEL (PlotSpectrum::OnMouseWheelMoved)
EVT_PAINT (PlotSpectrum::OnPaint)
EVT_SHOW (PlotSpectrum::OnShow)
EVT_KEY_DOWN (PlotSpectrum::OnKeyDown)
END_EVENT_TABLE()

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
Expand Down Expand Up @@ -263,11 +267,26 @@ void PlotSpectrum::drawGraticule(wxGraphicsContext* ctx)
// red rx tuning line

if (m_rxFreq != 0.0) {
ctx->SetPen(wxPen(RED_COLOR, 2));
float verticalBarLength = m_rCtrl.GetHeight() - (m_rGrid.GetHeight()+ PLOT_BORDER);

float sum = 0.0;
for (auto& f : rxOffsets_)
{
sum += f;
}
float averageOffset = sum / rxOffsets_.size();

// get average offset and draw sync tuning line
ctx->SetPen(wxPen(sync_ ? GREEN_COLOR : ORANGE_COLOR, 3));
x = (m_rxFreq + averageOffset) * freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
ctx->StrokeLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, m_rCtrl.GetHeight());

// red rx tuning line
ctx->SetPen(wxPen(RED_COLOR, 3));
x = m_rxFreq*freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
//printf("m_rxFreq %f x %d\n", m_rxFreq, x);
ctx->StrokeLine(x, m_rGrid.GetHeight()+ PLOT_BORDER, x, m_rCtrl.GetHeight());
ctx->StrokeLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, m_rCtrl.GetHeight() - verticalBarLength / 3);
}

}
Expand All @@ -289,7 +308,8 @@ void PlotSpectrum::OnDoubleClickCommon(wxMouseEvent& event)
// valid click if inside of plot
if ((pt.x >= 0) && (pt.x <= m_rGrid.GetWidth()) && (pt.y >=0) && m_clickTune) {
float freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ);
float clickFreq = (float)pt.x/freq_hz_to_px;
int clickFreq = (int)((float)pt.x/freq_hz_to_px);
clickFreq -= clickFreq % 10;

// see PlotWaterfall::OnMouseDown()

Expand All @@ -312,3 +332,68 @@ void PlotSpectrum::OnMouseRightDoubleClick(wxMouseEvent& event)
{
OnDoubleClickCommon(event);
}

//-------------------------------------------------------------------------
// OnMouseWheelMoved()
//-------------------------------------------------------------------------
void PlotSpectrum::OnMouseWheelMoved(wxMouseEvent& event)
{
float currRxFreq = FDMDV_FCENTRE - g_RxFreqOffsetHz;
float direction = 1.0;
if (event.GetWheelRotation() < 0)
{
direction = -1.0;
}

currRxFreq += direction * 10;
if (currRxFreq < MIN_F_HZ)
{
currRxFreq = MIN_F_HZ;
}
else if (currRxFreq > MAX_F_HZ)
{
currRxFreq = MAX_F_HZ;
}
clickTune(currRxFreq);
}

//-------------------------------------------------------------------------
// OnKeyDown()
//-------------------------------------------------------------------------
void PlotSpectrum::OnKeyDown(wxKeyEvent& event)
{
float currRxFreq = FDMDV_FCENTRE - g_RxFreqOffsetHz;
float direction = 0;

switch (event.GetKeyCode())
{
case WXK_DOWN:
direction = -1.0;
break;
case WXK_UP:
direction = 1.0;
break;
}

if (direction)
{
currRxFreq += direction * 10;
if (currRxFreq < MIN_F_HZ)
{
currRxFreq = MIN_F_HZ;
}
else if (currRxFreq > MAX_F_HZ)
{
currRxFreq = MAX_F_HZ;
}
clickTune(currRxFreq);
}
}

//-------------------------------------------------------------------------
// OnMouseMiddleDown()
//-------------------------------------------------------------------------
void PlotSpectrum::OnMouseMiddleDown(wxMouseEvent& event)
{
clickTune(FDMDV_FCENTRE);
}
3 changes: 3 additions & 0 deletions src/gui/controls/plot_spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class PlotSpectrum : public PlotPanel
void draw(wxGraphicsContext* ctx);
void OnMouseLeftDoubleClick(wxMouseEvent& event);
void OnMouseRightDoubleClick(wxMouseEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event);
void OnMouseMiddleDown(wxMouseEvent& event);
void OnKeyDown(wxKeyEvent& event);

private:
float m_rxFreq;
Expand Down
101 changes: 93 additions & 8 deletions src/gui/controls/plot_waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
#include "os/os_interface.h"

#include "plot_waterfall.h"
#include "codec2_fdmdv.h" // for FDMDV_FCENTRE

// Tweak accordingly
#define Y_PER_SECOND (30)

extern float g_avmag[]; // av mag spec passed in to draw()
extern float g_RxFreqOffsetHz;
void clickTune(float frequency); // callback to pass new click freq

BEGIN_EVENT_TABLE(PlotWaterfall, PlotPanel)
Expand All @@ -38,9 +40,11 @@ BEGIN_EVENT_TABLE(PlotWaterfall, PlotPanel)
EVT_LEFT_DCLICK (PlotWaterfall::OnMouseLeftDoubleClick)
EVT_LEFT_UP (PlotWaterfall::OnMouseLeftUp)
EVT_RIGHT_DCLICK (PlotWaterfall::OnMouseRightDoubleClick)
EVT_MIDDLE_DOWN (PlotWaterfall::OnMouseMiddleDown)
EVT_MOUSEWHEEL (PlotWaterfall::OnMouseWheelMoved)
EVT_SIZE (PlotWaterfall::OnSize)
EVT_SHOW (PlotWaterfall::OnShow)
EVT_KEY_DOWN (PlotWaterfall::OnKeyDown)
END_EVENT_TABLE()

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
Expand Down Expand Up @@ -73,6 +77,7 @@ PlotWaterfall::PlotWaterfall(wxWindow* parent, bool graticule, int colour): Plot
m_max_mag = MAX_MAG_DB;
m_min_mag = MIN_MAG_DB;
m_fullBmp = NULL;
sync_ = false;
}

// When the window size gets set we can work outthe size of the window
Expand Down Expand Up @@ -306,12 +311,27 @@ void PlotWaterfall::drawGraticule(wxGraphicsContext* ctx)
if (!overlappedText)
ctx->DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2);
}

// red rx tuning line
ctx->SetPen(wxPen(RED_COLOR, 2));
x = m_rxFreq*freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
ctx->StrokeLine(x, 0, x, PLOT_BORDER + YBOTTOM_TEXT_OFFSET + 5);

float verticalBarLength = PLOT_BORDER + YBOTTOM_TEXT_OFFSET + 5;

float sum = 0.0;
for (auto& f : rxOffsets_)
{
sum += f;
}
float averageOffset = sum / rxOffsets_.size();

// get average offset and draw sync tuning line
ctx->SetPen(wxPen(sync_ ? GREEN_COLOR : ORANGE_COLOR, 3));
x = (m_rxFreq + averageOffset) * freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
ctx->StrokeLine(x, 0, x, verticalBarLength);

// red rx tuning line
ctx->SetPen(wxPen(RED_COLOR, 3));
x = m_rxFreq*freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
ctx->StrokeLine(x, 0, x, 2 * verticalBarLength / 3);
}

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -435,13 +455,71 @@ void PlotWaterfall::OnDoubleClickCommon(wxMouseEvent& event)
if ((pt.x >= 0) && (pt.x <= m_imgWidth) && (pt.y >=0))
{
float freq_hz_to_px = (float)m_imgWidth/(MAX_F_HZ-MIN_F_HZ);
float clickFreq = (float)pt.x/freq_hz_to_px;

int clickFreq = (int)((float)pt.x/freq_hz_to_px);
clickFreq -= clickFreq % 10;

// communicate back to other threads
clickTune(clickFreq);
}
}

//-------------------------------------------------------------------------
// OnMouseWheelMoved()
//-------------------------------------------------------------------------
void PlotWaterfall::OnMouseWheelMoved(wxMouseEvent& event)
{
float currRxFreq = FDMDV_FCENTRE - g_RxFreqOffsetHz;
float direction = 1.0;
if (event.GetWheelRotation() < 0)
{
direction = -1.0;
}

currRxFreq += direction * 10;
if (currRxFreq < MIN_F_HZ)
{
currRxFreq = MIN_F_HZ;
}
else if (currRxFreq > MAX_F_HZ)
{
currRxFreq = MAX_F_HZ;
}
clickTune(currRxFreq);
}

//-------------------------------------------------------------------------
// OnKeyDown()
//-------------------------------------------------------------------------
void PlotWaterfall::OnKeyDown(wxKeyEvent& event)
{
float currRxFreq = FDMDV_FCENTRE - g_RxFreqOffsetHz;
float direction = 0;

switch (event.GetKeyCode())
{
case WXK_DOWN:
direction = -1.0;
break;
case WXK_UP:
direction = 1.0;
break;
}

if (direction)
{
currRxFreq += direction * 10;
if (currRxFreq < MIN_F_HZ)
{
currRxFreq = MIN_F_HZ;
}
else if (currRxFreq > MAX_F_HZ)
{
currRxFreq = MAX_F_HZ;
}
clickTune(currRxFreq);
}
}

//-------------------------------------------------------------------------
// OnMouseLeftDown()
//-------------------------------------------------------------------------
Expand All @@ -458,3 +536,10 @@ void PlotWaterfall::OnMouseRightDoubleClick(wxMouseEvent& event)
OnDoubleClickCommon(event);
}

//-------------------------------------------------------------------------
// OnMouseMiddleDown()
//-------------------------------------------------------------------------
void PlotWaterfall::OnMouseMiddleDown(wxMouseEvent& event)
{
clickTune(FDMDV_FCENTRE);
}
Loading

0 comments on commit fb9d36a

Please sign in to comment.