public void SetStartZ(IDeviceDelegateStop start)
 {
     startZ = start;
 }
 public void SetStopZ(IDeviceDelegateStop stop)
 {
     stopZ = stop;
 }
        private static void InitializeGCodeParser()
        {
            settings = new Settings();
            settings.OneStepZ_Angle_Positive = 30;
            settings.OneStepZ_Angle_Negative = 15;

            var servo = new Servo(
                PWMChannels.PWM_PIN_D10,
                new ServoConfig(0, 180, 500, 2500, 50));

            servo.RotateTo(15);
            Thread.Sleep(500);
            servo.RotateTo(35);

            var motorShield = new AdafruitMotorShield();
            IDeviceDelegateOneStep oneStepX = PrepareOneStepDelegate(motorShield, 1, OperationMode.FullStep);
            IDeviceDelegateOneStep oneStepY = PrepareOneStepDelegate(motorShield, 2, OperationMode.FullStep);
            IDeviceDelegateOneStep oneStepZ = (steps) =>
            {
                var a = servo.Angle;

                if (steps >= 0)
                {
                    servo.RotateTo(settings.OneStepZ_Angle_Negative);
                }
                else
                {
                    servo.RotateTo(settings.OneStepZ_Angle_Positive);
                }

                if (a != servo.Angle)
                {
                    Thread.Sleep(500);
                }
            };
            IDeviceDelegateStop startX = () => {  };
            IDeviceDelegateStop startY = () => {  };
            IDeviceDelegateStop startZ = () => {
                servo.RotateTo(settings.OneStepZ_Angle_Negative);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Positive);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Negative);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Positive);
            };

            IDeviceDelegateStop stopX = () => { motorShield.GetStepper(2).ReleaseHoldingTorque(); };
            IDeviceDelegateStop stopY = () => { motorShield.GetStepper(1).ReleaseHoldingTorque(); };
            IDeviceDelegateStop stopZ = () => { servo.RotateTo(settings.OneStepZ_Angle_Negative); };

            var device = new XYZGantryDevice();

            device.SetStepX(oneStepX);
            device.SetStepY(oneStepY);
            device.SetStepZ(oneStepZ);
            device.SetStartX(startX);
            device.SetStartY(startY);
            device.SetStartZ(startZ);
            device.SetStopX(stopX);
            device.SetStopY(stopY);
            device.SetStopZ(stopZ);

            device.Calibrate(25f, 25f, 1);


            var machine = new GCodeMachine(device);

            parser = new GCodeParser(machine);
        }