コード例 #1
0
        /// <summary>
        /// Creates a new instance of the PiFaceDigital class, used to communicate with a PiFaceDigital or PiFaceDigital2 extension board.
        /// </summary>
        /// <param name="spiDeviceInformation">The SPI device information.</param>
        /// <param name="chipSelectLevel">The chip select line level to use.</param>
        public PiFaceDigital(DeviceInformation spiDeviceInformation, byte chipSelectLevel = 0)
        {
            this._chip = new MCP23S17(spiDeviceInformation, chipSelectLevel);

            this.InputPort = new MCP23S17RegisterNeg(MCP23S17RegisterAddresses.GPIOB, this._chip);
            this.InputPins = new MCP23S17RegisterBitNeg[8];

            this.OutputPort = new MCP23S17Register(MCP23S17RegisterAddresses.GPIOA, this._chip);
            this.OutputPins = new MCP23S17RegisterBit[8];
            this.LEDs       = new MCP23S17RegisterBit[8];

            this.Relays   = new MCP23S17RegisterBit[2];
            this.Switches = new MCP23S17RegisterBitNeg[4];

            for (var i = 0; i < 8; i++)
            {
                if (i < 2)
                {
                    this.Relays[i] = new MCP23S17RegisterBit(i, MCP23S17RegisterAddresses.GPIOA, this._chip);
                }

                if (i < 4)
                {
                    this.Switches[i] = new MCP23S17RegisterBitNeg(i, MCP23S17RegisterAddresses.GPIOB, this._chip);
                }

                this.InputPins[i]  = new MCP23S17RegisterBitNeg(i, MCP23S17RegisterAddresses.GPIOB, this._chip);
                this.OutputPins[i] = new MCP23S17RegisterBit(i, MCP23S17RegisterAddresses.GPIOB, this._chip);
                this.LEDs[i]       = new MCP23S17RegisterBit(i, MCP23S17RegisterAddresses.GPIOA, this._chip);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of the MCP23S17Register class.
        /// </summary>
        /// <param name="address">The address of the register.</param>
        /// <param name="chip">The MCP23S17 chip which contains the register.</param>
        internal MCP23S17Register(byte address, MCP23S17 chip) : base(address, chip)
        {
            this.LowerNibble = new MCP23S17RegisterNibble(Nibble.Lower, address, chip);
            this.UpperNibble = new MCP23S17RegisterNibble(Nibble.Upper, address, chip);
            this.Bits        = new MCP23S17RegisterBit[8];

            for (var i = 0; i < this.Bits.Length; i++)
            {
                this.Bits[i] = new MCP23S17RegisterBit(i, address, chip);
            }
        }
コード例 #3
0
        internal MCP23S17RegisterNibble(Nibble nibble, byte address, MCP23S17 chip) : base(address, chip)
        {
            this._nibble = nibble;
            this.Bits    = new MCP23S17RegisterBit[4];

            var rangeStart = nibble.GetRangeStart();
            var rangeEnd   = nibble.GetRangeEnd();

            for (var i = rangeStart; i < rangeEnd; i++)
            {
                this.Bits[i - rangeStart] = new MCP23S17RegisterBit(i, address, chip);
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a new instance of the MCP23S17RegisterBaseNeg class.
 /// </summary>
 /// <param name="address">The address of the entity.</param>
 /// <param name="chip">The MCP23S17 chip which contains the register.</param>
 internal MCP23S17RegisterBaseNeg(byte address, MCP23S17 chip) : base(address, chip)
 {
 }
コード例 #5
0
 /// <summary>
 /// Instantiate a new MCP23S17 register bit.
 /// </summary>
 /// <param name="bitOffset"></param>
 /// <param name="address"></param>
 /// <param name="chip"></param>
 internal MCP23S17RegisterBit(int bitOffset, byte address, MCP23S17 chip) : base(address, chip)
 {
     this._bitOffset = bitOffset;
 }
コード例 #6
0
 /// <summary>
 /// Creates a new instance of the MCP23S17RegisterBase class.
 /// </summary>
 /// <param name="address">The address of the entity.</param>
 /// <param name="chip">The MCP23S17 chip which contains the register.</param>
 internal MCP23S17RegisterBase(byte address, MCP23S17 chip)
 {
     this.Address = address;
     this._chip   = chip;
 }