#3230 - Detection of 3Dconnexion devices every 2 seconds
This commit is contained in:
parent
b1047d2e26
commit
ab00f501f1
2 changed files with 12 additions and 0 deletions
|
@ -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<std::chrono::seconds>(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)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
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<std::chrono::steady_clock> m_last_time;
|
||||
|
||||
public:
|
||||
Mouse3DController();
|
||||
|
|
Loading…
Reference in a new issue