began work for GUI
parent
7a6f7bd792
commit
53f6b9ff28
@ -0,0 +1,15 @@
|
||||
CXX = clang++-10
|
||||
CXXFLAGS = --std=c++20 -Wall -Wextra -pedantic
|
||||
|
||||
CXXFILES = $(wildcard *.cpp)
|
||||
|
||||
OUTELF = stmdspgui
|
||||
|
||||
all: $(CXXFILES)
|
||||
@echo " CXX " $(CXXFILES)
|
||||
@$(CXX) $(CXXFLAGS) $(CXXFILES) -o $(OUTELF)
|
||||
|
||||
clean:
|
||||
@echo " CLEAN"
|
||||
@rm -f $(OUTELF)
|
||||
|
@ -0,0 +1,15 @@
|
||||
#include "stmdsp.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
stmdsp::scanner scanner;
|
||||
|
||||
scanner.scan();
|
||||
for (const auto& device : scanner.devices())
|
||||
std::cout << "Found stmdsp at: " << device.path() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
#include "stmdsp.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace stmdsp
|
||||
{
|
||||
void 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
#ifndef STMDSPSCANNER_H
|
||||
#define STMDSPSCANNER_H
|
||||
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace stmdsp
|
||||
{
|
||||
class device
|
||||
{
|
||||
public:
|
||||
device(const std::string& path) :
|
||||
m_path(path) {}
|
||||
|
||||
bool open() {
|
||||
m_stream.open(m_path, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
|
||||
return m_stream.is_open();
|
||||
}
|
||||
|
||||
std::size_t read(char *buffer, std::size_t count) {
|
||||
return m_stream.readsome(buffer, count);
|
||||
}
|
||||
|
||||
std::size_t write(const char *buffer, std::size_t count) {
|
||||
m_stream.write(buffer, count);
|
||||
return m_stream.good() ? count : 0;
|
||||
}
|
||||
|
||||
const std::string& path() const {
|
||||
return m_path;
|
||||
}
|
||||
|
||||
auto operator<=>(const device& other) const {
|
||||
return m_path <=> other.m_path;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_path;
|
||||
std::fstream m_stream;
|
||||
};
|
||||
|
||||
class scanner
|
||||
{
|
||||
private:
|
||||
constexpr static unsigned int STMDSP_VENDOR_ID = 0x0483;
|
||||
constexpr static unsigned int STMDSP_DEVICE_ID = 0x5740;
|
||||
|
||||
public:
|
||||
void scan();
|
||||
const auto& devices() const {
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<device> m_devices;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // STMDSPSCANNER_H
|
Loading…
Reference in New Issue