USB Device - HIDAPI or ?

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Sun Feb 28, 2021 7:18 pm

@
simon.schvartzman wrote:
Sun Feb 28, 2021 6:35 pm
Hi PaulDaMacMan, I've never done anything involving libraries (except using them) but since I'm working on a project that is going to use an RFID reader with HID support I'm interested on what you are doing.

I'm not sure if I will be able to help but for sure I will try. Please let me know what can I do to start with

Regards
Cool. Well for one thing if you could test it on Windows 10 or Linux and report about your experience, that would be helpful. I'm primarily a macOS user. I had a Windows 10 install for testing on a partition but wound up wiping it out while rearranging my m2 drive's layout and I haven't gotten around to reinstalling it.
richmond62 wrote:
Sun Feb 28, 2021 10:04 am
My "tethered" floor robots are still gathering dust in a cupboard . . .

Maybe they are slowling changing into zombies. 8)
My interest is the "Human Interface" in Human Interface Device, joysticks, buttons, knobs... I've got no robots to play with (actually, now that I think about it my 12yr old son does have some sort of toy robot that's programable via USB that he got for Christmas a couple of years ago, not sure if it's an USBHID device though)
Last edited by PaulDaMacMan on Mon Mar 01, 2021 1:27 am, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Sun Feb 28, 2021 7:37 pm

my 12yr old son does have some sort of toy robot that's programable via USB
Well, knowing kids, with any luck he's lost interest in it so you can 'borrow' it and . . . 8)
-
roamer-educational-robot.jpg
-
http://www.valiant-technology.com/uk/pa ... p?cat=8id1
-
This thing suffers from a number of problems:

The Valiant people sent me a free one of these about 6 years ago,
and asked me to design a front-end to control this thing via a USB cable . . .

1. I designed a front-end (this did NOT involve a way to get the signals from the front-end into
the robot as, apparently, the chap who had been hired to do that part of the work had high-tailed
it off to Cyprus with the money they had paid him in advance), which I sent them . . .

1.1. Sent it too Dave Caplin (the bloke [as in "bloke" = someone who knows next to nothing about software]
who runs the Valiant company), who took 14 months to acknowledge my email, claiming that he had sent
me the robot on loan (I then checked the original e-mail which stated that the Roamer 2 robot was a sample
for my use and testing to see if I wanted to do a bulk order), AND that my front-end did not answer certain
requirements (which he had not mentioned previously).

1.1.1 I, carefully, 'forgot' to rise to the bait about returning the robot.

1.2. Reverted to Dave Caplin anent those requirements, and received an answer after a month (Wow; record time).

