Exemple #1
0
        public void WaitForEventFallingEdgeTest()
        {
            TimeoutHelper.CompletesInTime(() =>
            {
                using (GpioController controller = new GpioController(GetTestNumberingScheme(), GetTestDriver()))
                {
                    CancellationTokenSource tokenSource = new CancellationTokenSource();
                    controller.OpenPin(InputPin, PinMode.Input);
                    controller.OpenPin(OutputPin, PinMode.Output);
                    controller.Write(OutputPin, PinValue.Low);

                    Task.Run(() =>
                    {
                        controller.Write(OutputPin, PinValue.High);
                        Thread.Sleep(WaitMilliseconds);
                        controller.Write(OutputPin, PinValue.Low);
                    });

                    WaitForEventResult result = controller.WaitForEvent(InputPin, PinEventTypes.Falling, tokenSource.Token);

                    Assert.False(result.TimedOut);
                    Assert.Equal(PinEventTypes.Falling, result.EventTypes);
                }
            }, TimeSpan.FromSeconds(30));
        }
Exemple #2
0
        private async Task <TimeSpan> ShowRound(int pin, int msTimeout)
        {
            _controller.Write(pin, PinValue.High);

            WaitForEventResult fake = await _controller.WaitForEventAsync(_buttonPin, PinEventTypes.Falling,
                                                                          TimeSpan.FromMilliseconds(msTimeout));

            _controller.Write(pin, PinValue.Low);

            return(fake.TimedOut ? TimeSpan.Zero : TimeSpan.FromSeconds(-1));
        }
        [Trait("SkipOnTestRun", "Windows_NT")] // The windows driver is returning none as the event type.
        public void WaitForEventCancelAfter10MillisecondsTest()
        {
            using (GpioController controller = new GpioController(GetTestNumberingScheme(), GetTestDriver()))
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource(WaitMilliseconds);
                controller.OpenPin(InputPin, PinMode.Input);
                controller.OpenPin(OutputPin, PinMode.Output);
                controller.Write(OutputPin, PinValue.Low);

                WaitForEventResult result = controller.WaitForEvent(InputPin, PinEventTypes.Falling, tokenSource.Token);

                Assert.True(result.TimedOut);
                Assert.Equal(PinEventTypes.Falling, result.EventTypes);
            }
        }
Exemple #4
0
        private async Task <TimeSpan> PlayButton(bool fakeOut)
        {
            int waitMs             = _r.Next(1500, 6000);
            WaitForEventResult pre = await _controller.WaitForEventAsync(_buttonPin, PinEventTypes.Falling,
                                                                         TimeSpan.FromMilliseconds(waitMs));

            if (!pre.TimedOut)
            {
                return(TimeSpan.FromSeconds(-1));
            }

            if (fakeOut)
            {
                return(await ShowFakeout());
            }
            else
            {
                return(await ShowReal());
            }
        }
Exemple #5
0
        public void WaitForEventBothEdgesTest()
        {
            using (GpioController controller = new GpioController(GetTestNumberingScheme(), GetTestDriver()))
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();
                tokenSource.CancelAfter(2000);
                controller.OpenPin(InputPin, PinMode.Input);
                controller.OpenPin(OutputPin, PinMode.Output);
                controller.Write(OutputPin, PinValue.High);

                // Wait for any events that happen because of the initialization
                controller.WaitForEvent(InputPin, PinEventTypes.Falling | PinEventTypes.Rising, tokenSource.Token);
                tokenSource.Dispose();

                var task = Task.Run(() =>
                {
                    controller.Write(OutputPin, PinValue.High);
                    Thread.Sleep(WaitMilliseconds);
                    controller.Write(OutputPin, PinValue.Low);
                    Thread.Sleep(WaitMilliseconds);
                    controller.Write(OutputPin, PinValue.High);
                });

                tokenSource = new CancellationTokenSource();
                tokenSource.CancelAfter(WaitMilliseconds * 4);

                // First event is falling, second is rising
                WaitForEventResult result = controller.WaitForEvent(InputPin, PinEventTypes.Falling | PinEventTypes.Rising, tokenSource.Token);
                Assert.False(result.TimedOut);
                Assert.Equal(PinEventTypes.Falling, result.EventTypes);
                result = controller.WaitForEvent(InputPin, PinEventTypes.Falling | PinEventTypes.Rising, tokenSource.Token);
                Assert.False(result.TimedOut);
                Assert.Equal(PinEventTypes.Rising, result.EventTypes);
                Assert.True(task.Wait(TimeSpan.FromSeconds(30))); // Should end long before that
                tokenSource.Dispose();
            }
        }