Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new Ads1115 device connected through I2C
        /// </summary>
        /// <param name="i2cDevice">The I2C device used for communication.</param>
        /// <param name="inputMultiplexer">Input Multiplexer</param>
        /// <param name="measuringRange">Programmable Gain Amplifier</param>
        /// <param name="dataRate">Data Rate</param>
        /// <param name="deviceMode">Initial device mode</param>
        public Ads1115(I2cDevice i2cDevice, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096,
                       DataRate dataRate = DataRate.SPS128, DeviceMode deviceMode = DeviceMode.Continuous)
        {
            _i2cDevice          = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
            _inputMultiplexer   = inputMultiplexer;
            _measuringRange     = measuringRange;
            _dataRate           = dataRate;
            _gpioController     = null;
            _gpioInterruptPin   = -1;
            _deviceMode         = deviceMode;
            ComparatorMode      = ComparatorMode.Traditional;
            _comparatorPolarity = ComparatorPolarity.Low;
            _comparatorLatching = ComparatorLatching.NonLatching;
            _comparatorQueue    = ComparatorQueue.Disable;

            SetConfig();
            DisableAlertReadyPin();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize a new Ads1115 device connected through I2C with an additional GPIO controller for interrupt handling.
        /// </summary>
        /// <param name="i2cDevice">The I2C device used for communication.</param>
        /// <param name="gpioController">The GPIO Controller used for interrupt handling</param>
        /// <param name="gpioInterruptPin">The pin number where the interrupt line is attached on the GPIO controller</param>
        /// <param name="shouldDispose">True (the default) if the GPIO controller shall be disposed when disposing this instance</param>
        /// <param name="inputMultiplexer">Input Multiplexer</param>
        /// <param name="measuringRange">Programmable Gain Amplifier</param>
        /// <param name="dataRate">Data Rate</param>
        /// <param name="deviceMode">Initial device mode</param>
        public Ads1115(I2cDevice i2cDevice,
                       GpioController?gpioController, int gpioInterruptPin, bool shouldDispose = true, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096,
                       DataRate dataRate = DataRate.SPS128, DeviceMode deviceMode = DeviceMode.Continuous)
            : this(i2cDevice, inputMultiplexer, measuringRange, dataRate, deviceMode)
        {
            _gpioController = gpioController ?? new GpioController();
            if (gpioInterruptPin < 0 || gpioInterruptPin >= _gpioController.PinCount)
            {
                throw new ArgumentOutOfRangeException(nameof(gpioInterruptPin), $"The given GPIO Controller has no pin number {gpioInterruptPin}");
            }

            _gpioInterruptPin = gpioInterruptPin;
            _shouldDispose    = shouldDispose || gpioController is null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize a new Ads1115 device connected through I2C
        /// </summary>
        /// <param name="sensor">I2C Device, like UnixI2cDevice or Windows10I2cDevice</param>
        /// <param name="inputMultiplexer">Input Multiplexer</param>
        /// <param name="measuringRange">Programmable Gain Amplifier</param>
        /// <param name="dataRate">Data Rate</param>
        public Ads1015(I2cDevice sensor, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096, DataRate dataRate = DataRate.SPS128)
            : base(sensor, inputMultiplexer, measuringRange, dataRate)
        {
            if (_measuringRange > (byte)MeasuringRange.FS4096)
            {
                throw new ArgumentOutOfRangeException($"Maximum resolution for ADS1015 is 12 bits");
            }

            Initialize();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize a new Ads1115 device connected through I2C
        /// </summary>
        /// <param name="sensor">I2C Device, like UnixI2cDevice or Windows10I2cDevice</param>
        /// <param name="inputMultiplexer">Input Multiplexer</param>
        /// <param name="measuringRange">Programmable Gain Amplifier</param>
        /// <param name="dataRate">Data Rate</param>
        public Ads1115(I2cDevice sensor, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096, DataRate dataRate = DataRate.SPS128)
        {
            _sensor           = sensor;
            _inputMultiplexer = (byte)inputMultiplexer;
            _measuringRange   = (byte)measuringRange;
            _dataRate         = (byte)dataRate;

            Initialize();
        }