ETS2LA/Euro-Truck-Simulator-2-Lane-Assist

Logitech SDK support

michalkundrat opened this issue · 3 comments

Hey there, a long time ago I was working on a similar project to this myself. However, I was seriously struggling with any progress with the Logitech SDK. Would you please be able to give me any insight as to how you were able to get it to work with Python?
P.S. Yes, I am aware that it doesn't work in this project due to issues with program handles.

Oh wow it's been so long since I wrote that code xD

Well this is what I used (though I think you might have already looked at this)

# Get the logitech wheel information
# This code is mosly from the documentation
if useLogitech:
    import logitech_steering_wheel as lsw
    import pygetwindow as gw
    # Apparently it needs a window?
    window_handle = gw.getActiveWindow()._hWnd
    initialized = lsw.initialize_with_window(ignore_x_input_controllers=True, hwnd=window_handle)
    
    print("Logitech SDK version is: " + str(lsw.get_sdk_version()))
    connected = lsw.is_device_connected(defaultControllerIndex, lsw.DeviceType.WHEEL)
    lsw.update()
    if connected:
        print("Logitech wheel on index {} : connected".format(defaultControllerIndex))
        print("Logitech wheel on index {} has force feedback : ".format(defaultControllerIndex) + str(lsw.has_force_feedback(defaultControllerIndex)))
        print("Testing force feedback...")
        lsw.play_constant_force(defaultControllerIndex, 20)
        for i in range(0, 30):
            time.sleep(.1)
            lsw.update()
            data = lsw.get_state(defaultControllerIndex)
            print("Playing force feedback for {} seconds".format(round(2.9-i/10, 1)) + " Current angle : " + str(data.lX / 32768 * 900)+ "\r", end='')
        lsw.stop_constant_force(defaultControllerIndex)
        print("\nForce feedback test complete")
    else:
        print("Logitech Steering Wheel not found")

I managed to get my wheel (G29) moving correctly with this code. Well as long as I kept the vscode window in focus.

Edit : I used this package https://pypi.org/project/logitech-steering-wheel/

Hey, thank you so much for giving me an answer despite it having been a while since you wrote the code.
I really do appreciate it!

No worries, happy to help!