OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Mouse3DHandlerMac.mm File Reference
#include "Mouse3DController.hpp"
#include <stdint.h>
#include <dlfcn.h>
#include <array>
#include <boost/log/trivial.hpp>
#include <cstdio>
Include dependency graph for Mouse3DHandlerMac.mm:

Go to the source code of this file.

Classes

struct  ConnexionDeviceState

Namespaces

namespace  Slic3r
 |/ Copyright (c) Prusa Research 2020 - 2023 Enrico Turri @enricoturri1966 |/ |/ PrusaSlicer is released under the terms of the AGPLv3 or higher |/
namespace  Slic3r::GUI

Macros

#define kConnexionClientModeTakeOver   1
#define kConnexionMaskAxis   0x3f00
#define kConnexionMaskAll   0x3fff
#define kConnexionMaskAllButtons   0xffffffff
#define kConnexionCmdHandleButtons   2
#define kConnexionCmdHandleAxis   3
#define kConnexionCmdAppSpecific   10
#define kConnexionMsgDeviceState   '3dSR'
#define kConnexionCtlGetDeviceID   '3did'
#define DECLARE_FUNC(name)
#define LOAD_FUNC(name)

Typedefs

typedef void(* AddedHandler) (uint32_t)
typedef void(* RemovedHandler) (uint32_t)
typedef void(* MessageHandler) (uint32_t, uint32_t msg_type, void *msg_arg)
typedef int16_t(* SetConnexionHandlers_ptr) (MessageHandler, AddedHandler, RemovedHandler, bool)
typedef int16_t(* InstallConnexionHandlers_ptr) (MessageHandler, AddedHandler, RemovedHandler)
typedef void(* CleanupConnexionHandlers_ptr) ()
typedef uint16_t(* RegisterConnexionClient_ptr) (uint32_t signature, const char *name, uint16_t mode, uint32_t mask)
typedef void(* SetConnexionClientButtonMask_ptr) (uint16_t clientID, uint32_t buttonMask)
typedef void(* UnregisterConnexionClient_ptr) (uint16_t clientID)
typedef int16_t(* ConnexionClientControl_ptr) (uint16_t clientID, uint32_t message, int32_t param, int32_t *result)

Functions

 DECLARE_FUNC (SetConnexionHandlers)
 DECLARE_FUNC (InstallConnexionHandlers)
 DECLARE_FUNC (CleanupConnexionHandlers)
 DECLARE_FUNC (RegisterConnexionClient)
 DECLARE_FUNC (SetConnexionClientButtonMask)
 DECLARE_FUNC (UnregisterConnexionClient)
 DECLARE_FUNC (ConnexionClientControl)
static void * load_func (void *module, const char *func_name)
static bool load_driver_functions ()
static void unload_driver ()
static void DeviceAdded (uint32_t unused)
static void DeviceRemoved (uint32_t unused)
static void DeviceEvent (uint32_t unused, uint32_t msg_type, void *msg_arg)

Variables

static Slic3r::GUI::Mouse3DController * mouse_3d_controller = nullptr
static uint16_t clientID = 0
static bool driver_loaded = false
static bool has_new_driver = false
static void * module

Class Documentation

◆ ConnexionDeviceState

struct ConnexionDeviceState
Class Members
uint16_t address
int16_t axis[6]
uint32_t buttons
uint16_t buttons8
uint16_t client
uint16_t command
int16_t param
uint8_t report[8]
uint64_t time
int32_t value
uint16_t version

Macro Definition Documentation

◆ DECLARE_FUNC

#define DECLARE_FUNC ( name)
Value:
name##_ptr name = nullptr

◆ kConnexionClientModeTakeOver

#define kConnexionClientModeTakeOver   1

◆ kConnexionCmdAppSpecific

#define kConnexionCmdAppSpecific   10

Referenced by DeviceEvent().

◆ kConnexionCmdHandleAxis

#define kConnexionCmdHandleAxis   3

Referenced by DeviceEvent().

◆ kConnexionCmdHandleButtons

#define kConnexionCmdHandleButtons   2

Referenced by DeviceEvent().

◆ kConnexionCtlGetDeviceID

#define kConnexionCtlGetDeviceID   '3did'

Referenced by DeviceAdded().

◆ kConnexionMaskAll

#define kConnexionMaskAll   0x3fff

◆ kConnexionMaskAllButtons

#define kConnexionMaskAllButtons   0xffffffff

◆ kConnexionMaskAxis

#define kConnexionMaskAxis   0x3f00

