public Vector read_vector(Bno055VectorType vec, int count = 3)
        {
            var data      = read_bytes((Bno055Registers)vec, count * 2);
            var rawResult = new int[count];

            for (int i = 0; i < count; i++)
            {
                rawResult[i] = ((data[i * 2 + 1] << 8) | data[i * 2]);
                if (rawResult[i] > 32767)
                {
                    rawResult[i] -= 65536;
                }
            }
            var modifier = 100.0f;

            // ReSharper disable once SwitchStatementMissingSomeCases - missing cases = 100.0f
            switch (vec)
            {
            case Bno055VectorType.VectorMagnetometer:
            case Bno055VectorType.VectorEuler:
                modifier = 16.0f;
                break;

            case Bno055VectorType.VectorGyroscope:
                modifier = 900.0f;
                break;
            }
            return(new Vector(rawResult[0] / modifier, rawResult[1] / modifier, rawResult[2] / modifier));
        }
Exemplo n.º 2
0
        public Vector read_vector(Bno055VectorType vec, int count = 3) {
            var data = read_bytes((Bno055Registers)vec, count*2);
            var rawResult = new int[count];
            for (int i = 0; i < count; i++) {
                rawResult[i] = ((data[i*2 + 1] << 8) | data[i*2]);
                if (rawResult[i] > 32767) rawResult[i] -= 65536;
            }
            var modifier = 100.0f;
            // ReSharper disable once SwitchStatementMissingSomeCases - missing cases = 100.0f
            switch (vec) {
                case Bno055VectorType.Vector_Magnetometer:
                case Bno055VectorType.Vector_Euler:
                    modifier = 16.0f;
                    break;
                case Bno055VectorType.Vector_Gyroscope:
                    modifier = 900.0f;
                    break;
            }
            return new Vector()
            {
                X = rawResult[0] / modifier,
                Y = rawResult[1] / modifier,
                Z = rawResult[2] / modifier
            };

        }