Hello Guest it is March 28, 2024, 05:37:07 PM

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

0 Members and 1 Guest are viewing this topic.

Re: mcX360 Plugin for Lua
« Reply #50 on: November 07, 2017, 01:36:43 PM »
Daz, sage advice as always.

One correction for anyone following this thread:
    if GetXin("Btn_A") == "1" then
should read:       
    if GetXin("Btn_A") == 1 then
   

After rethinking how I want to use the controller I want to toggle the controller on/off (xEnabled) using the start button.

The following code does what I want but the first press shows 'Pendant Disabled' rather than my expected 'Pendant Enabled'.  Where did I err in my code/logic?

Code: [Select]
-----------------Event Timers
X360_Timer:Start(100)
local StartVal=0
X360_Panel:Connect(wx.wxEVT_TIMER, function (event)
-- Toggle xEnabled when Start Button is depressed
  if GetXin("Btn_START") == 1 then
    if StartVal==1 then --more than one start signal received before release
      return
    end
    if xEnabled == false then
--      Btns_Timer:Start(50)
      mc.mcCntlSetLastError(mInst,"Pendant Enabeled")
      xEnabled=true
    else
--      Btns_Timer:Stop()
      mc.mcCntlSetLastError(mInst,"Pendant Disabeled")
      xEnabled=false
    end
    StartVal=1
  else
    StartVal=0
  end
end)

TIA

RT
Re: mcX360 Plugin for Lua
« Reply #51 on: November 07, 2017, 02:08:04 PM »
Amazing what a little lunch will do for you. 

I had declared local Xenabled=false and was using xEnabled instead

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #52 on: November 07, 2017, 04:42:05 PM »
Good spot on the   
Code: [Select]
if GetXin("Btn_A") == "1" then
When I first posted some code the GetXin function returned a string

Code: [Select]
function GetX360(xinput)
    local hreg = mc.mcRegGetHandle(inst, string.format("mcX360_LUA/%s", xinput))
    return mc.mcRegGetValueString(hreg)
end

Then after a while it was more beneficial to return an int, so the function was changed to

Code: [Select]
function GetXin(xinput)
    local hreg = mc.mcRegGetHandle(mInst, string.format("mcX360_LUA/%s", xinput))
    return mc.mcRegGetValueLong(hreg)
end

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #53 on: November 08, 2017, 12:13:45 PM »
I've been chasing my tail with trying to change the jog increment for a full day.  To test it without the xBox so as to limit the possible errors I have done the following:
on the jog panel added a DRO and set it to CurrentJogIncr.  When using the 'Incremental Jog Step' button it correctly updates.
I then added a button and in the left up script added the following code which is what I would be doing in the xBox controller:

Code: [Select]
       local mInst=0
        local CurInc = mc.mcProfileGetInt(mInst,"Preferences","JogIncSet",0) --make a new setting in profile to hold our current inc number
        local SetInc = mc.mcProfileGetDouble(mInst,"Preferences","JogInc"..CurInc,0.00) -- fetch our inc value from the profile JogInc + 2 say = [Preferences][JogInc2]

        CurInc = CurInc + 1 -- increment our CurInc by 1
        if CurInc > 10 then CurInc = 1 end -- if our CurInc is greater than 10 then go back to 1
        
        mc.mcJogSetInc(mInst, mc.X_AXIS, SetInc) -- set inc for axis
        mc.mcJogSetInc(mInst, mc.Y_AXIS, SetInc) -- set inc for axis
        mc.mcJogSetInc(mInst, mc.Z_AXIS, SetInc) -- set inc for axis

        mc.mcProfileWriteInt(mInst,"Preferences","JogIncSet",CurInc) --set our profile to new CurInc
        local s=tostring(CurInc)
        mc.mcCntlSetLastError(0,s)

When I use the button the txtJogInc control updates but the DRO does not.  You can see from the error messages that the CurInc is updating but when the 'Incremental Jog Step' button is used it is not synced to the last change.  There seems to be a flaw in the way the dro works or in the way mach checks to see what the current increment has been changed to...or...in my understanding!

Any help?

RT
Re: mcX360 Plugin for Lua
« Reply #54 on: November 10, 2017, 05:51:42 PM »
Daz,

Everyone always something more. ;D

In Lee's mach3 plugin the thumb sticks had another capability by depressing them straight down.  Would it be possible to expose that as a button click in your next release of the  plugin?

RT

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #55 on: November 11, 2017, 08:38:32 AM »
It should already be there as Btn_LTH and Btn_RTH but anyway heres a version compiled with latest sdk

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #56 on: November 11, 2017, 05:53:58 PM »
Daz, works a charm!

They may have been in the other one but I have never seen a list of all the codes listed anywhere.

Thanks!

RT

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: mcX360 Plugin for Lua
« Reply #57 on: November 11, 2017, 10:49:36 PM »
go into the diagnostic menu and open the the regfile diagnostic window, you will get a full list from the tree and see live data being populated on the tree.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: mcX360 Plugin for Lua
« Reply #58 on: January 17, 2018, 08:47:47 AM »
Hi Daz,

I'm watching your mcx360 yutube part1 and following your code.

But I got stuck...

When I move any AXIS to negative direction, it stuck.

I can't find what's wrong... I do that same as in the video...

I used the latest plugin you posted (dated, 2017-11-11)

Would you please take a look?
(Script, attached)

And... do you have some full fledged mcx360 script?
For me, scripting from null is too hard.... it would be a great help if I have a complete script that I can modify myself.

Re: mcX360 Plugin for Lua
« Reply #59 on: March 17, 2018, 08:33:24 PM »
Just curious if any game controller can work, or is an X-Box 360 controller necessary? Wired/wireless? I'm trying to help a friend get his Bridgeport NC mill running again, and I'm lousy with usb generic game controllers, but they don't seem to show up when plugged in. Any help would be appreciated