/// <summary> /// Initializes a new instance of the <see cref="Mfrc522Connection" /> class. /// </summary> /// <param name="spiDevicePath">The spi device path.</param> /// <param name="resetConnectorPin">The reset connector pin.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="rfidConnectionReporter">The rfid connection reporter.</param> public Mfrc522Connection( string spiDevicePath, ConnectorPin?resetConnectorPin, IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null, IThreadFactory?threadFactory = null, IRfidConnectionReporter?rfidConnectionReporter = null) { this.spiDevicePath = spiDevicePath; this.resetConnectorPin = resetConnectorPin; this.rfidConnectionReporter = rfidConnectionReporter; this.rfidConnectionReporter?.SetSource(typeof(IRfidConnectionReporter), this); this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get(); this.mfrc522Device = new Mfrc522Device(this.thread, this.gpioConnectionDriver); this.scanningJob = new ContinuousJob(this.CheckForTags, (Exception exception, ref bool _) => this.rfidConnectionReporter?.OnException(exception)); }
/// <summary> /// Initializes a new instance of the <see cref="Ky040Device" /> class. /// </summary> /// <param name="clockConnectorPin">The clock connector pin.</param> /// <param name="dataConnectorPin">The data connector pin.</param> /// <param name="buttonConnectorPin">The button connector pin.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="rotaryEncoderReporter">The ky040 reporter.</param> public Ky040Device( ConnectorPin clockConnectorPin, ConnectorPin dataConnectorPin, ConnectorPin buttonConnectorPin, IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null, IRotaryEncoderReporter?rotaryEncoderReporter = null) { this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get(); this.rotaryEncoderReporter = rotaryEncoderReporter; this.rotaryEncoderReporter?.SetSource(typeof(IRotaryEncoderReporter), this); this.clkPinConfiguration = clockConnectorPin.Input().PullUp(); this.clkPinConfiguration.OnStatusChanged(this.OnEncoderChanged); this.dtPinConfiguration = dataConnectorPin.Input().PullUp(); this.dtPinConfiguration.OnStatusChanged(this.OnEncoderChanged); this.buttonPinConfiguration = buttonConnectorPin.Input().PullUp(); this.buttonPinConfiguration.OnStatusChanged(this.OnButtonPressed); this.clockProcessorPin = clockConnectorPin.ToProcessor(); this.dataProcessorPin = dataConnectorPin.ToProcessor(); }
/// <summary> /// Initializes a new instance of the <see cref="Max9744Device" /> class. /// </summary> /// <param name="i2cAddress">The i2c address.</param> /// <param name="mutePin">The mute pin.</param> /// <param name="shutdownPin">The shutdown pin.</param> /// <param name="sdaPin">The sda pin.</param> /// <param name="sclPin">The SCL pin.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="i2CDeviceConnectionReporter">The i2 c device connection reporter.</param> public Max9744Device( byte i2cAddress, ConnectorPin mutePin, ConnectorPin shutdownPin, ProcessorPin sdaPin, ProcessorPin sclPin, IGpioConnectionDriverFactory? gpioConnectionDriverFactory, II2cDeviceConnectionReporter? i2CDeviceConnectionReporter = null) { this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get(); // connect volume via i2c this.i2CDriver = new I2cDriver(sdaPin, sclPin); this.connection = this.i2CDriver.Connect(i2cAddress, i2CDeviceConnectionReporter); // connect shutdown via gpio this.mutePin = mutePin.Output().Revert(); this.shutdownPin = shutdownPin.Output().Revert(); this.gpioConnection = new GpioConnection(this.gpioConnectionDriverFactory, this.shutdownPin, this.mutePin); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdDevice"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="hd44780DataPins">The HD44780 data pins.</param> /// <param name="backlight">The backlight.</param> /// <param name="readWrite">The read write.</param> /// <param name="threadFactory">The thread factory.</param> /// <exception cref="ArgumentOutOfRangeException"> /// pins - There must be either 4 or 8 data pins /// or /// settings - ScreenHeight must be between 1 and 4 rows /// or /// settings - PatternWidth must be 5 pixels /// or /// settings - PatternWidth must be either 7 or 10 pixels height. /// </exception> /// <exception cref="ArgumentException"> /// At most 80 characters are allowed /// or /// 10 pixels height pattern cannot be used with an even number of rows. /// </exception> public Hd44780LcdDevice( Hd44780LcdDeviceSettings settings, IGpioConnectionDriverFactory gpioConnectionDriverFactory, ConnectorPin registerSelectPin, ConnectorPin clockPin, Hd44780DataPins hd44780DataPins, ConnectorPin?backlight = null, ConnectorPin?readWrite = null, IThreadFactory threadFactory = null) { this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = gpioConnectionDriverFactory.Get(); this.pins = new Hd44780Pins(this.gpioConnectionDriver, registerSelectPin, clockPin, backlight, readWrite, hd44780DataPins.ConnectorPins); this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.syncDelay = settings.SyncDelay; if (this.pins.Data.Length != 4 && this.pins.Data.Length != 8) { throw new ArgumentOutOfRangeException(nameof(hd44780DataPins), this.pins.Data.Length, "There must be either 4 or 8 data pins"); } this.width = settings.ScreenWidth; this.height = settings.ScreenHeight; if (this.height < 1 || this.height > MaxHeight) { throw new ArgumentOutOfRangeException(nameof(settings.ScreenHeight), this.height, "ScreenHeight must be between 1 and 4 rows"); } if (this.width * this.height > MaxChar) { throw new ArgumentException("At most 80 characters are allowed"); } if (settings.PatternWidth != 5) { throw new ArgumentOutOfRangeException(nameof(settings.PatternWidth), settings.PatternWidth, "PatternWidth must be 5 pixels"); } if (settings.PatternHeight != 8 && settings.PatternHeight != 10) { throw new ArgumentOutOfRangeException(nameof(settings.PatternHeight), settings.PatternHeight, "PatternHeight must be either 7 or 10 pixels height"); } if (settings.PatternHeight == 10 && this.height % 2 == 0) { throw new ArgumentException("10 pixels height pattern cannot be used with an even number of rows"); } this.functions = (settings.PatternHeight == 8 ? Functions.Matrix5X8 : Functions.Matrix5X10) | (this.height == 1 ? Functions.OneLine : Functions.TwoLines) | (this.pins.Data.Length == 4 ? Functions.Data4Bits : Functions.Data8Bits); this.entryModeFlags = /*settings.RightToLeft * ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement * :*/EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement; this.encoding = settings.Encoding; this.BacklightEnabled = false; this.pins.ReadWrite?.Write(false); this.pins.RegisterSelect.Write(false); this.pins.Clock.Write(false); foreach (var dataPin in this.pins.Data) { dataPin.Write(false); } this.WriteByte(0x33, false); // Initialize this.WriteByte(0x32, false); this.thread.Sleep(TimeSpanUtility.FromMicroseconds(50)); this.WriteCommand(Command.SetFunctions, (int)this.functions); this.WriteCommand(Command.SetDisplayFlags, (int)this.displayFlags); this.WriteCommand(Command.SetEntryModeFlags, (int)this.entryModeFlags); this.Clear(); this.BacklightEnabled = true; }