fasteddy516 / CircuitPython_JoystickXL

Turn a CircuitPython device into a joystick controller with lots of inputs.
MIT License
19 stars 8 forks source link

TypeError: object of type 'Device' has not len() #2

Closed bighans closed 3 years ago

bighans commented 3 years ago

It is an unexpected maker ESP32S2.

output from boot_out.txt: Adafruit CircuitPython 7.0.0-alpha.5 on 2021-07-21; FeatherS2 with ESP32S2 boot.py output:

code.py output: Traceback (most recent call last): File "code.py", line 18, in File "/lib/joystick_xl/joystick.py", line 83, in init File "/lib/joystick_xl/hid.py", line 165, in _get_device ValueError: Could not find JoystickXL HID device - check boot.py.)

fasteddy516 commented 3 years ago

This usually happens when you try to pass create_joystick() by itself directly to the usb_hid.enable() function in boot.py. The enable function always expects a tuple of devices even if you're only passing a single device, which means you need some extra parentheses and a comma in there to force it to see a single-element tuple, like this:

usb_hid.enable((create_joystick(axes=2, buttons=2, hats=1)),)

If your code already looks like the example above, please let me know, and post the code from your boot.py so I can have a look.

bighans commented 3 years ago

Yes, this fixed that problem. I had used a different boot.py which did not have the extra paranthesis (and the comma).

BTW, excellent software.

fasteddy516 commented 3 years ago

Perfect, I'm glad that helped! If the boot.py code you were using was from one of the examples or in the documentation here, please let me know so I can fix it.

Also, just a heads up - I am putting the finishing touches on JoystickXL version 0.4.0, which includes some small fixes, as well as some improvements to input objects and the TestConsole(). It shouldn't affect anything you're doing now with version 0.3.0, unless you're using any input suppress functionality, which has been renamed to bypass in 0.4.0. I'm hoping to get the new version posted some time this weekend.

bighans commented 3 years ago

Well, I am really interested in following this. I can see from testing the joystick loop runs > 100 times / sec for this sample, which should be fine for flying helicopters in DCS which is a bit sensitive to latency. I have two other joystick boards runining adafruit 32u4 boards running Arduino. However, I am using an external ADS1015 with separate voltage regulators. It works like a charm, but need to get the data into the axis function not as a pin.

fasteddy516 commented 3 years ago

I just posted version 0.4.0, which should help with what you're trying to do. If you're using the Adafruit CircuitPython drivers for the ADS1015, you should be able to tie its channels to axis sources similar to this MCP3008 ADC example. I haven't tested latency when using the off-board ADCs, though, so you'll want to make sure the data acquisition time doesn't slow down the update loop too much.

I also did some quick tests in DCS, and it looks like it supports all 8 axes, 128 buttons and 4 hat switches. I've added it to the list of known/supported applications, so thank you for bringing it to my attention!