LightSensor
LightSensor
LightSensor
LightSensor
LightSensor
Class
Definition
Represents an ambient-light sensor.
This sensor returns the ambient-light reading as a LUX value.
For an example implementation, see the light sensor sample.
public : sealed class LightSensor
struct winrt::Windows::Devices::Sensors::LightSensor
public sealed class LightSensor
Public NotInheritable Class LightSensor
// This class does not provide a public constructor.
- Attributes
Windows 10 requirements
Device family |
Windows 10 (introduced v10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
The following example demonstrates how a UWP app built with XAML and C# uses the GetDefault method to establish a connection to a light sensor. If no integrated light sensor is found, the method will return a null value.
_sensor = LightSensor.GetDefault();
The following example demonstrates how a UWP app built with XAML registers a ReadingChanged event handler.
private void ScenarioEnable(object sender, RoutedEventArgs e)
{
if (_sensor != null)
{
// Establish the report interval
_sensor.ReportInterval = _desiredReportInterval;
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_sensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(ReadingChanged);
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No light sensor found", NotifyType.StatusMessage);
}
}
The following example shows the ReadingChanged event handler.
async private void ReadingChanged(object sender, LightSensorReadingChangedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
LightSensorReading reading = e.Reading;
ScenarioOutput_LUX.Text = String.Format("{0,5:0.00}", reading.IlluminanceInLux);
});
}
Version history
Windows version | SDK version | Value added |
---|---|---|
1709 | 16299 | FromIdAsync |
1709 | 16299 | GetDeviceSelector |
1709 | 16299 | MaxBatchSize |
1709 | 16299 | ReportLatency |
Properties
DeviceId DeviceId DeviceId DeviceId DeviceId |
Gets the device identifier. |
MaxBatchSize MaxBatchSize MaxBatchSize MaxBatchSize MaxBatchSize |
Gets the maximum number of events that can be batched by the sensor. |
MinimumReportInterval MinimumReportInterval MinimumReportInterval MinimumReportInterval MinimumReportInterval |
Gets the minimum report interval supported by the sensor. |
ReportInterval ReportInterval ReportInterval ReportInterval ReportInterval |
Gets or sets the current report interval for the ambient light sensor. |
ReportLatency ReportLatency ReportLatency ReportLatency ReportLatency |
Gets or sets the delay between batches of sensor information. |
Methods
FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) |
Asynchronously obtains the sensor from its identifier. |
GetCurrentReading() GetCurrentReading() GetCurrentReading() GetCurrentReading() GetCurrentReading() |
Gets the current ambient-light sensor reading. |
GetDefault() GetDefault() GetDefault() GetDefault() GetDefault() |
Returns the default ambient-light sensor. |
GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() |
Gets the device selector. |
Events
ReadingChanged ReadingChanged ReadingChanged ReadingChanged ReadingChanged |
Occurs each time the ambient-light sensor reports a new sensor reading. |
See also
Feedback
Loading feedback...