PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: mice - usb devices  (Read 839 times)

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #15 on: September 24, 2018, 06:57:38 AM »

Thanks Pierre, for taking an interest. I'll pick over what you have written, see if I can get it to something like it in freebasic. I really appreciate your help.
Best wishes,

Ray
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 83
Re: mice - usb devices
« Reply #16 on: September 26, 2018, 03:21:52 PM »

I may have some FB code for you soon...

Later...
Both previous posts
September 24, 2018, 12:30:44 AM
and
September 24, 2018, 12:31:22 AM
have been updated and translated to fb.
« Last Edit: September 26, 2018, 09:05:01 PM by Pierre Bellisle »
Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #17 on: October 02, 2018, 04:23:37 PM »

Hi Pierre, thanks, I didn't  notice you'd converted it to fb, until I got your pm.
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 83
Re: mice - usb devices
« Reply #18 on: October 02, 2018, 11:03:57 PM »

The FieldGet() function was a paste from a bad template.
It is now updated in my previous main code post.
It should looks more like this...

Code: [Select]
'______________________________________________________________________________

Function FieldGet(ByVal sData As String, ByVal sSplit As String, ByVal FieldTarget As Long) As String
 Dim ChrPos     As Long = 1
 Dim SplitPos   As Long
 Dim FieldIndex As Long

 If Len(sData) * Len(sSplit) Then                       'Both string lenght must be non zero
   Do                                                   'Loop for every field
     SplitPos = InStr(ChrPos, sData, sSplit)            'Get split position, use InStr/ANY if needed
     FieldIndex += 1                                    'Increment field  count
     If FieldIndex = FieldTarget Then                   'Wanted field index
       If SplitPos = 0 THEN SplitPos = Len(sData) + 1   'Unique or last field
       Function = Mid(sData, ChrPos, SplitPos - ChrPos) 'Return data
       Exit Do                                          'Job done
     End If
     ChrPos = SplitPos + Len(sSplit)                    'Prepare for possible next search
   Loop While SplitPos                                  'Done if no more found
 End If

End Function
'_____________________________________________________________________________
'
Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #19 on: October 29, 2018, 02:01:15 PM »

Thanks Pierre, I've returned to this project and tried your software. It seems to work fine. I've modified it a little, to get the minimum information I need wrt mouse id, buttons and movement. Spending some time trying to find out about this, on the web, it appears that there is not a specific api for usb, but that c#, etc. uses a windows sdk. I'm not at all certain if that can be used within free basic, but it seems to be that which most of the web help is based on.
Anyway, back to what you have so generously provided, I'm not certain that the cursor is what I need - I would need one per mouse, and I'm not sure if that is possible. Also, afaik, the cursor xpos/ypos is based on the screen resolution. I've tried using the lLastx/lLasty values, (which you've rem'd out) but they seem to be always zero for the usb mouse devices I have. Anyone any further ideas?
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 83
Re: mice - usb devices
« Reply #20 on: October 30, 2018, 01:42:05 PM »

Hey,

I'm not certain that the cursor is what I need - I would need one per mouse, and I'm not sure if that is possible.
Yes this is possible, see reply #9 for the freeware EitherMouse link.
This said, I never looked on the "how to do it".

... it appears that there is not a specific api for usb
Note that RawInput* functions work with keyboard, mouse, and HID

Also, afaik, the cursor xpos/ypos is based on the screen resolution.
Have a look at ScreenToClient(), ClientToScreen(), MapWindowPoints()

Could a joystick be used?
Depending on your specific needs, it might be much easier to implement, see joyGetPos(ex), joyGetPos(Ex), JOYINFO.
Plus, some third party or manufacturer often provide DLL to make life easy.
Logged

SeaVipe

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 118
  • Windows 10
Re: mice - usb devices
« Reply #21 on: October 30, 2018, 03:37:40 PM »

Hi Ray, I've been keeping an eye on this thread and I don't recall why a touch screen (an overlay on an existing screen) can't be used.
Logged
Clive Richey

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #22 on: October 30, 2018, 05:56:41 PM »

Thanks for the replies. The idea is to be able to add a cheap, easily built reasonably accurate measuring device. Two applications immediately come to mind. Some mice have a resolution of 6000dpi (maybe not raw, but interpolated) and could possibly be used instead of the far more expensive linear scales for various simple diy machines, possibly converting open loop stepper systems to closed loop. The second application is to use as an encoder, either spindle driven, or by means of a hand-wheel - simply use a rotating disk below the sensor. I would like to be able to incorporate this concept within other programs that I may write in free basic to drive various m/c tools. 6000 dpi is a resolution of 0.0042mm which is more or less the accuracy of a half decent industrial mill, and is a far higher resolution than the usual hobbyist machine can achieve. If it works, it will be interesting calibrating the system, and discovering how temperature variations effect the results (and if buffering will cause jitter...)

