modified your code a bit:
Impossible to talk correctly with Chinese manufacturer (Rattmotor / Powace in aliexpress).
I go to use the spindle without the tool clamped sensor, if one day i disassemble the spindle for change bearings i go to adjust this sensor, but for the moment i don't want to disassembly the spindle.
Here i post a video for see this issue (short video).
https://www.youtube.com/watch?v=MDXX0MyDeL8
I think i right to think this isn't good no?
Tomorrow maybe arrive the rails (12mm non hiwin rails) and start to try the macro.
Thanks another time for your time.