/// <summary> /// Sets the direction of a particular port. /// </summary> /// <param name="pin"></param> /// <param name="direction"></param> public void SetPortDirection(int pin, GpioPinDriveMode direction) { if (IsValidPin(pin)) { // if it's already configured, get out. (1 = input, 0 = output) if (direction == GpioPinDriveMode.Input) { if (BitHelpers.GetBitValue(_iodir, (byte)pin)) { return; } //if ((_iodir & (byte)(1 << pin)) != 0) return; } else { if (!BitHelpers.GetBitValue(_iodir, (byte)pin)) { return; } //if ((_iodir & (byte)(1 << pin)) == 0) return; } // set the IODIR bit and write the setting _iodir = BitHelpers.SetBit(_iodir, (byte)pin, (byte)direction); _mcpDevice.WriteRegister(RegisterAddresses.IODirectionRegister, _iodir); } else { throw new Exception("Pin is out of range"); } }
public void SetDriveMode(GpioPinDriveMode driveMode) { //var path = GpioController.DevicePath; // write in or out to the "direction" file for this pin. File.WriteAllText(Path.Combine(this.GpioPath, "direction"), "out"); Directory.SetLastWriteTime(Path.Combine(this.GpioPath), DateTime.UtcNow); }
public SwitchDriver(GpioController gpioController, GpioPins pin, GpioPinDriveMode pinMode, TimeSpan debounceTimeout = default) { if (debounceTimeout == default) { debounceTimeout = TimeSpan.FromMilliseconds(20); } _gpioController = gpioController; _gpioPin = pin; _pinMode = pinMode; _debounceTimeout = debounceTimeout; Init(); _reinitializeThread = new Thread(() => { while (true) { Thread.Sleep(30000); _pin.ValueChanged -= PinValueChangedHandler; _pin.Dispose(); if (_isDisposed) { break; } Init(); } }); _reinitializeThread.Start(); }
public GpioModule(GpioController controller, int pinNumber, GpioPinDriveMode driveMode = GpioPinDriveMode.Input, LogicValue logicValue = LogicValue.Positive) : base(controller) { Pin = Controller.OpenPin(pinNumber); // Shows an error if the pin wasn't initialized properly if (Pin == null) { throw new ArgumentException($"There were problems initializing the GPIO {GetType().Name} pin."); } if (logicValue == LogicValue.Positive) { ActualHighPinValue = GpioPinValue.High; ActualLowPinValue = GpioPinValue.Low; } else { ActualHighPinValue = GpioPinValue.Low; ActualLowPinValue = GpioPinValue.High; } Pin.Write(ActualLowPinValue); Pin.SetDriveMode(driveMode); }
public IGpioPin CreatePin(BcmPin id, GpioPinDriveMode mode = GpioPinDriveMode.Output) { var pin = new TestGpioPin(id); pin.PinMode = mode; return(pin); }
public IGetResponse setDriveMode1(int pin3, int value4) { try { GpioPinDriveMode newDriveMode = (GpioPinDriveMode)value4; Pin pin1 = pinList.FirstOrDefault(c => c.pinNumber == pin3); if (pin1.open != 1) { pin1.open = 1; updatePin(pin1); } if (pin1.open == 1) { if (pin1.gpioPin.IsDriveModeSupported(newDriveMode)) { pin1.gpioPin.SetDriveMode(newDriveMode); } else { Debug.WriteLine($"Pin {pin1} {newDriveMode} Unsuported"); } } updatePin(pin1); return(new GetResponse(GetResponse.ResponseStatus.OK)); } catch (Exception e) { var v1 = e; throw; } }
public static void SetAllPinModes(GpioPinDriveMode mode) { Pi.Gpio[LeftMotorReversePin].PinMode = mode; Pi.Gpio[LeftMotorForwardsPin].PinMode = mode; Pi.Gpio[RightMotorReversePin].PinMode = mode; Pi.Gpio[RightMotorForwardsPin].PinMode = mode; }
private void SetPinModeBulk(GpioPinDriveMode mode, byte[] cmd, int length) { switch (mode) { case GpioPinDriveMode.Output: Write(SeeSawBaseAddress.Gpio, SeeSawGpio.DirectionSetBulk, cmd, length); break; case GpioPinDriveMode.Input: Write(SeeSawBaseAddress.Gpio, SeeSawGpio.DirectionClearBulk, cmd, length); break; case GpioPinDriveMode.InputPullUp: Write(SeeSawBaseAddress.Gpio, SeeSawGpio.DirectionClearBulk, cmd, length); Write(SeeSawBaseAddress.Gpio, SeeSawGpio.PullEnableSet, cmd, length); Write(SeeSawBaseAddress.Gpio, SeeSawGpio.BulkSet, cmd, length); break; case GpioPinDriveMode.InputPullDown: Write(SeeSawBaseAddress.Gpio, SeeSawGpio.DirectionClearBulk, cmd, length); Write(SeeSawBaseAddress.Gpio, SeeSawGpio.PullEnableSet, cmd, length); Write(SeeSawBaseAddress.Gpio, SeeSawGpio.BulkClear, cmd, length); break; } }
/// <summary> /// Costruttore che permette di indicare il canale da usare come integer. /// Usa un trucco, perchè la libreria non supporta l'uso di un integer /// per istanziare la classe di controllo dell'IO digitale /// </summary> /// <param name="NumConnectorPin"> /// Numero del canale /// E' il numero del piedino nel connettore Gpio del Raspberry Pi, NON quello /// del SoC Broadcom /// </param> /// <param name="IsInput"> /// Direzione dell'IO: se true è un Input, altrimenti è un output /// </param> public DigitalIO(int NumConnectorPin, GpioPinDriveMode DriveMode) { foreach (ConnectorPin pin in Enum.GetValues(typeof(ConnectorPin))) { try { if (Enum.GetName(typeof(ConnectorPin), pin).ToString().IndexOf(NumConnectorPin.ToString(), 0) >= 0) { connectorPin = pin; processorPin = connectorPin.ToProcessor(); Console.WriteLine("Numero pin: {0} Definizione pin:{1}", NumConnectorPin, Enum.GetName(typeof(ConnectorPin), pin).ToString()); } PinDirection dir; if (DriveMode == GpioPinDriveMode.Input) { dir = PinDirection.Input; } else if (DriveMode == GpioPinDriveMode.Output) { dir = PinDirection.Output; } else { throw new NotImplementedException("Drive mode dell'I/O non ancora possibile con Mono"); } driver.Allocate(processorPin, dir); } catch { // se quel pin non c'è nel Raspberry che uso, dà errore } } }
/// <summary> /// Creates an instance using the default GpioController. /// </summary> /// <param name="pin">The internal pin number to use.</param> /// <param name="driveMode">The mode of the pin. This must be valid for the intended operation (input or /// output).</param> protected DigitalInputOutputBase( int pin, GpioPinDriveMode driveMode) { _pin = GpioController.GetDefault().OpenPin(pin); _pin.SetDriveMode(driveMode); }
public PinCommand(int pin, GpioPinDriveMode driveMode, GpioController controller) { if (controller == null) { controller = GpioController.GetDefault(); } try { // Validate GpioController again if (controller == null) { throw new TeaInitializationException("Unable to initialize a GpioController."); // TODO } try { gpioPin = controller.OpenPin(pin); gpioPin.SetDriveMode(driveMode); } catch (System.Runtime.InteropServices.COMException ex) { throw new TeaInitializationException($"Cannot open Gpio Pin #{pin}.", ex); // TODO } } catch (TeaInitializationException e) { MotorController.Current.Machine.Engine.Debugger.HandleTeaException(e, MotorController.Current); // Log error but don't break } }
/// <summary> /// Connects to a GPIO pin if it exists. /// </summary> /// <param name="controllerIndex">Controller index.</param> /// <param name="pinNumber">Pin number.</param> /// <param name="driveMode">Drive mode.</param> /// <param name="exclusive"> /// Set true for I2C <see cref="GpioSharingMode.Exclusive"/> or false for <see cref="GpioSharingMode.SharedReadOnly"/>. /// </param> /// <returns>Pin when controller and device exist, otherwise null.</returns> public static GpioPin ConnectGpio(int controllerIndex, int pinNumber, GpioPinDriveMode driveMode, bool exclusive) { // Validate if (controllerIndex < 0) { throw new ArgumentOutOfRangeException(nameof(controllerIndex)); } // Initialize Initialize(); // Get controller (return null when doesn't exist) if (Gpio.Count < controllerIndex + 1) { return(null); } var controller = Gpio[controllerIndex]; // Connect to device (return null when doesn't exist) var pin = controller.OpenPin(pinNumber, exclusive ? GpioSharingMode.Exclusive : GpioSharingMode.SharedReadOnly); if (pin == null) { return(null); } // Configure and return pin if (pin.GetDriveMode() != driveMode) { pin.SetDriveMode(driveMode); } return(pin); }
public PulseFeedback(GpioController gpioController, int pulsePinNumber, int echoPinNumber, PulseFeedbackMode mode) { if (!(gpioController.Provider is Gpio.Provider.GpioControllerApiWrapper p)) { throw new NotSupportedException(); } this.DisableInterrupts = false; this.Timeout = TimeSpan.FromMilliseconds(100); this.PulseLength = TimeSpan.FromMilliseconds(20); this.PulsePinValue = GpioPinValue.High; this.EchoPinValue = GpioPinValue.High; this.PulsePinDriveMode = GpioPinDriveMode.Input; this.EchoPinDriveMode = GpioPinDriveMode.Input; this.mode = mode; this.gpioApi = p.Api.Implementation; this.pulsePinNumber = pulsePinNumber; this.echoPinNumber = echoPinNumber; this.pulsePin = gpioController.OpenPin(pulsePinNumber); if (this.pulsePinNumber != this.echoPinNumber) { this.echoPin = gpioController.OpenPin(echoPinNumber); } this.pulsePin.SetDriveMode(GpioPinDriveMode.Input); this.echoPin?.SetDriveMode(GpioPinDriveMode.Input); }
public MainPage() { InitializeComponent(); try { var gpioController = GpioController.GetDefault(); _inputPin = gpioController.OpenPin(INDEX_INPUT_PIN, GpioSharingMode.Exclusive); _outputPin = gpioController.OpenPin(INDEX_OUTPUT_PIN, GpioSharingMode.Exclusive); // Use InputPullUp if supported, otherwise fall back to Input (floating) _inputDriveMode = _inputPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ? GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input; _inputPin.SetDriveMode(_inputDriveMode); _outputPin.Write(GpioPinValue.Low); _outputPin.SetDriveMode(GpioPinDriveMode.Output); _changeReader = new GpioChangeReader(_inputPin, 43) { Polarity = GpioChangePolarity.Falling, }; _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(INTERVAL_DATA_READING); _timer.Tick += HandleEvent_DispatcherTimer_Tick; } catch (Exception ex) { UpdateStatus(ex.Message); } }
public IGpioPin CreatePin(BcmPin id, GpioPinDriveMode mode = GpioPinDriveMode.Output) { IGpioPin pin = Pi.Gpio[id]; pin.PinMode = mode; return(pin); }
private GpioPin InitPin(int pinId, GpioPinDriveMode mode) { var pin = Pi.Gpio.GetGpioPinByBcmPinNumber(pinId); pin.PinMode = mode; return(pin); }
public void Setup(int pinNumber, GpioPinDriveMode _mode) { GpioController gpio = GpioController.GetDefault(); _gpioPin = gpio.OpenPin(pinNumber); //initialization _gpioPin.Write(GpioPinValue.Low); //set LOW state (GND, 0V) on led _gpioPin.SetDriveMode(_mode); // GpioPinDriveMode.Output); //Set directory (input/output) }
public ButtonController(int gpio, GpioPinDriveMode driveMode) { Gpio = gpio; pin_ = GpioController.GetDefault().OpenPin(gpio); pin_.SetDriveMode(driveMode); pin_.DebounceTimeout = TimeSpan.FromMilliseconds(50); pin_.ValueChanged += ButtonPressedHandler; }
public bool IsDriveModeSupported(GpioPinDriveMode driveMode) { if ((driveMode == GpioPinDriveMode.Input) || (driveMode == GpioPinDriveMode.InputPullUp) || (driveMode == GpioPinDriveMode.Output)) { return(true); } return(false); }
private GpioPin CreateAndOpenPin(GpioController controller, int pinNumber, GpioPinDriveMode driveMode = GpioPinDriveMode.Output) { var gpioPin = controller.OpenPin(pinNumber); gpioPin.SetDriveMode(driveMode); return(gpioPin); }
/// <summary> /// Send mode pin to seesaw controller /// </summary> /// <param name="pins">pins to set</param> /// <param name="mode">mode to set</param> protected void PinModeBulk(uint pins, GpioPinDriveMode mode) { _wBuffer[2] = (byte)(pins >> 24); _wBuffer[3] = (byte)(pins >> 16); _wBuffer[4] = (byte)(pins >> 8); _wBuffer[5] = (byte)(pins); SetPinModeBulk(mode, _wBuffer, 6); }
private GpioPin configureGpio(GpioController gpioController, int gpioId, GpioPinDriveMode pinDriveMode) { GpioPin pinTemp; pinTemp = gpioController.OpenPin(gpioId); pinTemp.SetDriveMode(pinDriveMode); return(pinTemp); }
public XGpio(int pinNumber, GpioController gpio, GpioSharingMode sharingMode, GpioPinDriveMode driveMode) { _pinNumber = pinNumber; _gpio = gpio; _sharingMode = sharingMode; _driveMode = driveMode; _init(); }
/// <summary> /// Instantiates a new RotaryEncoder on the specified pins that has an integrated button. /// </summary> /// <param name="aPhasePin"></param> /// <param name="bPhasePin"></param> /// <param name="buttonPin"></param> /// <param name="resistor"></param> /// <param name="debounceDuration"></param> public RotaryEncoderWithButton(int aPhasePin, int bPhasePin, int buttonPin, GpioPinDriveMode resistor = GpioPinDriveMode.InputPullDown, int debounceDuration = 20) : base(aPhasePin, bPhasePin) { _button = new PushButton(buttonPin, resistor, debounceDuration); _button.Clicked += ButtonClicked; _button.PressEnded += ButtonPressEnded; _button.PressStarted += ButtonPressStarted; }
/// <summary> /// Sets the drive mode of the given pin. /// </summary> /// <param name="pin">The pin to set.</param> /// <param name="driveMode">The new drive mode of the pin.</param> public void SetDigitalDriveMode(DigitalPin pin, GpioPinDriveMode driveMode) { if (!Enum.IsDefined(typeof(DigitalPin), pin)) { throw new ArgumentException(nameof(pin)); } this.gpio.SetDriveMode((int)pin, driveMode); }
public void Init(GpioPin gpioPin) { // Use InputPullUp if supported, otherwise fall back to Input (floating) inputDriveMode = gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ? GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input; gpioPin.SetDriveMode(inputDriveMode); pin = gpioPin; }
/// <summary> /// Constructor. /// </summary> /// <param name="pin"></param> /// <param name="mode">The drive mode of the pin. When inputPullUp is used, the pressed state will be true when a falling edge is detected.</param> public Button(IGpioPin pin, GpioPinDriveMode mode) { if (pin == null) throw new ArgumentNullException("pin"); if (mode != GpioPinDriveMode.Input && mode != GpioPinDriveMode.InputPullDown && mode != GpioPinDriveMode.InputPullUp) throw new ArgumentOutOfRangeException("mode", "Drive mode should be an input drive type."); _pin = pin; _pressedEdge = mode == GpioPinDriveMode.InputPullUp ? GpioPinEdge.FallingEdge : GpioPinEdge.RisingEdge; _pin.SetDriveMode(mode); _pin.ValueChanged += _pin_ValueChanged; }
/// <summary> /// Sets a drive mode with a fallback mode if the requested mode is not supported. /// </summary> /// <param name="pin"> /// The pin to set. /// </param> /// <param name="driveMode"> /// The requested drive mode. /// </param> /// <param name="fallbackMode"> /// The fallback drive mode. /// </param> public static void SetDriveModeWithFallback(this GpioPin pin, GpioPinDriveMode driveMode, GpioPinDriveMode fallbackMode) { if (pin.IsDriveModeSupported(driveMode)) { pin.SetDriveMode(driveMode); } else { pin.SetDriveMode(fallbackMode); } }
/// <summary> /// Sets a drive mode with a fallback mode if the requested mode is not supported. /// </summary> /// <param name="pin"> /// The pin to set. /// </param> /// <param name="driveMode"> /// The requested drive mode. /// </param> /// <param name="fallbackMode"> /// The fallback drive mode. /// </param> static public void SetDriveModeWithFallback(this GpioPin pin, GpioPinDriveMode driveMode, GpioPinDriveMode fallbackMode) { if (pin.IsDriveModeSupported(driveMode)) { pin.SetDriveMode(driveMode); } else { pin.SetDriveMode(fallbackMode); } }
public void SetDriveMode(GpioPinDriveMode value) { if (this.IsDriveModeSupported(value) == false) { throw new Exception("DriveMode not supported"); } this._gpioController.SetPinPullup((byte)this.PinNumber, value == GpioPinDriveMode.InputPullUp); this._gpioController.SetPinDirection((byte)this.PinNumber, value != GpioPinDriveMode.Output); this._driveMode = value; }
/// <summary> /// Creates a new DipSwitch connected to the specified switchPins, with the InterruptMode and ResisterMode specified by the type parameters. /// </summary> /// <param name="device"></param> /// <param name="switchPins"></param> /// <param name="interruptMode"></param> /// <param name="resistorMode"></param> /// <param name="debounceDuration"></param> /// <param name="glitchFilterCycleCount"></param> public DipSwitch(int[] switchPins, GpioPinEdge interruptMode, GpioPinDriveMode resistorMode, int debounceDuration = 20, int glitchFilterCycleCount = 0) { Switches = new ISwitch[switchPins.Length]; for (int i = 0; i < switchPins.Length; i++) { Switches[i] = new SpstSwitch(switchPins[i], interruptMode, resistorMode, debounceDuration, glitchFilterCycleCount); int index = i; Switches[i].Changed += (s, e) => HandleSwitchChanged(index); } }
/// Checks whether a GpioPinDriveMode is suitable for output. /// </summary> /// <param name="mode">The mode to check.</param> /// <returns>The mode if it is valid for output. Otherwise, an exception gets thrown.</returns> public static GpioPinDriveMode CheckOutputMode(GpioPinDriveMode mode) { if (mode >= GpioPinDriveMode.Output) { return(mode); } else { throw new ArgumentOutOfRangeException(nameof(mode)); } }
public void InitGPIO(int pinNr, GpioPinDriveMode mode) { var gpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (gpio == null) { throw new Exception("No GPIO Controller"); } pin = gpio.OpenPin(pinNr); pin.SetDriveMode(mode); }
public void AddPin(int pinNumber, GpioPinValue value, GpioPinDriveMode mode) { if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController")) { var gpioPin = _gpioController.OpenPin(pinNumber, GpioSharingMode.Exclusive); gpioPin.Write(value); gpioPin.SetDriveMode(mode); _pins.Add(pinNumber, gpioPin); } else { throw new NotSupportedException("Device doesn't support GPIO"); } }
private Pi2Port OpenPort(int number, GpioPinDriveMode mode) { Pi2Port port; if (!_openPorts.TryGetValue(number, out port)) { GpioPin pin = _gpioController.OpenPin(number, GpioSharingMode.Exclusive); pin.SetDriveMode(mode); port = new Pi2Port(pin); _openPorts.Add(number, port); } return port; }
public static GpioPin InitGpioPin(this GpioController controller, int pinNumber, GpioPinDriveMode driverMode, GpioSharingMode sharingMode) { GpioPin pin; GpioOpenStatus openStatus; if (!controller.TryOpenPin(pinNumber, sharingMode, out pin, out openStatus)) throw new IOException($"Unable to open Pin Number {pinNumber}!"); pin.Write(GpioPinValue.Low); pin.SetDriveMode(driverMode); if (openStatus != GpioOpenStatus.PinOpened) throw new IOException($"Pin Number {pinNumber} was opened but has an open status of [{openStatus}]!"); return pin; }
/// <summary> /// Sets a drive mode with automatic fallback if the requested mode is not supported. /// </summary> /// <param name="pin"> /// The pin to set. /// </param> /// <param name="driveMode"> /// The requested drive mode. /// </param> public static void SetDriveModeWithFallback(this GpioPin pin, GpioPinDriveMode driveMode) { switch (driveMode) { case GpioPinDriveMode.InputPullDown: case GpioPinDriveMode.InputPullUp: SetDriveModeWithFallback(pin, driveMode, GpioPinDriveMode.Input); break; case GpioPinDriveMode.OutputOpenDrain: case GpioPinDriveMode.OutputOpenDrainPullUp: SetDriveModeWithFallback(pin, driveMode, GpioPinDriveMode.Output); break; case GpioPinDriveMode.OutputOpenSourcePullDown: SetDriveModeWithFallback(pin, driveMode, GpioPinDriveMode.OutputOpenSource); break; default: pin.SetDriveMode(driveMode); break; } }
public void SetDirection(XGpioDirection direction) { GpioPinDriveMode mode; if (direction == XGpioDirection.Input) { mode = GpioPinDriveMode.Input; } else { mode = GpioPinDriveMode.Output; } if (!_pin.IsDriveModeSupported(mode)) { throw new NotSupportedException($"Drive mode {mode} not supported on pin {_pinNumber}"); } _pin.SetDriveMode(mode); _driveMode = mode; }
public GpioModule(GpioController controller, int pinNumber, GpioPinDriveMode driveMode = GpioPinDriveMode.Input, LogicValue logicValue = LogicValue.Positive) : base(controller) { Pin = Controller.OpenPin(pinNumber); // Shows an error if the pin wasn't initialized properly if (Pin == null) throw new ArgumentException($"There were problems initializing the GPIO {GetType().Name} pin."); if (logicValue == LogicValue.Positive) { ActualHighPinValue = GpioPinValue.High; ActualLowPinValue = GpioPinValue.Low; } else { ActualHighPinValue = GpioPinValue.Low; ActualLowPinValue = GpioPinValue.High; } Pin.Write(ActualLowPinValue); Pin.SetDriveMode(driveMode); }
/// <summary> /// Connects to a GPIO pin if it exists. /// </summary> /// <param name="controllerIndex">Controller index.</param> /// <param name="pinNumber">Pin number.</param> /// <param name="driveMode">Drive mode.</param> /// <param name="sharingMode">Sharing mode.</param> /// <returns>Pin when controller and device exist, otherwise null.</returns> public static GpioPin ConnectGpio(int controllerIndex, int pinNumber, GpioPinDriveMode driveMode = GpioPinDriveMode.Input, GpioSharingMode sharingMode = GpioSharingMode.Exclusive) { // Validate if (controllerIndex < 0) throw new ArgumentOutOfRangeException(nameof(controllerIndex)); // Initialize Initialize(); // Get controller (return null when doesn't exist) if (Gpio.Count < controllerIndex + 1) return null; var controller = Gpio[controllerIndex]; // Connect to device (return null when doesn't exist) var pin = controller.OpenPin(pinNumber, sharingMode); if (pin == null) return null; // Configure and return pin if (pin.GetDriveMode() != driveMode) pin.SetDriveMode(driveMode); return pin; }
private GpioPin configureGpio(GpioController gpioController, int gpioId, GpioPinValue pinValue, GpioPinDriveMode pinDriveMode) { GpioPin pinTemp; pinTemp = gpioController.OpenPin(gpioId); pinTemp.Write(pinValue); pinTemp.SetDriveMode(pinDriveMode); return pinTemp; }
public void SetDriveMode(GpioPinDriveMode value) { this.Pin.SetDriveMode(value); }
extern private void SetDriveModeInternal(GpioPinDriveMode driveMode);
public void SetDriveMode(int pin, GpioPinDriveMode driveMode) { if (this.disposed) throw new ObjectDisposedException(nameof(PCA9685)); if (!((pin >= 0 && pin <= 7) || (pin >= 10 && pin <= 17))) throw new ArgumentOutOfRangeException(nameof(pin)); if (driveMode == GpioPinDriveMode.Input) { if (pin < 8) { this.config0 |= (byte)(1 << pin); this.WriteRegister(Register.ConfigurationPort0, this.config0); } else { this.config1 |= (byte)(1 << (pin - 10)); this.WriteRegister(Register.ConfigurationPort1, this.config1); } } else { if (pin < 8) { this.config0 &= (byte)~(1 << pin); this.WriteRegister(Register.ConfigurationPort0, this.config0); } else { this.config1 &= (byte)~(1 << (pin - 10)); this.WriteRegister(Register.ConfigurationPort1, this.config1); } } }
public bool IsDriveModeSupported(GpioPinDriveMode driveMode) { return this.Pin.IsDriveModeSupported(driveMode); }
/// <summary> /// Sets the drive mode of the given pin. /// </summary> /// <param name="pin">The pin to set.</param> /// <param name="driveMode">The new drive mode of the pin.</param> public void SetDigitalDriveMode(DigitalPin pin, GpioPinDriveMode driveMode) { if (!Enum.IsDefined(typeof(DigitalPin), pin)) throw new ArgumentException(nameof(pin)); this.gpio.SetDriveMode((int)pin, driveMode); }
public IndirectedDigitalIO(int channel, PCA9535 pca) { this.pin = channel; this.gpio = pca; this.driveMode = GpioPinDriveMode.Input; }
public double ReadVoltage() { this.DriveMode = GpioPinDriveMode.Input; return this.ReadInternal(); }
public void WriteVoltage(double value) { this.DriveMode = GpioPinDriveMode.Output; this.WriteInternal(value); }
/// <summary> /// Sets the drive mode of the general-purpose I/O (GPIO) pin. The drive mode specifies whether the pin is /// configured as an input or an output, and determines how values are driven onto the pin. /// </summary> /// <param name="driveMode">An enumeration value that specifies drive mode to use for the GPIO pin. The drive /// mode specifies whether the pin is configured as an input or an output, and determines how values are /// driven onto the pin.</param> public void SetDriveMode(GpioPinDriveMode driveMode) { lock (m_syncLock) { if (m_disposed) { throw new ObjectDisposedException(); } if (driveMode != m_driveMode) { SetDriveModeInternal(driveMode); m_driveMode = driveMode; } } }
public static GpioPin InitGPIO(int GPIOpin, GpioPinDriveMode mode, GpioPinValue HiLow) { var gpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (gpio == null) { return null; } var pin = gpio.OpenPin(GPIOpin); if (pin == null) { return null; } pin.SetDriveMode(mode); pin.Write(HiLow); return pin; }
/// <summary> /// Sets the pin direction. /// </summary> /// <param name="pin">Pin to set direction for.</param> /// <param name="driveMode">The pin direction</param> internal void SetDriveMode(int pin, GpioPinDriveMode driveMode) { if (driveMode == GpioPinDriveMode.InputPullDown) throw new ArgumentException("The MCP chip only support pull up resistors", "direction"); var isInput = driveMode == GpioPinDriveMode.Input || driveMode == GpioPinDriveMode.InputPullUp; this.IODIR.Write(pin, isInput); var pullUpEnabled = driveMode == GpioPinDriveMode.InputPullUp; this.EnablePullUpResistor(pin, pullUpEnabled); if(isInput) { this.SetInterrupt(pin, true); } }
public GpioModule(int pinNumber, GpioPinDriveMode driveMode = GpioPinDriveMode.Input, LogicValue logicValue = LogicValue.Positive) : this(GpioController.GetDefault(), pinNumber, driveMode, logicValue) { }
public void SetDriveMode(GpioPinDriveMode mode) { pin.SetDriveMode(mode); }
/// <summary> /// Gets whether the general-purpose I/O (GPIO) pin supports the specified drive mode. /// </summary> /// <param name="driveMode">The drive mode to check for support.</param> /// <returns>True if the GPIO pin supports the drive mode that driveMode specifies; otherwise false. If you /// specify a drive mode for which this method returns false when you call SetDriveMode, SetDriveMode /// generates an exception.</param> public bool IsDriveModeSupported(GpioPinDriveMode driveMode) { switch (driveMode) { case GpioPinDriveMode.Input: case GpioPinDriveMode.Output: case GpioPinDriveMode.InputPullUp: case GpioPinDriveMode.InputPullDown: return true; } return false; }
public static GpioPin DriveMode(this GpioPin t, GpioPinDriveMode mode) { t.SetDriveMode(mode); return t; }