Esempio n. 1
0
 public float GetPressure(Accurateness accuracy, long rawTemp)
 {
     var waitTime = StartPressureMeasurement(accuracy);
     Thread.Sleep(waitTime);
     return FinishPressureMeasurement(accuracy, rawTemp);
 }
Esempio n. 2
0
 private TimeSpan StartPressureMeasurement(Accurateness accuracy)
 {
     var oss = (int)accuracy;
     //Reading raw pressure-data
     WriteByte(0xF4, (byte)(0x34 + (oss << 6)));
     if (accuracy == Accurateness.UltraLowPower)
         return new TimeSpan(0, 0, 0, 0, 5);
     else if (accuracy == Accurateness.Standard)
         return new TimeSpan(0, 0, 0, 0, 8);
     else if (accuracy == Accurateness.HighResolution)
         return new TimeSpan(0, 0, 0, 0, 14);
     else if (accuracy == Accurateness.UltraHighResolution)
         return new TimeSpan(0, 0, 0, 0, 26);
     else
         throw new I2CException("Invalid accurateness");
 }
Esempio n. 3
0
 public IAsyncTask<float> AsyncGetPressure(Accurateness accuracy, long rawTemp, AsyncCallback callback)
 {
     return DoWaitingTask(
         (int)StartPressureMeasurement(accuracy).TotalMilliseconds,
         () => FinishPressureMeasurement(accuracy, rawTemp));
 }
Esempio n. 4
0
        private float FinishPressureMeasurement(Accurateness accuracy, long rawTemp)
        {
            var oss = (int)accuracy;
            byte xlsb = 0;
            long up;

            if (accuracy == Accurateness.UltraHighResolution)
                xlsb = ReadByte(0xF8);

            up = ((ReadByte(0xF6) << 16) + (ReadByte(0xF7) << 8) + xlsb) >> (8 - oss);

            long b6 = rawTemp - 4000;
            long x1 = (B2 * (b6 * b6 / (1 << 12))) / (1 << 11);
            long x2 = AC2 * b6 / (1 << 11);
            long x3 = x1 + x2;
            long b3 = (((AC1 * 4 + x3) << oss) + 2) / 4;
            x1 = AC3 * b6 / (1 << 13);
            x2 = (B1 * (b6 * b6 / (1 << 12))) / (1 << 16);
            x3 = ((x1 + x2) + 2) / (1 << 2);
            ulong b4 = AC4 * (ulong)(x3 + (1 << 15)) / (1 << 15);
            ulong b7 = (ulong)(up - b3) * (ulong)(50000 >> oss);
            long p;
            if (b7 < 0x80000000)
                p = (long)((b7 * 2) / b4);
            else
                p = (long)((b7 / b4) * 2);
            x1 = (p / (1 << 8)) * (p / (1 << 8));
            x1 = (x1 * 3038) / (1 << 16);
            x2 = (-7357 * p) / (1 << 16);
            p = p + (x1 + x2 + 3791) / (1 << 4);

            return p / 100f;
        }