diff --git a/src/handler.cpp b/src/handler.cpp index ae7b3a0c..e0cbf1ad 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -34,6 +34,24 @@ void initDevices() { // std::cout << "Device initialization complete.\n"; } +void searchDevices() { + initDevices(); + if (devices.empty()) { + std::cout << "No devices found.\n"; + } + stopAllDevices(); +} + +void stopAllDevices() { + if (sampler.has_value()) { + for (auto &device : sampler->sampleDevices) { + device.first->send(Omniscope::Stop{}); + } + } + devices.clear(); + deviceManager.clearDevices(); +} + void consoleHandler(bool &flagPaused, std::set& selected_serials) { std::string input; while (running) { @@ -53,9 +71,8 @@ void consoleHandler(bool &flagPaused, std::set& selected_serials) { input.erase(0, pos + 1); } selected_serials.insert(input); - } - else { - std::cout << "No devices fpound.\n"; + } else { + std::cout << "No devices found.\n"; } } else if (input == "Start") { @@ -97,5 +114,6 @@ void signalHandler(int signal) { if (signal == SIGINT) { std::cout << "\nSIGINT received, shutting down gracefully...\n"; running = false; + stopAllDevices(); } } diff --git a/src/handler.hpp b/src/handler.hpp index 8e463997..007175bc 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -16,7 +16,10 @@ inline std::map>> captureDa inline std::atomic running{true}; void initDevices(); +void searchDevices(std::set& selected_serials); void consoleHandler(bool &flagPaused, std::set& selected_serials); void signalHandler(int signal); +void stopAllDevices(); +void searchDevices(); #endif diff --git a/src/main.cpp b/src/main.cpp index 2d150429..fbfdfcf9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,13 +9,20 @@ int main(int argc, char** argv) { bool flagPaused{true}; std::set selected_serials; std::string wsURI; + bool search = false; CLI::App app{"OmniView"}; app.add_option("-w, --wsuri", wsURI, "WebSocket URI")->type_name(""); + app.add_flag("--search", search, "Search for devices"); CLI11_PARSE(app, argc, argv); + if (search) { + searchDevices(); + return 0; + } + WebSocketHandler wsHandler(wsURI); // Signal handler for SIGINT