Exemplo n.º 1
0
            return 44330 * (1 - System.Math.Pow((pressure / 100 / 1013.25), 1 / 5.255));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mode"></param>
        /// <returns>Presure in [Pa]</returns>
        public long GetPressure(PresureAccurancyMode mode)
        {
            GetTemperature();
            int oss = (int)mode;
            long UP = GetRawPressure(mode);
            long b6 = _B5 - 4000;
            _X1 = (_B2 * (b6 * b6 / (1 << 12))) / (1 << 11);
            _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) / 4;

            ulong b4 = _AC4 * (ulong)(x3 + 32768) / (1 << 15);
            ulong b7 = (ulong)((UP - b3) * (50000 >> oss));
            long p;

            if (b7 < 0x80000000) { p = (long)((b7 * 2) / b4); }
            else { p = (long)((b7 / b4) * 2); }

            _X1 = (p / 256) * (p / 256);
            _X1 = (_X1 * 3038) / (1 << 16);
            _X2 = (-7357 * p) / (1 << 16);
Exemplo n.º 2
0
            return p;
        }

        public long GetRawPressure(PresureAccurancyMode mode)
        {
            int data = 0x34 + ((byte)mode << 6);
            int waitingTime = 5;
            switch (mode)
            {
                case PresureAccurancyMode.UltraLowPower:
                    waitingTime = 5;
                    break;
                case PresureAccurancyMode.Standard:
                    waitingTime = 8;
                    break;
                case PresureAccurancyMode.HighResolution:
                    waitingTime = 14;
                    break;
                case PresureAccurancyMode.UltraHighResolution:
                    waitingTime = 26;
                    break;
            }
            WriteCommand((byte)data);
            Thread.Sleep(waitingTime);    //defined waiting time
            write(0xF6);
            byte[] readedVal = read(3);