diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2020-08-22 10:31:45 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2020-08-22 10:31:45 -0400 |
commit | b3eccbc1b9f0194d9f71345113acdc4518b991c1 (patch) | |
tree | 67e77c98ac03776e43347f2bd7e9daa5e6510013 /gui | |
parent | 989f4038c6d2a3e5bbee04fa25df181810af621e (diff) |
working: continuous signal passthrough
Diffstat (limited to 'gui')
-rw-r--r-- | gui/stmdsp.cpp | 31 | ||||
-rw-r--r-- | gui/stmdsp.hpp | 6 | ||||
-rw-r--r-- | gui/wxmain.hpp | 9 |
3 files changed, 39 insertions, 7 deletions
diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp index 837d09c..ed152f7 100644 --- a/gui/stmdsp.cpp +++ b/gui/stmdsp.cpp @@ -16,7 +16,14 @@ namespace stmdsp } device::device(const std::string& file) : - m_serial(file, 230400, serial::Timeout::simpleTimeout(50)) {} + m_serial(file, 230400, serial::Timeout::simpleTimeout(50)) + { + if (m_serial.isOpen()) { + m_serial.write("i"); + if (m_serial.read(6) != "stmdsp") + m_serial.close(); + } + } std::vector<adcsample_t> device::sample(unsigned long int count) { if (connected()) { @@ -27,11 +34,29 @@ namespace stmdsp }; m_serial.write(request, 3); std::vector<adcsample_t> data (count); - m_serial.read(reinterpret_cast<uint8_t *>(data.data()), - data.size() * sizeof(adcsample_t)); + m_serial.read(reinterpret_cast<uint8_t *>(data.data()), data.size() * sizeof(adcsample_t)); return data; } else { return {}; } } + + void device::continuous_start() { + if (connected()) + m_serial.write("R"); + } + + std::vector<adcsample_t> device::continuous_read() { + if (connected()) { + m_serial.write("s"); + std::vector<adcsample_t> data (2048); + m_serial.read(reinterpret_cast<uint8_t *>(data.data()), 2048 * sizeof(adcsample_t)); + return data; + } + } + + void device::continuous_stop() { + if (connected()) + m_serial.write("S"); + } } diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp index 2148fa1..c179955 100644 --- a/gui/stmdsp.hpp +++ b/gui/stmdsp.hpp @@ -35,11 +35,15 @@ namespace stmdsp } bool connected() { - return m_serial.isOpen() && (m_serial.write("i"), m_serial.read(6) == "stmdsp"); + return m_serial.isOpen(); } std::vector<adcsample_t> sample(unsigned long int count = 1); + void continuous_start(); + std::vector<adcsample_t> continuous_read(); + void continuous_stop(); + private: serial::Serial m_serial; }; diff --git a/gui/wxmain.hpp b/gui/wxmain.hpp index 97baae3..1fc74bd 100644 --- a/gui/wxmain.hpp +++ b/gui/wxmain.hpp @@ -78,7 +78,7 @@ public: void doSingle() { m_device_samples_future = std::async(std::launch::async, - [this]() { return m_device->sample(250); }); + [this]() { return m_device->continuous_read(); }); } void onSinglePressed(wxCommandEvent& ce) { @@ -87,8 +87,10 @@ public: if (!m_render_timer->IsRunning()) { m_device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); if (m_device->connected()) { - doSingle(); - m_render_timer->Start(100); + m_device->continuous_start(); + m_device_samples_future = std::async(std::launch::async, + []() { return decltype(m_device_samples)(); }); + m_render_timer->Start(1000); button->SetLabel("Stop"); } else { delete m_device; @@ -96,6 +98,7 @@ public: } } else { m_render_timer->Stop(); + m_device->continuous_stop(); button->SetLabel("Single"); delete m_device; |