aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-10-20 12:27:21 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-10-20 12:27:21 -0400
commit30cd119dba0e2caf48b6bf5016f60dcede62f511 (patch)
treedfc6d4321938bfb2e32cf9b6ca6af82274ac2625 /gui
parentf1ad9796741daa8368f4885bbce360522df24367 (diff)
signal gen with dac channel 2
Diffstat (limited to 'gui')
-rw-r--r--gui/stmdsp.cpp23
-rw-r--r--gui/stmdsp.hpp7
-rw-r--r--gui/wxmain.cpp64
-rw-r--r--gui/wxmain.hpp2
4 files changed, 96 insertions, 0 deletions
diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp
index 8f19065..87b608d 100644
--- a/gui/stmdsp.cpp
+++ b/gui/stmdsp.cpp
@@ -77,6 +77,29 @@ namespace stmdsp
m_serial.write("S");
}
+ void device::siggen_upload(dacsample_t *buffer, unsigned int size) {
+ if (connected()) {
+ uint8_t request[3] = {
+ 'D',
+ static_cast<uint8_t>(size),
+ static_cast<uint8_t>(size >> 8)
+ };
+ m_serial.write(request, 3);
+
+ m_serial.write((uint8_t *)buffer, size * sizeof(dacsample_t));
+ }
+ }
+
+ void device::siggen_start() {
+ if (connected())
+ m_serial.write("W");
+ }
+
+ void device::siggen_stop() {
+ if (connected())
+ m_serial.write("w");
+ }
+
void device::upload_filter(unsigned char *buffer, size_t size) {
if (connected()) {
uint8_t request[3] = {
diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp
index 2d336c5..a9b8b7e 100644
--- a/gui/stmdsp.hpp
+++ b/gui/stmdsp.hpp
@@ -24,6 +24,7 @@ namespace stmdsp
};
using adcsample_t = uint16_t;
+ using dacsample_t = uint16_t;
class device
{
@@ -40,12 +41,18 @@ namespace stmdsp
//std::vector<adcsample_t> sample(unsigned long int count = 1);
+ void continuous_set_buffer_size(unsigned int size);
void continuous_start();
void continuous_start_measure();
uint32_t continuous_start_get_measurement();
std::vector<adcsample_t> continuous_read();
void continuous_stop();
+ void siggen_upload(dacsample_t *buffer, unsigned int size);
+ void siggen_start();
+ void siggen_stop();
+
+ // buffer is ELF binary
void upload_filter(unsigned char *buffer, size_t size);
void unload_filter();
diff --git a/gui/wxmain.cpp b/gui/wxmain.cpp
index 58f0d37..aa57066 100644
--- a/gui/wxmain.cpp
+++ b/gui/wxmain.cpp
@@ -10,6 +10,9 @@
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/statusbr.h>
+#include <wx/textdlg.h>
+
+#include <vector>
enum Id {
MeasureTimer = 1,
@@ -25,6 +28,8 @@ enum Id {
MRunMeasure,
MRunUpload,
MRunUnload,
+ MRunGenUpload,
+ MRunGenStart,
MCodeCompile,
MCodeDisassemble
};
@@ -99,6 +104,12 @@ MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50)
Bind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY,
menuRun->Append(MRunUnload, "U&nload code"));
+ menuRun->AppendSeparator();
+ Bind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY,
+ menuRun->Append(MRunGenUpload, "&Load signal generator..."));
+ Bind(wxEVT_MENU, &MainFrame::onRunGenStart, this, Id::MRunGenStart, wxID_ANY,
+ menuRun->AppendCheckItem(MRunGenStart, "Start &generator"));
+
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY,
menuCode->Append(MCodeCompile, "&Compile code"));
Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY,
@@ -398,6 +409,59 @@ void MainFrame::onRunStart(wxCommandEvent& ce)
}
}
+void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
+{
+ if (m_device != nullptr && m_device->connected()) {
+ wxTextEntryDialog dialog (this, "Enter generator values", "Hey");
+ if (dialog.ShowModal() == wxID_OK) {
+ if (wxString values = dialog.GetValue(); !values.IsEmpty()) {
+ std::vector<stmdsp::dacsample_t> samples;
+ while (!values.IsEmpty()) {
+ if (auto number_end = values.find_first_not_of("0123456789");
+ number_end != wxString::npos && number_end > 0)
+ {
+ auto number = values.Left(number_end);
+ if (unsigned long n; number.ToULong(&n))
+ samples.push_back(n & 4095);
+
+ if (auto next = values.find_first_of("0123456789", number_end + 1);
+ next != wxString::npos)
+ {
+ values = values.Mid(next);
+ } else {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ m_device->siggen_upload(&samples[0], samples.size());
+ }
+ }
+ } else {
+ wxMessageBox("No device connected!", "Run", wxICON_WARNING);
+ m_status_bar->SetStatusText("Please connect.");
+ }
+}
+
+void MainFrame::onRunGenStart(wxCommandEvent& ce)
+{
+ auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
+ if (m_device != nullptr && m_device->connected()) {
+ if (menuItem->IsChecked()) {
+ m_device->siggen_start();
+ menuItem->SetItemLabel("Stop &generator");
+ } else {
+ m_device->siggen_stop();
+ menuItem->SetItemLabel("Start &generator");
+ }
+ } else {
+ wxMessageBox("No device connected!", "Run", wxICON_WARNING);
+ m_status_bar->SetStatusText("Please connect.");
+ }
+}
+
void MainFrame::onRunUpload([[maybe_unused]] wxCommandEvent&)
{
if (auto file = compileEditorCode(); !file.IsEmpty()) {
diff --git a/gui/wxmain.hpp b/gui/wxmain.hpp
index ce3e5a5..0da0b79 100644
--- a/gui/wxmain.hpp
+++ b/gui/wxmain.hpp
@@ -36,6 +36,8 @@ public:
void onRunStart(wxCommandEvent&);
void onRunUpload(wxCommandEvent&);
void onRunUnload(wxCommandEvent&);
+ void onRunGenUpload(wxCommandEvent&);
+ void onRunGenStart(wxCommandEvent&);
void onRunCompile(wxCommandEvent&);
void onCodeDisassemble(wxCommandEvent&);