◆ kConnexionMsgDeviceState

#define kConnexionMsgDeviceState   '3dSR'

Referenced by DeviceEvent().

◆ LOAD_FUNC

#define LOAD_FUNC ( name)
Value:
name = (name##_ptr)load_func(module, #name)
static void * module
Definition Mouse3DHandlerMac.mm:93
static void * load_func(void *module, const char *func_name)
Definition Mouse3DHandlerMac.mm:77

Referenced by load_driver_functions().

Typedef Documentation

◆ AddedHandler

typedef void(* AddedHandler) (uint32_t)

◆ CleanupConnexionHandlers_ptr

typedef void(* CleanupConnexionHandlers_ptr) ()

◆ ConnexionClientControl_ptr

typedef int16_t(* ConnexionClientControl_ptr) (uint16_t clientID, uint32_t message, int32_t param, int32_t *result)

◆ InstallConnexionHandlers_ptr

typedef int16_t(* InstallConnexionHandlers_ptr) (MessageHandler, AddedHandler, RemovedHandler)

◆ MessageHandler

typedef void(* MessageHandler) (uint32_t, uint32_t msg_type, void *msg_arg)

◆ RegisterConnexionClient_ptr

typedef uint16_t(* RegisterConnexionClient_ptr) (uint32_t signature, const char *name, uint16_t mode, uint32_t mask)

◆ RemovedHandler

typedef void(* RemovedHandler) (uint32_t)

◆ SetConnexionClientButtonMask_ptr

typedef void(* SetConnexionClientButtonMask_ptr) (uint16_t clientID, uint32_t buttonMask)

◆ SetConnexionHandlers_ptr

typedef int16_t(* SetConnexionHandlers_ptr) (MessageHandler, AddedHandler, RemovedHandler, bool)

◆ UnregisterConnexionClient_ptr

typedef void(* UnregisterConnexionClient_ptr) (uint16_t clientID)

Function Documentation

◆ DECLARE_FUNC() [1/7]

DECLARE_FUNC ( CleanupConnexionHandlers )

◆ DECLARE_FUNC() [2/7]

DECLARE_FUNC ( ConnexionClientControl )

◆ DECLARE_FUNC() [3/7]

DECLARE_FUNC ( InstallConnexionHandlers )

◆ DECLARE_FUNC() [4/7]

DECLARE_FUNC ( RegisterConnexionClient )

◆ DECLARE_FUNC() [5/7]

DECLARE_FUNC ( SetConnexionClientButtonMask )

◆ DECLARE_FUNC() [6/7]

DECLARE_FUNC ( SetConnexionHandlers )

◆ DECLARE_FUNC() [7/7]

DECLARE_FUNC ( UnregisterConnexionClient )

◆ DeviceAdded()

void DeviceAdded ( uint32_t unused)
static
139{
140 BOOST_LOG_TRIVIAL(info)<<"3dx device added";
141 // determine exactly which device is plugged in
142 int32_t result;
143 ConnexionClientControl(clientID, kConnexionCtlGetDeviceID, 0, &result);
144 int vendorID = result >> 16;
145 int productID = result & 0xffff;
146 //TODO: verify device
147 char buf[64];
148 sprintf(buf, "VID%04X,PID%04X", vendorID, productID);
149 mouse_3d_controller->connected(buf);
150}
static uint16_t clientID
Definition Mouse3DHandlerMac.mm:14
#define kConnexionCtlGetDeviceID
Definition Mouse3DHandlerMac.mm:29
static Slic3r::GUI::Mouse3DController * mouse_3d_controller
Definition Mouse3DHandlerMac.mm:12

References clientID, kConnexionCtlGetDeviceID, and mouse_3d_controller.

◆ DeviceEvent()

void DeviceEvent ( uint32_t unused,
uint32_t msg_type,
void * msg_arg )
static
162{
163 if (msg_type == kConnexionMsgDeviceState) {
165 if (s->client == clientID) {
166 switch (s->command) {
168 // The axis field is an array of 6 signed 16-bit integers corresponding to the 6 device axes. Data is ordered as Tx, Tz, Ty, Rx, Rz, Ry. The values reported are scaled by the driver according to the speed slider settings on the 3Dconnexion preference panel. At maximum speed, the range is - 1024 to 1024. Typical range that you should optimize your application for should be -500 to 500.
169 // Actually we are getting values way over 1024. Max is probably 2048 now.
170 Slic3r::GUI::Mouse3DController::DataPacketAxis packet;
171 for (int i = 0; i < 6; ++ i)
172 packet[i] = (double)s->axis[i]/350.0;//wanted to divide by 500 but 350 is used at raw input so i used same value.
173 mouse_3d_controller->handle_input(packet);
174 break;
175 }
177 break;
179 break;
180 default:
181 break;
182 }
183 }
184 }
185}
#define kConnexionCmdAppSpecific
Definition Mouse3DHandlerMac.mm:27
#define kConnexionCmdHandleButtons
Definition Mouse3DHandlerMac.mm:25
#define kConnexionMsgDeviceState
Definition Mouse3DHandlerMac.mm:28
uint16_t command
Definition Mouse3DHandlerMac.mm:35
#define kConnexionCmdHandleAxis
Definition Mouse3DHandlerMac.mm:26
int16_t axis[6]
Definition Mouse3DHandlerMac.mm:41
uint16_t client
Definition Mouse3DHandlerMac.mm:34
Definition Mouse3DHandlerMac.mm:32

