public void SetPinMode(byte gpioIndex, MadeInTheUSB.GPIO.PinMode mode) { var k = MCP230XX_Base.BuildGpioName(gpioIndex); if (this.GPIOS.ContainsKey(k)) { this.GPIOS[k].Mode = mode; } else { throw new ArgumentException(string.Format("Gpio {0} not available", gpioIndex)); } var mcpIndex = gpioIndex - this.GpioStartIndex; if (mcpIndex > (this.GetMaxGPIO() - 1)) { throw new ArgumentException(string.Format("Gpio {0} not available", gpioIndex)); } int iodir = this._i2c.Send1ByteRead1Byte(MCP230XX_IODIR); if (iodir == -1) { throw new ArgumentException(string.Format("Cannot read state of MCP230XX")); } if (mode == GPIO.PinMode.Input || mode == GPIO.PinMode.InputPullUp) { iodir |= (byte)(1 << mcpIndex); } else { iodir &= (byte)(~(1 << mcpIndex)); } if (!this._i2c.Send2BytesCommand(MCP230XX_IODIR, (byte)iodir)) { throw new ArgumentException(string.Format("Cannot set state of MCP230XX")); } if (mode == GPIO.PinMode.InputPullUp) { this.SetPullUp(gpioIndex, PinState.High); } if (mode == GPIO.PinMode.Input) { this.SetPullUp(gpioIndex, PinState.Low); } }
public void SetPinMode(int p, MadeInTheUSB.GPIO.PinMode mode) { SetPinMode((byte)p, mode); }
public void SetPinMode(string gpio, MadeInTheUSB.GPIO.PinMode mode) { SetPinMode(McpGpio.ExtractGpioIndex(gpio), mode); }