From 1c05d88c008c9d2b27cc43722e322c8df5fd9b05 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 11 Oct 2019 15:29:57 +0200 Subject: [PATCH] ENABLE_3DCONNEXION_DEVICES -> Added support for 3Dconnexion universal receiver and battery level report --- resources/udev/90-3dconnexion.rules | 42 ++++++++++++++++----- src/slic3r/GUI/Mouse3DController.cpp | 55 ++++++++++++---------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/resources/udev/90-3dconnexion.rules b/resources/udev/90-3dconnexion.rules index 035d17125..670d91790 100644 --- a/resources/udev/90-3dconnexion.rules +++ b/resources/udev/90-3dconnexion.rules @@ -1,23 +1,45 @@ # See src/slic3r/GUI/Mouse3DController.cpp for the list of devices # Logitech vendor devices -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c623", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c626", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c628", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c627", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c603", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62b", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c605", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c606", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c621", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c623", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c625", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c626", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c627", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c628", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c629", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62b", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62e", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62f", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c631", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c632", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c633", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c635", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c636", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c640", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c652", MODE="0666" # 3D Connexion vendor devices -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c623", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c626", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c628", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c627", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c603", MODE="0666" -SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62b", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c605", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c606", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c621", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c623", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c625", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c626", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c627", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c628", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c629", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62b", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62e", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62f", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c631", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c632", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c633", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c635", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c636", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c640", MODE="0666" +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c652", MODE="0666" diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 7e3be9047..d75ad4390 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -46,8 +46,7 @@ static const std::vector _3DCONNEXION_DEVICES = 0xc635, /* 50741 spacemouse compact *TESTED* */ 0xc636, /* 50742 spacemouse module */ 0xc640, /* 50752 nulooq */ - -// 0xc652, /* 50770 3Dconnexion universal receiver */ + 0xc652, /* 50770 3Dconnexion universal receiver *TESTED* */ }; namespace Slic3r { @@ -336,12 +335,11 @@ bool Mouse3DController::connect_device() } // Searches for 1st connected 3Dconnexion device + std::string path = ""; unsigned short vendor_id = 0; unsigned short product_id = 0; #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT - unsigned short usage_page = 0; - unsigned short usage = 0; hid_device_info* cur = devices; while (cur != nullptr) { @@ -371,13 +369,10 @@ bool Mouse3DController::connect_device() { for (size_t i = 0; i < _3DCONNEXION_DEVICES.size(); ++i) { - if (_3DCONNEXION_DEVICES[i] == current->product_id) + if ((_3DCONNEXION_DEVICES[i] == current->product_id) && (current->usage_page == 1) && (current->usage == 8)) { product_id = current->product_id; -#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT - usage_page = current->usage_page; - usage = current->usage; -#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT + path = current->path; break; } } @@ -398,8 +393,8 @@ bool Mouse3DController::connect_device() if (vendor_id == 0) return false; - // Open the 3Dconnexion device using the VID, PID - m_device = hid_open(vendor_id, product_id, nullptr); + // Open the 3Dconnexion device using the device path + m_device = hid_open_path(path.c_str()); if (m_device != nullptr) { @@ -415,27 +410,9 @@ bool Mouse3DController::connect_device() #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT std::cout << std::endl << "Connected device:" << std::endl; - std::cout << "Manufacturer/product..........: " << m_device_str << std::endl; - std::cout << "Manufacturer id/product id....: " << vendor_id << "/" << product_id << std::endl; - std::cout << "Manufacturer id/product id hex: " << std::hex << vendor_id << "/" << product_id << std::dec << std::endl; - std::cout << "Usage page....................: " << usage_page << std::endl; - std::cout << "Usage.........................: " << usage << std::endl << std::endl; - - std::cout << "Feature reports:" << std::endl; - for (int i = 0; i < 256; ++i) - { - DataPacket packet = { 0 }; - packet[0] = (unsigned char)i; - int res = hid_get_feature_report(m_device, packet.data(), packet.size()); - if (res > 0) - { - for (int j = 0; j < res; ++j) - { - std::cout << " " << (int)packet[j]; - } - std::cout << std::endl; - } - } + std::cout << "Manufacturer/product: " << m_device_str << std::endl; + std::cout << "Manufacturer id.....: " << vendor_id << " (" << std::hex << vendor_id << std::dec << ")" << std::endl; + std::cout << "Product id..........: " << product_id << " (" << std::hex << product_id << std::dec << ")" << std::endl; #endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT // get device parameters from the config, if present @@ -552,6 +529,13 @@ bool Mouse3DController::handle_packet(const DataPacket& packet) if (handle_packet_button(packet, 6)) return true; + break; + } + case 23: // Battery charge + { +#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT + std::cout << m_device_str << " - battery level: " << (int)packet[1] << " percent" << std::endl; +#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT break; } default: @@ -585,6 +569,13 @@ bool Mouse3DController::handle_wireless_packet(const DataPacket& packet) if (handle_packet_button(packet, 12)) return true; + break; + } + case 23: // Battery charge + { +#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT + std::cout << m_device_str << " - battery level: " << (int)packet[1] << " percent" << std::endl; +#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT break; } default: