private void DispatcherTimerOnTick(object sender, object o) { var lightReading = _lightSensor.GetCurrentReading(); LuxLums = string.Format("{0,5:0.00}", lightReading.IlluminanceInLux); Brightness = lightReading.IlluminanceInLux / 100; }
public MainPage() { InitializeComponent(); _locator = new Geolocator(); Loaded += OnControlLoaded; _lightSensor = LightSensor.GetDefault(); if (_lightSensor != null) { //For now we get a base reading to use to compare later _baseReading = _lightSensor.GetCurrentReading(); //Register for the reading change _lightSensor.ReadingChanged += OnLightReadingChanged; } _accelerometerSensor = Accelerometer.GetDefault(); if (_accelerometerSensor != null) { _accelerometerSensor.Shaken += OnShaken; } _compassSensor = Compass.GetDefault(); if (_compassSensor != null) { _compassSensor.ReadingChanged += OnCompassReadingChanged; } _gyroSensor = Gyrometer.GetDefault(); if (_gyroSensor != null) { _gyroSensor.ReadingChanged += OnGyroReadingChanged; } _inclineSensor = Inclinometer.GetDefault(); if (_inclineSensor != null) { _inclineSensor.ReadingChanged += OnInclineReadingChanged; } _orientationSensor = OrientationSensor.GetDefault(); if (_orientationSensor != null) { _orientationSensor.ReadingChanged += OnOrientationReadingChanged; } }
public Glance() { _updateSensor = new DispatcherTimer(); _updateSensor.Interval = TimeSpan.FromSeconds(0.25); _updateSensor.Tick += UpdateSensor_Tick; sensor = LightSensor.GetDefault(); if (sensor != null) { //sensor.ReportInterval = sensor.MinimumReportInterval; lastEffectiveReadingTime = DateTime.Now; lastState = sensor.GetCurrentReading().IlluminanceInLux <= Dark ? GlanceEventArgs.Dark : GlanceEventArgs.Light; } }