From 32fc992f6a41a9a139aaaa6569f549b54c8a912f Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 22 Aug 2020 20:34:03 -0400 Subject: filter loading and real-time execution --- gui/stmdsp.cpp | 15 +++++++++++++++ gui/stmdsp.hpp | 2 ++ gui/wxmain.hpp | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) (limited to 'gui') diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp index ed152f7..73ae880 100644 --- a/gui/stmdsp.cpp +++ b/gui/stmdsp.cpp @@ -53,10 +53,25 @@ namespace stmdsp m_serial.read(reinterpret_cast(data.data()), 2048 * sizeof(adcsample_t)); return data; } + + return {}; } void device::continuous_stop() { if (connected()) m_serial.write("S"); } + + void device::upload_filter(unsigned char *buffer, size_t size) { + if (connected()) { + uint8_t request[3] = { + 'e', + static_cast(size), + static_cast(size >> 8) + }; + m_serial.write(request, 3); + + m_serial.write(buffer, size); + } + } } diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp index c179955..ec58e5a 100644 --- a/gui/stmdsp.hpp +++ b/gui/stmdsp.hpp @@ -44,6 +44,8 @@ namespace stmdsp std::vector continuous_read(); void continuous_stop(); + void upload_filter(unsigned char *buffer, size_t size); + private: serial::Serial m_serial; }; diff --git a/gui/wxmain.hpp b/gui/wxmain.hpp index 1fc74bd..289e891 100644 --- a/gui/wxmain.hpp +++ b/gui/wxmain.hpp @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include class MainFrame : public wxFrame { @@ -18,6 +20,7 @@ class MainFrame : public wxFrame Welcome = 1, Single, SelectDevice, + UploadFilter, RenderTimer }; @@ -36,6 +39,7 @@ public: { new wxStaticText(this, Id::Welcome, "Welcome to the GUI.", wxPoint(20, 20)); new wxButton(this, Id::Single, "Single", wxPoint(20, 60)); + new wxButton(this, Id::UploadFilter, "Upload Filter", wxPoint(120, 60)); m_device_combo = new wxComboBox(this, Id::SelectDevice, "", wxPoint(470, 20), wxSize(150, 30)); m_device_combo->SetEditable(false); stmdsp::scanner scanner; @@ -47,6 +51,7 @@ public: m_render_timer = new wxTimer(this, Id::RenderTimer); Bind(wxEVT_BUTTON, &MainFrame::onSinglePressed, this, Id::Single); + Bind(wxEVT_BUTTON, &MainFrame::onUploadPressed, this, Id::UploadFilter); Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY); Bind(wxEVT_TIMER, &MainFrame::onRenderTimer, this, Id::RenderTimer); } @@ -106,6 +111,22 @@ public: } } + void onUploadPressed(wxCommandEvent& ce) { + wxFileDialog dialog (this, "Select filter to upload", "", "", "*.so", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (dialog.ShowModal() != wxID_CANCEL) { + if (wxFileInputStream file_stream (dialog.GetPath()); file_stream.IsOk()) { + auto size = file_stream.GetSize(); + auto buffer = new unsigned char[size]; + auto device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); + if (device->connected()) { + file_stream.ReadAll(buffer, size); + device->upload_filter(buffer, size); + } + } + } + } + void onRenderTimer([[maybe_unused]] wxTimerEvent& te) { updateDrawing(); } -- cgit v1.2.3