aboutsummaryrefslogtreecommitdiffstats
path: root/gui/stmdsp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/stmdsp.cpp')
-rw-r--r--gui/stmdsp.cpp48
1 files changed, 27 insertions, 21 deletions
diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp
index 267bebc..837d09c 100644
--- a/gui/stmdsp.cpp
+++ b/gui/stmdsp.cpp
@@ -1,31 +1,37 @@
#include "stmdsp.hpp"
-#include <chrono>
-#include <filesystem>
-#include <thread>
-
-using namespace std::chrono_literals;
+#include <serial/serial.h>
namespace stmdsp
{
- void scanner::scan()
+ std::list<std::string>& scanner::scan()
{
- std::string path ("/dev/ttyACM0");
+ auto devices = serial::list_ports();
+ for (auto& device : devices) {
+ if (device.hardware_id.find(STMDSP_USB_ID) != std::string::npos)
+ m_available_devices.emplace_front(device.port);
+ }
+
+ return m_available_devices;
+ }
+
+ device::device(const std::string& file) :
+ m_serial(file, 230400, serial::Timeout::simpleTimeout(50)) {}
- for (unsigned int i = 0; i < 10; i++) {
- path.back() = '0' + i;
- if (std::filesystem::exists(path)) {
- if (device dev (path); dev.open()) {
- dev.write("i", 1);
- std::this_thread::sleep_for(1s);
- char buf[7];
- if (dev.read(buf, 6) == 6) {
- buf[6] = '\0';
- if (std::string(buf) == "stmdsp")
- m_devices.emplace(std::move(dev));
- }
- }
- }
+ std::vector<adcsample_t> device::sample(unsigned long int count) {
+ if (connected()) {
+ uint8_t request[3] = {
+ 'r',
+ static_cast<uint8_t>(count),
+ static_cast<uint8_t>(count >> 8)
+ };
+ 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));
+ return data;
+ } else {
+ return {};
}
}
}