Exemplo n.º 1
0
 public McpGpio(MCP230XX_Base mcp, string name)
 {
     this._mcp  = mcp;
     this.Mode  = PinMode.Output;
     this.Name  = name;
     this.Index = McpGpio.ExtractGpioIndex(name);
 }
Exemplo n.º 2
0
 public McpGpio(MCP230XX_Base mcp, string name)
 {
     this._mcp  = mcp;
     this.Mode  = PinMode.Output;
     this.Name  = name;
     this.Index = McpGpio.ExtractGpioIndex(name);
 }
Exemplo n.º 3
0
        public MCP23008(Nusbio nusbio, NusbioGpio sdaPin, NusbioGpio sclPin, int gpioStartIndex = 8)
            : base(nusbio, sdaPin, sclPin)
        {
            this._gpioStartIndex = (byte)gpioStartIndex;

            for (var i = 0; i < this.GetMaxGPIO(); i++)
            {
                base.AddGPIO(MCP230XX_Base.BuildGpioName(this.GpioStartIndex + i), PinMode.Output, true);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }