Hello Guest it is March 28, 2024, 01:43:15 PM

Author Topic: mcX360 Plugin for Lua  (Read 44974 times)

0 Members and 1 Guest are viewing this topic.

Re: mcX360 Plugin for Lua
« Reply #40 on: May 22, 2017, 03:13:33 AM »
I'm new to Mach4 and cant seem to get the mcX360_LUA.rar plugin to work on my computer. When Mach4 is loading the Xbox Controller light flashes and once the screen comes up the message line at the bottom reads "mcX360 Controller Found and Active" but nothing moves when I work the joypad. I do have xinput9_1_0 dll in system32. Am I missing a step?
Thanks for any help on this!
-Pat
« Last Edit: May 22, 2017, 03:23:42 AM by patpat »
Just makin' chips!

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #41 on: May 22, 2017, 06:55:26 AM »
mcX360 will not configure itself, its a plugin to enable you to write your own scripts in lua to setup the controller how you want it. Take a look at the videos for examples.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #42 on: June 07, 2017, 02:58:15 PM »
Hi Daz, I'm setting up a CNC Mill for the very first time and I'm completely new to this. Purchased Mach4 and I'm trying to get a Play Station 3 style (Snakebite brand) game controller to work.

You mentioned that there are videos that show how to write LUA scripts for the mcX360? Where are these videos?
Thanks,
Kevin.

I found Part 1 at:  https://www.youtube.com/watch?v=zMUFlBt61Ic
Is there a part 2?
« Last Edit: June 07, 2017, 03:06:02 PM by keinert »

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #43 on: June 07, 2017, 03:31:59 PM »
There didnt seem a point of doing a part 2 as the way it works is for anyone to set it up how they want and part 1 was just a pointer to show how to access the values in the registry.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #44 on: June 07, 2017, 03:41:58 PM »
OK, I understand, Thanks Daz, you may have answered these questions already but I'll ask again:
1) where can I get the mcX360_LUA.m4pw and mcX360_LUA.sig files? (Do I need them both to run a generic PS3 style game controller?)
2) will these work if my game controller is not for the Xbox360?

Thanks

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #45 on: June 07, 2017, 04:52:05 PM »
You can get the files from the first post of this thread http://www.machsupport.com/forum/index.php/topic,33121.0.html,
I have never had a PS3 so I couldnt answer if they will work.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #46 on: August 12, 2017, 06:55:14 PM »
Hi there. I first tried the original plugin but then wanted to try the Lua version so I could customize. I feel pretty confident I followed you pretty well watching your video but for some reason I can't figure out, nothing happens when I press the buttons on the controller. I have the plugin active and can see the buttons are working using the register diagnostics. Maybe I'm missing some other setting? Here's what I have so far in the enabled and hidden Lua panel. Any help would be greatly appreciated.

Code: [Select]
-------------------------------------------------------
-- X_360 Lua by DazTheGas
-------------------------------------------------------

-------------------Declares
local mInst = mc.mcGetInstance()
local mInst = mc.mcGetInstance()
local Xenabled = false
local ESSTate = false

-- X360 Init Panel
    X360_Panel = wx.wxPanel(wx.NULL, wx.wxID_ANY, wx.wxDefaultPostion, wx.wxDefaultSize)
    X360_Timer = wx.wxTimer(X360_Panel)
    X360_Timer:Start(100)
-- EStop
    Estop_Panel = wx.wxPanel(wx.NULL, wx.wxID_ANY, wx.wxDefaultPostion, wx.wxDefaultSize)
    Estop_Timer = wx.wxTimer(Estop_Panel)
EStop_Timer:Start(50)

-------------------Functions

function SetXin(xinput)
    local hreg = mc.mcRegGetHandle(mInst, string.format("mcX360_LUA/%s", xinput))
    mc.mcRegSetValueLong(hreg, speed)
end

-------------------Event Timers

X360_Panel:Connect(wx.wxEVT_TIMER, function (event)
    if GetXin("LTR_Val") > 150 and Xenabled == 0 then
        EStop_Timer:Start(50)
        Xenabled = 1
        mc.mcCntlSetLastError(mInst,"X_360 Running")
    elseif GetXin("LTR_Val") < 50 and Xenabled == 1 then
        EStop_Timer:Stop()
        Xenabled = 0
        mc.mcCntlSetLastError(mInst,"X_360 Stopped")
    end
end)

EStop_Panel:Connect(wx.wxEVT_TIMER, function (event)
    if GetXin("Btn_B") == 1 and ESSTate == false then
        local Estop = mc.mcSignalGetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY))
        if (EStop == 1) then
            mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY), 0)
        else
            mc.mcSignalSetState (mc.mcSignalGetHandle (mInst, mc.ISIG_EMERGENCY), 1)
        end
        ESState = true
    end
    if GetXin("Btn_B") == 0 and ESState == true then
        ESState = false
    end
end)

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #47 on: August 13, 2017, 04:04:52 AM »
You seem to be missing the function GetXin

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #48 on: November 06, 2017, 04:45:12 PM »
First thanks to all that have contributed to this effort on the xBox controller.

I saw that the plugin was already present in the plugins directory so,


What I did:

Watched the video twice.
Enabled the xBox360 plugin. Restarted Mach4.
From 'Diagnostics->RegFile I can see the Btn_B entry change from 0 to one when I press the xBox B
copied the code from Franco (I am using on a lathe as well):
  https://www.machsupport.com/forum/index.php/topic,33121.30.html
reply 31

Created the Lua panel and inserted the code
Saved the changes.
Added the on unload script to check to see if the timer is still running.


From the history button I see:  'mcX360 found and active'.

Pressing the B button nothing happens but shows in the RegFile as being changed.

The GetXin function and the X360_Panel:Connect are being constantly called.(Put a wxMessageBox in the function, thanks for the command line \e tip)
Neither the EStop_panel:Connect nor the Btns-Panel:Connect are ever called.

What did I miss?


TIA

RT

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #49 on: November 06, 2017, 05:34:10 PM »
One thing I would suggest is to start with the most minimum script to test first

Code: [Select]
local inst = mc.mcGetInstance()

local X360_PNL = mcLuaPanelParent;


    function GetXin(xinput)
    local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
    return mc.mcRegGetValueString(hreg)
    end


X360_timer = wx.wxTimer(X360_PNL)

    X360_PNL:Connect(wx.wxEVT_TIMER,   function (event)

    if GetXin("Btn_A") == "1" then
     -- do something after button A is pressed
    end
   
    if GetXin("Btn_B") == "1" then
     -- do something after button B is pressed
    end
 
    end)

    X360_timer:Start(100)

DazTheGas
New For 2022 - Instagram: dazthegas