Example #1
0
 public bool Init(ADD0 addressSelect)
 {
     return Init(addressSelect, false, AlertPolarity.activeHigh, ConversionRate.four_Hz, ThermostatMode.ComparatorMode, ConsecutiveFaults.one, 0, 0);
 }
Example #2
0
 public bool Init(
     ADD0 addressSelect = ADD0.Gnd,
     bool oneShotMode = false,
     AlertPolarity alertPolarity = AlertPolarity.activeHigh,
     ConversionRate conversionRate = ConversionRate.four_Hz,
     ThermostatMode thermostatMode = ThermostatMode.ComparatorMode)
 {
     return Init(addressSelect, oneShotMode, alertPolarity, conversionRate, thermostatMode, ConsecutiveFaults.one, 0, 0);
 }
Example #3
0
        // -------------------------------------------------------------------------------------------------------------------------------------
        private bool Init(
            ADD0 addressSelect,
            bool oneShotMode,
            AlertPolarity alertPolarity,
            ConversionRate conversionRate,
            ThermostatMode thermostatMode,
            ConsecutiveFaults consecutiveFaults,
            ushort limitHigh,
            ushort limitLow)
        {
            // Sleep past first conversion
            Thread.Sleep(30);

            switch (addressSelect)
            {
                case ADD0.Gnd: _sensorAddress = 0x90 >> 1; break;
                case ADD0.Vcc: _sensorAddress = 0x92 >> 1; break;
                case ADD0.SDA: _sensorAddress = 0x94 >> 1; break;
                case ADD0.SCL: _sensorAddress = 0x96 >> 1; break;
            }

            _TMP102 = new I2CDevice(new I2CDevice.Configuration(_sensorAddress, 100));

            _alertPolarity = alertPolarity;
            _oneShotMode = oneShotMode;
            _thermostatMode = thermostatMode;
            _consecutiveFaults = consecutiveFaults;

            _registerNum[0] = (byte)Registers.Configuration;
            int bytesTransfered = ReadRegister();

            if (bytesTransfered == 3)
            {
                if (_oneShotMode)
                    _registerValue[0] = (byte)(_registerValue[0] | 0x01);
                else
                    _registerValue[0] = (byte)(_registerValue[0] & 0xfe);

                if (_thermostatMode == ThermostatMode.InterruptMode)
                    _registerValue[0] = (byte)(_registerValue[0] | 0x02);
                else
                    _registerValue[0] = (byte)(_registerValue[0] & 0xfd);

                if (_alertPolarity == AlertPolarity.activeLow)
                    _registerValue[0] = (byte)(_registerValue[0] | 0x04);
                else
                    _registerValue[0] = (byte)(_registerValue[0] & ~0x04);

                switch (conversionRate)
                {
                    case ConversionRate.quarter_Hz: _registerValue[1] = (byte)((_registerValue[1] & 0x3f) | (0x00 << 6)); break;
                    case ConversionRate.one_Hz: _registerValue[1] = (byte)((_registerValue[1] & 0x3f) | (0x01 << 6)); break;
                    case ConversionRate.four_Hz: _registerValue[1] = (byte)((_registerValue[1] & 0x3f) | (0x02 << 6)); break;
                    case ConversionRate.eight_Hz: _registerValue[1] = (byte)((_registerValue[1] & 0x3f) | (0x03 << 6)); break;
                }

                bytesTransfered = WriteRegister();
                Thread.Sleep(30);
            }

            return (bytesTransfered == 3);
        }