public void Timer_Tick(object state)
        {
            switch (_boardAlignmentState)
            {
            case BoardAlignmentState.MovingToOrigin:
                if (!Machine.Busy)
                {
                    Machine.SendCommand("G10 L20 P0 X0 Y0");
                    _boardAlignmentState = BoardAlignmentState.Idle;
                    Status = "Completed";
                }
                break;

            case BoardAlignmentState.MovingToSecondFiducial:
            case BoardAlignmentState.Idle:
                break;

            default:
                if ((DateTime.Now - _lastActivity).TotalSeconds > 10)
                {
                    _boardAlignmentState = BoardAlignmentState.Idle;
                    Status = "Timeout";
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);
                }
                break;
            }
        }
        public override void CircleCentered(Point2D <double> point, double diameter)
        {
            if (!Machine.Busy)
            {
                switch (_boardAlignmentState)
                {
                case BoardAlignmentState.FindingFiducialOne:
                    _lastActivity = DateTime.Now;
                    Status        = "Moving to Second Fiducial";
                    _positionManager.FirstLocated = RequestedPosition;
                    _boardAlignmentState          = BoardAlignmentState.MovingToSecondFiducial;

                    var fiducialX = RequestedPosition.X + (Machine.PCBManager.SecondFiducial.X - Machine.PCBManager.FirstFiducial.X);
                    var fiducialY = RequestedPosition.Y + (Machine.PCBManager.SecondFiducial.Y - Machine.PCBManager.FirstFiducial.Y);
                    RequestedPosition = new Point2D <double>(fiducialX, fiducialY);

                    Machine.GotoPoint(RequestedPosition);

                    break;

                case BoardAlignmentState.FindingFiducialTwo:
                    _lastActivity = DateTime.Now;
                    _positionManager.SecondLocated = RequestedPosition;
                    _boardAlignmentState           = BoardAlignmentState.MovingToOrigin;
                    Machine.PCBManager.SetMeasuredOffset(_positionManager.OffsetPoint, _positionManager.RotationOffset.ToDegrees());
                    Machine.GotoPoint(_positionManager.OffsetPoint);
                    Status = "Returning to Board Origin";
                    break;
                }
            }
        }
        public void AlignBoard()
        {
            _lastActivity = DateTime.Now;

            _boardAlignmentState = BoardAlignmentState.FindingFiducialOne;
            Status = "Centering On First Fiducial";

            _timer.Change(0, 500);
        }
        public override void CircleLocated(Point2D <double> offset, double diameter, Point2D <double> stdDev)
        {
            if (!Machine.Busy)
            {
                _lastActivity = DateTime.Now;

                switch (_boardAlignmentState)
                {
                case BoardAlignmentState.FindingFiducialOne:
                case BoardAlignmentState.FindingFiducialTwo:
                    JogToLocation(offset);
                    break;

                case BoardAlignmentState.MovingToSecondFiducial:
                    Status = "Searching for Second Fiducial";
                    _boardAlignmentState = BoardAlignmentState.FindingFiducialTwo;
                    break;
                }
            }
        }
 public void CancelBoardAlignment()
 {
     _boardAlignmentState = BoardAlignmentState.Idle;
     Status = "Idle";
     _timer.Change(Timeout.Infinite, Timeout.Infinite);
 }