Exemplo n.º 1
0
        /// <inheritdoc />
        public override I2cDevice CreateDevice(int deviceAddress)
        {
            if (_usedAddresses.Contains(deviceAddress))
            {
                throw new InvalidOperationException($"Device number {deviceAddress} is already in use");
            }

            var device = new ArduinoI2cDevice(_board, this, new I2cConnectionSettings(_busId, deviceAddress));

            _usedAddresses.Add(deviceAddress);
            return(device);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override I2cDevice CreateDevice(int deviceAddress)
        {
            if (_usedAddresses.Contains(deviceAddress))
            {
                throw new InvalidOperationException($"Device number {deviceAddress} is already in use");
            }

            if (!_busInitialized)
            {
                // Ensure the corresponding pins are set to I2C (not strictly necessary, but consistent)
                foreach (SupportedPinConfiguration supportedPinConfiguration in _board.SupportedPinConfigurations.Where(x => x.PinModes.Contains(SupportedMode.I2c)))
                {
                    _board.Firmata.SetPinMode(supportedPinConfiguration.Pin, SupportedMode.I2c);
                }

                _board.Firmata.SendI2cConfigCommand();
                _busInitialized = true;
            }

            var device = new ArduinoI2cDevice(_board, this, new I2cConnectionSettings(_busId, deviceAddress));

            _usedAddresses.Add(deviceAddress);
            return(device);
        }