2. I then designed several front-ends [ https://www.dropbox.com/sh/3bvfqxzozjp3 ... ISTGa?dl=0 ]
and sent them to him.

2.1. Last week (20th February) wrote and pointed out that I had sent him what he had requested in February 2019 and heard nothing.

2.2. Caplin replied that he had never received the e-mail. I checked my gmail account, and "there it was":
reposted the email, and, predictably, have had no response.

3. How do you write "Dear Sir, I think you are a complete plonker." without actually being offensive? Hey, wait a mo'. . . 8)

This device is exactly the sort of thing that should lend itself to a LiveCode bit of software to program it . . .
Last edited by richmond62 on Fri Mar 19, 2021 11:53 am, edited 3 times in total.

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Sun Feb 28, 2021 8:24 pm

This is, supposedly, a piece of junk:
-
41JRDZSJTPL._AC_.jpg
-
A Belkin Nostromo gamepad n52.

The 'latest' software for Windows and Macintosh was released about 17 years ago.

BUT, hooked up to a Mac Mini running MacOS 11 it delivers these keyUp signals:
-
keyUpsNostromo.jpg
-
So, obviously, it is not a piece of junk, and maybe used to input signals.

LiveCode picks up any USB signals the underlying operating system picks up.

Going "the other way": i.e. sending signals out, via a USN connexion using LiveCode, is where things get a bit dicky.

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Sun Feb 28, 2021 8:40 pm

https://www.bkohg.com/service/softwareX_e.html
Die Seite wurde nicht gefunden.
After only 3 years: bad.

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: USB Device - HIDAPI or ?

Post by simon.schvartzman » Sun Feb 28, 2021 9:20 pm

@PaulDaMacMan
Well for one thing if you could test it on Windows 10 or Linux and report about your experience, that would be helpful. I'm primarily a macOS user
Unfortunatly (or fortunatly) I'm exclusevely macOS user. Have neither Windows nor Linux machine to test.

Moreover at the moment I don't even have the RFID reader (with HID support) available.

So I guess there is no much I can do right now
Simon
________________________________________
To ";" or not to ";" that is the question

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: USB Device - HIDAPI or ?

Post by SparkOut » Sun Feb 28, 2021 10:16 pm

I am predominantly a Windows user. If I get a chance, and have a clue about what to try testing, I will report. But not confident about either.

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Mon Mar 01, 2021 1:22 am

richmond62 wrote:
Sun Feb 28, 2021 8:24 pm
A Belkin Nostromo gamepad n52.
The 'latest' software for Windows and Macintosh was released about 17 years ago.
BUT, hooked up to a Mac Mini running MacOS 11 it delivers these keyUp signals:
So, obviously, it is not a piece of junk, and maybe used to input signals.
Hah, I've currently got a Gravis GamePad "Pro" (PlayStation 1 style, it doesn't even have analog sticks) from the 1990s hooked up to my laptop just to have another HID device connected while testing.
richmond62 wrote:
Sun Feb 28, 2021 8:24 pm
LiveCode picks up any USB signals the underlying operating system picks up.
Going "the other way": i.e. sending signals out, via a USN connexion using LiveCode, is where things get a bit dicky.
I didn't realize that LiveCode could pick up "USB signals the underlying operating system", I mean beyond signals from a keyboard or mouse like device, without some sort of external/extension. Can you read signals from that D-Pad into LiveCode?

It does look like this HIDAPI Library has functions for writing out too. Ideally I'd like to get the entire library wrapped, it doesn't look very big, but I've already hit some stumbling blocks (not that ^block at least :-D ).
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Mon Mar 01, 2021 2:49 pm

Can you read signals from that D-Pad into LiveCode?
The way I worked out the signals being sent into my machine with this:
-
keyUpsNostromoSMALL.jpg
keyUpsNostromoSMALL.jpg (17.75 KiB) Viewed 4853 times
-
was with this sort of code:

Code: Select all

on keyUp KP
put KP
end keyUp
and then pressing the keys on the Nostromo n52.

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Mon Mar 01, 2021 3:05 pm

Screenshot 2021-03-01 at 16.02.03.png
-
Nothing quite like:

1. Good, old-fashioned juvenile fun.

2. Inventing the wheel for the 95th time.

3. Especially as this features 3 fairly crappy interfaces.

4. Reaching for the headache pills when one works out that this is 100% dead easy, while getting those commands out
to either USB-tethered or Bluetooth enabled robots is another thing altogether.
Attachments
Bluebot.livecode.zip
(168.78 KiB) Downloaded 122 times

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Mon Mar 01, 2021 3:52 pm

richmond62 wrote:
Mon Mar 01, 2021 2:49 pm
Can you read signals from that D-Pad into LiveCode?
The way I worked out the signals being sent into my machine with this:
-
keyUpsNostromoSMALL.jpg
-
was with this sort of code:

Code: Select all

on keyUp KP
put KP
end keyUp
and then pressing the keys on the Nostromo n52.
That Belkin device must have been programmed to send standard keyboard signals for you to be able to capture them like that. That does nothing with my Gravis Gamepad. Not trapping with rawKeyDown/rawKeyUp either. With HIDAPI I can see the GamePad signals which is about 6 bytes worth of data, byte 1 & 2 are there Directional Pad (each byte one of 0,7F, or FF) and bytes 3 & 4 handle the buttons (byte is a button number), bytes 5 & 6 are Select & Start.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by richmond62 » Mon Mar 01, 2021 4:03 pm

must have been programmed to send standard keyboard signals for you to be able to capture them
Well, yes, I would suppose so.

Surely ALL USB input devices are programmed to send some sort of signal "down the USB pipe" to the computer.

