--------------Declares local mInst = mc.mcGetInstance() local Xenabled = false local ESState = false local JogInc = 1 local XPState = false local XNState = false local YPState = false local YNState = false local ZPState = false local ZNState = false -- X360 Init Panel X360_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize) X360_Timer = wx.wxTimer(X360_Panel) X360_Timer:Start(100) -- EStop EStop_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize) EStop_Timer = wx.wxTimer(EStop_Panel) -- DPad DPad_Panel = wx.wxPanel( wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize) DPad_Timer = wx.wxTimer(DPad_Panel) --------------Functions function GetXin(xinput) local hreg = mc.mcRegGetHandle(mInst, string.format("mcX360_LUA/%s", xinput)) return mc.mcRegGetValueLong(hreg) end --------------Event Timers X360_Panel:Connect(wx.wxEVT_TIMER, function (event) if GetXin("LTR_Val") > 150 and Xenabled == false then EStop_Timer:Start(50) DPad_Timer:Start(100) Xenabled = true mc.mcCntlSetLastError(mInst,"x_360 Running") elseif GetXin("LTR_Val") < 50 and Xenabled == true then EStop_Timer:Stop() DPad_Timer:Stop() Xenabled = false 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) DPad_Panel:Connect(wx.wxEVT_TIMER, function (event) -- X++ if GetXin("DPad_RIGHT") == 1 and GetXin("Btn_LS") == 0 and XPState == false then mc.mcJogIncStart (mInst, mc.X_AXIS, JogInc) XPState = true end if GetXin("DPad_RIGHT") == 0 and GetXin("Btn_LS") == 0 and XPState == true then mc.mcJogIncStop (mInst, mc.X_AXIS, .1) XPState = false end -- X-- if GetXin("DPad_LEFT") == 1 and GetXin("Btn_LS") == 0 and XNState == false then mc.mcJogIncStart (mInst, mc.X_AXIS, -1 * JogInc) XNState = true end if GetXin("DPad_LEFT") == 0 and GetXin("Btn_LS") == 0 and XNState == true then mc.mcJogIncStop (mInst, mc.X_AXIS, .1) XPState = false end -- Y++ if GetXin("DPad_UP") == 1 and GetXin("Btn_LS") == 0 and YPState == false then mc.mcJogIncStart (mInst, mc.Y_AXIS, JogInc) YPState = true end if GetXin("DPad_UP") == 0 and GetXin("Btn_LS") == 0 and YPState == true then mc.mcJogIncStop (mInst, mc.Y_AXIS, .1) YPState = false end -- Y-- if GetXin("DPad_DOWN") == 1 and GetXin("Btn_LS") == 0 and YNState == false then mc.mcJogIncStart (mInst, mc.Y_AXIS, -1 * JogInc) YNState = true end if GetXin("DPad_DOWN") == 0 and GetXin("Btn_LS") == 0 and YNState == true then mc.mcJogIncStop (mInst, mc.Y_AXIS, .1) YPState = false end -- Z++ if GetXin("DPad_UP") == 1 and GetXin("Btn_LS") == 1 and ZPState == false then mc.mcJogIncStart (mInst, mc.Z_AXIS, JogInc) ZPState = true end if GetXin("DPad_UP") == 0 and GetXin("Btn_LS") == 1 and ZPState == true then mc.mcJogIncStop (mInst, mc.Z_AXIS, .1) ZPState = false end -- Z-- if GetXin("DPad_DOWN") == 1 and GetXin("Btn_LS") == 1 and ZNState == false then mc.mcJogIncStart (mInst, mc.Z_AXIS, -1 * JogInc) ZNState = true end if GetXin("DPad_DOWN") == 0 and GetXin("Btn_LS") == 1 and ZNState == true then mc.mcJogIncStop (mInst, mc.Z_AXIS, .1) ZPState = false end end)