Add the histogram viewer and clock guess button.

This commit is contained in:
dg
2023-04-05 20:43:49 +00:00
parent 56a4926bd3
commit 8e0ca85d1e
7 changed files with 1174 additions and 848 deletions

View File

@@ -8,6 +8,7 @@ FLUXENGINE_GUI_SRCS = \
src/gui/fileviewerwindow.cc \ src/gui/fileviewerwindow.cc \
src/gui/fluxviewercontrol.cc \ src/gui/fluxviewercontrol.cc \
src/gui/fluxviewerwindow.cc \ src/gui/fluxviewerwindow.cc \
src/gui/histogramviewer.cc \
src/gui/iconbutton.cc \ src/gui/iconbutton.cc \
src/gui/idlepanel.cc \ src/gui/idlepanel.cc \
src/gui/imagerpanel.cc \ src/gui/imagerpanel.cc \

View File

@@ -109,7 +109,13 @@ private:
UpdateExplorerData(); UpdateExplorerData();
} }
private: void OnGuessClockButton(wxCommandEvent& event) override
{
nanoseconds_t clock = histogram->GetMedian();
explorerClockSpinCtrl->SetValue(clock / 1e3);
UpdateExplorerData();
}
void OnQueueEmpty() override void OnQueueEmpty() override
{ {
SetState(STATE_IDLE); SetState(STATE_IDLE);
@@ -159,9 +165,9 @@ private:
FluxmapReader fmr(*_explorerFluxmap); FluxmapReader fmr(*_explorerFluxmap);
fmr.seek(explorerStartTimeSpinCtrl->GetValue() * 1e6); fmr.seek(explorerStartTimeSpinCtrl->GetValue() * 1e6);
FluxDecoder fluxDecoder(&fmr, nanoseconds_t clock =
explorerClockSpinCtrl->GetValue() * 1e3, explorerClockSpinCtrl->GetValue() * 1e3;
DecoderProto()); FluxDecoder fluxDecoder(&fmr, clock, DecoderProto());
fluxDecoder.readBits( fluxDecoder.readBits(
explorerBitOffsetSpinCtrl->GetValue()); explorerBitOffsetSpinCtrl->GetValue());
auto bits = fluxDecoder.readBits(); auto bits = fluxDecoder.readBits();
@@ -183,9 +189,10 @@ private:
std::stringstream s; std::stringstream s;
hexdump(s, bytes); hexdump(s, bytes);
explorerText->SetValue(s.str()); explorerText->SetValue(s.str());
histogram->Redraw(*_explorerFluxmap, clock);
if (_explorerUpdatePending) if (_explorerUpdatePending)
UpdateExplorerData(); UpdateExplorerData();
}); });

View File

@@ -0,0 +1,83 @@
#include "lib/globals.h"
#include "gui.h"
#include "lib/fluxmap.h"
#include "histogramviewer.h"
static constexpr int BORDER = 10;
static constexpr int WIDTH = 256;
static constexpr int HEIGHT = 100;
// clang-format off
wxBEGIN_EVENT_TABLE(HistogramViewer, wxWindow)
EVT_PAINT(HistogramViewer::OnPaint)
wxEND_EVENT_TABLE();
// clang-format on
HistogramViewer::HistogramViewer(wxWindow* parent,
wxWindowID winid,
const wxPoint& pos,
const wxSize& size,
long style):
wxWindow(parent,
winid,
pos,
wxSize(WIDTH + 2 * BORDER, HEIGHT + 2 * BORDER),
style)
{
_font = GetFont().MakeSmaller().MakeSmaller().MakeSmaller();
}
void HistogramViewer::Redraw(const Fluxmap& fluxmap, nanoseconds_t clock)
{
_data = fluxmap.guessClock();
_clock = clock;
Refresh();
}
void HistogramViewer::OnPaint(wxPaintEvent&)
{
wxPaintDC dc(this);
dc.SetBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK));
dc.Clear();
uint32_t max =
*std::max_element(std::begin(_data.buckets), std::end(_data.buckets));
dc.SetPen(*wxGREY_PEN);
for (int x = 0; x < 256; x++)
{
double v = (double)_data.buckets[x] / (double)max;
dc.DrawLine({BORDER + x, BORDER + HEIGHT},
{BORDER + x, BORDER + HEIGHT - (int)(v * HEIGHT)});
}
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine({BORDER, BORDER + HEIGHT}, {BORDER + WIDTH, BORDER + HEIGHT});
dc.DrawLine({BORDER, BORDER + HEIGHT}, {BORDER, BORDER});
dc.SetPen(*wxRED_PEN);
{
int y = ((double)_data.signalLevel / (double)max) * HEIGHT;
dc.DrawLine({0, BORDER + HEIGHT - y},
{2 * BORDER + WIDTH, BORDER + HEIGHT - y});
}
{
int x = _clock / NS_PER_TICK;
dc.DrawLine({BORDER + x, 2 * BORDER + HEIGHT}, {BORDER + x, 0});
}
{
wxString text = "Clock interval";
dc.SetFont(_font);
auto size = dc.GetTextExtent(text);
dc.DrawText(text, {BORDER + WIDTH - size.GetWidth(), BORDER + HEIGHT});
}
{
wxString text = "Frequency";
dc.SetFont(_font);
auto size = dc.GetTextExtent(text);
dc.DrawRotatedText(
text, BORDER - size.GetHeight(), BORDER + size.GetWidth(), 90);
}
}

