コード例 #1
0
ファイル: PiTopModule.cs プロジェクト: jonsequitur/pi-top
        public PiTopModule(IGpioController controller)
        {
            _controller         = controller ?? throw new ArgumentNullException(nameof(controller));
            _moduleDriverClient = new ModuleDriverClient();
            _moduleDriverClient.MessageReceived += ModuleDriverClientMessageReceived;
            _disposables.Add(Disposable.Create(() =>
            {
                var plates = _plates.Values.ToList();
                foreach (var piTopPlate in plates)
                {
                    piTopPlate.Dispose();
                }

                var busses = _i2cBusses.Values.ToList();
                foreach (var i2CDevice in busses)
                {
                    i2CDevice.Dispose();
                }

                var spiDevices = _spiDevices.Values.ToList();
                foreach (var spiDevice in spiDevices)
                {
                    spiDevice.Dispose();
                }
            }));

            _disposables.Add(Disposable.Create(() => _moduleDriverClient.ReleaseDisplay()));
            _moduleDriverClient.Start();
            _disposables.Add(_moduleDriverClient);
            _disposables.Add(_controller);
        }
コード例 #2
0
        private PiTop4Board(IGpioController controller, Func <SpiConnectionSettings, SpiDevice> spiDeviceFactory, Func <I2cConnectionSettings, I2cDevice> i2cDeviceFactory)
        {
            BatteryState        = BatteryState.Empty;
            _controller         = controller ?? throw new ArgumentNullException(nameof(controller));
            _spiDeviceFactory   = spiDeviceFactory ?? throw new ArgumentNullException(nameof(spiDeviceFactory));
            _i2CDeviceFactory   = i2cDeviceFactory ?? throw new ArgumentNullException(nameof(i2cDeviceFactory));
            _moduleDriverClient = new ModuleDriverClient();
            _moduleDriverClient.MessageReceived += ModuleDriverClientMessageReceived;
            _disposables.Add(Disposable.Create(() =>
            {
                using var operation = Log.OnEnterAndExit();

                operation.Info("disposing devices.");
                var plates = _plates.Values.ToList();
                foreach (var piTopPlate in plates)
                {
                    piTopPlate.Dispose();
                }

                var busses = _i2cDevices.Values.ToList();
                foreach (var i2CDevice in busses)
                {
                    i2CDevice.Dispose();
                }

                var spiDevices = _spiDevices.Values.ToList();
                foreach (var spiDevice in spiDevices)
                {
                    spiDevice.Dispose();
                }
            }));

            _disposables.Add(Disposable.Create(() => _moduleDriverClient.ReleaseDisplay()));
            _moduleDriverClient.Start();
            _disposables.Add(_moduleDriverClient);
            _disposables.Add(_controller);

            _moduleDriverClient.RequestBatteryState();
        }