Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: compewter_numerical on January 15, 2021, 02:24:58 AM

Title: Mouse MPG Module
Post by: compewter_numerical on January 15, 2021, 02:24:58 AM
I am expiremtning with the mouse mpg I found here https://www.youtube.com/watch?v=MRyaRQwhYWk.

I was wondering if there is any way to listen for the scroll wheel without having to enter the window or a lua panel with the mouse?

I tried making a lua panel the size of the entire screen and then selecting the hidden check box in the screen editor. It worked but then I couldn't press any of the buttons on screen.
Title: Re: Mouse MPG Module
Post by: Brian Barker on January 15, 2021, 10:00:30 AM
I don’t think you can do it with Lua. In c++ I know I can do it but it is a low level windows call. This could be done in the keyboard plugin as it has the low level windows hooks.
Title: Re: Mouse MPG Module
Post by: compewter_numerical on January 19, 2021, 10:13:01 PM
do you think it would be possible for the devs to give us access to a register for the mousewheel rotation in the keyboard plugin? HID devices are easy to emulate with cheap hardware and could open the door to some cool stuff via bluetooth.

currently doing this like the youtube tutorial but only works in panel or wizard:
Code: [Select]
        panel:Connect(wx.wxID_ANY, wx.wxEVT_MOUSEWHEEL, function(event)
mpgRotation = mpgRotation + event:GetWheelRotation()
mc.mcRegSetValueLong(mpgPosReg, (mpgRotation / 120))
         end)

working on a bluetooth conversion for cheap MPG pendant
https://github.com/kethort/esp32-bluetooth-cnc-mpg-mach4
Title: Re: Mouse MPG Module
Post by: Brian Barker on January 21, 2021, 01:17:52 PM
Let me see if I can do that .. my list is getting long of things I need to do :( But let me see !
Title: Re: Mouse MPG Module
Post by: Brian Barker on January 22, 2021, 11:51:08 PM
I didn’t forget about this. I have been updating the code for the mouse mpg wizard. I will try to make a video showing shuttle mode. It really works slick! I will post it here soon.
Title: Re: Mouse MPG Module
Post by: Brian Barker on January 23, 2021, 08:39:10 AM
Hi all,
Here is my updated Mouse MPG code. The code looks a bit rough as I have not gone to clean it back up. I really made this to test the functionality of shuttle mode so I didn't have to wire anything into my development PC. What can I say! Walking over getting a board wiring an MPG is simply more work than sitting at your desk enjoying your coffee. Anyway enough about the origin of this.

Instructions to test it out and use it ... Place the lua file into the Wizards directory (mach4hobby/Wizards). To start it up go to Wizards menu and select MouseMPG .  Now to test it simply select Shuttle. Load of your favorite Gcode files and press cycle start. The machine will NOT move if Shuttle mode is active. Mouse back over and give focus to the MouseMPG window that is up. Move the mouse wheel and proportional to your wheel speed the machine will do the Gcode file. You stop moving it stops.  Now you don't have to go forward only.. You can just wiggle the wheel back and forth. If you select some other selection in the MouseMPG dialog it will take off and start running. at programmed feedrate. I think that should be enough to test. Please tell me how it works for you and if you think this is worth going into the release. I can add it to the installer or even put it as an item on the main screen of 4.

Thanks
Brian
 
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 01, 2021, 04:36:38 PM
This shuttle mode is cool, but the original question was a bit different.
 
... I was wondering if there is any way to listen for the scroll wheel without having to enter the window or a lua panel with the mouse? ...

I was asking if the devs could allow listening to scroll wheel in the keyboard plugin so the mouse doesn't have to be in a window or panel in order to get the counts. No worries if not possible, just thought it would be useful.
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 01, 2021, 04:54:09 PM
Yeah, it looks like it can be done.. I have been trying to get things off my plate. I will give it an hour tomorrow and see if I can get this https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa to  work. I have a hook in now to grab the low level keyboard so I should be able to make that work as well. Mucking around with this stuff is on my list of things I don't like so it takes a push to do it :)

Thanks
Brian
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 02, 2021, 06:45:31 PM
Update, I got the mouse wheel so I can  read it, the question is do you want the mouse wheel to keep being sent to the rest of windows or do you want me to stop the message propagation? In other words the mouse wheel will stop working in whatever you have selected. I can add a toggle as a key binding or as an output you can map. You asked for it lol
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 02, 2021, 07:20:43 PM
That’s cool. Is this feature in the keyboard plugin? Can I get a link to test it out? I won’t really know if the key binding will be necessary until I can test it
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 02, 2021, 08:07:46 PM
I will post a link tomorrow :)
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 03, 2021, 10:19:29 AM
Okay you asked for it! I guess it works as you would like. I made it so you can map it to an MPG in configure->controller MPG's . Set the MPG to the Keyboard/MouseWheel and one Click per , Acceleration to 100 Velocity at 100. Also it would be a good idea to enable it!