29
src/gui/histogramviewer.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include "lib/globals.h"
#include "lib/fluxmap.h"
class HistogramViewer : public wxWindow
{
public:
HistogramViewer(wxWindow* parent,
wxWindowID winid,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0);
virtual ~HistogramViewer() {}
public:
void Redraw(const Fluxmap& fluxmap, nanoseconds_t clock);
nanoseconds_t GetMedian() const { return _data.median; }
private:
void OnPaint(wxPaintEvent&);
private:
Fluxmap::ClockData _data;
wxFont _font;
nanoseconds_t _clock;
wxDECLARE_EVENT_TABLE();
};

View File

@@ -891,6 +891,13 @@ ExplorerPanelGen::ExplorerPanelGen( wxWindow* parent, wxWindowID id, const wxPoi
fgSizer12->SetFlexibleDirection( wxBOTH ); fgSizer12->SetFlexibleDirection( wxBOTH );
fgSizer12->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); fgSizer12->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
wxFlexGridSizer* fgSizer13;
fgSizer13 = new wxFlexGridSizer( 0, 1, 0, 0 );
fgSizer13->AddGrowableCol( 0 );
fgSizer13->AddGrowableRow( 1 );
fgSizer13->SetFlexibleDirection( wxBOTH );
fgSizer13->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
wxFlexGridSizer* fgSizer10; wxFlexGridSizer* fgSizer10;
fgSizer10 = new wxFlexGridSizer( 0, 2, 0, 0 ); fgSizer10 = new wxFlexGridSizer( 0, 2, 0, 0 );
fgSizer10->AddGrowableCol( 1 ); fgSizer10->AddGrowableCol( 1 );
@@ -919,9 +926,22 @@ ExplorerPanelGen::ExplorerPanelGen( wxWindow* parent, wxWindowID id, const wxPoi
explorerStartTimeSpinCtrl->SetDigits( 3 ); explorerStartTimeSpinCtrl->SetDigits( 3 );
fgSizer10->Add( explorerStartTimeSpinCtrl, 0, wxALL|wxEXPAND, 5 ); fgSizer10->Add( explorerStartTimeSpinCtrl, 0, wxALL|wxEXPAND, 5 );
wxFlexGridSizer* fgSizer121;
fgSizer121 = new wxFlexGridSizer( 0, 2, 0, 0 );
fgSizer121->AddGrowableCol( 0 );
fgSizer121->AddGrowableRow( 0 );
fgSizer121->SetFlexibleDirection( wxBOTH );
fgSizer121->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText24 = new wxStaticText( this, wxID_ANY, wxT("Clock (us)"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText24 = new wxStaticText( this, wxID_ANY, wxT("Clock (us)"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText24->Wrap( -1 ); m_staticText24->Wrap( -1 );
fgSizer10->Add( m_staticText24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgSizer121->Add( m_staticText24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
guessButton = new wxButton( this, wxID_ANY, wxT("Guess"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgSizer121->Add( guessButton, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALIGN_TOP, 5 );
fgSizer10->Add( fgSizer121, 1, wxEXPAND, 5 );
explorerClockSpinCtrl = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 100, 4, 1 ); explorerClockSpinCtrl = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 100, 4, 1 );
explorerClockSpinCtrl->SetDigits( 1 ); explorerClockSpinCtrl->SetDigits( 1 );
@@ -952,7 +972,13 @@ ExplorerPanelGen::ExplorerPanelGen( wxWindow* parent, wxWindowID id, const wxPoi
fgSizer10->Add( explorerReverseCheckBox, 0, wxALL, 5 ); fgSizer10->Add( explorerReverseCheckBox, 0, wxALL, 5 );
fgSizer12->Add( fgSizer10, 1, wxEXPAND, 5 ); fgSizer13->Add( fgSizer10, 1, wxEXPAND, 5 );
histogram = new HistogramViewer( this, wxID_ANY, wxDefaultPosition, wxSize( 256,100 ), 0 );
fgSizer13->Add( histogram, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_TOP|wxALL, 5 );
fgSizer12->Add( fgSizer13, 1, wxEXPAND, 5 );
explorerText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxTE_DONTWRAP|wxTE_MULTILINE|wxTE_READONLY ); explorerText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxTE_DONTWRAP|wxTE_MULTILINE|wxTE_READONLY );
explorerText->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); explorerText->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
@@ -972,6 +998,7 @@ ExplorerPanelGen::ExplorerPanelGen( wxWindow* parent, wxWindowID id, const wxPoi
explorerTrackSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerTrackSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerSideSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerSideSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerStartTimeSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerStartTimeSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
guessButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ExplorerPanelGen::OnGuessClockButton ), NULL, this );
explorerClockSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerClockSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerBitOffsetSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerBitOffsetSpinCtrl->Connect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerDecodeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerDecodeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
@@ -986,6 +1013,7 @@ ExplorerPanelGen::~ExplorerPanelGen()
explorerTrackSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerTrackSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerSideSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerSideSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerStartTimeSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerStartTimeSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
guessButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ExplorerPanelGen::OnGuessClockButton ), NULL, this );
explorerClockSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerClockSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxSpinDoubleEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerBitOffsetSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerBitOffsetSpinCtrl->Disconnect( wxEVT_COMMAND_SPINCTRL_UPDATED, wxSpinEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );
explorerDecodeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this ); explorerDecodeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( ExplorerPanelGen::OnExplorerSettingChange ), NULL, this );

