示例#1
0
        public void TemperatureImageTest()
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            Temperature[,] referenceImage = new Temperature[Amg88xx.Width, Amg88xx.Height];
            Random rnd = new Random();

            for (int y = 0; y < Amg88xx.Height; y++)
            {
                for (int x = 0; x < Amg88xx.Width; x++)
                {
                    referenceImage[x, y] = Temperature.FromDegreesCelsius(rnd.Next(-80, 321) * PixelTemperatureResolution);
                    (byte tl, byte th)   = Amg88xxUtils.ConvertFromTemperature(referenceImage[x, y]);
                    i2cDevice.DataToRead.Enqueue(tl);
                    i2cDevice.DataToRead.Enqueue(th);
                }
            }

            // read image from sensor
            sensor.ReadImage();

            // expectation: one write access to register T01L (lower byte of first pixel) to trigger readout
            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.T01L, i2cDevice.DataWritten.Dequeue());

            // expectation: all pixels have been read, so nothing is remaining
            Assert.Empty(i2cDevice.DataToRead);

            Assert.Equal(referenceImage, sensor.TemperatureImage);
        }
示例#2
0
        public void FlagResetTest()
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.ResetAllFlags();

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.RST, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)ResetType.Flag, i2cDevice.DataWritten.Dequeue());
        }
示例#3
0
        public void OperatingModeSetTest(OperatingMode targetOperatingMode, byte expectedMode)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.OperatingMode = targetOperatingMode;

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.PCLT, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedMode, i2cDevice.DataWritten.Dequeue());
        }
示例#4
0
        public void ClearAllFlagsTest()
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.ClearAllFlags();

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.SCLR, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)(1 << (byte)StatusClearBit.OVFCLR) | (1 << (byte)StatusClearBit.OVFTHCLR) | (1 << (byte)StatusClearBit.INTCLR), i2cDevice.DataWritten.Dequeue());
        }
示例#5
0
        public void ClearInterruptTest()
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.ClearInterrupt();

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.SCLR, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(1 << (byte)StatusClearBit.INTCLR, i2cDevice.DataWritten.Dequeue());
        }
示例#6
0
        public void ClearThermistorOverflowTest()
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.ClearThermistorOverflow();

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.SCLR, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(1 << (byte)StatusClearBit.OVFTHCLR, i2cDevice.DataWritten.Dequeue());
        }
示例#7
0
        public void OperatingModeGetTest(byte registerContent, OperatingMode expectedOperatingMode)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(registerContent);

            var actualOperatingMode = sensor.OperatingMode;

            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.PCLT, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedOperatingMode, actualOperatingMode);
        }
示例#8
0
        public void FrameRateGetTest(byte registerContent, FrameRate expectedFrameRate)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(registerContent);

            var actualFrameRate = sensor.FrameRate;

            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.FPSC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedFrameRate, actualFrameRate);
        }
示例#9
0
        public void HasThermistorOverflowTest(byte statusRegisterContent, bool thermistorOverflow)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(statusRegisterContent);

            bool status = sensor.HasThermistorOverflow();

            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.STAT, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(thermistorOverflow, status);
        }
示例#10
0
        public void UseMovingAverageModeGetTest(byte registerContent, bool expectedState)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(registerContent);

            bool actualState = sensor.UseMovingAverageMode;

            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.AVE, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedState, actualState);
        }
示例#11
0
        public void HasInterruptTest(byte statusRegisterContent, bool interrupt)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(statusRegisterContent);

            bool status = sensor.HasInterrupt();

            Assert.Single(i2cDevice.DataWritten);
            Assert.Equal((byte)Register.STAT, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(interrupt, status);
        }
示例#12
0
        public void InterruptPinEnabledGetTest(bool expectedState, byte registerValue)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(registerValue);

            bool actualState = sensor.InterruptPinEnabled;

            Assert.Single(i2cDevice.DataWritten);
            // register address is expected two times: once for reading the current register value and once for writing the new one
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedState, actualState);
        }
示例#13
0
        public void SensorTemperatureGetTest(byte th, byte tl, double expectedTemperature)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            // target temperature is 25°C which is equivalent to 0x190
            i2cDevice.DataToRead.Enqueue(tl);
            i2cDevice.DataToRead.Enqueue(th);

            Assert.Equal(expectedTemperature, sensor.SensorTemperature.DegreesCelsius);
            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.TTHL, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.TTHH, i2cDevice.DataWritten.Dequeue());
        }
示例#14
0
        public void InterruptPinEnabledSetTest(byte initialRegisterContent, bool targetState, byte expectedRegisterContent)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(initialRegisterContent);

            sensor.InterruptPinEnabled = targetState;

            Assert.Equal(3, i2cDevice.DataWritten.Count);
            // register address is expected two times: once for reading the current register value and once for writing the new one
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedRegisterContent, i2cDevice.DataWritten.Dequeue());
        }
示例#15
0
        public void UseMovingAverageModeSetTest(bool targetState, byte initialRegisterContent, byte expectedRegisterContent)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            // bit 5: if set, moving average is on
            i2cDevice.DataToRead.Enqueue(initialRegisterContent);

            sensor.UseMovingAverageMode = targetState;

            Assert.Equal(3, i2cDevice.DataWritten.Count);
            // register address is expected two times: once for reading the current register value and once for writing the new one
            Assert.Equal((byte)Register.AVE, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.AVE, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedRegisterContent, i2cDevice.DataWritten.Dequeue());
        }
示例#16
0
        public void InterruptHysteresisLevelSetTest()
        {
            Temperature expectedTemperature = Temperature.FromDegreesCelsius(125);

            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            sensor.InterruptHysteresis = expectedTemperature;

            Assert.Equal(4, i2cDevice.DataWritten.Count);

            (byte refTl, byte refTh) = Amg88xxUtils.ConvertFromTemperature(expectedTemperature);
            Assert.Equal((byte)Register.INTSL, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(refTl, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.INTSH, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(refTh, i2cDevice.DataWritten.Dequeue());
        }
示例#17
0
        public void InterruptHysteresisLevelGetTest()
        {
            // expected temeperature: 72.75°C
            // two's complement representation:
            byte expectedTl = 0x23;
            byte expectedTh = 0x01;

            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(expectedTl);
            i2cDevice.DataToRead.Enqueue(expectedTh);

            Temperature actualTemperature = sensor.InterruptHysteresis;

            Assert.Equal(2, i2cDevice.DataWritten.Count);
            Assert.Equal((byte)Register.INTSL, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.INTSH, i2cDevice.DataWritten.Dequeue());

            Assert.Equal(Amg88xxUtils.ConvertToTemperature(expectedTl, expectedTh).DegreesCelsius, actualTemperature.DegreesCelsius);
        }