Beispiel #1
0
        public async Task <Bmp180SensorData> GetSensorDataAsync(Bmp180AccuracyMode oss)
        {
            // Create the return object.
            var sensorData = new Bmp180SensorData();

            // Read the Uncompestated values from the sensor.
            var tData = await ReadUncompestatedTemperature();

            var pData = await ReadUncompestatedPressure(oss);

            // Keep raw data for debug
            sensorData.UncompestatedTemperature = tData;
            sensorData.UncompestatedPressure    = pData;

            var ut = (tData[0] << 8) + tData[1];
            var up = (pData[0] * 256.0) + pData[1] + (pData[2] / 256.0);

            // Calculate real values
            var b5 = calculateB5(ut);

            var t = (b5 + 8) >> 4;

            sensorData.Temperature = t / 10.0;

            var s = sensorData.Temperature - 25.0;
            var x = (x2 * Math.Pow(s, 2)) + (x1 * s) + x0;
            var y = (y2 * Math.Pow(s, 2)) + (y1 * s) + y0;
            var z = (up - x) / y;

            sensorData.Pressure = (p2 * Math.Pow(z, 2)) + (p1 * z) + p0;

            return(sensorData);
        }
Beispiel #2
0
        public async Task <Bmp180SensorData> GetSensorDataAsync(Bmp180AccuracyMode oss)
        {
            // Create the return object.
            var sensorData = new Bmp180SensorData();

            // Read the Uncompestated values from the sensor.
            var tData = await ReadUncompestatedTemperature();

            var pData = await ReadUncompestatedPressure(oss);

            // Keep raw data for debug

            sensorData.UncompestatedTemperature = tData;
            sensorData.UncompestatedPressure    = pData;

            var ut = (tData[0] << 8) + tData[1];
            var up = pData[0] * 256.0 + pData[1] + pData[2] / 256.0;

            // Calculate real values
            var b5 = calculateB5(ut);

            var t = (b5 + 8) >> 4;

            sensorData.TemperatureInCelcius   = t / 10.0;
            sensorData.TemperatureFarenheight = (9.0 / 5.0) * sensorData.TemperatureInCelcius + 32;
            var s = sensorData.TemperatureInCelcius - 25.0;
            var x = x2 * Math.Pow(s, 2) + x1 * s + x0;
            var y = y2 * Math.Pow(s, 2) + y1 * s + y0;
            var z = (up - x) / y;

            sensorData.Pressure = p2 * Math.Pow(z, 2) + p1 * z + p0;

            return(sensorData);
        }
Beispiel #3
0
        public async Task <byte[]> ReadUncompestatedPressure(Bmp180AccuracyMode ossMode)
        {
            byte presssureCommand = 0;
            var  delay            = 5;

            switch (ossMode)
            {
            case Bmp180AccuracyMode.UltraLowPower:
                presssureCommand = BMP180_COM_PRESSURE0;
                delay            = 5;
                break;

            case Bmp180AccuracyMode.Standard:
                presssureCommand = BMP180_COM_PRESSURE1;
                delay            = 8;
                break;

            case Bmp180AccuracyMode.HighResolution:
                presssureCommand = BMP180_COM_PRESSURE2;
                delay            = 14;
                break;

            case Bmp180AccuracyMode.UltraHighResolution:
                presssureCommand = BMP180_COM_PRESSURE3;
                delay            = 26;
                break;
            }

            var command = new[] { BMP180_REG_CONTROL, presssureCommand };

            _i2CBarometer.Write(command);

            await Task.Delay(delay);

            return(WriteRead(BMP180_REG_RESULT, 3));;
        }
        public async Task<Bmp180SensorData> GetSensorDataAsync(Bmp180AccuracyMode oss)
        {
            // Create the return object.
            var sensorData = new Bmp180SensorData();

            // Read the Uncompestated values from the sensor.
            var tData = await ReadUncompestatedTemperature();
            var pData = await ReadUncompestatedPressure(oss);

            // Keep raw data for debug
            sensorData.UncompestatedTemperature = tData;
            sensorData.UncompestatedPressure = pData;

            var ut = (tData[0] << 8) + tData[1];
            var up = (pData[0] * 256.0) + pData[1] + (pData[2] / 256.0);

            // Calculate real values
            var b5 = calculateB5(ut);

            var t = (b5 + 8) >> 4;
            sensorData.Temperature = t/10.0;

            var s = sensorData.Temperature - 25.0;
            var x = (x2 * Math.Pow(s, 2)) + (x1 * s) + x0;
            var y = (y2 * Math.Pow(s, 2)) + (y1 * s) + y0;
            var z = (up - x) / y;

            sensorData.Pressure = (p2 * Math.Pow(z, 2)) + (p1 * z) + p0;

            return sensorData;
        }
        public async Task<byte[]> ReadUncompestatedPressure(Bmp180AccuracyMode ossMode)
        {
            byte presssureCommand = 0;
            var delay = 5;

            switch (ossMode)
            {
                case Bmp180AccuracyMode.UltraLowPower:
                    presssureCommand = BMP180_COM_PRESSURE0;
                    delay = 5;
                    break;
                case Bmp180AccuracyMode.Standard:
                    presssureCommand = BMP180_COM_PRESSURE1;
                    delay = 8;
                    break;
                case Bmp180AccuracyMode.HighResolution:
                    presssureCommand = BMP180_COM_PRESSURE2;
                    delay = 14;
                    break;
                case Bmp180AccuracyMode.UltraHighResolution:
                    presssureCommand = BMP180_COM_PRESSURE3;
                    delay = 26;
                    break;
            }

            var command = new[] { BMP180_REG_CONTROL, presssureCommand };
            _i2CBarometer.Write(command);

            await Task.Delay(delay);

            return WriteRead(BMP180_REG_RESULT, 3); ;
        }