View File

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,7 @@
#include <wx/dataview.h> #include <wx/dataview.h>
#include <wx/gauge.h> #include <wx/gauge.h>
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include "histogramviewer.h"
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@@ -458,6 +459,7 @@ class ExplorerPanelGen : public wxPanel
wxStaticText* m_staticText231; wxStaticText* m_staticText231;
wxSpinCtrlDouble* explorerStartTimeSpinCtrl; wxSpinCtrlDouble* explorerStartTimeSpinCtrl;
wxStaticText* m_staticText24; wxStaticText* m_staticText24;
wxButton* guessButton;
wxSpinCtrlDouble* explorerClockSpinCtrl; wxSpinCtrlDouble* explorerClockSpinCtrl;
wxStaticText* m_staticText25; wxStaticText* m_staticText25;
wxSpinCtrl* explorerBitOffsetSpinCtrl; wxSpinCtrl* explorerBitOffsetSpinCtrl;
@@ -465,6 +467,7 @@ class ExplorerPanelGen : public wxPanel
wxChoice* explorerDecodeChoice; wxChoice* explorerDecodeChoice;
wxStaticText* m_staticText241; wxStaticText* m_staticText241;
wxCheckBox* explorerReverseCheckBox; wxCheckBox* explorerReverseCheckBox;
HistogramViewer* histogram;
wxTextCtrl* explorerText; wxTextCtrl* explorerText;
// Virtual event handlers, override them in your derived class // Virtual event handlers, override them in your derived class
@@ -472,6 +475,7 @@ class ExplorerPanelGen : public wxPanel
virtual void OnExplorerRefreshButton( wxCommandEvent& event ) { event.Skip(); } virtual void OnExplorerRefreshButton( wxCommandEvent& event ) { event.Skip(); }
virtual void OnExplorerSettingChange( wxSpinEvent& event ) { event.Skip(); } virtual void OnExplorerSettingChange( wxSpinEvent& event ) { event.Skip(); }
virtual void OnExplorerSettingChange( wxSpinDoubleEvent& event ) { event.Skip(); } virtual void OnExplorerSettingChange( wxSpinDoubleEvent& event ) { event.Skip(); }
virtual void OnGuessClockButton( wxCommandEvent& event ) { event.Skip(); }
virtual void OnExplorerSettingChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnExplorerSettingChange( wxCommandEvent& event ) { event.Skip(); }