aboutsummaryrefslogtreecommitdiffstats
path: root/gui/stmdsp.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-06-18 19:35:11 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-06-18 19:35:11 -0400
commit6473b57cefe4c13cb262ed78bf0e49fe18a20267 (patch)
tree339cd8492b9bc055330037f7d6a0036415de902f /gui/stmdsp.cpp
parent65b755658c62c8cf608c0ba46af4607fd7c74cc5 (diff)
using serial lib, can connect to device
Diffstat (limited to 'gui/stmdsp.cpp')
-rw-r--r--gui/stmdsp.cpp30
1 files changed, 8 insertions, 22 deletions
diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp
index 267bebc..5445264 100644
--- a/gui/stmdsp.cpp
+++ b/gui/stmdsp.cpp
@@ -1,31 +1,17 @@
#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");
-
- 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));
- }
- }
- }
+ auto serialDevices = serial::list_ports();
+ for (auto& device : serialDevices) {
+ if (device.hardware_id.find(STMDSP_USB_ID) != std::string::npos)
+ m_devices.emplace_front(device.port);
}
+
+ return m_devices;
}
}