See https://duet3d.dozuki.com/Wiki/Gcode?revisionid=HEAD#Section_M594_Enter_Leave_Height_Following_mode.

The IR sensor doesn't have a true analog output, although it could do with modified firmware and a smoothing capacitor on the output.