/// <summary> /// Initializes a new instance of the Mcp25625 class. /// </summary> /// <param name="spiDevice">The SPI device used for communication.</param> /// <param name="reset">The output pin number that is connected to Reset.</param> /// <param name="tx0rts">The output pin number that is connected to Tx0RTS.</param> /// <param name="tx1rts">The output pin number that is connected to Tx1RTS.</param> /// <param name="tx2rts">The output pin number that is connected to Tx2RTS.</param> /// <param name="standby">The output pin number that is connected to STBY.</param> /// <param name="interrupt">The input pin number that is connected to INT.</param> /// <param name="rx0bf">The input pin number that is connected to Rx0BF.</param> /// <param name="rx1bf">The input pin number that is connected to Rx1BF.</param> /// <param name="clkout">The input pin number that is connected to CLKOUT.</param> /// <param name="gpioController"> /// The GPIO controller for defined external pins. If not specified, the default controller will be used. /// </param> public Mcp25625( SpiDevice spiDevice, int reset = -1, int tx0rts = -1, int tx1rts = -1, int tx2rts = -1, int standby = -1, int interrupt = -1, int rx0bf = -1, int rx1bf = -1, int clkout = -1, IGpioController gpioController = null) : base( spiDevice, reset, tx0rts, tx1rts, tx2rts, interrupt, rx0bf, rx1bf, clkout, gpioController) { _standby = standby; if (_standby != -1) { // Master controller should already be configured if other pins are used. _gpioController = _gpioController ?? new GpioController(); _gpioController.OpenPin(_standby, PinMode.Output); } }
/// <summary> /// Initialise ultra sonic distance sensor /// </summary> /// <param name="trig_Pin"></param> /// <param name="echo_Pin"></param> /// <param name="maxDistance">Set Ultra Sonic maximum distance to detect. This is approximate only. Based on 34.3 cm per millisecond, 20 degrees C at sea level</param> public HCSR04(IGpioController gpio, byte trig_Pin, byte echo_Pin, Length maxDistance) { _gpio = gpio; int milliSeconds = (int)(maxDistance.Centimeters / 34.3 * 2); Initialise(trig_Pin, echo_Pin, milliSeconds); }
/// <summary> /// Initializes a new HD44780 LCD controller. /// </summary> /// <param name="registerSelect">The pin that controls the regsiter select.</param> /// <param name="enable">The pin that controls the enable switch.</param> /// <param name="data">Collection of pins holding the data that will be printed on the screen.</param> /// <param name="size">The logical size of the LCD.</param> /// <param name="backlight">The optional pin that controls the backlight of the display.</param> /// <param name="backlightBrightness">The brightness of the backlight. 0.0 for off, 1.0 for on.</param> /// <param name="readWrite">The optional pin that controls the read and write switch.</param> /// <param name="controller">The controller to use with the LCD. If not specified, uses the platform default.</param> public Hd44780(int registerSelect, int enable, int[] data, Size size, int backlight = -1, float backlightBrightness = 1.0f, int readWrite = -1, IGpioController controller = null) { _rwPin = readWrite; _rsPin = registerSelect; _enablePin = enable; _dataPins = data; _backlight = backlight; _backlightBrightness = backlightBrightness; Size = size; _rowOffsets = InitializeRowOffsets(size.Height); if (data.Length == 8) { _displayFunction |= DisplayFunction.EightBit; } else if (data.Length != 4) { throw new ArgumentException($"The length of the array given to parameter {nameof(data)} must be 4 or 8"); } _controller = controller ?? new GpioController(PinNumberingScheme.Logical); Initialize(size.Height); }
public WindowsPwmProvider(IGpioController controller) { m_DimmablePwmControllerProvider = new WindowsPwmControllerProvider(controller); m_DimmablePwmControllerProvider.SetDesiredFrequency(240); m_InfraredPwmControllerProvider = new WindowsPwmControllerProvider(controller); m_InfraredPwmControllerProvider.SetDesiredFrequency(3800); }
public void InitGpio() { try { gpioController = GpioController.Instance; //Set Direction of pins (Input or Output) pin17 = gpioController.OpenPin(17); pin17.SetDriveMode(GpioPinDriveMode.Input); pin22 = gpioController.OpenPin(22); pin22.SetDriveMode(GpioPinDriveMode.Input); //Init value dt1 = DateTime.Now; stateChange = 0; oldStatusPin17 = ""; DeviceReady = true; } catch (Exception ex) { Console.WriteLine("Init Gpio Error : " + ex.Message); DeviceReady = false; } }
public DCMotor3Pin( PwmChannel pwmChannel, int pin0, int pin1, IGpioController controller) : base(controller ?? new GpioController()) { if (pwmChannel == null) { throw new ArgumentNullException(nameof(pwmChannel)); } _pwm = pwmChannel; _pin0 = pin0; _pin1 = pin1; _speed = 0; _pwm.Start(); Controller.OpenPin(_pin0, PinMode.Output); Controller.Write(_pin0, PinValue.Low); Controller.OpenPin(_pin1, PinMode.Output); Controller.Write(_pin1, PinValue.Low); }
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); }
/// <summary> /// Remote I/O expander for I2C-bus with interrupt. /// </summary> /// <param name="device">The I2C device.</param> /// <param name="interrupt">The interrupt pin number, if present.</param> /// <param name="gpioController"> /// The GPIO controller for the <paramref name="interrupt"/>. /// If not specified, the default controller will be used. /// </param> public Pcx857x(I2cDevice device, int interrupt = -1, IGpioController gpioController = null) { Device = device ?? throw new ArgumentNullException(nameof(device)); _interrupt = interrupt; if (_interrupt != -1) { _masterGpioController = gpioController ?? new GpioController(); _masterGpioController.OpenPin(_interrupt, PinMode.Input); } // These controllers do not have commands, setting the pins to high designates // them as able to recieve input. As we don't want to set high on pins intended // for output we'll set all of the pins to low for our initial state. if (PinCount == 8) { WriteByte(0x00); } else { InternalWriteUInt16(0x0000); } _pinModes = 0xFFFF; }
public SoftwarePwmController(IGpioController controller) { // Get GPIO m_GpioController = controller; // How many pins m_PinCount = m_GpioController.PinCount; // Create pin lookup m_Pins = new Dictionary <GpioEnum, SoftPwmPin>(m_PinCount); // Create m_Stopwatch = new Stopwatch(); // Defaults m_ActualFrequency = MIN_FREQUENCY; m_TicksPerSecond = Stopwatch.Frequency; // Create the updater. Default to 0 seconds between updates, meaning run as fast as possible. // IMPORTANT: Do not use Scheduler.Default, create a new Scheduler. // This puts us in parallel priority with other sensors and allows // us to run on a separate core if available. m_Updater = new ScheduledUpdater(new ScheduleOptions(0), new Scheduler()); m_Updater.SetUpdateAction(Update); }
public void Dispose() { _gpioController?.Dispose(); _gpioController = null; _spiDevice?.Dispose(); _spiDevice = null; }
public LedDriver(IGpioController controller, LedDriverSettings settings) { controller.ThrowIfNull(nameof(controller)); settings.ThrowIfNull(nameof(settings)); Controller = controller; Settings = settings; SetUpController(); }
public PinCheckerService(IGpioController gpioController, IOptions <PinSettings> pinOptions, ILogger <PinCheckerService> logger) { _logger = logger; _gpioController = gpioController; _pinSettings = pinOptions.Value; }
public static IGpioController Share(this IGpioController controller) { if (controller == null) { throw new ArgumentNullException(nameof(controller)); } return(new SharedGpioController(controller)); }
/// <summary> /// Releases the resources used by the <see cref="DCMotor"/> instance. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { Controller?.Dispose(); Controller = null; } }
public void Dispose() { if (_controller != null) { _controller.Dispose(); _controller = null; } }
public LedControl(IGpioController gpio) { mRedLed = new Led(gpio, PinAssignment.RED_LED); mYellowLed = new Led(gpio, PinAssignment.YELLOW_LED); mGreenLed = new Led(gpio, PinAssignment.GREEN_LED); TurnAllLedsOn(); Thread.Sleep(500); TurnAllLedsOff(); }
public GpioService( IConfigurationService configurationService, IGpioController gpioController, ILogService logService) { _configurationService = configurationService; _gpioController = gpioController; _logService = logService; }
public RelayClient(ILoggerFactory loggerFactory, IGpioController gpioController, IRelayClientOptions relayClientOptions) { _logger = loggerFactory.CreateLogger <RelayClient>(); _gpioController = gpioController; SetRelays(relayClientOptions.Relays); }
public Button(IGpioController controller, GpioEnum gpio, ILoggerService loggerService = null) { ButtonPin = controller.OpenPin(gpio); ButtonPin.SetDriveMode(GpioPinDriveModeEnum.InputPullUp); if (loggerService != null) { TurnedOn += (s, a) => loggerService.Log(LogLevelEnum.Information, $"{Name} is turned on"); TurnedOff += (s, a) => loggerService.Log(LogLevelEnum.Information, $"{Name} is turned off"); } }
public GpioService( IOptions <GpioOptions> gpioOptions, ILogger <GpioService> logger) { _gpioOptions = gpioOptions; _logger = logger; _gpioController = new GpioController(); _gpioController.OpenPin(_gpioOptions.Value.ServoPin, PinMode.Output); }
public SensorClient(ILoggerFactory loggerFactory, IGpioController gpioController, ISensorClientOptions sensorClientOptions, ISensorReadingClientFactory sensorReadingClientFactory) { _gpioController = gpioController; _logger = loggerFactory.CreateLogger <SensorClient>(); _sensorReadingClientFactory = sensorReadingClientFactory; _sensors = sensorClientOptions.Sensors; }
public RadioService(ILogger <RadioService> logger, IGpioController pins, InternalNodeHubApi hubApi, CapabilityService capabilityService) { _logger = logger; _hubApi = hubApi; _capabilityService = capabilityService; _transmitter433 = new Transmitter433(pins[BcmPin.Gpio17]); _receiver433 = new Receiver433(pins[BcmPin.Gpio23]); _blinds = new BlindsCapability(new BlindsDevice(_transmitter433)); }
public Motor(IGpioController gpio, byte in1, byte in2) { _gpio = gpio; _in1 = in1; _in2 = in2; _gpio.OpenPin(in1, PinMode.Output); _gpio.OpenPin(in2, PinMode.Output); _gpio.Write(in1, PinValue.Low); _gpio.Write(in2, PinValue.Low); }
private void Init() { #if DEBUG this.redLed = new GpioConsoleController((int)EnumLed.Red); this.yellowLed = new GpioConsoleController((int)EnumLed.Yellow); this.greenLed = new GpioConsoleController((int)EnumLed.Green); #else this.redLed = new GpioController((int)EnumLed.Red); this.yellowLed = new GpioController((int)EnumLed.Yellow); this.greenLed = new GpioController((int)EnumLed.Green); #endif }
public Gpio() { try { _gpioController = Bifrost.Devices.Gpio.GpioController.Instance; _fake = false; } catch (Exception e) { Debug.WriteLine(e.ToString()); _gpioController = new FakeGpioController(); } }
public RelayService( Config config, IGpioController controller, ILogger <RelayService> logger) { this.config = config; this.controller = controller; this.logger = logger; foreach (var device in this.config.RelayDevices) { InitializeRelayDevice(device); } }
/// <summary> /// Creates <see cref="DCMotor"/> instance which allows to control speed in one direction. /// </summary> /// <param name="speedControlPin">Pin used to control the speed of the motor with software PWM (frequency will default to 50Hz)</param> /// <param name="controller"><see cref="IGpioController"/> related to the <paramref name="speedControlPin"/></param> /// <returns><see cref="DCMotor"/> instance</returns> /// <remarks> /// <paramref name="speedControlPin"/> can be connected to either enable pin of the H-bridge. /// or directly to the input related with the motor (if H-bridge allows inputs to change frequently). /// Connecting motor directly to GPIO pin is not recommended and may damage your board. /// </remarks> public static DCMotor Create(int speedControlPin, IGpioController controller = null) { if (speedControlPin == -1) { throw new ArgumentOutOfRangeException(nameof(speedControlPin)); } controller = controller ?? new GpioController(); return(new DCMotor2PinNoEnable( new SoftwarePwmChannel(speedControlPin, DefaultPwmFrequency, 0.0, controller: controller), -1, controller)); }
public SpiInterface(SpiDevice device, IGpioController controller, int dcPin, int rstPin) { _device = device ?? throw new ArgumentNullException(nameof(device)); _controller = controller ?? throw new ArgumentNullException(nameof(controller)); _dcPin = dcPin; _rstPin = rstPin; _disposables.Add(_controller.OpenPin(_dcPin, PinMode.Output)); _disposables.Add(_controller.OpenPin(_rstPin, PinMode.Output)); _controller.Write(_rstPin, PinValue.Low); _controller.Write(_rstPin, PinValue.High); }
/// <summary> /// Initialize a Uln2003 class. /// </summary> /// <param name="pin1">The GPIO pin number which corresponds pin A on ULN2003 driver board.</param> /// <param name="pin2">The GPIO pin number which corresponds pin B on ULN2003 driver board.</param> /// <param name="pin3">The GPIO pin number which corresponds pin C on ULN2003 driver board.</param> /// <param name="pin4">The GPIO pin number which corresponds pin D on ULN2003 driver board.</param> /// <param name="controller">The controller.</param> public Uln2003(int pin1, int pin2, int pin3, int pin4, IGpioController controller = null) { _pin1 = pin1; _pin2 = pin2; _pin3 = pin3; _pin4 = pin4; _controller = controller ?? new GpioController(); _controller.OpenPin(_pin1, PinMode.Output); _controller.OpenPin(_pin2, PinMode.Output); _controller.OpenPin(_pin3, PinMode.Output); _controller.OpenPin(_pin4, PinMode.Output); }
/// <summary> /// A general purpose parallel I/O expansion for I2C or SPI applications. /// </summary> /// <param name="bus">The bus the device is connected to.</param> /// <param name="reset">The output pin number that is connected to the hardware reset.</param> /// <param name="interruptA">The input pin number that is connected to the interrupt for Port A (INTA).</param> /// <param name="interruptB">The input pin number that is connected to the interrupt for Port B (INTB).</param> /// <param name="masterController"> /// The controller for the reset and interrupt pins. If not specified, the default controller will be used. /// </param> /// <param name="bankStyle"> /// The current bank style of the ports. This does not set the bank style- it tells us what the bank style is. /// It is *highly* recommended not to change the bank style from the default as there is no direct way to /// detect what style the chip is in and most apps will fail if the chip is not set to defaults. This setting /// has no impact on 8-bit expanders. /// </param> protected Mcp23xxx(BusAdapter bus, int reset = -1, int interruptA = -1, int interruptB = -1, IGpioController masterController = null, BankStyle bankStyle = BankStyle.Sequential) { _bus = bus; _bankStyle = bankStyle; _reset = reset; _interruptA = interruptA; _interruptB = interruptB; // Only need master controller if there are external pins provided. if (_reset != -1 || _interruptA != -1 || _interruptB != -1) { _masterGpioController = masterController ?? new GpioController(); if (_interruptA != -1) { _masterGpioController.OpenPin(_interruptA, PinMode.Input); } if (_interruptB != -1) { _masterGpioController.OpenPin(_interruptB, PinMode.Input); } if (_reset != -1) { _masterGpioController.OpenPin(_reset, PinMode.Output); Disable(); } } if (!_disabled) { // Set all of the pins to input, GPIO outputs to low, and set input polarity to match the input. // This is the normal power-on / reset state of the Mcp23xxx chips. if (PinCount == 8) { InternalWriteByte(Register.IODIR, 0xFF, Port.PortA); InternalWriteByte(Register.GPIO, 0x00, Port.PortA); InternalWriteByte(Register.IPOL, 0x00, Port.PortA); } else { InternalWriteUInt16(Register.IODIR, 0xFFFF); InternalWriteUInt16(Register.GPIO, 0x0000); InternalWriteUInt16(Register.IPOL, 0x0000); } } }