Exemplo n.º 1
0
        public async Task SetupCommandInterpreter()
        {
            if (commandInterpreter != null)
            {
                return;
            }
            commandInterpreter = await CommandInterpreter.CreateAsync();

            commandInterpreter.CommandReceived += commandReceived;
        }
Exemplo n.º 2
0
        public static async Task <GameManager> CreateAsync()
        {
            var commandInterpreterConstructor = CommandInterpreter.CreateAsync();

            ChessLogic logic = new ChessLogic();

            var stepCountPinX     = new GpioPinWrapper(5, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp);
            var stepClearPinX     = new GpioPinWrapper(13, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low);
            var motorInformationX = new MotorInformation(Axis.X, stepCountPinX);
            var motorDriverX      = new MotorDrv(20, 21, motorInformationX);
            var motorLocatorX     = new MotorLocator(stepClearPinX, motorDriverX.Information);
            var positionSignalerX = new PositionSignaler(motorLocatorX);
            var motorMoverX       = new MotorMover(50, positionSignalerX, motorLocatorX, motorDriverX);

            var stepCountPinY     = new GpioPinWrapper(6, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp);
            var stepClearPinY     = new GpioPinWrapper(19, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low);
            var motorInformationY = new MotorInformation(Axis.Y, stepCountPinY);
            var motorDriverY      = new MotorDrv(24, 23, motorInformationY);
            var motorLocatorY     = new MotorLocator(stepClearPinY, motorDriverY.Information);
            var positionSignalerY = new PositionSignaler(motorLocatorY);
            var motorMoverY       = new MotorMover(50, positionSignalerY, motorLocatorY, motorDriverY);

            var topInterrupterX    = new PhotoInterrupter(17, 1, 150);
            var bottomInterrupterX = new PhotoInterrupter(27, -1, -150);
            var motorCalibratorX   = new MotorCalibrator(-23, 23, motorMoverX, motorInformationX, topInterrupterX, bottomInterrupterX);

            var topInterrupterY    = new PhotoInterrupter(25, 1, 150);
            var bottomInterrupterY = new PhotoInterrupter(22, -1, -150);
            var motorCalibratorY   = new MotorCalibrator(-17, 17, motorMoverY, motorInformationY, topInterrupterY, bottomInterrupterY);

            var preciseMoverX = new PreciseMotorMover(motorMoverX);
            var gridMoverX    = new GridMotorMover(preciseMoverX, motorCalibratorX);

            var preciseMoverY = new PreciseMotorMover(motorMoverY);
            var gridMoverY    = new GridMotorMover(preciseMoverY, motorCalibratorY);

            var magnetDriver = new MagnetDrv(26);

            var movePerformer        = new MovePerformer(gridMoverX, gridMoverY, magnetDriver);
            var motorCalibrationTask = movePerformer.CalibrateAsync();
            var movePlanner          = new MovePlanner(logic.Board);
            var moveManager          = new MoveManager(movePlanner, movePerformer);

            GameManager manager = new GameManager(await commandInterpreterConstructor, logic, moveManager);

            await motorCalibrationTask;

#if DEBUG
            manager.DebugMovePerformer = movePerformer;
#endif
            return(manager);
        }