#3230 - Detection of 3Dconnexion devices every 2 seconds

This commit is contained in:
Enrico Turri 2019-11-25 10:34:42 +01:00
parent b1047d2e26
commit ab00f501f1
2 changed files with 12 additions and 0 deletions

View file

@ -186,6 +186,7 @@ Mouse3DController::Mouse3DController()
, m_running(false) , m_running(false)
, m_settings_dialog(false) , m_settings_dialog(false)
{ {
m_last_time = std::chrono::high_resolution_clock::now();
} }
void Mouse3DController::init() void Mouse3DController::init()
@ -332,9 +333,18 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign
bool Mouse3DController::connect_device() bool Mouse3DController::connect_device()
{ {
static const long long DETECTION_TIME = 2; // seconds
if (is_device_connected()) if (is_device_connected())
return false; return false;
// check time since last detection took place
auto now = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(now - m_last_time).count() < DETECTION_TIME)
return false;
m_last_time = now;
// Enumerates devices // Enumerates devices
hid_device_info* devices = hid_enumerate(0, 0); hid_device_info* devices = hid_enumerate(0, 0);
if (devices == nullptr) if (devices == nullptr)

View file

@ -12,6 +12,7 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <chrono>
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -130,6 +131,7 @@ class Mouse3DController
std::string m_device_str; std::string m_device_str;
bool m_running; bool m_running;
bool m_settings_dialog; bool m_settings_dialog;
std::chrono::time_point<std::chrono::steady_clock> m_last_time;
public: public:
Mouse3DController(); Mouse3DController();