public bool SetGpioValue(int pin, GpioPinState state) { if (!PiController.IsValidPin(pin)) { return(false); } GpioPin GpioPin = (GpioPin)Pi.Gpio[pin]; if (GpioPin.PinMode == GpioPinDriveMode.Output) { GpioPin.Write((GpioPinValue)state); Logger.Trace($"Configured ({pin}) gpio pin to ({state.ToString()}) state."); return(true); } return(false); }
public bool SetGpioValue(int pin, GpioPinState state) { if (!PinController.IsValidPin(pin) || !IsDriverProperlyInitialized) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(false); } try { if (DriverController == null) { return(false); } DriverController.OpenPin(pin); if (!DriverController.IsPinOpen(pin)) { return(false); } DriverController.Write(pin, state == GpioPinState.Off ? PinValue.High : PinValue.Low); CastDriver <IGpioControllerDriver>(this)?.Logger.Trace($"Configured ({pin}) gpio pin to ({state.ToString()}) state."); CastDriver <IGpioControllerDriver>(this)?.UpdatePinConfig(new Pin(pin, state)); return(true); } finally { if (DriverController != null) { if (DriverController.IsPinOpen(pin)) { DriverController.ClosePin(pin); } } Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
public bool SetGpioValue(int pin, GpioPinState state) { if (!PinController.IsValidPin(pin)) { return(false); } try { GpioPin GpioPin = (GpioPin)Pi.Gpio[pin]; if (GpioPin.PinMode == GpioPinDriveMode.Output) { GpioPin.Write((GpioPinValue)state); CastDriver <IGpioControllerDriver>(this).Logger.Trace($"Configured ({pin}) gpio pin to ({state.ToString()}) state."); CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(new Pin(pin, state)); return(true); } return(false); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }