public void SetPinMode(string pinName, PinMode mode) { const string kPinStatePath = "/sys/devices/ocp.*/{0}_pinmux.*/state"; string pinStatePath = internalFileSystemProxy.ResolveAbsolutePath(kPinStatePath.F(pinName)); var state = mode.GetAttributeOrNull<DescriptionAttribute>().Description; internalFileSystemProxy.WriteText(pinStatePath, state); }
public static void SafePinMode(this RemoteDevice device, string pin, PinMode pinMode) { lock (_lock) { device.pinMode(pin, pinMode); } }
protected void SetPinMode(PinMode mode) { foreach (var pin in Pins) { Board.PinMode(pin, mode); } }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/> /// class with the physical pin represented by this class. /// </summary> /// <param name="pin"> /// The physical pin being wrapped by this class. /// </param> protected PiFaceGpioBase(PiFacePins pin) { this._innerPin = pin; switch (pin) { case PiFacePins.Input00: case PiFacePins.Input01: case PiFacePins.Input02: case PiFacePins.Input03: case PiFacePins.Input04: case PiFacePins.Input05: case PiFacePins.Input06: case PiFacePins.Input07: this._mode = PinMode.IN; break; case PiFacePins.Output00: case PiFacePins.Output01: case PiFacePins.Output02: case PiFacePins.Output03: case PiFacePins.Output04: case PiFacePins.Output05: case PiFacePins.Output06: case PiFacePins.Output07: this._mode = PinMode.OUT; break; case PiFacePins.None: default: break; } }
public override void SetIOMode(PinMode mode) { if (mode == PinMode.Input) { SetMode(GPIOPinMode.Input); } else if (mode == PinMode.Output) { SetMode(GPIOPinMode.Output); } }
public override void SetIOMode(int pin, PinMode mode) { if (mode == PinMode.Input) { WriteRegisterBit(ADDR_IODIR, pin, 1); } else if (mode == PinMode.Output) { WriteRegisterBit(ADDR_IODIR, pin, 0); } }
/// <summary> /// Checks if a pin supports a specific mode. /// </summary> /// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param> /// <param name="mode">The mode to check.</param> /// <returns>The status if the pin supports the mode.</returns> protected internal abstract bool IsPinModeSupported(int pinNumber, PinMode mode);
public bool IsPinModeSupported(int pinNumber, PinMode mode) { return(_controller.IsPinModeSupported(pinNumber, mode)); }
public void SetPinMode(int pin, PinMode mode) { this._DigitalWriteRead.SetPinMode(pin, mode); }
/// <summary> /// Exports the GPIO setting the direction. This creates the /// /sys/class/gpio/gpioXX directory. /// </summary> /// <param name="pin"> /// The GPIO pin on the board. /// </param> /// <param name="mode"> /// The I/O mode. /// </param> private static void ExportPin(GpioPins pin, PinMode mode) { String name = Enum.GetName(typeof(GpioPins), pin); internal_ExportPin((Int32)pin, mode, GetGpioPinNumber(pin), name); }
public void SetPinMode(ShifterPin pin, PinMode mode) { if (pin == ShifterPin.None) return; byte iodir = ReadReg8(Register.IODIR); SetRegBit(ref iodir, pin, mode == PinMode.Input); WriteReg8(Register.IODIR, iodir); }
public void OpenPin(int pinNumber, PinMode mode) { _controller.OpenPin(pinNumber, mode); }
// Basic digital pin // Input/Output modes only, pull up/down, read/write, interrupt on input change public abstract void SetIOMode(PinMode mode);
/// <summary> /// Init a pin /// </summary> /// <param name="string">Target Name</param> /// <param name="pin">Pin to init</param> /// <param name="mode">PinMode to init pin</param> public void InitPin(string target, AnalogPin pin, PinMode mode) { InitPin((int)pin, mode); }
public void PinMode(Pin pin, PinMode mode) { var buffer = new[] { (byte)Commands.PinMode, (byte)pin, (byte)mode, Constants.Unused }; DirectAccess.Write(buffer); }
/// <summary> /// Init a pin /// </summary> /// <param name="pin">Analog pin to initialize</param> /// <param name="mode">PinMode to init pin</param> public void InitPin(AnalogPin pin, PinMode mode) { InitPin(null, (int)pin, mode); }
/// <summary> /// Initialize an arduino pin /// </summary> /// <param name="pin">Pin to initialize</param> /// <param name="mode">PinMode to init pin</param> public void InitPin(int pin, PinMode mode) { InitPin(null, pin, mode); }
/// <inheritdoc cref="IFirmataProtocol.SetDigitalPinMode"/> public void SetDigitalPinMode(int pinNumber, PinMode mode) { if (pinNumber < 0 || pinNumber > 127) throw new ArgumentOutOfRangeException("pinNumber", Messages.ArgumentEx_PinRange0_127); _connection.Write(new byte[] { 0xF4, (byte)pinNumber, (byte)mode }, 0, 3); }
private void SetInputPullMode(int pinNumber, PinMode mode) { /* * NoOptimization is needed to force wait time to be at least minimum required cycles. * Also to ensure that pointer operations optimizations won't be using any locals * which would introduce time period where multiple threads could override value set * to this register. */ if (IsPi4) { SetInputPullModePi4(pinNumber, mode); return; } byte modeToPullMode = mode switch { PinMode.Input => (byte)0, PinMode.InputPullDown => (byte)1, PinMode.InputPullUp => (byte)2, _ => throw new ArgumentException($"{mode} is not supported as a pull up/down mode.") }; /* * This is the process outlined by the BCM2835 datasheet on how to set the pull mode. * The GPIO Pull - up/down Clock Registers control the actuation of internal pull-downs on the respective GPIO pins. * These registers must be used in conjunction with the GPPUD register to effect GPIO Pull-up/down changes. * The following sequence of events is required: * * 1. Write to GPPUD to set the required control signal (i.e.Pull-up or Pull-Down or neither to remove the current Pull-up/down) * 2. Wait 150 cycles – this provides the required set-up time for the control signal * 3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to modify * – NOTE only the pads which receive a clock will be modified, all others will retain their previous state. * 4. Wait 150 cycles – this provides the required hold time for the control signal * 5. Write to GPPUD to remove the control signal * 6. Write to GPPUDCLK0/1 to remove the clock */ uint *gppudPointer = &_registerViewPointer->GPPUD; *gppudPointer &= ~0b11U; *gppudPointer |= modeToPullMode; // Wait 150 cycles – this provides the required set-up time for the control signal for (int i = 0; i < 150; i++) { } int index = pinNumber / 32; int shift = pinNumber % 32; uint *gppudclkPointer = &_registerViewPointer->GPPUDCLK[index]; uint pinBit = 1U << shift; *gppudclkPointer |= pinBit; // Wait 150 cycles – this provides the required hold time for the control signal for (int i = 0; i < 150; i++) { } // Spec calls to reset clock after the control signal // Since context switch between those two instructions can potentially // change pull up/down value we reset the clock first. *gppudclkPointer &= ~pinBit; *gppudPointer &= ~0b11U; // This timeout is not documented in the spec // but lack of it is causing intermittent failures when // pull up/down is changed frequently. for (int i = 0; i < 150; i++) { } }
public static void PinMode(int pin, PinMode mode) { PinMode(pin, (int)mode); }
public PinState(PinMode currentMode) { CurrentPinMode = currentMode; InUseByInterruptDriver = false; }
/// <summary> /// Sets the resistor pull up/down mode for an input pin. /// </summary> /// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param> /// <param name="mode">The mode of a pin to set the resistor pull up/down mode.</param> private void SetInputPullMode(int pinNumber, PinMode mode) { byte modeToPullMode; switch (mode) { case PinMode.Input: modeToPullMode = 0; break; case PinMode.InputPullDown: modeToPullMode = 1; break; case PinMode.InputPullUp: modeToPullMode = 2; break; default: throw new ArgumentException($"{mode} is not supported as a pull up/down mode."); } /* * This is the process outlined by the BCM2835 datasheet on how to set the pull mode. * The GPIO Pull - up/down Clock Registers control the actuation of internal pull-downs on the respective GPIO pins. * These registers must be used in conjunction with the GPPUD register to effect GPIO Pull-up/down changes. * The following sequence of events is required: * * 1. Write to GPPUD to set the required control signal (i.e.Pull-up or Pull-Down or neither to remove the current Pull-up/down) * 2. Wait 150 cycles – this provides the required set-up time for the control signal * 3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to modify * – NOTE only the pads which receive a clock will be modified, all others will retain their previous state. * 4. Wait 150 cycles – this provides the required hold time for the control signal * 5. Write to GPPUD to remove the control signal * 6. Write to GPPUDCLK0/1 to remove the clock */ uint *gppudPointer = &_registerViewPointer->GPPUD; uint register = *gppudPointer; register &= ~0b11U; register |= modeToPullMode; *gppudPointer = register; // Wait 150 cycles – this provides the required set-up time for the control signal Thread.SpinWait(150); int index = pinNumber / 32; int shift = pinNumber % 32; uint *gppudclkPointer = &_registerViewPointer->GPPUDCLK[index]; register = *gppudclkPointer; register |= 1U << shift; *gppudclkPointer = register; // Wait 150 cycles – this provides the required hold time for the control signal Thread.SpinWait(150); register = *gppudPointer; register &= ~0b11U; *gppudPointer = register; *gppudclkPointer = 0; }
/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/> /// object. /// </summary> /// <remarks> /// Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/>. The /// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/> /// in an unusable state. After calling <see cref="Dispose"/>, you must /// release all references to the <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/> /// so the garbage collector can reclaim the memory that the /// <see cref="CyrusBuilt.MonoPi.IO.PiFaceGpioBase"/> was occupying. /// </remarks> public virtual void Dispose() { if (this._isDisposed) { return; } _exportedPins.Clear(); _exportedPins = null; this.StateChanged = null; this._innerPin = PiFacePins.None; this._mode = PinMode.IN; this._isDisposed = true; this._name = null; this._tag = null; GC.SuppressFinalize(this); }
/// <summary> /// Sets the mode of the specified pin (INPUT or OUTPUT). /// </summary> /// <param name="pin">The arduino pin.</param> /// <param name="mode">Mode Arduino.INPUT or Arduino.OUTPUT.</param> public void PinMode(int pin, PinMode mode) { Log("[PinMode] - Setting pin {0} to {1}".FormatWith(pin, mode)); var message = new byte[3]; message[0] = SetPinMode; message[1] = (byte) (pin); message[2] = (byte) ((int) mode); _serialPort.Write(message, 0, 3); }
public void SetMode(PinMode mode) { _pin.SetDriveMode(mode == PinMode.In ? GpioPinDriveMode.Input : GpioPinDriveMode.Output); }
/// <summary>Executes the command asynchronously.</summary> /// <returns>The command's exit code.</returns> /// <remarks> /// NOTE: This test app uses the base class's <see cref="CreateGpioController"/> method to create a device.<br/> /// Real-world usage would simply create an instance of <see cref="GpioController"/>: /// <code>using (var controller = new GpioController())</code> /// </remarks> public Task <int> ExecuteAsync() { if (OnValue != 0) { OnValue = 1; } if (LedPin != null) { Console.WriteLine($"Driver={Driver}, Scheme={Scheme}, ButtonPin={ButtonPin}, LedPin={LedPin}, PressedValue={PressedValue}, OnValue={OnValue}"); } else { Console.WriteLine($"Driver={Driver}, Scheme={Scheme}, ButtonPin={ButtonPin}, PressedValue={PressedValue}, OnValue={OnValue}"); } using (GpioController controller = CreateGpioController()) { using (var cancelEvent = new ManualResetEvent(false)) { int count = 0; Console.WriteLine($"Listening for button presses on GPIO {Enum.GetName(typeof(PinNumberingScheme), Scheme)} pin {ButtonPin} . . ."); // This example runs until Ctrl+C (or Ctrl+Break) is pressed, so register a local function handler. Console.CancelKeyPress += Console_CancelKeyPress; controller.OpenPin(ButtonPin); // Set the mode based on if input pull-up resistors are supported. PinMode inputMode = controller.IsPinModeSupported(ButtonPin, PinMode.InputPullUp) ? PinMode.InputPullUp : PinMode.Input; controller.SetPinMode(ButtonPin, inputMode); // Open the GPIO pin connected to the LED if one was specified. if (LedPin != null) { controller.OpenPin(LedPin.Value, PinMode.Output); controller.Write(LedPin.Value, OffValue); } // Set the event handler for changes to the pin value. PinEventTypes bothPinEventTypes = PinEventTypes.Falling | PinEventTypes.Rising; controller.RegisterCallbackForPinValueChangedEvent(ButtonPin, bothPinEventTypes, valueChangeHandler); // Wait for the cancel (Ctrl+C) console event. cancelEvent.WaitOne(); // Unregister the event handler for changes to the pin value controller.UnregisterCallbackForPinValueChangedEvent(ButtonPin, valueChangeHandler); controller.ClosePin(ButtonPin); if (LedPin != null) { controller.ClosePin(LedPin.Value); } Console.WriteLine("Operation cancelled. Exiting."); Console.OpenStandardOutput().Flush(); return(Task.FromResult(0)); // Declare a local function to handle the pin value changed events. void valueChangeHandler(object sender, PinValueChangedEventArgs pinValueChangedEventArgs) { if (LedPin != null) { PinValue ledValue = pinValueChangedEventArgs.ChangeType == PressedValue ? OnValue : OffValue; controller.Write(LedPin.Value, ledValue); } var pressedOrReleased = pinValueChangedEventArgs.ChangeType == PressedValue ? "pressed" : "released"; Console.WriteLine($"[{count++}] Button {pressedOrReleased}: logicalPinNumber={pinValueChangedEventArgs.PinNumber}, ChangeType={pinValueChangedEventArgs.ChangeType}"); } // Local function void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; cancelEvent.Set(); Console.CancelKeyPress -= Console_CancelKeyPress; } } } }
/// <summary> /// Sets the mode of the specified pin. /// </summary> /// <param name="pin"> /// The pin to alter. /// </param> /// <param name="mode"> /// The mode to set. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="pin"/> cannot be null. /// </exception> /// <exception cref="ObjectDisposedException"> /// This instance has been disposed and can no longer be used. /// </exception> /// <exception cref="ArgumentException"> /// The specified pin does not exist in the pin cache. /// </exception> public void SetPinMode(IPCF8574Pin pin, PinMode mode) { if (pin == null) { throw new ArgumentNullException("pin"); } if (this._isDisposed) { throw new ObjectDisposedException("CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"); } if (!this._pinCache.Contains(pin)) { throw new ArgumentException("Cannot set the mode of a pin that does not exist in the pin cache.", "pin"); } this._pinCache[this._pinCache.IndexOf(pin)].SetMode(mode); }
/// <inheritdoc/> protected internal override bool IsPinModeSupported(int pinNumber, PinMode mode) => _internalDriver.IsPinModeSupported(pinNumber, mode);
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.GpioFile"/> /// class with the Rev1 pin to access and the I/O direction. /// </summary> /// <param name="pin"> /// The pin on the board to access. /// </param> /// <param name="mode"> /// The I/0 mode of the pin. /// </param> public GpioFile(GpioPins pin, PinMode mode) : base(pin, mode, PinState.Low) { }
/// <inheritdoc/> protected internal override void SetPinMode(int pinNumber, PinMode mode) => _internalDriver.SetPinMode(pinNumber, mode);
public PinModeEventArgs(int pin, PinMode mode) { Pin = pin; Mode = mode; }
/// <summary> /// Setup the pin mode, equivalent of pinMod on Arduino /// </summary> /// <param name="pin">The GroovePi pin to setup</param> /// <param name="mode">THe mode to setup Intput or Output</param> public void PinMode(GrovePort pin, PinMode mode) => WriteCommand(GrovePiCommand.PinMode, pin, (byte)mode, 0);
/// <summary> /// Sets the mode to a pin. /// </summary> /// <param name="pinNumber">The pin number in the driver's logical numbering scheme.</param> /// <param name="mode">The mode to be set.</param> protected internal abstract void SetPinMode(int pinNumber, PinMode mode);
public IDisposable OpenPin(int pinNumber, PinMode mode) { OpenPins.Add(pinNumber); SetPinMode(pinNumber, mode); return(Disposable.Create(() => ClosePin(pinNumber))); }
/// <inheritdoc/> protected override bool IsPinModeSupported(int pinNumber, PinMode mode) => (mode == PinMode.Input || mode == PinMode.Output);
public void SetPinMode(int pinNumber, PinMode mode) { _pinMode[pinNumber] = mode; }
public bool CanPin(TabPinMode mode) { return(!PinMode.Equals(mode)); }
public bool IsPinModeSupported(int pinNumber, PinMode mode) { throw new NotImplementedException(); }
/// <summary> /// This function will determine which pin mode image should be applied for a given digital pin and apply it to the correct Image object /// </summary> /// <param name="pin">the pin number to be updated</param> private void UpdateDigitalPinIndicators(byte pin) { if (!digitalModeToggleSwitches.ContainsKey(pin)) { return; } if (disabledPins.Contains(pin)) { digitalModeToggleSwitches[pin].IsEnabled = false; digitalStateToggleSwitches[pin].IsEnabled = false; digitalStateToggleSwitches[pin].Visibility = Visibility.Collapsed; digitalStateTextBlocks[pin].Visibility = Visibility.Visible; } else { PinMode mode = arduino.getPinMode(pin); bool applyUsageMessage = false; switch (mode) { case PinMode.INPUT: digitalModeToggleSwitches[pin].IsEnabled = true; digitalModeToggleSwitches[pin].IsOn = true; navigated = false; digitalStateToggleSwitches[pin].IsEnabled = true; digitalStateToggleSwitches[pin].Visibility = Visibility.Collapsed; digitalStateTextBlocks[pin].Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 0)); digitalStateTextBlocks[pin].Text = ((arduino.digitalRead(pin)) == PinState.HIGH) ? "5v" : "0v"; digitalStateTextBlocks[pin].Visibility = Visibility.Visible; break; case PinMode.OUTPUT: digitalModeToggleSwitches[pin].IsEnabled = true; digitalModeToggleSwitches[pin].IsOn = false; navigated = false; digitalStateToggleSwitches[pin].IsEnabled = true; digitalStateToggleSwitches[pin].Visibility = Visibility.Visible; digitalStateTextBlocks[pin].Visibility = Visibility.Collapsed; break; default: applyUsageMessage = true; digitalModeToggleSwitches[pin].IsEnabled = false; digitalStateToggleSwitches[pin].IsEnabled = false; digitalStateToggleSwitches[pin].Visibility = Visibility.Collapsed; digitalStateTextBlocks[pin].Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 106, 107, 106)); digitalStateTextBlocks[pin].Visibility = Visibility.Visible; break; } //PWM and ANALOG have the same UI config as 'default' in the switch above, but we want a custom message. Two switches reduce duplicate code. if (applyUsageMessage) { switch (mode) { case PinMode.PWM: digitalStateTextBlocks[pin].Text = "Disabled for PWM use."; break; case PinMode.ANALOG: digitalStateTextBlocks[pin].Text = "Disabled for Analog use."; break; default: digitalStateTextBlocks[pin].Text = "Disabled for other use."; break; } } } }
/// <summary> /// Sets the mode of the specified pin (INPUT or OUTPUT). /// </summary> /// <param name="pin">The arduino pin.</param> /// <param name="mode">Mode Arduino.INPUT or Arduino.OUTPUT.</param> /// public void pinMode(int pin, PinMode mode) { pinMode(pin, (int)mode); }
/// <summary> /// ピンモードの設定 /// </summary> /// <param name="no">ピン番号</param> /// <param name="mode">モード</param> public void PinMode(int no, PinMode mode) { this.ProcessExec("-g mode " + no + " " + (mode == MonoRaspberryPi.PinMode.In ? "in" : "out")); }
/// <summary> /// Sets the pin mode. /// </summary> /// <param name="mode"> /// The pin mode. /// </param> public void SetMode(PinMode mode) { this._mode = mode; }
protected void SetPinMode(PinMode mode) { Board.PinMode(Pin, mode); }
public void AddGPIO(string gpio, PinMode mode, bool removeIfExist = false) { if (removeIfExist && this.GPIOS.ContainsKey(gpio)) this.GPIOS.Remove(gpio); this.GPIOS.Add(gpio, new McpGpio(this, gpio)); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574Pin"/>. The /// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574Pin"/> in an unusable state. /// After calling <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574Pin"/> so the garbage collector can reclaim the memory that the /// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574Pin"/> was occupying.</remarks> public void Dispose() { if (this._isDisposed) { return; } this._name = null; this._provName = null; this._tag = null; this._state = PinState.Low; this._mode = PinMode.TRI; this._address = -1; this._isDisposed = true; GC.SuppressFinalize(this); }
void SetPinModeCommand(PinMode mode, int pin) { CommandBuffer.Enqueue(Command.SETPINMODE); CommandBuffer.Enqueue((byte)pin); CommandBuffer.Enqueue((byte)mode); }
public abstract void SetIOMode(int pin, PinMode mode);
void SetPinStates(ISpread <double> values) { // get the number of output ports // FIXME: Get only those ports, whos values have changed int[] digital_out = new int[NUM_PORTS]; Queue <byte> AnalogCommandBuffer = new Queue <byte>(); int analogOutCount = 0; int pinCount = Math.Min(Default.MaxDigitalPins, Math.Min(NUM_PINS, values.SliceCount)); for (int pin = 0; pin < pinCount; pin++) { double value = values[pin]; PinMode mode = PinModeForPin(pin); switch (mode) { case PinMode.PWM: case PinMode.SERVO: byte LSB, MSB; value *= mode == PinMode.SERVO ? 180 : 255; // servo is in degrees FirmataUtils.GetBytesFromValue((int)value, out MSB, out LSB); if (pin <= 0x0F) { AnalogCommandBuffer.Enqueue((byte)(Command.ANALOGMESSAGE | pin)); AnalogCommandBuffer.Enqueue(LSB); AnalogCommandBuffer.Enqueue(MSB); } else { AnalogCommandBuffer.Enqueue(Command.SYSEX_START); AnalogCommandBuffer.Enqueue(Command.EXTENDED_ANALOG); AnalogCommandBuffer.Enqueue((byte)(pin & 0x7F)); // mask 7 Bit AnalogCommandBuffer.Enqueue(LSB); AnalogCommandBuffer.Enqueue(MSB); AnalogCommandBuffer.Enqueue(Command.SYSEX_END); } break; case PinMode.OUTPUT: case PinMode.INPUT: // fixes PullUp enabling issue, thx to motzi! int port = PortIndexForPin(pin); // Break, if we have no outputports we can get if (port < NUM_PORTS) { int state = (value >= 0.5 ? 0x01 : 0x00) << pin % 8; state |= digital_out[port]; state &= OUTPUT_PORT_MASKS[port]; digital_out[port] = (byte)state; } break; } } /// Write all the output ports to the command buffer for (int port = 0; port < digital_out.Length; port++) { byte LSB, MSB; FirmataUtils.GetBytesFromValue(digital_out[port], out MSB, out LSB); CommandBuffer.Enqueue((byte)(Command.DIGITALMESSAGE | port)); CommandBuffer.Enqueue(LSB); CommandBuffer.Enqueue(MSB); } /// Append the Commands for the analog messages if (AnalogCommandBuffer.Count > 0) { foreach (byte b in AnalogCommandBuffer) { CommandBuffer.Enqueue(b); } } }
/// <summary> /// Sets the basic mode for a particular pin. /// </summary> /// <param name="pin">The pin to set the mode on.</param> /// <param name="mode">The mode.</param> public void PinMode(int pin, PinMode mode) { Debug.WriteLine(string.Format("Sending pin mode {0} to pin {1}", mode.ToString(), pin)); SerialConnector.Send( new Command(CommandMap.PinMode, pin, (int)mode)); }
public void OpenPin(int pinNumber, PinMode mode) => SetPinMode(pinNumber, mode);
public void SetMode(PinMode mode) { _mode = mode; }
public void OpenPin(int pinNumber, PinMode mode) { }
/// <summary> /// Exports the GPIO setting the direction. This creates the /// /sys/class/gpio/gpioXX directory. /// </summary> /// <param name="pin"> /// The GPIO pin. /// </param> /// <param name="mode"> /// The I/O mode. /// </param> /// <param name="pinnum"> /// The pin number. /// </param> /// <param name="pinname"> /// The name of the pin. /// </param> private static void internal_ExportPin(Int32 pin, PinMode mode, String pinnum, String pinname) { String pinpath = GPIO_PATH + "gpio" + pinnum; String m = Enum.GetName(typeof(PinMode), mode); // If the pin is already exported, check it's in the proper direction. if (ExportedPins.ContainsKey(pin)) { // If the direction matches, return out of the function. If not, // change the direction. if (ExportedPins[pin] == mode) { return; } else { // Set the direction on the pin and update the exported list. File.WriteAllText(pinpath + "/direction", m); ExportedPins[pin] = mode; return; } } // Export. if (!Directory.Exists(pinpath)) { Debug.WriteLine("Exporting pin " + pinnum); File.WriteAllText(GPIO_PATH + "export", pinnum); } // Set I/O direction. Debug.WriteLine("Setting direction on pin " + pinname + "/gpio" + pin.ToString() + " as " + m); File.WriteAllText(pinpath + "/direction", m); // Update the pin. ExportedPins[pin] = mode; }
protected override void SetPinMode(int pinNumber, PinMode mode) { _pinModes.AddOrUpdate(pinNumber, mode, (key, oldValue) => mode); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.GpioFile"/> /// class with the Rev1 pin to access, the I/O direction, and the initial value. /// </summary> /// <param name="pin"> /// The pin on the board to access. /// </param> /// <param name="mode"> /// The I/0 mode of the pin. /// </param> /// <param name="initialValue"> /// The pin's initial value. /// </param> public GpioFile(GpioPins pin, PinMode mode, PinState initialValue) : base(pin, mode, initialValue) { }
protected override bool IsPinModeSupported(int pinNumber, PinMode mode) => true;
void SetPinModeCommand(PinMode mode, int pin) { CommandBuffer.Enqueue(Command.SETPINMODE); CommandBuffer.Enqueue((byte) pin); CommandBuffer.Enqueue((byte) mode); }
public void SetPinMode(int pinNumber, PinMode mode) { _controller.SetPinMode(pinNumber, mode); }
public IDisposable OpenPin(int pinNumber, PinMode mode) { _controller.OpenPin(pinNumber, mode); return(Disposable.Create(() => ClosePin(pinNumber))); }
public static byte[] SetPinMode(int pin, PinMode mode) { byte[] cmd = { (byte) Command.SET_PIN_MODE, (byte) pin, (byte) mode }; return cmd; }