-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_wrapper.py
461 lines (314 loc) · 15 KB
/
_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import os
import ctypes
import sys
from logitech_steering_wheel._enums import *
from logitech_steering_wheel._controllerproperties import ControllerPropertiesData, LogiControllerPropertiesData
from logitech_steering_wheel._state import State, DIJOYSTATE2
# import dll and define return types for all functions
_sys_arch = 'x64' if sys.maxsize > 2 ** 32 else 'x86'
_dll_handle = ctypes.windll.LoadLibrary(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib', _sys_arch, 'LogitechSteeringWheelEnginesWrapper.dll'))
_dll_handle.LogiSteeringInitialize.restype = ctypes.c_bool
_dll_handle.LogiSteeringInitializeWithWindow.restype = ctypes.c_bool
_dll_handle.LogiSteeringInitialize.restype = ctypes.c_bool
_dll_handle.LogiSteeringGetSdkVersion.restype = ctypes.c_bool
_dll_handle.LogiUpdate.restype = ctypes.c_bool
_dll_handle.LogiGetState.restype = ctypes.POINTER(DIJOYSTATE2)
_dll_handle.LogiGetDevicePath.restype = ctypes.c_bool
_dll_handle.LogiGetFriendlyProductName.restype = ctypes.c_bool
_dll_handle.LogiIsConnected.restype = ctypes.c_bool
_dll_handle.LogiIsDeviceConnected.restype = ctypes.c_bool
_dll_handle.LogiIsManufacturerConnected.restype = ctypes.c_bool
_dll_handle.LogiIsModelConnected.restype = ctypes.c_bool
_dll_handle.LogiButtonTriggered.restype = ctypes.c_bool
_dll_handle.LogiButtonReleased.restype = ctypes.c_bool
_dll_handle.LogiButtonIsPressed.restype = ctypes.c_bool
_dll_handle.LogiGenerateNonLinearValues.restype = ctypes.c_bool
_dll_handle.LogiGetNonLinearValue.restype = ctypes.c_int
_dll_handle.LogiHasForceFeedback.restype = ctypes.c_bool
_dll_handle.LogiIsPlaying.restype = ctypes.c_bool
_dll_handle.LogiPlaySpringForce.restype = ctypes.c_bool
_dll_handle.LogiStopSpringForce.restype = ctypes.c_bool
_dll_handle.LogiPlayConstantForce.restype = ctypes.c_bool
_dll_handle.LogiStopConstantForce.restype = ctypes.c_bool
_dll_handle.LogiPlayDamperForce.restype = ctypes.c_bool
_dll_handle.LogiStopDamperForce.restype = ctypes.c_bool
_dll_handle.LogiPlaySideCollisionForce.restype = ctypes.c_bool
_dll_handle.LogiPlayFrontalCollisionForce.restype = ctypes.c_bool
_dll_handle.LogiPlayDirtRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiStopDirtRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiPlayBumpyRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiStopBumpyRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiPlaySlipperyRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiStopSlipperyRoadEffect.restype = ctypes.c_bool
_dll_handle.LogiPlaySurfaceEffect.restype = ctypes.c_bool
_dll_handle.LogiStopSurfaceEffect.restype = ctypes.c_bool
_dll_handle.LogiPlayCarAirborne.restype = ctypes.c_bool
_dll_handle.LogiStopCarAirborne.restype = ctypes.c_bool
_dll_handle.LogiPlaySoftstopForce.restype = ctypes.c_bool
_dll_handle.LogiStopSoftstopForce.restype = ctypes.c_bool
_dll_handle.LogiSetPreferredControllerProperties.restype = ctypes.c_bool
_dll_handle.LogiGetCurrentControllerProperties.restype = ctypes.c_bool
_dll_handle.LogiGetShifterMode.restype = ctypes.c_int
_dll_handle.LogiSetOperatingRange.restype = ctypes.c_bool
_dll_handle.LogiGetOperatingRange.restype = ctypes.c_bool
_dll_handle.LogiPlayLeds.restype = ctypes.c_bool
_dll_handle.LogiSteeringShutdown.restype = ctypes.c_void_p
def initialize_with_window(ignore_x_input_controllers: bool, hwnd: int):
"""
Call this function to initialize if you have already the window handle
"""
return _dll_handle.LogiSteeringInitializeWithWindow(ctypes.c_bool(ignore_x_input_controllers), ctypes.c_long(hwnd))
def initialize(ignore_x_input_controllers: bool):
"""
Call this function before any other of the following
"""
return _dll_handle.LogiSteeringInitialize(ctypes.c_bool(ignore_x_input_controllers))
def get_sdk_version():
"""
Get the current SDK Version number
"""
major_version = ctypes.c_int64()
minor_version = ctypes.c_int64()
build_version = ctypes.c_int64()
result = _dll_handle.LogiSteeringGetSdkVersion(ctypes.byref(major_version),
ctypes.byref(minor_version),
ctypes.byref(build_version))
return major_version.value, minor_version.value, build_version.value, result
def update():
"""
Update the status of the controller
"""
return _dll_handle.LogiUpdate()
def get_state(index: int) -> State:
"""
Get the state of the controller in the standard way.
:returns DIJOYSTATE2*
"""
c_struct_state_pointer = _dll_handle.LogiGetState(ctypes.c_int(index))
return State.from_c_struct(c_struct_state_pointer.contents)
def get_c_state(index: int) -> DIJOYSTATE2:
"""
Get the state of the controller in the standard way.
:returns DIJOYSTATE2*
"""
c_struct_state_pointer = _dll_handle.LogiGetState(ctypes.c_int(index))
return c_struct_state_pointer.contents
def get_device_path(index: int, buffer_size: int):
"""
Get the computer specific operating system assigned controller GUID at a given index
"""
buffer = ctypes.create_unicode_buffer(buffer_size)
result = _dll_handle.LogiGetDevicePath(ctypes.c_int(index), ctypes.byref(buffer), ctypes.c_int(buffer_size))
return buffer.value, result
def get_friendly_product_name(index: int, buffer_size: int):
"""
Get the friendly name of the product at index
"""
buffer = ctypes.create_unicode_buffer(buffer_size)
result = _dll_handle.LogiGetFriendlyProductName(ctypes.c_int(index), ctypes.byref(buffer),
ctypes.c_int(buffer_size))
return buffer.value, result
def is_connected(index: int):
"""
Check if a generic device at index is connected
"""
return _dll_handle.LogiIsConnected(ctypes.c_int(index))
def is_device_connected(index: int, device_type: DeviceType):
"""
Check if the device connected at index is of the same type specified by deviceType
"""
return _dll_handle.LogiIsDeviceConnected(ctypes.c_int(index), ctypes.c_int(device_type.value))
def is_manufacturer_connected(index: int, manufacturer: Manufacurer):
"""
Check if the device connected at index is made from the manufacturer specified by manufacturerName
"""
return _dll_handle.LogiIsManufacturerConnected(ctypes.c_int(index), ctypes.c_int(manufacturer.value))
def is_model_connected(index: int, model: Model):
"""
Check if the device connected at index is the model specified by modelName
"""
return _dll_handle.LogiIsModelConnected(ctypes.c_int(index), ctypes.c_int(model.value))
def button_triggered(index: int, button_number: int):
"""
Check if the device connected at index is currently triggering the button specified by button_number
"""
return _dll_handle.LogiButtonTriggered(ctypes.c_int(index), ctypes.c_int(button_number))
def button_released(index: int, button_number: int):
"""
Check if on the device connected at index has been released the button specified by button_number
"""
return _dll_handle.LogiButtonReleased(ctypes.c_int(index), ctypes.c_int(button_number))
def button_is_pressed(index: int, button_number: int):
"""
Check if on the device connected at index is currently being pressed the button specified by button_number
"""
return _dll_handle.LogiButtonIsPressed(ctypes.c_int(index), ctypes.c_int(button_number))
def generate_non_linear_values(index: int, non_linear_coefficient: int):
"""
Generate non-linear values for the axis of the controller at index
"""
return _dll_handle.LogiGenerateNonLinearValues(ctypes.c_int(index), ctypes.c_int(non_linear_coefficient))
def get_non_linear_value(index: int, input_value: int):
"""
Get a non-linear value from a table previously generated
"""
return _dll_handle.LogiGetNonLinearValue(ctypes.c_int(index), ctypes.c_int(input_value))
def has_force_feedback(index: int):
"""
Check if the controller at index has force feedback
"""
return _dll_handle.LogiHasForceFeedback(ctypes.c_int(index))
def is_playing(index: int, force_type: ForceType):
"""
Check if the controller at index is playing the force specified by forceType
"""
return _dll_handle.LogiIsPlaying(ctypes.c_int(index), ctypes.c_int(force_type.value))
def play_spring_force(index: int, offset_percentage: int, saturation_percentage: int, coefficient_percentage: int):
"""
Play the spring force on the controller at index with the specified parameters
"""
return _dll_handle.LogiPlaySpringForce(ctypes.c_int(index), ctypes.c_int(offset_percentage),
ctypes.c_int(saturation_percentage), ctypes.c_int(coefficient_percentage))
def stop_spring_force(index: int):
"""
Stop the spring force on the controller at index
"""
return _dll_handle.LogiStopSpringForce(ctypes.c_int(index))
def play_constant_force(index: int, magnitude_percentage: int):
"""
Play the constant force on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlayConstantForce(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def stop_constant_force(index: int):
"""
Stop the constant force on the controller at index
"""
return _dll_handle.LogiStopConstantForce(ctypes.c_int(index))
def play_damper_force(index: int, coefficient_percentage: int):
"""
Play the damper force on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlayDamperForce(ctypes.c_int(index), ctypes.c_int(coefficient_percentage))
def stop_damper_force(index: int):
"""
Stop the damper force on the controller at index
"""
return _dll_handle.LogiStopDamperForce(ctypes.c_int(index))
def play_side_collision_force(index: int, magnitude_percentage: int):
"""
Play the side collision force on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlaySideCollisionForce(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def play_frontal_collision_force(index: int, magnitude_percentage: int):
"""
Play the frontal collision force on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlayFrontalCollisionForce(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def play_dirt_road_effect(index: int, magnitude_percentage: int):
"""
Play the dirt road effect on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlayDirtRoadEffect(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def stop_dirt_road_effect(index: int):
"""
Stop the dirt road effect on the controller at index
"""
return _dll_handle.LogiStopDirtRoadEffect(ctypes.c_int(index))
def play_bumpy_road_effect(index: int, magnitude_percentage: int):
"""
Play the bumpy road effect on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlayBumpyRoadEffect(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def stop_bumpy_road_effect(index: int):
"""
Stop the bumpy road effect on the controller at index
"""
return _dll_handle.LogiStopBumpyRoadEffect(ctypes.c_int(index))
def play_slippery_road_effect(index: int, magnitude_percentage: int):
"""
Play the slippery road effect on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlaySlipperyRoadEffect(ctypes.c_int(index), ctypes.c_int(magnitude_percentage))
def stop_slippery_road_effect(index: int):
"""
Stop the slippery road effect on the controller at index
"""
return _dll_handle.LogiStopSlipperyRoadEffect(ctypes.c_int(index))
def play_surface_effect(index: int, effect_type: int, magnitude_percentage: int,
periodic_effect: PeriodicSurfaceEffect):
"""
Play the surface effect on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlaySurfaceEffect(ctypes.c_int(index), ctypes.c_int(effect_type),
ctypes.c_int(magnitude_percentage), ctypes.c_int(periodic_effect.value))
def stop_surface_effect(index: int):
"""
Stop the surface effect on the controller at index
"""
return _dll_handle.LogiStopSurfaceEffect(ctypes.c_int(index))
def play_car_airborne(index: int):
"""
Play the car airborne effect on the controller at index
"""
return _dll_handle.LogiPlayCarAirborne(ctypes.c_int(index))
def stop_car_airborne(index: int):
"""
Stop the car airborne effect on the controller at index
"""
return _dll_handle.LogiStopCarAirborne(ctypes.c_int(index))
def play_soft_stop_force(index: int, usable_range_percentage: int):
"""
Play the soft stop force on the controller at index with the specified parameter
"""
return _dll_handle.LogiPlaySoftstopForce(ctypes.c_int(index), ctypes.c_int(usable_range_percentage))
def stop_soft_stop_force(index: int):
"""
Stop the soft stop force on the controller at index
"""
return _dll_handle.LogiStopSoftstopForce(ctypes.c_int(index))
def set_preferred_controller_properties(properties: ControllerPropertiesData):
"""
Set preferred wheel properties specified by the struct properties
"""
return _dll_handle.LogiSetPreferredControllerProperties(properties.as_c_struct())
def get_current_controller_properties(index: int):
"""
Fills the properties parameter with the current controller properties
"""
c_type_properties = LogiControllerPropertiesData()
data = ctypes.create_unicode_buffer(36)
result = _dll_handle.LogiGetCurrentControllerProperties(ctypes.c_int(index), ctypes.pointer(c_type_properties))
if result:
python_properties = ControllerPropertiesData.from_c_struct(c_type_properties)
return python_properties, result
else:
return None, result
def get_shifter_mode(index: int):
"""
get current shifter mode (gated or sequential)
"""
return _dll_handle.LogiGetShifterMode(ctypes.c_int(index))
def set_operating_range(index: int, motion_range: int):
"""
Sets the operating range in degrees on the controller at the index.
"""
return _dll_handle.LogiSetOperatingRange(ctypes.c_int(index), ctypes.c_int(motion_range))
def get_operating_range(index: int):
"""
Gets the current operating range in degrees on the controller at the index.
"""
motion_range = ctypes.c_int()
result = _dll_handle.LogiGetOperatingRange(ctypes.c_int(index), ctypes.byref(motion_range))
return motion_range.value, result
def play_leds(index: int, current_rpm: float, rpm_first_led_turns_on: float, rpm_red_line: float):
"""
Play the LEDs on the controller at index applying the specified parameters.
"""
return _dll_handle.LogiPlayLeds(ctypes.c_int(index), ctypes.c_float(current_rpm),
ctypes.c_float(rpm_first_led_turns_on),
ctypes.c_float(rpm_red_line))
def shutdown():
"""
Call this function to shutdown the SDK and destroy the controller and wheel objects
"""
return _dll_handle.LogiSteeringShutdown()