How much of how those signals are interpreted is the responsibility of the operating system on the computer
and how much is dependent on the nature of the signals sent is, surely, where the antique sits . . .

"For within the hollow Crowne
That rounds the mortall Temples of a King,
Keepes Death his Court, and there the Antique sits" Richard II, Shakespeare.

Having said that, my Nostromo n50 keypad (which works just fine when connected to one of my Mac G5 machines)
doesn't seem much good connected to the Mac Mini running MacOS 11 when trying to type into a TextEdit document.
-
n50SMALL.jpg
n50SMALL.jpg (6.99 KiB) Viewed 4824 times
-
HOWEVER Gamepad Companion allows me to use the Nostromo n50
as a handy navigator & so on when I am working on my multi-card Devawriter Pro stack.
-
Screenshot 2021-03-01 at 17.15.05.png
-
http://www.carvware.com/

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Mon Mar 01, 2021 7:46 pm

@richmond62 wrote:
Mon Mar 01, 2021 10:03 am
must have been programmed to send standard keyboard signals for you to be able to capture them
Well, yes, I would suppose so.

Surely ALL USB input devices are programmed to send some sort of signal "down the USB pipe" to the computer.
Yeah 'some sort of signal', but not necessarily signals that look like keyboard or mouse/scrollwheel signals

I now have my HIDAPI wrapper reading input from my ancient Gravis GamePad and passing it back to LC Engine as Decimal values.
It's sending 4 bytes per signal:
127 0 0 0 (pressing the 'Up' on the D-Pad)
255 255 0 0 (pressing the 'Down' on the D-Pad)
0 127 0 0 (pressing the 'Left' on the D-Pad)
255 127 0 0 (pressing the 'Right' on the D-Pad)
127 127 0 0 (pressing diagonaly 'Up+Right'' on the D-Pad)
127 127 0 1 (pressing the 'select' button)
127 127 0 2 (pressing the 'start' button)
127 127 1 0 (pressing the 'red' button, which would be the 'square' on a Playstation Controller)
127 127 64 0 (pressing the 'front lower left shoulder' button, 'L1' on a Playstation Controller)
etc.

I did some testing with a few other devices including a MicroSoft "Desktop" receiver/mouse, and another old GamePad from Logitec (same style controller, sends completely different values).
I sort of hacked together a "sizeof" replacement for wchar_t type strings (previously I had extra junk characters showing after manufacturers / product names).
Sadly, I don't think this library has any way to get a feature descriptor which would tell you how to programatically parse the incoming data.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Tue Mar 02, 2021 10:59 pm

I have only a handful of HID devices to test this out with and they're almost all USB gaming controllers, GuitarHero/Rockband things, or adapters for game controllers. Already from testing two different game controllers I found out I needed to expand a block to accommodate longer Product Name strings, so it would be helpful if anyone on any platform could test with any HID devices they have. Also this library should support Bluetooth HID (not just USB HID), so if you have any bluetooth HID devices to test with that would be great. I do have some Nintendo Wiimotes somewhere, but I'm not sure if they're proper HID devices or not.

Right now the only handler that pulls in data from a device is blocking, it will lock up the engine while waiting until it receives a signal from whatever device you pass it. There is also a non-blocking mode that I'll be getting to soon. Is this actually useful? I guess you could use this to continuously poll your device at a given interval to see if there's any signals at that particular moment, and then compare it known values for that device. Not quite as automatic or Scripter friendly as I'd hoped, but it is what it is.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Wed Mar 03, 2021 6:45 am

Now I'm considering trying to wrap libusb, which has a bit more features beyond USB HID, for one thing it looks like it can get device descriptors. It's also crossplatform and "userland" friendly (no elevated privileges required). The main problem is I have too many ongoing projects now, and the more musical stuff I was working on is much more fun for me (part of my thinking was to integrate HID input devices into that as well, PS3 Rockband drum game controllers are HID devices for example).
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: USB Device - HIDAPI or ?

Post by PaulDaMacMan » Thu Mar 04, 2021 4:07 pm

A bit more progress and cleanup done, and here's a demo video of testing with a few different Joystick/Gamepad type USB HID devices:
https://www.youtube.com/watch?v=Ga1WLIc31fk
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “Talking LiveCode”