OK, you are right - it seems that LUA doesn't follow the same idioms that some other languages do. It needs an explicit equality check.
But not done yet - it seems that Running, rc = mc.mcCntlIsInCycle(inst) may not be the right test.That appears to test if a *file* is running, not that the machine is active (so it doesn't work for MDI programs).
--------------------------------------------------------------
-- Control Panel Feed Hold
-- One push for Feed Hold, two pushes for Cycle Stop
---------------------------------------------------------------
function InputFeedHold()
-- Momentary pushbutton, so we get TWO signals with each button press:
-- an "ON" and an "OFF"
-- So check state and ignore the "OFF"
local hHoldButton
local HoldButtonState
hHoldButton, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2) -- signal 2
HoldButtonState, rc = mc.mcSignalGetState(hHoldButton)
if (HoldButtonState == 1) then
mc.mcCntlSetLastError(inst, "Control Panel Feed Hold PRESS")
-- If we are running a program, pause
-- If we are already paused, stop
local Running
local Paused
Running, rc = mc.mcCntlIsInCycle(inst)
Paused, rc = mc.mcCntlFeedHoldState(inst)
if (Paused == 1) then -- We are paused, so stop
CycleStop()
-- rc = mc.mcCntlFeedHold(inst) -- TODO This is wrong, but I want hold not stop right now
mc.mcCntlSetLastError(inst, "Control Panel CYCLE STOP")
elseif (Running == 1) then -- We are running, so do something
rc = mc.mcCntlFeedHold(inst) -- Should this maybe be FeedHold()?
mc.mcCntlSetLastError(inst, "Control Panel FEED HOLD")
else
-- Spurious button press
mc.mcCntlSetLastError(inst, "Not running or paused - IGNORE ME")
end
else
mc.mcCntlSetLastError(inst, "Control Panel Feed Hold RELEASE")
end
end
This will CycleStop if the machine is in feed hold (via the GUI) but doen't respond to a button press feed hold; it follows the IGNORE ME path.
CONFIRMED - works perfectly if I load a gcode from *file*, but MDI fails.
There doesn't seem to be an API call that returns true if an MDI file is running?