实现串口监控功能,重构 ComKit::Work 方法以支持指定端口

This commit is contained in:
JIe
2024-11-07 17:35:02 +08:00
parent cea5209222
commit 7316c326d0
7 changed files with 365 additions and 312 deletions

View File

@@ -1,4 +1,5 @@
#include "ComKit.h"
#include "ComWatch.h"
#include "imgui_helper.h"
#include "imgui_stdlib.h"
#include "spdlog/sinks/basic_file_sink.h"
@@ -67,6 +68,25 @@ int main(int argc, char **) {
filterComName = config.at("ComPorts").as_string();
inputCommands = config.at("Commands").as_string();
}
SerialWatch watcher;
watcher.set_callback([](const std::string &port_name, SIGNAL_TYPE type) {
switch (type) {
case SIGNAL_TYPE::REMOVE_:
spdlog::log(spdlog::level::debug,
std::format("port: [{}] removed", port_name));
ComKit::FlushLog();
ComKit::GetAllComPortNames();
break;
case SIGNAL_TYPE::ADD_:
spdlog::log(spdlog::level::debug,
std::format("port: [{}] add", port_name));
ComKit::FlushLog();
ComKit::GetAllComPortNames();
ComKit::Work(port_name);
break;
}
});
watcher.work();
while (isRunning)
helper.Render(
[&]() {