No-one spotted the huge errors in the pseudocode?
The first version didn't work right for AI Servo, especially with a static target. This does -
function phase detect ()
.. if AF
..... if One-Shot
........ disable shutter firing
..... else
........ enable shutter firing
........ previous phase difference = current phase difference
..... while true
........ while current phase difference =/= 0
........... while current phase difference is indeterminate or out of range
.............. rack lens
.............. focus confirmation light = blink
.............. wait a while then try again
........... focus confirmation light = off
........... if One-Shot
.............. calculate lens command from current phase difference
........... else
.............. calculate lens command from current and previous phase diffs
.............. previous phase difference = current phase difference
........... update lens command
........ if One-Shot
........... beep
........... flash AF point
........... focus confirmation light = on
........... enable shutter firing
........... return
.. else
..... enable shutter firing
..... while true
........ if current phase difference =/= 0
........... focus confirmation light = off
........ else
........... beep
........... flash AF point
........... focus confirmation light = on