-- настройка от двух датчиков пробинга
require("Common")
function m115(probe_direction)
	local ProbeFeedFast = GetGeneralProbeFeed()
	local ProbeFeedSlow = ProbeFeedFast / 10
	local TipHeight
	if (probe_direction == Directions.Z_Minus) then
		TipHeight = GetGeneralTipHeight()
	else
		TipHeight = 0
	end
	local Bounce = 3
	
	PushCurrentDistanceMode()
	PushCurrentMotionMode()
	local savedFeed = GetGCodeFeedrate()
	
	local AxesNumber, AxesLetter, Sign
	if (probe_direction == Directions.X_Minus or probe_direction == Directions.X_Plus) then
		AxesNumber = Axis.X
		AxesLetter = "X"
	elseif (probe_direction == Directions.Y_Minus or probe_direction == Directions.Y_Plus) then
		AxesNumber = Axis.Y
		AxesLetter = "Y"
	else
		AxesNumber = Axis.Z
		AxesLetter = "Z"
	end
	
	if (probe_direction == Directions.X_Plus or probe_direction == Directions.Y_Plus) then
		Sign = 1
	else
		Sign = -1
	end
	local CurrCoord = AxisGetPos(AxesNumber)
	
	if (IsProbingPinConfigured()) then
		if (PinGetState(Inputs.Probing)) then
			DisplayMessage(GetMessage(Messages.ProbeActive))
			return
		end
		
		local ProbeLim = 1000
		local ProbingMaximum = CurrCoord + Sign * ProbeLim

		if (AxesNumber ~= Axis.Z) then
			ExecuteMDI("G90 G38.2 "..AxesLetter..str(ProbingMaximum).." F"..ProbeFeedFast)
			local Raise = AxisGetPos(AxesNumber) - Sign * Bounce
			ExecuteMDI("G90 G0 "..AxesLetter..str(Raise))
			ExecuteMDI("G90 G38.2 "..AxesLetter..str(ProbingMaximum).." F"..ProbeFeedSlow)
			ExecuteMDI("G10 L20 P0 "..AxesLetter..TipHeight)
			Raise = AxisGetPos(AxesNumber) - Sign * Bounce
			ExecuteMDI("G90 G0 "..AxesLetter..str(Raise))
		else
			if (IsSpecificProbingPinConfigured(1) and IsSpecificProbingPinConfigured(2)) then
				ExecuteMDI("G90 G38.2 "..AxesLetter..str(ProbingMaximum).." F"..ProbeFeedFast)
				Sleep(100)
				if ( not PinGetState(Inputs.Probing)) then
					DisplayMessage("Первый вход пробинга не активен")
					return
				end
				ProbingMaximum = AxisGetPos(AxesNumber) - 10
				ExecuteMDI("G90 G38.2 P2"..AxesLetter..str(ProbingMaximum).." F"..ProbeFeedSlow)
				ExecuteMDI("G10 L20 P0 "..AxesLetter..TipHeight)
				
				GotoSafeZ()
			else 
				DisplayMessage("Требуется настроить оба входа пробинга")
				return
			end
		end

	else
		DisplayMessage(GetMessage(Messages.ProbeNotConfigured))
		return
	end
	
	ExecuteMDI("F"..savedFeed)
end