USB Device - HIDAPI or ?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Wed Mar 17, 2021 9:44 pm

SparkOut wrote:
Wed Mar 17, 2021 8:47 pm
Great, thanks Paul. I can't tell you how much I applaud your efforts.
I will probably get a chance to try it out this weekend, hopefully so, because I'll be away in the Western Isles without decent mobile data or my own computer next week. I will give you feedback as soon as I can.
Thanks! I very much appreciate your testing it as well. I have Windows 10 reinstalled now so I can test too, but the more testing with a variety of devices the better. I have a feeling it might stumble a little on Manufacturer/Product names that have non-ANSI characters (like Unicode Chinese characters) for example, but none of the devices I own and tested with have multi-byte characters in those name elements.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5652
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: USB Device - HIDAPI or ?

Post by richmond62 » Fri Mar 19, 2021 12:01 pm

I think I'm being a bit stupid:
-
SShot 2021-03-19 at 13.00.59.png

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Sun Mar 21, 2021 5:02 pm

richmond62 wrote:
Fri Mar 19, 2021 12:01 pm
I think I'm being a bit stupid:
-
SShot 2021-03-19 at 13.00.59.png
Is that a rhetorical question? Is the HIDAPI LiveCode Builder Extension loaded? If not then the stack isn't going to do anything but throw errors. HIDAPIInit() should init the library and either return the version string of the HIDAPI Library or the message "error initializing HID API". The rest is commented out because I moved those lines to a separate button that gets the device list and updates the dataGrid. This is all very much a work in progress and so I'm changing things around frequently.

I made a new video showing using the lib with a Nintendo Wiimote, filtering of incoming data through a "data description string" (in the bottom field, filter function in the button script that does the device polling). https://www.youtube.com/watch?v=oeh5VOE-N5E
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Tue Apr 13, 2021 2:32 am

Hi Paul,

Your HIDAPI lcb extension works fine on MacOSX 10.11.6
using Livecode Indy 9.6.1

I have to search "How to install LCB in Livecode" on google:
https://livecode.com/topic/installing-an-lcb-library-2/

Somehow, I managed to stuck my mouse pointer and had to
quit Livecode using the keyboard. After quitting, the mouse
worked again.

Using a broken gamepad, I tested again and found with surprise
that every gamepad button works fine.

This gamepad generates a string of 8 numbers but only 1 or 2
actually change after pressing a button.

Number values are just one of these 3 numbers: 255, 128, 0

Vendor name is Honey Bee identified with ID 1A5C

https://www.flipkart.com/genius-maxfire ... z9czk5g4yp

Al

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5652
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: USB Device - HIDAPI or ?

Post by richmond62 » Tue Apr 13, 2021 9:15 am

OK: Here I am being really stupid, BUT, HOW do I download a unified X.lcb from here?

https://github.com/PaulMcClernan/LCB_HIDAPI

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Wed Apr 14, 2021 9:20 pm

richmond62 wrote:
Tue Apr 13, 2021 9:15 am
OK: Here I am being really stupid, BUT, HOW do I download a unified X.lcb from here?

https://github.com/PaulMcClernan/LCB_HIDAPI
I'm not sure what you mean by "unified X.lcb" from there? There isn't a file named that in this project.
If you want to try it out you'll have to download the project and load it into Extension Builder in LC
Screen Shot 2021-04-14 at 4.12.38 PM.png
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Wed Apr 14, 2021 9:48 pm

capellan wrote:
Tue Apr 13, 2021 2:32 am
Hi Paul,

Your HIDAPI lcb extension works fine on MacOSX 10.11.6
using Livecode Indy 9.6.1
Excellent! Thanks so much for testing! I've tried to keep backwards compatibility wherever I can, some of my other LCB should. theoretically, work as far back as SnowLeo 10.6. I was on Sierra for a long time for that reason, but I recently got forced into updating to macOS 10.14.6.
capellan wrote:
Tue Apr 13, 2021 2:32 am
I have to search "How to install LCB in Livecode" on google:
https://livecode.com/topic/installing-an-lcb-library-2/
A good slide show to keep as general LCB reference!
capellan wrote:
Tue Apr 13, 2021 2:32 am
Somehow, I managed to stuck my mouse pointer and had to
quit Livecode using the keyboard. After quitting, the mouse
worked again.
Hah! I did the same testing it with an MS mouse. After that I thought I had added another escape from the polling loop script. Try holding down the escape key to stop the loop and close the device, which should release it back to OS control. Could be considered a useful feature ;-) for making kiosks interface.
capellan wrote:
Tue Apr 13, 2021 2:32 am
Using a broken gamepad, I tested again and found with surprise
that every gamepad button works fine.

