protected override void OnCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs eventArgs)
        {
            if (sender.Uuid == MagnetometerCharacteristicUuid)
            {
                if (_magnetometerValueChanged != null)
                {
                    uint dataLength = eventArgs.CharacteristicValue.Length;
                    using (DataReader reader = DataReader.FromBuffer(eventArgs.CharacteristicValue))
                    {
                        if (dataLength == 6)
                        {
                            var data = new byte[dataLength];
                            reader.ReadBytes(data);

                            MagnetometerMeasurement measurement = new MagnetometerMeasurement();

                            int x = (int)data[0] + ((sbyte)data[1] << 8);
                            int y = (int)data[2] + ((sbyte)data[3] << 8);
                            int z = (int)data[4] + ((sbyte)data[5] << 8);

                            measurement.X = (double)x * (2000.0 / 65536.0);
                            measurement.Y = (double)y * (2000.0 / 65536.0);
                            measurement.Z = (double)z * (2000.0 / 65536.0);

                            OnMagnetometerMeasurementValueChanged(new MagnetometerMeasurementEventArgs(measurement, eventArgs.Timestamp));
                        }
                    }
                }
            }
        }
 public MagnetometerMeasurementEventArgs(MagnetometerMeasurement measurement, DateTimeOffset timestamp)
 {
     Measurement = measurement;
     Timestamp   = timestamp;
 }