Ejemplo n.º 1
0
 public void Open()
 {
     state            = GateStates.Stutter;
     originalPosition = transform.position;
     basePosition     = originalPosition;
     targetPosition   = originalPosition + new Vector2(0, stutterDistance);
     currentDuration  = stutterDuration;
 }
Ejemplo n.º 2
0
 // Constructor for leaf node
 public Node(string name)
 {
     Name      = name;
     GateState = GateStates.Undefined;
     Left      = null;
     Right     = null;
     IsLeaf    = true;
     Balls     = new List <Ball>();
 }
Ejemplo n.º 3
0
    private void Update()
    {
        if (state == GateStates.Closed || state == GateStates.Open)
        {
            return;
        }

        elapsed += Time.deltaTime;

        if (elapsed >= currentDuration)
        {
            if (state != GateStates.Holding)
            {
                transform.position = new Vector3(targetPosition.x, targetPosition.y, ZValue);
            }

            elapsed -= currentDuration;

            switch (state)
            {
            case GateStates.Stutter:
                state           = GateStates.Holding;
                currentDuration = holdTime;

                break;

            case GateStates.Holding:
                state           = GateStates.Opening;
                basePosition    = targetPosition;
                targetPosition  = originalPosition + new Vector2(0, height);
                currentDuration = openDuration;

                break;

            case GateStates.Opening:
                state = GateStates.Open;

                return;
            }
        }

        if (state != GateStates.Holding)
        {
            float amount = elapsed / currentDuration;

            EaseTypes easeType = state == GateStates.Stutter ? EaseTypes.CubicOut : EaseTypes.CubicIn;

            Vector2 p = Vector2.Lerp(basePosition, targetPosition, EaseFunctions.Ease(amount, easeType));

            // Adding a small Z value causes gates to render behind the tilemap as they open.
            transform.position = new Vector3(p.x, p.y, ZValue);
        }
    }
Ejemplo n.º 4
0
 // Constructor for non-leaf node
 public Node(GateStates gateState, Node left, Node right)
 {
     if (gateState == GateStates.Undefined)
     {
         throw new ArgumentException("A non-leaf node cannot have 'Undefined' gate state");
     }
     GateState = gateState;
     Left      = left;
     Right     = right;
     IsLeaf    = false;
     Balls     = null;
 }
Ejemplo n.º 5
0
        public void GetStateOf_DoesNotContainRequestedGate_ThrowsKeyNotFoundException()
        {
            // Arrange
            var someNonexistingGatenr = 75159;

            var dut = new GateStates();

            // Act
            var actual = Assert.Throws <KeyNotFoundException>(() => dut.GetStateOf(someNonexistingGatenr));

            // Assert
            actual.Message.Should()
            .Contain($"{someNonexistingGatenr}");
        }
Ejemplo n.º 6
0
        public void Add_AlreadyContainsGateWithSameGatenr_ThrowsArgumentException()
        {
            // Arrange
            var someNonuniqueGatenr = 3263827;

            var dut = new GateStates();

            dut.Add(NewGate(), someNonuniqueGatenr);

            // Act
            var actual = Assert.Throws <ArgumentException>(() => dut.Add(NewGate(), someNonuniqueGatenr));

            // Assert
            actual.Message.Should()
            .Contain($"{someNonuniqueGatenr}");
        }
Ejemplo n.º 7
0
        public void Add_Empty_CanBeRetrievedByGatenr()
        {
            // Arrange
            var mockGate   = new Mock <IGateState>();
            var someGatenr = 4711;

            var dut = new GateStates();

            var expected = mockGate.Object;

            // Act
            dut.Add(expected, someGatenr);
            var actual = dut.GetStateOf(someGatenr);

            // Assert
            Assert.Same(expected, actual);
        }
Ejemplo n.º 8
0
        public void Add_ContainsOtherGates_CanBeRetrievedByGatenr()
        {
            // Arrange
            var mockGate   = new Mock <IGateState>();
            var someGatenr = 2187;

            var dut = new GateStates();

            // Add other gates - gate numbers are not significant, except that they be unique.
            dut.Add(NewGate(), 1138);
            dut.Add(NewGate(), 4711);

            var expected = mockGate.Object;

            // Act
            dut.Add(expected, someGatenr);
            var actual = dut.GetStateOf(someGatenr);

            // Assert
            Assert.Same(expected, actual);
        }
Ejemplo n.º 9
0
        public async Task InitializeHardware()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

                var pmwProvider = LightningPwmProvider.GetPwmProvider();

//                var pwmControllers = await Windows.Devices.Pwm.PwmController.GetControllersAsync(pmwProvider);
                var pwmControllers = Windows.Devices.Pwm.PwmController.GetControllersAsync(pmwProvider).GetAwaiter().GetResult();
                var pwmController  = pwmControllers[1]; // the on-device controller

                // This seems to go bad
                //pwmController.SetDesiredFrequency(100);

                _gpioController = await GpioController.GetDefaultAsync();

                IPin GetInputPin(int pinNr)
                {
                    return(new GpioPinWrapper(_gpioController.OpenPin(pinNr, GpioSharingMode.Exclusive), GpioPinDriveMode.InputPullUp));
                }

                _gateStates = new GateStates();
                _gateStates.Add(
                    // Center switches (on bread board)
                    new GateState(
                        // Yellow button, Closed
                        GetInputPin(27),
                        // Red button, Open
                        GetInputPin(22)),
                    1);
                _gateStates.Add(
                    // Top switches (on bread board)
                    new GateState(
                        // Yellow button, Closed
                        GetInputPin(4),
                        // Red button, Open
                        GetInputPin(17)),
                    2);

                IPwmPin GetPwmPin(int pinNr)
                {
                    //var pin = _gpioController.OpenPin(pinNr);
                    //pin.SetDriveMode(GpioPinDriveMode.Output);
                    return(new PwmPinWrapper(pwmController.OpenPin(pinNr)));
                }

                GateController =
                    new GateController(
                        // TODO : pins in settings, selector: 6, 13, 19
                        new Selector(GetOutputPins(6, 13, 19)),
                        new PwmController(
                            // TODO : pins in settings: 20, 21
                            GetPwmPin(20),
                            GetPwmPin(21),
                            // TODO : steps per change in settings
                            3),
                        _gateStates);

                // TODO : pins in settings: 24
                _heartBeatPin   = GetOutputPins(24).First();
                _heartBeatTimer = new Timer(HandleHeartBeat, _heartBeatState, 100, Timeout.Infinite);
            }
        }