/// <summary> /// Initializes a new instance of the <see cref="RemotePiDevice" /> class. /// </summary> /// <param name="gpioController">The gpio controller.</param> /// <param name="shutdownButtonDevice">The shutdown button device.</param> /// <param name="shutdownOutPin">The shutdown out pin.</param> /// <param name="operatingSystemShutdown">The operation system shutdown.</param> /// <param name="activate">if set to <c>true</c> [activate].</param> /// <param name="shutdownTimeSpan">The shutdown time span.</param> /// <param name="dateTime">The date time.</param> public RemotePiDevice( GpioController gpioController, IButtonDevice shutdownButtonDevice, int shutdownOutPin, IOperatingSystemShutdown operatingSystemShutdown, bool activate, TimeSpan shutdownTimeSpan, IDateTime?dateTime = null) { this.gpioController = gpioController; this.shutdownButtonDevice = shutdownButtonDevice; this.shutdownOutPin = shutdownOutPin; this.operatingSystemShutdown = operatingSystemShutdown; this.shutdownTimeSpan = shutdownTimeSpan > MaxShutdownTimeSpan ? MaxShutdownTimeSpan : shutdownTimeSpan; this.dateTime = dateTime ?? new DateTimeProvider(); this.thread = new CurrentThread(); this.shutdownButtonDevice.Pressed += this.OnShutdown; this.activation = new Activation( () => this.shutdownButtonDevice.IsActivated, () => { this.shutdownButtonDevice.SetActivation(true); this.gpioController.OpenPin(this.shutdownOutPin, PinMode.Output); }, () => { this.shutdownButtonDevice.SetActivation(false); this.gpioController.ClosePin(this.shutdownOutPin); }, activate); }
/// <summary> /// Initializes a new instance of the <see cref="RemotePiDevice" /> class. /// </summary> /// <param name="shutdownInConnectorPin">The shutdown in connector pin.</param> /// <param name="shutdownOutConnectorPin">The shutdown out connector pin.</param> /// <param name="operatingSystemShutdown">The operation system shutdown.</param> /// <param name="shutdownTimeSpan">The shutdown time span.</param> public RemotePiDevice( ConnectorPin shutdownInConnectorPin, ConnectorPin shutdownOutConnectorPin, IOperatingSystemShutdown operatingSystemShutdown, TimeSpan shutdownTimeSpan = default) : this( shutdownInConnectorPin, shutdownOutConnectorPin, operatingSystemShutdown, shutdownTimeSpan, null, null) { }
/// <summary> /// Initializes a new instance of the <see cref="RemotePiDevice" /> class. /// </summary> /// <param name="shutdownInConnectorPin">The shutdown in connector pin.</param> /// <param name="shutdownOutConnectorPin">The shutdown out connector pin.</param> /// <param name="operatingSystemShutdown">The operation system shutdown.</param> /// <param name="shutdownTimeSpan">The shutdown time span.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> public RemotePiDevice( ConnectorPin shutdownInConnectorPin, ConnectorPin shutdownOutConnectorPin, IOperatingSystemShutdown operatingSystemShutdown, TimeSpan shutdownTimeSpan = default, IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null) : this( shutdownInConnectorPin, shutdownOutConnectorPin, operatingSystemShutdown, shutdownTimeSpan, gpioConnectionDriverFactory, null) { }
/// <summary> /// Initializes a new instance of the <see cref="RemotePiDevice" /> class. /// </summary> /// <param name="gpioController">The gpio controller.</param> /// <param name="shutdownButtonDevice">The shutdown button device.</param> /// <param name="shutdownOutPin">The shutdown out pin.</param> /// <param name="operatingSystemShutdown">The operation system shutdown.</param> /// <param name="activate">if set to <c>true</c> [activate].</param> /// <param name="shutdownTimeSpan">The shutdown time span.</param> public RemotePiDevice( GpioController gpioController, IButtonDevice shutdownButtonDevice, int shutdownOutPin, IOperatingSystemShutdown operatingSystemShutdown, bool activate, TimeSpan shutdownTimeSpan = default) : this( gpioController, shutdownButtonDevice, shutdownOutPin, operatingSystemShutdown, activate, shutdownTimeSpan, null) { }
/// <summary> /// Initializes a new instance of the <see cref="RemotePiDevice" /> class. /// </summary> /// <param name="shutdownInConnectorPin">The shutdown in connector pin.</param> /// <param name="shutdownOutConnectorPin">The shutdown out connector pin.</param> /// <param name="operatingSystemShutdown">The operation system shutdown.</param> /// <param name="shutdownTimeSpan">The shutdown time span.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="dateTime">The date time.</param> /// <param name="threadFactory">The thread factory.</param> public RemotePiDevice( ConnectorPin shutdownInConnectorPin, ConnectorPin shutdownOutConnectorPin, IOperatingSystemShutdown operatingSystemShutdown, TimeSpan shutdownTimeSpan, IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null, IDateTime?dateTime = null, IThreadFactory?threadFactory = null) { this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get(); this.shutdownInConnectorPin = shutdownInConnectorPin; this.shutdownOutConnectorPin = shutdownOutConnectorPin; this.operatingSystemShutdown = operatingSystemShutdown; this.shutdownTimeSpan = shutdownTimeSpan < TimeSpan.FromSeconds(4) ? TimeSpan.FromSeconds(4) : shutdownTimeSpan; this.dateTime = dateTime ?? new DateTimeProvider(); this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); var pinConfiguration = shutdownInConnectorPin.Input().PullDown(); pinConfiguration.OnStatusChanged(this.OnShutdown); this.gpioConnection = new GpioConnection(new GpioConnectionDriverFactory(this.gpioConnectionDriver), pinConfiguration); }