protected override void OnCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs eventArgs) { if (sender.Uuid == LightIntensityCharacteristicUuid) { if (_lightValueChanged != null) { uint dataLength = eventArgs.CharacteristicValue.Length; using (DataReader reader = DataReader.FromBuffer(eventArgs.CharacteristicValue)) { if (dataLength == 2) { ushort rawData = ReadBigEndianU16bit(reader); uint m = (uint)(rawData & 0x0FFF); uint e = ((uint)(rawData & 0xF000)) >> 12; double lux = (double)m * (0.01 * Math.Pow(2.0, e)); var measurement = new LightIntensityMeasurement(); measurement.Lux = lux; OnLightIntensityMeasurementValueChanged(new LightIntensityMeasurementEventArgs(measurement, eventArgs.Timestamp)); } } } } }
public LightIntensityMeasurementEventArgs(LightIntensityMeasurement measurement, DateTimeOffset timestamp) { Measurement = measurement; Timestamp = timestamp; }