I had looked at either mouse, it worked OK, as far as it went, but I was 'put off' by it's scripting language, and not knowing how to incorporate it in other programs.
Best wishes,
Ray

Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #23 on: November 01, 2018, 10:22:31 AM »

I wonder if the problems I'm getting wrt usb, could be possibly due to the cable. Maybe I need one of these https://www.mackenziehifi.com/purist-audio-design-ultimate-usb-cable-1244-p.asp   
There must be an emoji for that...
Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #24 on: November 06, 2018, 10:23:51 AM »

Has anyone any experience of this? https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/virtual-hid-framework--vhf- ? Seeing as I'm using w10, and it seems there was never a usb api for earlier windows version, it looks like it is now possible to roll your own. It will take me a while to pick my way through this, since I really haven't a clue as to what is involved, only just skimmed through the page/links, so any suggestions/guidance greatly appreciated.

Best wishes,

Ray
Logged

SeaVipe

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 118
  • Windows 10
Re: mice - usb devices
« Reply #25 on: November 06, 2018, 11:44:24 AM »

Logged
Clive Richey

David Kenny

  • FireFly3 Registered User
  • Senior Member
  • *
  • Posts: 445
  • Windows 7
Re: mice - usb devices
« Reply #26 on: November 06, 2018, 03:27:28 PM »

Ray,

I've been watching this thread since you started it.  Your October 30 post was the first time I was able to get an idea of what you are trying to do.  I have some questions if you don't mind.  What mouse technology are you looking at? Optical, laser?  In either case, I think you will have to do some testing to see if this idea is workable.  I have some doubts.  While the resolution is very high, as you mentioned, the repeatability might not be there.  We don't really need repeatability in mice, at least not to the degree you need with CNC mills. 

Consider this:  You have a linear rail, and rigidly mounted a mouse to it such that it could only travel in a straight line, with a solid stop on each end.  You slide it to one side, zero your travel count, slide it to the other side counting up your mouse output as you go.  Then back to the starting position, counting down.  Do that a few times to see if the start-location value floats around. How close you come to zero when you get back will tell you if your idea has merit. It should remain zero every time (or at least not float around) for CNC.

David
Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #27 on: November 06, 2018, 04:29:28 PM »

Hi David,

Thanks for your questions. I'm also not sure about the repeatability as a linear scale, but I will not know until I've tried it. I suspect (if the internal optical mouse algorithm is similar to the earlier serial mouse type) that there is a buffer inbuilt, which may be rapidly filled, before values can be read out. I think the actual mechanics may be quite good once calibrated (allowing for errors caused by temperature, humidity, whatever). I've a suspicion that the optical principal is similar to the capacitance detection in the cheap digital calipers. The actual accuracy of the pcb in the calipers can be quite variable, but the scanning head is quite accurate. Anyway for my original use, as a cheap rotary encoder, I don't think the accuracy/repeatability is of a major concern. The only calibration is that the faster the handwheel turns, the faster the axis must jog, and if precision location is required, you go slow as you get near to where you want to be. I can apply multiplying/dividing factors as required to get a finer or coarser resolution. For real consistency/accuracy, I'd have to disable much of what w10 wants to do, since it is far from a rtos, when I'm actually trying to do any measuring.

If the resolution/accuracy is not good enough for metal, then it'll most likely be good enough for wood machining ;-)

I have done some very rough tests, a year or two back, running a mouse along a plank with a couple of stops, and observing on screen where it was stopping. It seemed good enough for me to consider what I'm trying to do now. (Obviously plenty of room for errors in such a crude test)

Best wishes,

Ray
Logged

raymw

  • FireFly3 User
  • Senior Member
  • *
  • Posts: 208
Re: mice - usb devices
« Reply #28 on: November 06, 2018, 04:42:10 PM »

Hi Clive,
Thanks for your post. I think I'd better make a start on the virtual driver framework, see if I understand any of it, before I try to contact the developers. I'm not sure how you found them, I never noticed any names on the url I had. I see I'll have to translate the c++ code to free basic, too. I hope it's not involving .net... Still, if it was easy, everybody would be doing it.
Best wishes,
Ray
Logged
Pages: 1 [2]