Esempio n. 1
0
        public async void LoadCharacteristics()
        {
            IEnumerable <ICharacteristic> characteristics = await ServiceInstance.GetCharacteristicsAsync();

            foreach (ICharacteristic characteristic in characteristics)
            {
                if (characteristic.Id == TemperatureCharacteristicId)
                {
                    characteristic.ValueUpdated += (sender, e) =>
                    {
                        byte[] tempBytes = e.Characteristic.Value;
                        Temperature = (sbyte)(tempBytes.First());
                        System.Diagnostics.Debug.WriteLine("Temperature: " + " " + Temperature);
                    };
                    MarkCharacteristicForUpdate(characteristic);
                }
                else if (characteristic.Id == TemperaturePeriodCharacteristicId)
                {
                    byte[] val = await characteristic.ReadAsync();

                    int period = ConversionHelpers.ByteArrayToShort16BitLittleEndian(val);
                    TemperaturePeriod = period;
                    System.Diagnostics.Debug.WriteLine("Temperature period: " + " " + Temperature);
                }
            }

            StartUpdates();
        }
Esempio n. 2
0
        public async void LoadCharacteristics()
        {
            IEnumerable <ICharacteristic> characteristics = await ServiceInstance.GetCharacteristicsAsync();

            foreach (ICharacteristic characteristic in characteristics)
            {
                if (characteristic.Id == ButtonACharacteristicId)
                {
                    characteristic.ValueUpdated += (sender, e) =>
                    {
                        byte[] tempBytes = e.Characteristic.Value;
                        AButton = (sbyte)(tempBytes.First());
                    };
                    MarkCharacteristicForUpdate(characteristic);
                }
                else if (characteristic.Id == ButtonBCharacteristicId)
                {
                    characteristic.ValueUpdated += (sender, e) =>
                    {
                        byte[] tempBytes = e.Characteristic.Value;
                        BButton = (sbyte)(tempBytes.First());
                    };
                    MarkCharacteristicForUpdate(characteristic);
                }
            }

            StartUpdates();
        }
        public async void LoadCharacteristics()
        {
            IEnumerable <ICharacteristic> characteristics = await ServiceInstance.GetCharacteristicsAsync();

            foreach (ICharacteristic characteristic in characteristics)
            {
                if (characteristic.Id == MagnetometerCharacteristicId)
                {
                    characteristic.ValueUpdated += (sender, e) =>
                    {
                        byte[] rawBytes = e.Characteristic.Value;
                        if (rawBytes.Length != 6)
                        {
                            throw new InvalidDataException("Magnetometer characteristic should have 6 bytes");
                        }

                        short rawX = ConversionHelpers.ByteArrayToShort16BitLittleEndian(new byte[] { rawBytes[0], rawBytes[1] });
                        short rawY = ConversionHelpers.ByteArrayToShort16BitLittleEndian(new byte[] { rawBytes[2], rawBytes[3] });
                        short rawZ = ConversionHelpers.ByteArrayToShort16BitLittleEndian(new byte[] { rawBytes[4], rawBytes[5] });

                        X = ((double)rawX) / 1000.0;
                        Y = ((double)rawY) / 1000.0;
                        Z = ((double)rawZ) / 1000.0;
                    };
                    MarkCharacteristicForUpdate(characteristic);
                }
                else if (characteristic.Id == MagnetometerBearingCharacteristicId)
                {
                    characteristic.ValueUpdated += (sender, e) =>
                    {
                        byte[] rawBytes = e.Characteristic.Value;
                        if (rawBytes.Length != 2)
                        {
                            throw new InvalidDataException("Magnetometer Bearing characteristic should have 2 bytes");
                        }

                        MagnetometerBearing = ConversionHelpers.ByteArrayToShort16BitLittleEndian(rawBytes);
                    };
                    MarkCharacteristicForUpdate(characteristic);
                }
                else if (characteristic.Id == MagnetometerPeriodCharacteristicId)
                {
                    byte[] val = await characteristic.ReadAsync();

                    int period = ConversionHelpers.ByteArrayToShort16BitLittleEndian(val);
                    MagnetometerPeriod = period;
                }
            }

            StartUpdates();
        }
Esempio n. 4
0
        public async void LoadCharacteristics()
        {
            IEnumerable <ICharacteristic> characteristics = await ServiceInstance.GetCharacteristicsAsync();

            foreach (ICharacteristic characteristic in characteristics)
            {
                if (characteristic.Id == LedTextCharacteristicId)
                {
                    _ledTextCharacteristic         = characteristic;
                    LedTextCharacteristicAvailable = true;
                }
                else if (characteristic.Id == LedMatrixStateCharacteristicId)
                {
                    _ledMatrixCharacteristic         = characteristic;
                    LedMatrixCharacteristicAvailable = true;
                }
            }
        }
        public async void LoadCharacteristics()
        {
            IEnumerable <ICharacteristic> characteristics = await ServiceInstance.GetCharacteristicsAsync();

            foreach (ICharacteristic characteristic in characteristics)
            {
                CharacteristicField field;
                if (_characteristicMapping.TryGetValue(characteristic.Id, out field))
                {
                    await characteristic.ReadAsync();

                    switch (field)
                    {
                    case CharacteristicField.ModelNumber:
                        ModelNumber = characteristic.StringValue;
                        OnPropertyChanged(nameof(ModelNumber));
                        break;

                    case CharacteristicField.SerialNumber:
                        SerialNumber = characteristic.StringValue;
                        OnPropertyChanged(nameof(SerialNumber));
                        break;

                    case CharacteristicField.HardwareRevision:
                        HardwareRevision = characteristic.StringValue;
                        OnPropertyChanged(nameof(HardwareRevision));
                        break;

                    case CharacteristicField.FirmwareRevision:
                        FirmwareRevision = characteristic.StringValue;
                        OnPropertyChanged(nameof(FirmwareRevision));
                        break;

                    case CharacteristicField.ManufacturerName:
                        ManufacturerName = characteristic.StringValue;
                        OnPropertyChanged(nameof(ManufacturerName));
                        break;
                    }
                }
            }
        }