aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/stmdsp.cpp15
-rw-r--r--gui/stmdsp.hpp2
-rw-r--r--gui/wxmain.hpp21
3 files changed, 38 insertions, 0 deletions
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<uint8_t *>(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<uint8_t>(size),
+ static_cast<uint8_t>(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<adcsample_t> 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 <wx/button.h>
#include <wx/combobox.h>
#include <wx/dcclient.h>
+#include <wx/filedlg.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/timer.h>
+#include <wx/wfstream.h>
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();
}