This gamepad generates a string of 8 numbers but only 1 or 2
actually change after pressing a button.

Number values are just one of these 3 numbers: 255, 128, 0

Vendor name is Honey Bee identified with ID 1A5C

https://www.flipkart.com/genius-maxfire ... z9czk5g4yp

Al
Yes, a lot of gamepads are easy to figure out the mapping. If you put the polling on "bits" instead of decimal, and look at each bit of the bytes coming in, you'll find that each button corresponds to a single bit in one of the bytes coming in. Directional "DPad" rockers are "Nybles" (Half a byte or 4 bits of a Byte), with an 8 direction clock wise sequence that goes from 0=north 1=northeast 2=east etc. up to 7 (with 8 or 16 if no direction is pushed). Analog sticks send one signed byte X, and one signed byte Y (in decimal -127 to 127,-127 to 127). The Sony Dual Shock 4 controllers L1 & R1 "Triggers" buttons also send 2 bytes on the end that correspond to how far in the trigger is squeezed.
Fun stuff.
Once all the controller's bytes are mapped out with a string telling it how to parse the bytes for a particular controller, then you can save that string that corresponds to VendorID & DeviceID and you can reload it later.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Thu Apr 15, 2021 1:50 am

Today, I borrowed another gamepad: Vendor ID 0079 - Manufacturer: Microntek

All buttons of this new gamepad actually works.
The brand is Agiler Model: AGI-4010
https://www.agiler.us/?product=usb-2-0-gamepad

Did all gamepads always send a "No Input" string?

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Thu Apr 15, 2021 11:37 pm

capellan wrote:
Thu Apr 15, 2021 1:50 am
Today, I borrowed another gamepad: Vendor ID 0079 - Manufacturer: Microntek

All buttons of this new gamepad actually works.
The brand is Agiler Model: AGI-4010
https://www.agiler.us/?product=usb-2-0-gamepad
Cool, all HID USB gamepads should work at least for RAW input (unlike SONY & NINTENDO's controllers, Microsoft X-Box controllers are not HID and so need a driver). Are you using one of the Playstation controller "profiles" strings I set up in the demo stack?
capellan wrote:
Thu Apr 15, 2021 1:50 am
Did all gamepads always send a "No Input" string?
I'm confused, I thought you just said it worked?
If it's an USB or BT HID device that's properly connected to the the OS, and you pasted in the system path of the device in the "paste system path here" field, then when you start one of the polling loop buttons on the demo stack you should start receiving input from the device.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Tue Apr 27, 2021 5:43 am

Hi Paul,

Yes, it worked great!
This misunderstanding it's my own mistake.

I am calling "NO INPUT STRING" to the hexadecimal string
produced by the gamepad when is connected, but no function
button, analog button or direction button is pressed.

Here I will post the codes for the two gamepads that tested.
agiler gamepad.jpg
Agiler gamepad codes

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Tue Apr 27, 2021 5:44 am

These are the codes for the discontinued Genius gamepad:
genius gamepad.jpg
Genius gamepad codes

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Tue May 04, 2021 3:07 am

capellan wrote:
Tue Apr 27, 2021 5:44 am
These are the codes for the discontinued Genius gamepad:
genius gamepad.jpg
That info (translated from hex to decimal) is basically all that's needed to make parsing string for my polling script.

I haven't worked on this lately because I've been working on several widgets that are sort-of spin-offs from working on the GUI for the demo stack for this. One of these spin-offs has turned into another major project (which I had sort-of planned long ago)... I will get back to this project eventually.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Tue May 04, 2021 3:17 am

Great! Many thanks for making this project, Paul!

Could this LCB works with two or more gamepads
at the same time?

PaulDaMacMan
Posts: 436
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Mon May 10, 2021 9:57 pm

capellan wrote:
Tue May 04, 2021 3:17 am
Great! Many thanks for making this project, Paul!
You're welcome!
capellan wrote:
Tue May 04, 2021 3:17 am
Could this LCB works with two or more gamepads
at the same time?
"Sort-of" I guess is the answer to that question. The way the LCB lib is currently set-up, you would just have to poll the devices one after the other, but LC could probably do it fast enough that it would seem like the "same time" from the end user's persepctive. I do plan to add something in that vein to the LCB when I add the pre-parsing of the incoming data based on that byte/bit description string. It will never really be "same time" but hopefully it will be not-a-noticeable amount-of-time-in-between.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: USB Device - HIDAPI or ?

Post by capellan » Tue May 11, 2021 8:21 pm

Great! Thanks a lot again.
Your MIDI Player works great too.
Now, I have to find a way to use
the Analog Sticks to send MIDI
messages.

Post Reply

Return to “Talking LiveCode”