Example #1
0
        protected override void OnCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs eventArgs)
        {
            if (sender.Uuid == MovementCharacteristicUuid)
            {
                if (_movementValueChanged != null)
                {
                    uint dataLength = eventArgs.CharacteristicValue.Length;
                    using (DataReader reader = DataReader.FromBuffer(eventArgs.CharacteristicValue))
                    {
                        if (dataLength == 18)
                        {
                            MovementMeasurement measurement = new MovementMeasurement();

                            short gx = ReadBigEndian16bit(reader);
                            short gy = ReadBigEndian16bit(reader);
                            short gz = ReadBigEndian16bit(reader);
                            short ax = ReadBigEndian16bit(reader);
                            short ay = ReadBigEndian16bit(reader);
                            short az = ReadBigEndian16bit(reader);
                            short mx = ReadBigEndian16bit(reader);
                            short my = ReadBigEndian16bit(reader);
                            short mz = ReadBigEndian16bit(reader);

                            measurement.GyroX = ((double)gx * 500.0) / 65536.0;
                            measurement.GyroY = ((double)gy * 500.0) / 65536.0;
                            measurement.GyroZ = ((double)gz * 500.0) / 65536.0;

                            measurement.timestamp = eventArgs.Timestamp;
                            measurement.mac       = _sensortag_mac;
                            measurement.AccelX    = ((double)ax / 32768);
                            measurement.AccelY    = ((double)ay / 32768);
                            measurement.AccelZ    = ((double)az / 32768);

                            // on SensorTag CC2650 the conversion to micro tesla's is done in the firmware.
                            measurement.MagX = (double)mx;
                            measurement.MagY = (double)my;
                            measurement.MagZ = (double)mz;

                            OnMovementMeasurementValueChanged(new MovementEventArgs(measurement, eventArgs.Timestamp));
                        }
                    }
                }
            }
        }
 public MovementEventArgs(MovementMeasurement measurement, DateTimeOffset timestamp)
 {
     Measurement = measurement;
     Timestamp   = timestamp;
 }
 public SingleRecord()
 {
     this.Value = new MovementMeasurement(0, 0, 0);
     this.Time  = DateTime.Now;
 }