public async Task RegisterForTemperatureChanges(BluetoothLEDevice bluetoothLeDevice) { var service = await bluetoothLeDevice.GetGattServiceForUuidAsync(serviceGuid); var accessStatus = await service.RequestAccessAsync(); var openStatus = await service.OpenAsync(GattSharingMode.Exclusive); foreach (var characteristics in await service.GetCharacteristics2Async()) { if (!Probes.Contains(characteristics.Uuid)) { continue; } Debug.WriteLine("Registering probe " + characteristics.Uuid); await characteristics.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); var byteArray = await characteristics.ReadBytesAsync(); TemperatureChanged?.Invoke(this, new TemperatureChangedEventArg( Probes.IndexOf(characteristics.Uuid), CalculateTemperature(byteArray))); characteristics.ValueChanged += (GattCharacteristic sender, GattValueChangedEventArgs args) => { var temperature = ReadTemperature(args.CharacteristicValue); TemperatureChanged?.Invoke(this, new TemperatureChangedEventArg( Probes.IndexOf(characteristics.Uuid), CalculateTemperature(temperature))); }; } }
/// <summary> /// Update the temperature on Flutter using the event. /// </summary> /// <param name="celsius"></param> public void OnTemperatureChanged(double celsius, double fahrenheit) { // Send the event to flutter TemperatureChanged?.Invoke(this, new TemperatureChangedArgs { Celsius = celsius, Fahrenheit = fahrenheit }); }
public void CheckSensor() { if (_rawDevice == null || _rawDevice.Handle == IntPtr.Zero || _handler == null || _temperatureConversion == null || _humidityConversion == null) { return; } ReadSensor(out var humidity, out var temperature); if (humidity.HasValue) { if (!Equals(Humidity, humidity)) { HumidityChanged?.Invoke(this, new HumidityChangedEventArgs(humidity.Value)); } Humidity = humidity; } if (temperature.HasValue) { if (!Equals(Temperature, temperature)) { TemperatureChanged?.Invoke(this, new TemperatureChangedEventArgs(temperature.Value)); } Temperature = temperature; } _handler.PostDelayed(_listenerAction, DELAY_MS); }
/// <summary> /// Updates the current temparature /// </summary> /// <param name="temperature"></param> public override void UpdateTemperature(ITemperature temperature) { var temp = temperature.Unit != ThermometerUnit ? temperature.Convert(ThermometerUnit) : temperature; base.UpdateTemperature(temp); TemperatureChanged?.Invoke(null, new TemperatureChangedEventArgs(Temperature)); }
/// <summary> /// Called when a barometer value is being notified /// </summary> /// <param name="characteristic">Characteristic which notified the value</param> /// <param name="value">New characteristic value</param> private void OnBarometerNotification(BleGattCharacteristic characteristic, BleValue value) { if (characteristic.Guid == PressureGuid) { PressureChanged?.Invoke(value.ToUInt32()); } else if (characteristic.Guid == TemperatureGuid) { TemperatureChanged?.Invoke(value.ToInt16()); } else { } }
// Performs the actual invocation of delegates private void OnTemperatureChanged() { // If TemperatureChanged is not null, Invoke all of them TemperatureChanged?.Invoke(_temperature); }
protected virtual void OnTemperatureChanged(MeasurementChangedEventArgs e) { TemperatureChanged?.Invoke(this, e); }
public override void UpdateTemperature(double temperature) { base.UpdateTemperature(temperature); TemperatureChanged?.Invoke(null, new TemperatureChangedEventArgs(Temperature)); }
private void OnTemperatureChanged(object sender, EventArgs e) { float.TryParse(txtTemperature.Text, out _temperature); _eventArgs.Temperature = _temperature; TemperatureChanged?.Invoke(this, _eventArgs); }
public void NotifyOnTempratureChanged(TemperatureChangedEventArgs temperatureChangedEventArgs) { TemperatureChanged?.Invoke(temperatureChangedEventArgs); }
private void OnTemperatureChanged() { TemperatureChanged?.Invoke(_temperature); }