示例#1
0
        public async Task StartAsync_OpensMCVAndValvePins()
        {
            var pinsToOpen = new List <int> {
                _config.MasterControlValveGpio
            };

            pinsToOpen.AddRange(_config.Valves.Select(v => v.GpioPin));

            await _pinInitializer.StartAsync(CancellationToken.None);

            for (var pin = 0; pin < _gpioDriver.Pins.Count; pin++)
            {
                var shouldBeOpen     = false;
                var shouldBeMode     = default(PinMode);
                var shouldBePinValue = default(PinValue);

                if (pinsToOpen.Contains(pin))
                {
                    shouldBeOpen     = true;
                    shouldBeMode     = PinMode.Output;
                    shouldBePinValue = PinValue.High;
                }

                Assert.Equal(shouldBeOpen, _gpioDriver.Pins[pin].IsOpen);
                Assert.Equal(shouldBeMode, _gpioDriver.Pins[pin].Mode);
                Assert.Equal(shouldBePinValue, _gpioDriver.Pins[pin].Value);
            }
        }
示例#2
0
        public IrrigationProcessorTests()
        {
            _channel = Channel.CreateUnbounded <IrrigationJob>(
                new UnboundedChannelOptions()
            {
                AllowSynchronousContinuations = false,
                SingleWriter = true,
                SingleReader = true
            });

            _gpioDriver = new MemoryGpioDriver(pinCount: 50);

            var gpioController = new GpioController(PinNumberingScheme.Logical, _gpioDriver);

            _stopper = new IrrigationStopper();
            _config  = new IrrigationConfig
            {
                MasterControlValveGpio = 1,
                PressureBleedTime      = TimeSpan.Zero,
                ZoneSwitchDelay        = TimeSpan.Zero,
                Valves = new List <PinMapping>
                {
                    new PinMapping {
                        GpioPin = 2, ValveNumber = 1
                    },
                    new PinMapping {
                        GpioPin = 3, ValveNumber = 2
                    },
                    new PinMapping {
                        GpioPin = 4, ValveNumber = 3
                    }
                }
            };

            var pins       = (_config.Valves.Select(v => v.GpioPin).Union(new[] { _config.MasterControlValveGpio })).ToArray();
            var relayBoard = new RelayBoard(RelayType.NormallyOpen, gpioController, pins);

            var irrigationOptionsMock = new Mock <IOptions <IrrigationConfig> >();

            irrigationOptionsMock.SetupGet(x => x.Value).Returns(_config);

            _loggerMock = new Mock <ILogger <IrrigationProcessor> >();
            _status     = new IrrigationProcessorStatus();

            _processor = new IrrigationProcessor(_channel.Reader, relayBoard, _stopper, _status, irrigationOptionsMock.Object, _loggerMock.Object);

            //before the Microsoft GPIO controller can be used, the pins must be opened and set to the desired input/output state
            //run our initializer code to make that happen
            var pinInitializer = new PinInitializer(relayBoard, irrigationOptionsMock.Object);

            pinInitializer.StartAsync(CancellationToken.None).Wait();
        }