From 876bbbec3a6bf3d02d4ab7020cc73eaa6e247e9e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 12 Jun 2020 18:49:09 -0400 Subject: have basic wxwidgets gui working --- gui/main.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'gui/main.cpp') diff --git a/gui/main.cpp b/gui/main.cpp index 48f2990..ae6ecb4 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,15 +1,19 @@ #include "stmdsp.hpp" +#include "wxapp.hpp" #include +#include -int main() -{ - stmdsp::scanner scanner; +wxIMPLEMENT_APP(MainApp); - scanner.scan(); - for (const auto& device : scanner.devices()) - std::cout << "Found stmdsp at: " << device.path() << std::endl; - - return 0; -} +//int main() +//{ +// stmdsp::scanner scanner; +// +// scanner.scan(); +// for (const auto& device : scanner.devices()) +// std::cout << "Found stmdsp at: " << device.path() << std::endl; +// +// return 0; +//} -- cgit v1.2.3 From da8d7ffe8a12c10f819f103de1194511bdb3776e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 18 Jun 2020 20:40:37 -0400 Subject: drafted device interface --- gui/main.cpp | 13 ------------- gui/stmdsp.cpp | 8 ++++---- gui/stmdsp.hpp | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 20 deletions(-) (limited to 'gui/main.cpp') diff --git a/gui/main.cpp b/gui/main.cpp index ae6ecb4..29f74d3 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,19 +1,6 @@ -#include "stmdsp.hpp" #include "wxapp.hpp" -#include #include wxIMPLEMENT_APP(MainApp); -//int main() -//{ -// stmdsp::scanner scanner; -// -// scanner.scan(); -// for (const auto& device : scanner.devices()) -// std::cout << "Found stmdsp at: " << device.path() << std::endl; -// -// return 0; -//} - diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp index 5445264..4812884 100644 --- a/gui/stmdsp.cpp +++ b/gui/stmdsp.cpp @@ -6,12 +6,12 @@ namespace stmdsp { std::list& scanner::scan() { - auto serialDevices = serial::list_ports(); - for (auto& device : serialDevices) { + auto devices = serial::list_ports(); + for (auto& device : devices) { if (device.hardware_id.find(STMDSP_USB_ID) != std::string::npos) - m_devices.emplace_front(device.port); + m_available_devices.emplace_front(device.port); } - return m_devices; + return m_available_devices; } } diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp index 7695abe..030038d 100644 --- a/gui/stmdsp.hpp +++ b/gui/stmdsp.hpp @@ -1,8 +1,9 @@ #ifndef STMDSP_HPP_ #define STMDSP_HPP_ -#include +#include #include +#include #include namespace stmdsp @@ -15,11 +16,45 @@ namespace stmdsp public: std::list& scan(); auto& devices() { - return m_devices; + return m_available_devices; } private: - std::list m_devices; + std::list m_available_devices; + }; + + using adcsample_t = uint16_t; + + class device + { + public: + device(const std::string& file) : + m_serial(file, 115200, serial::Timeout::simpleTimeout(1000)) {} + + ~device() { + m_serial.close(); + } + + bool connected() { + return m_serial.isOpen() && (m_serial.write("i"), m_serial.read(6) == "stmdsp"); + } + + std::vector sample(unsigned long int count = 1) { + if (connected()) { + m_serial.write(std::vector {'r', + static_cast(count), + static_cast(count >> 8)}); + std::vector data (count); + m_serial.read(reinterpret_cast(data.data()), + data.size() * sizeof(adcsample_t)); + return data; + } else { + return {}; + } + } + + private: + serial::Serial m_serial; }; } -- cgit v1.2.3