Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="a0addrSelect">A0 pin connection for address selection</param>
        /// <param name="clockRateKhz">I2C clock rate in KHz</param>
        public TMP102(A0AddressSelect a0addrSelect = A0AddressSelect.GND,
            int clockRateKhz = CLOCK_RATE_KHZ_DEFAULT)
        {
            // create buffers for one and two bytes for I2C communications
            this.regAddress = new byte[REG_ADDRESS_SIZE];
            this.regData = new byte[REG_DATA_SIZE];

            // configure and create I2C reference device
            this.i2cConfig = new I2cConnectionSettings((int)(TMP102_ADDRESS_BASE + a0addrSelect));
            I2cBusSpeed i2cBusSpeed = (clockRateKhz == CLOCK_RATE_KHZ_DEFAULT) ? I2cBusSpeed.StandardMode : I2cBusSpeed.FastMode;
            this.i2cConfig.BusSpeed = i2cBusSpeed;
            this.i2cConfig.SharingMode = I2cSharingMode.Exclusive;
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="a0addrSelect">A0 pin connection for address selection</param>
        /// <param name="clockRateKhz">I2C clock rate in KHz</param>
        /// <param name="conversionRate">Conversion rate</param>
        /// <param name="shutdownMode">Shutdown mode</param>
        /// <param name="thermostatMode">Thermostat mode</param>
        /// <param name="alertPolarity">Polarity of the alert pin</param>
        /// <param name="consecutiveFaults">Consecutive faults before activate alert pin</param>
        /// <param name="temperatureHigh">Temperature High for alert</param>
        /// <param name="temperatureLow">Temperature Low for alert</param>
        public TMP102(A0AddressSelect a0addrSelect        = A0AddressSelect.GND,
                      int clockRateKhz                    = CLOCK_RATE_KHZ_DEFAULT,
                      ConversionRate conversionRate       = ConversionRate._4Hz,
                      bool shutdownMode                   = false,
                      ThermostatMode thermostatMode       = ThermostatMode.Comparator,
                      AlertPolarity alertPolarity         = AlertPolarity.ActiveLow,
                      ConsecutiveFaults consecutiveFaults = ConsecutiveFaults._1,
                      float temperatureHigh               = TEMP_HIGH_DEFAULT,
                      float temperatureLow                = TEMP_LOW_DEFAULT)
        {
            // create buffers for one and two bytes for I2C communications
            this.regAddress = new byte[REG_ADDRESS_SIZE];
            this.regData    = new byte[REG_DATA_SIZE];

            // configure and create I2C reference device
            I2CDevice.Configuration i2cConfig = new I2CDevice.Configuration((ushort)(TMP102_ADDRESS_BASE + a0addrSelect), clockRateKhz);
            this.i2c = new I2CDevice(i2cConfig);

            // load configuration register
            this.LoadConfiguration();

            // set conversion rate
            this.configuration  = (ushort)(this.configuration & ~CONV_RATE_MASK);
            this.configuration |= (ushort)conversionRate;
            // set shutdown mode
            this.configuration = (shutdownMode) ? (ushort)(this.configuration | SHUTDOWN_MODE) : (ushort)(this.configuration & ~SHUTDOWN_MODE);
            // set thermostat mode
            this.configuration = (thermostatMode == ThermostatMode.Interrupt) ? (ushort)(this.configuration | THERMOSTAT_MODE) : (ushort)(this.configuration & ~THERMOSTAT_MODE);
            // set alert pin polarity
            this.configuration = (alertPolarity == AlertPolarity.ActiveHigh) ? (ushort)(this.configuration | POLARITY) : (ushort)(this.configuration & ~POLARITY);
            // set consecutive faults for alert
            this.configuration  = (ushort)(this.configuration & ~FAULT_QUEUE_MASK);
            this.configuration |= (ushort)consecutiveFaults;

            // save configuration register
            this.ChangeConfiguration();

            // set temperature high for alert
            this.regAddress[0] = TEMP_HIGH_REG_ADDR;
            this.regData       = this.TemperatureToBytes(temperatureHigh);
            this.WriteRegister(this.regAddress, this.regData);
            // set temperature low for alert
            this.regAddress[0] = TEMP_LOW_REG_ADDR;
            this.regData       = this.TemperatureToBytes(temperatureLow);
            this.WriteRegister(this.regAddress, this.regData);
        }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="a0addrSelect">A0 pin connection for address selection</param>
 /// <param name="clockRateKhz">I2C clock rate in KHz</param>
 public TMP102(A0AddressSelect a0addrSelect, int clockRateKhz)
     : this(a0addrSelect, clockRateKhz, ConversionRate._4Hz, false, ThermostatMode.Comparator, AlertPolarity.ActiveLow, ConsecutiveFaults._1, TEMP_HIGH_DEFAULT, TEMP_LOW_DEFAULT)
 {
 }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="a0addrSelect">A0 pin connection for address selection</param>
        /// <param name="clockRateKhz">I2C clock rate in KHz</param>
        /// <param name="conversionRate">Conversion rate</param>
        /// <param name="shutdownMode">Shutdown mode</param>
        /// <param name="thermostatMode">Thermostat mode</param>
        /// <param name="alertPolarity">Polarity of the alert pin</param>
        /// <param name="consecutiveFaults">Consecutive faults before activate alert pin</param>
        /// <param name="temperatureHigh">Temperature High for alert</param>
        /// <param name="temperatureLow">Temperature Low for alert</param>
        public TMP102(A0AddressSelect a0addrSelect = A0AddressSelect.GND,
            int clockRateKhz = CLOCK_RATE_KHZ_DEFAULT,
            ConversionRate conversionRate = ConversionRate._4Hz,
            bool shutdownMode = false,
            ThermostatMode thermostatMode = ThermostatMode.Comparator,
            AlertPolarity alertPolarity = AlertPolarity.ActiveLow,
            ConsecutiveFaults consecutiveFaults = ConsecutiveFaults._1,
            float temperatureHigh = TEMP_HIGH_DEFAULT,
            float temperatureLow = TEMP_LOW_DEFAULT)
        {
            // create buffers for one and two bytes for I2C communications
            this.regAddress = new byte[REG_ADDRESS_SIZE];
            this.regData = new byte[REG_DATA_SIZE];

            // configure and create I2C reference device
            I2CDevice.Configuration i2cConfig = new I2CDevice.Configuration((ushort)(TMP102_ADDRESS_BASE + a0addrSelect), clockRateKhz);
            this.i2c = new I2CDevice(i2cConfig);

            // load configuration register
            this.LoadConfiguration();

            // set conversion rate
            this.configuration = (ushort)(this.configuration & ~CONV_RATE_MASK);
            this.configuration |= (ushort)conversionRate;
            // set shutdown mode
            this.configuration = (shutdownMode) ? (ushort)(this.configuration | SHUTDOWN_MODE) : (ushort)(this.configuration & ~SHUTDOWN_MODE);
            // set thermostat mode
            this.configuration = (thermostatMode == ThermostatMode.Interrupt) ? (ushort)(this.configuration | THERMOSTAT_MODE) : (ushort)(this.configuration & ~THERMOSTAT_MODE);
            // set alert pin polarity
            this.configuration = (alertPolarity == AlertPolarity.ActiveHigh) ? (ushort)(this.configuration | POLARITY) : (ushort)(this.configuration & ~POLARITY);
            // set consecutive faults for alert
            this.configuration = (ushort)(this.configuration & ~FAULT_QUEUE_MASK);
            this.configuration |= (ushort)consecutiveFaults;

            // save configuration register
            this.ChangeConfiguration();

            // set temperature high for alert
            this.regAddress[0] = TEMP_HIGH_REG_ADDR;
            this.regData = this.TemperatureToBytes(temperatureHigh);
            this.WriteRegister(this.regAddress, this.regData);
            // set temperature low for alert
            this.regAddress[0] = TEMP_LOW_REG_ADDR;
            this.regData = this.TemperatureToBytes(temperatureLow);
            this.WriteRegister(this.regAddress, this.regData);
        }
Example #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="a0addrSelect">A0 pin connection for address selection</param>
 /// <param name="clockRateKhz">I2C clock rate in KHz</param>
 public TMP102(A0AddressSelect a0addrSelect, int clockRateKhz)
     : this(a0addrSelect, clockRateKhz, ConversionRate._4Hz, false, ThermostatMode.Comparator, AlertPolarity.ActiveLow, ConsecutiveFaults._1, TEMP_HIGH_DEFAULT, TEMP_LOW_DEFAULT)
 {
 }