Skip to content

Commit

Permalink
chore: Make sensor retrieval ubiquitous
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 26, 2024
1 parent a9d3360 commit 9199193
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/Uno.UWP/Devices/Sensors/Barometer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#if __ANDROID__ || __IOS__

using Uno.Extensions;
using Uno.Helpers;
using Uno.Logging;
using Windows.Foundation;

namespace Windows.Devices.Sensors
Expand Down Expand Up @@ -56,6 +58,18 @@ public event TypedEventHandler<Barometer, BarometerReadingChangedEventArgs> Read
add => _readingChangedWrapper.AddHandler(value);
remove => _readingChangedWrapper.RemoveHandler(value);
}


private void OnReadingChanged(BarometerReading reading)
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Barometer reading received " +
$"StationPressureInHectopascals:{reading.StationPressureInHectopascals}, " +
$"Timestamp:{reading.Timestamp}");
}
_readingChangedWrapper.Invoke(this, new GyrometerReadingChangedEventArgs(reading));
}
}
}
#endif
2 changes: 1 addition & 1 deletion src/Uno.UWP/Devices/Sensors/HingeAngleSensor.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ private void StopReading() =>
_hingeAngleSensor.ReadingChanged -= OnNativeReadingChanged;

private void OnNativeReadingChanged(object sender, NativeHingeAngleReading e) =>
_readingChanged.Event?.Invoke(this, new HingeAngleSensorReadingChangedEventArgs(new HingeAngleReading(e.AngleInDegrees, e.Timestamp)));
_readingChanged.Invoke(this, new HingeAngleSensorReadingChangedEventArgs(new HingeAngleReading(e.AngleInDegrees, e.Timestamp)));
}
}
2 changes: 1 addition & 1 deletion src/Uno.UWP/Devices/Sensors/Magnetometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public event TypedEventHandler<Magnetometer, MagnetometerReadingChangedEventArgs

private void OnReadingChanged(MagnetometerReading reading)
{
_readingChangedWrapper.Event?.Invoke(this, new MagnetometerReadingChangedEventArgs(reading));
_readingChangedWrapper.Invoke(this, new MagnetometerReadingChangedEventArgs(reading));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Devices/Sensors/Pedometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public event TypedEventHandler<Pedometer, PedometerReadingChangedEventArgs> Read

private void OnReadingChanged(PedometerReading reading)
{
_readingChangedWrapper.Event?.Invoke(this, new PedometerReadingChangedEventArgs(reading));
_readingChangedWrapper.Invoke(this, new PedometerReadingChangedEventArgs(reading));
}
}
}
Expand Down

0 comments on commit 9199193

Please sign in to comment.