My own thoughts on how to do this are to have the sewing machine driven by a servo motor. When the CNC program calls for stitching, as in "spindle on" or M03, the
motor runs at some set speed. When the spindle command is turned off, (M05)
then the servo drive is commanded to a lower speed, and when the needle full up
sensor on the sewing machine detects it is there, the motor is stopped. If every
place in the G-code where the spindle is stopped has a short dwell for the needle(s)
to reach full up, then it will be safe to slew to the next part of the embroidery
pattern.
This scheme could be implemented in physical hardware, some simple analog circuits and a FF to trip the servo off when the sensor senses the needle up.
Or, it could all be done with a few HAL components. You couldl also have a
DAC that sets the normal speed and the needle up seek speeds, and use an
enable command to stop each motor at the right time.
Jon