Exemple #1
0
        /// <summary>
        /// Exctract data from raw byte response.
        /// </summary>
        /// <param name="cal1">First word.</param>
        /// <param name="cal2">Second word.</param>
        /// <param name="cal3">Third word.</param>
        /// <returns>Sensor digit dictionary.</returns>
        public static Dictionary <SensorDigit, int> ExtractcalibrationData(byte[] cal1, byte[] cal2, byte[] cal3)
        {
            var calibrationData = new Dictionary <SensorDigit, int>(18)
            {
                { SensorDigit.DigitT1, ByteOperations.GetUShort(cal1, 0) },
                { SensorDigit.DigitT2, ByteOperations.GetShort(cal1, 2) },
                { SensorDigit.DigitT3, ByteOperations.GetShort(cal1, 4) },
                { SensorDigit.DigitP1, ByteOperations.GetUShort(cal1, 6) },
                { SensorDigit.DigitP2, ByteOperations.GetShort(cal1, 8) },
                { SensorDigit.DigitP3, ByteOperations.GetShort(cal1, 10) },
                { SensorDigit.DigitP4, ByteOperations.GetShort(cal1, 12) },
                { SensorDigit.DigitP5, ByteOperations.GetShort(cal1, 14) },
                { SensorDigit.DigitP6, ByteOperations.GetShort(cal1, 16) },
                { SensorDigit.DigitP7, ByteOperations.GetShort(cal1, 18) },
                { SensorDigit.DigitP8, ByteOperations.GetShort(cal1, 20) },
                { SensorDigit.DigitP9, ByteOperations.GetShort(cal1, 22) },
                { SensorDigit.DigitH1, ByteOperations.GetUChar(cal2, 0) },
                { SensorDigit.DigitH2, ByteOperations.GetUShort(cal3, 0) },
                { SensorDigit.DigitH3, ByteOperations.GetUChar(cal3, 2) },
                { SensorDigit.DigitH4, CalculateH4Offset(cal3, 3, 4) },
                { SensorDigit.DigitH5, CalculateH5Offset(cal3, 4, 5) },
                { SensorDigit.DigitH6, ByteOperations.GetChar(cal3, 6) },
            };

            return(calibrationData);
        }
Exemple #2
0
        /// <inheritdoc/>
        public override void Initialize()
        {
            this.LogStartInitialization();
            this.Device = this.Controller.GetI2CConnection(this.DeviceId);
            var resetCommand = new byte[] { CCS811SWRESET, 0x11, 0xE5, 0x72, 0x8A };

            this.Device.Write(resetCommand);

            Thread.Sleep(100);

            byte hwId = (byte)ByteOperations.GetUChar(this.ReadRawByte(CCS811HWID));

            if (hwId != CCS811ID)
            {
                throw new System.Exception(string.Format("Incorrect ID, expected {0}, got {1}", CCS811HWID, hwId));
            }

            // check internal status
            this.CheckError("Init");

            // app valid
            var status = this.ReadRawByte(CCS811STATUS);

            this.LogMessage(string.Format("Status afer INIT OK? {0}", status == 16));
            if ((status & 1) << 4 != 0)
            {
                this.CheckError("App not valid");
            }

            this.Device.WriteByte(CCS811APPSTART);
            Thread.Sleep(100);
            this.CheckError("Start");

            this.WriteByte(CCS811MEASMODE, CCS811MEAS1S);
            this.CheckError("MEAS");

            Thread.Sleep(1500);
            var bytes = this.ReadRawBytes(CCS811BASELINE, 2);

            this.LogMessage(string.Format("Baseline: {0}", (bytes[0] << 8) | bytes[1]));

            // data availabe?
            this.LogMessage(string.Format("Data available: {0}", !((this.ReadRawByte(CCS811STATUS) & 1) << 3 == 0)));
            this.CheckError("READ");

            this.LogMessage("Warm up");
            for (int i = 0; i < this.warmupCount; i++)
            {
                var data = this.ReadRawBytes(CCS811ALGRESULTDATA, 4);
                this.LogMessage($"RawBytes: {ByteOperations.PrintByteArray(data)}");
                Thread.Sleep(5000);
            }

            this.CheckError("WARMUP");
            this.LogMessage("CCS811 Ready");
            this.LogStartSuccess();
        }