From ab00f501f1363802282986ea9ab86d2e305bc24d Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 25 Nov 2019 10:34:42 +0100 Subject: [PATCH] #3230 - Detection of 3Dconnexion devices every 2 seconds --- src/slic3r/GUI/Mouse3DController.cpp | 10 ++++++++++ src/slic3r/GUI/Mouse3DController.hpp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 44bc0fd34..39542e652 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -186,6 +186,7 @@ Mouse3DController::Mouse3DController() , m_running(false) , m_settings_dialog(false) { + m_last_time = std::chrono::high_resolution_clock::now(); } void Mouse3DController::init() @@ -332,9 +333,18 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign bool Mouse3DController::connect_device() { + static const long long DETECTION_TIME = 2; // seconds + if (is_device_connected()) return false; + // check time since last detection took place + auto now = std::chrono::high_resolution_clock::now(); + if (std::chrono::duration_cast(now - m_last_time).count() < DETECTION_TIME) + return false; + + m_last_time = now; + // Enumerates devices hid_device_info* devices = hid_enumerate(0, 0); if (devices == nullptr) diff --git a/src/slic3r/GUI/Mouse3DController.hpp b/src/slic3r/GUI/Mouse3DController.hpp index 161274b5a..40c489853 100644 --- a/src/slic3r/GUI/Mouse3DController.hpp +++ b/src/slic3r/GUI/Mouse3DController.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace Slic3r { namespace GUI { @@ -130,6 +131,7 @@ class Mouse3DController std::string m_device_str; bool m_running; bool m_settings_dialog; + std::chrono::time_point m_last_time; public: Mouse3DController();