This will be taken down once we are done and it is in the release...
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 03, 2021, 05:24:08 PM
thanks. I think your idea to map a key to toggle it on or off makes sense than having it always listening. it would be much safer that way.
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 03, 2021, 08:14:41 PM
I will do a Key or an output you can map I guess. Sound good? I will do that when I get in tomorrow.
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 03, 2021, 08:46:19 PM
okay thanks i think the key map would be easier to work with. thanks for the work you put in this.
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 04, 2021, 12:29:41 PM
Here you are with 300% more settings to enable and disable the wheel. I added a button action to do the following:
1.) Toggle the Mouse Wheel enable
2.) Mouse Wheel On
3.) Mouse Wheel Off

I put the code in and your job is to test it :)
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 05, 2021, 08:35:29 AM
This had no ill effects so it is now in the versions after 4690 ;) . We are testing for release so we should have this on the web if all goes well in testing. All features are cut off for now.
Title: Re: Mouse MPG Module
Post by: jbuehn on February 05, 2021, 03:32:15 PM
Is 4609 what you're release testing right now?
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 05, 2021, 03:38:43 PM
It is but we will have a new version out soon!
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 05, 2021, 08:08:02 PM
...I put the code in and your job is to test it :)

It's working great after testing it some. I used it for a bluetooth device that emulates a Mouse/Keyboard to simulate a MPG.

Here's demo:
https://www.youtube.com/watch?v=MvadVEjZ93Q

Thanks for adding this feature!
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 06, 2021, 05:24:57 PM
Hey is that one of the Arduino but not really ESP866 boards? if so... I just got a few of them I was going to goof around with. I am way more than happy to code the TCP on my side and help with the source code. I know I can make this all work in Lua! I was able to talk to JRMI from MAch4 to run my son's train layout :)
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 06, 2021, 10:47:51 PM
Hey is that one of the Arduino but not really ESP866 boards? if so... I just got a few of them I was going to goof around with. I am way more than happy to code the TCP on my side and help with the source code. I know I can make this all work in Lua! I was able to talk to JRMI from MAch4 to run my son's train layout :)

The demo video I posted the device is using Bluetooth and acting like a keyboard in Windows so no TCP development necessary. The device is an ESP32, here is a giant Amazon link. You can get them cheaper if you shop around.

Code: [Select]
https://www.amazon.com/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated/dp/B0718T232Z/ref=sr_1_1_sspa?dchild=1&keywords=esp32&qid=1612668987&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUFVUkxSR00yT1RVUVkmZW5jcnlwdGVkSWQ9QTA2MDg5NzkyQVo5NjkwUDNHTkczJmVuY3J5cHRlZEFkSWQ9QTAyMDg0MzEyTzNRU1ZWVFJUQTFOJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==
I'm not sure if the ESP8266 has bluetooth but if it does, it should work the same it's just a slower processor.

There is no LUA code necessary except updating the signal library, thanks to your update to the keyboard plugin, all the inputs are going through the keyboard plugin.

I just barely completed this, but here is firmware and the Mach4 auto installer: https://github.com/kethort/esp32-bluetooth-cnc-mpg-mach4 (https://github.com/kethort/esp32-bluetooth-cnc-mpg-mach4)

The MPGInstaller.exe in the dist folder will auto install all the settings and the plugin into Mach4, you just need to select the Mach4 directory and profile and hit install.

The MPGInstaller.exe will overwrite inputs 55 to 63 in Mach4 input config.

In the video, I am using rotary analog knobs, they are not typical switch knobs so there are two different versions of the firmware. In the Arduino folder of the repo there are two sketches. The one with analog is the only one I've been able to test so far. The other sketch is for regular switch knobs.

If you have a regular switch knob, the firmware is programmed so the inputs react to a ground signal (inputs are pullups).

You need two Arduino libraries which I linked in the repo and you also need to know how to program the ESP but I assume you already know how to if you own some ESP's already. I'll probably be updating the repo with instructions but you can find similar instructions for using the installer in another project I worked on here: https://github.com/kethort/esp32-cnc-mpg-handwheel-conversion-mach4

The input hardware mapping in the (Arduino) firmware is shown in the sharp defines in the top of the sketch.

If you get this working and test and find issues let me know I'll try to fix it.
 
Title: Re: Mouse MPG Module
Post by: compewter_numerical on February 06, 2021, 11:49:09 PM
Forgot to mention, the MPGInstaller.exe will also automatically edit the screen and put in the LUA code for the signal library. 
Title: Re: Mouse MPG Module
Post by: Brian Barker on February 07, 2021, 06:49:35 AM
Ahh I have some of the esp32’s, I want to use Ethernet :) my problem is time but I love what you have done! Keep up the great work and if I can help I will donate some more time ;)