References ConnexionDeviceState::axis, ConnexionDeviceState::client, clientID, ConnexionDeviceState::command, kConnexionCmdAppSpecific, kConnexionCmdHandleAxis, kConnexionCmdHandleButtons, kConnexionMsgDeviceState, and mouse_3d_controller.

◆ DeviceRemoved()

void DeviceRemoved ( uint32_t unused)
static
153{
154 BOOST_LOG_TRIVIAL(info) << "3dx device removed\n";
155// not accessible in a free function
156// assert(m_connected);
157// assert(! m_device_str.empty());
158 mouse_3d_controller->disconnected();
159}

References mouse_3d_controller.

◆ load_driver_functions()

bool load_driver_functions ( )
static
96{
97 if (driver_loaded)
98 return true;
99
100 module = dlopen("/Library/Frameworks/3DconnexionClient.framework/3DconnexionClient",
101 RTLD_LAZY | RTLD_LOCAL);
102
103 if (module) {
104 BOOST_LOG_TRIVIAL(info) << "loading 3dx drivers";
105 LOAD_FUNC(SetConnexionHandlers);
106
107 if (SetConnexionHandlers != nullptr) {
108 driver_loaded = true;
109 has_new_driver = true;
110 }
111 else {
112 BOOST_LOG_TRIVIAL(info) << "installing 3dx drivers";
113 LOAD_FUNC(InstallConnexionHandlers);
114 driver_loaded = (InstallConnexionHandlers != nullptr);
115 }
116
117 if (driver_loaded) {
118 LOAD_FUNC(CleanupConnexionHandlers);
119 LOAD_FUNC(RegisterConnexionClient);
120 LOAD_FUNC(SetConnexionClientButtonMask);
121 LOAD_FUNC(UnregisterConnexionClient);
122 LOAD_FUNC(ConnexionClientControl);
123 }
124 }
125 else {
126 BOOST_LOG_TRIVIAL(error) << "3dx drivers module loading error: "<< dlerror() ;
127 }
128
129 BOOST_LOG_TRIVIAL(info) << "3dx drivers loaded: " << (driver_loaded ? (has_new_driver ? "YES, new" : "YES, old") : "NO");
130 return driver_loaded;
131}
static bool driver_loaded
Definition Mouse3DHandlerMac.mm:16
static bool has_new_driver
Definition Mouse3DHandlerMac.mm:17
#define LOAD_FUNC(name)
Definition Mouse3DHandlerMac.mm:91

References driver_loaded, has_new_driver, LOAD_FUNC, and module.

◆ load_func()

void * load_func ( void * module,
const char * func_name )
static
78{
79 void *func = dlsym(module, func_name);
80
81 if (func) {
82 BOOST_LOG_TRIVIAL(info) << func_name <<" loaded";
83 }
84 else {
85 BOOST_LOG_TRIVIAL(error) <<"loading 3dx drivers dlsym error: "<< dlerror();
86 }
87
88 return func;
89}

References module.

◆ unload_driver()

void unload_driver ( )
static
134{
135 dlclose(module);
136}

References module.

Variable Documentation

◆ clientID

uint16_t clientID = 0
static

Referenced by DeviceAdded(), and DeviceEvent().

◆ driver_loaded

bool driver_loaded = false
static

Referenced by load_driver_functions().

◆ has_new_driver

bool has_new_driver = false
static

Referenced by load_driver_functions().

◆ module

◆ mouse_3d_controller

Slic3r::GUI::Mouse3DController* mouse_3d_controller = nullptr
static