public ThemeClass() { _lightSensor = LightSensor.GetDefault(); _autoLightDetectionEnabled = false; SetWindowsVersion(); SetWindowsRegistryKey(); }
public CapteurDeLuminosité() { lightsensor = LightSensor.GetDefault(); if (lightsensor == null) { capteurDeLumièrePresent = false; } }
private void OnGetLight2(object sender, RoutedEventArgs e) { sensor = LightSensor.GetDefault(); sensor.ReportInterval = sensor.MinimumReportInterval; sensor.ReadingChanged += (sender1, e1) => { this.DefaultViewModel["LightResult"] = string.Format("{0:T}\tIlluminance: {1} Lux", e1.Reading.Timestamp, e1.Reading.IlluminanceInLux); }; }
public MainPage() { InitializeComponent(); _sensor = LightSensor.GetDefault(); if (_sensor != null) { _sensor.ReportInterval = Math.Max(16, _sensor.MinimumReportInterval); _sensor.ReadingChanged += Sensor_ReadingChanged; } }
/// <summary> /// Attempts to get ambient light illuminance. /// </summary> /// <param name="illuminance">Illuminance in lux</param> /// <returns>True if successfully gets</returns> public static bool TryGetAmbientLight(out float illuminance) { var reading = LightSensor.GetDefault()?.GetCurrentReading(); if (reading is null) { illuminance = default; return(false); } illuminance = reading.IlluminanceInLux; return(true); }
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; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { sensor = LightSensor.GetDefault(); if (sensor != null) { sensor.ReadingChanged += sensor_ReadingChanged; Data.Visibility = Visibility.Visible; } else { NoSensorMessage.Visibility = Visibility.Visible; } }
private void OnGetLight(object sender, RoutedEventArgs e) { LightSensor sensor = LightSensor.GetDefault(); if (sensor != null) { LightSensorReading reading = sensor.GetCurrentReading(); this.DefaultViewModel["LightResult"] = string.Format("Illuminance: {0} Lux", reading.IlluminanceInLux); } else { this.DefaultViewModel["LightResult"] = "No light sensor found"; } }
public void OnGetLight() { LightSensor sensor = LightSensor.GetDefault(); if (sensor != null) { LightSensorReading reading = sensor.GetCurrentReading(); Illuminance = $"Illuminance: {reading?.IlluminanceInLux}"; } else { Illuminance = "Light sensor not found"; } }
private void ToggleLightSensor() { if (this.SensorSwitches.P != null) { if (this.SensorSwitches.P.Value > 0) { if (this.lightSensor == null) { this.lightSensor = LightSensor.GetDefault(); } if (this.lightSensor != null) { this[LIGHTSENSOR].Id = this.SensorSwitches.Id; this[LIGHTSENSOR].Delta = this.SensorSwitches.Delta; this.lightSensor.ReportInterval = Math.Max( Math.Max(baseMinimum, (uint)this.SensorSwitches.Interval), this.lightSensor.MinimumReportInterval); if (this.SensorSwitches.P.Value != 1) { this.lightSensor.ReadingChanged += this.NewLight; } if (this.SensorSwitches.P.Value != 3) { this.SensorSwitches.P = null; this.NewLight(this.lightSensor, null); } else { this.SensorSwitches.P = null; } } } else { if (this.lightSensor != null) { this.lightSensor.ReadingChanged -= this.NewLight; this.NewQuan(null, null); } this.SensorSwitches.P = null; } } }
public MainWindow() { InitializeComponent(); // 光センサー lightSensor = LightSensor.GetDefault(); if (lightSensor == null) { TextLight.Text = @"光センサーはありません"; } timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(100); timer.add_Tick(timer_Tick); timer.Start(); }
public override async Task OnNavigatedTo(NavigationEventArgs args) { _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; _lightSensor = LightSensor.GetDefault(); if (_lightSensor != null) { uint minReportInterval = _lightSensor.MinimumReportInterval; _lightSensor.ReportInterval = minReportInterval > 1000 ? minReportInterval : 1000; _lightSensor.ReadingChanged += _lightSensor_ReadingChanged; } else { Debug.WriteLine("El dispositivo no cuenta con el sensor de luz"); } }
public MainPage() { InitializeComponent(); _lightsensor = LightSensor.GetDefault(); // Get the default light sensor object // Assign an event handler for the ALS reading-changed event if (_lightsensor != null) { // Establish the report interval for all scenarios uint minReportInterval = _lightsensor.MinimumReportInterval; uint reportInterval = minReportInterval > 20 ? minReportInterval : 20; _lightsensor.ReportInterval = reportInterval; // Establish the even thandler _lightsensor.ReadingChanged += new TypedEventHandler <LightSensor, LightSensorReadingChangedEventArgs>(ReadingChangedAsync); } }
public Scenario1_DataEvents() { this.InitializeComponent(); _sensor = LightSensor.GetDefault(); if (_sensor != null) { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. uint minReportInterval = _sensor.MinimumReportInterval; _desiredReportInterval = minReportInterval > 100 ? minReportInterval : 100; } else { rootPage.NotifyUser("No light sensor found", NotifyType.ErrorMessage); } }
public LightSensorImpl() { _sensor = LightSensor.GetDefault(); if (_sensor == null) { return; } _sensor.ReadingChanged += (sender, args) => { var reading = new LightSensorReport { IlluminanceInLux = args.Reading.IlluminanceInLux, Timestamp = args.Reading.Timestamp }; if (ReadingChanged != null) { ReadingChanged(reading); } }; }
public void OnGetLightReport() { LightSensor sensor = LightSensor.GetDefault(); if (sensor != null) { sensor.ReportInterval = Math.Max(sensor.MinimumReportInterval, 1000); sensor.ReadingChanged += async(s, e) => { LightSensorReading reading = e.Reading; await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { IlluminanceReport = $"{reading.IlluminanceInLux} {reading.Timestamp:T}"; }); }; } }
/// <summary> /// Initialize hardware sensors on the device /// </summary> private void InitSensors() { // Get default light sensor light = LightSensor.GetDefault(); if (light != null) { light.ReportInterval = RealSensorDataTick; light.ReadingChanged += light_ReadingChanged; } // Get default acelerometer sensor accelerometer = Accelerometer.GetDefault(); if (accelerometer != null) { accelerometer.ReportInterval = RealSensorDataTick; accelerometer.ReadingChanged += accelerometer_ReadingChanged; } }
void MainPage_Loaded(object sender, RoutedEventArgs _e) { var lightSensor = LightSensor.GetDefault(); lightSensor.ReportInterval = 500; Action <LightSensorReading> notifyLight = r => LightText.Text = $"Light: {r.IlluminanceInLux} lx"; notifyLight(lightSensor.GetCurrentReading()); lightSensor.ReadingChanged += (o, e) => RunOnUIAsync(() => notifyLight(e.Reading)); var compass = Compass.GetDefault(); compass.ReportInterval = 500; Action <CompassReading> notifyCompass = r => CompassText.Text = $"Compass: {r.HeadingMagneticNorth:N3} °"; notifyCompass(compass.GetCurrentReading()); compass.ReadingChanged += (o, e) => RunOnUIAsync(() => notifyCompass(e.Reading)); }
public LightSensorTestsViewModel(CoreDispatcher dispatcher) : base(dispatcher) { _LightSensor = LightSensor.GetDefault(); if (_LightSensor != null) { _LightSensor.ReportInterval = 250; SensorStatus = "LightSensor created"; } else { SensorStatus = "LightSensor not available on this device"; } Disposables.Add(Disposable.Create(() => { if (_LightSensor != null) { _LightSensor.ReadingChanged -= LightSensor_ReadingChanged; } })); }
private void ConfigureLightSensor() { // Get the reference to the sensor and see if it is available _lightSensor = LightSensor.GetDefault(); if (_lightSensor == null) { return; } _sensorSettings.IsLightSensorAvailable = true; // Set the minimum report interval. Care must be taken to ensure // it is not set to a value smaller than the device minimum var minInterval = _lightSensor.MinimumReportInterval; _lightSensor.ReportInterval = Math.Max(_sensorSettings.SensorReportInterval, minInterval); _lightSensor.ReadingChanged += LightSensorOnReadingChanged; // Read the initial sensor value _sensorSettings.LatestLightSensorReading = GetLightSensorReading(); }
public Scenario2() { this.InitializeComponent(); _sensor = LightSensor.GetDefault(); if (_sensor != null) { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. uint minReportInterval = _sensor.MinimumReportInterval; _desiredReportInterval = minReportInterval > 100 ? minReportInterval : 100; // Set up a DispatchTimer _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Tick += DisplayCurrentReading; _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval); } else { rootPage.NotifyUser("No light sensor found", NotifyType.StatusMessage); } }
static void Main(string[] args) { var lightSensor = LightSensor.GetDefault(); lightSensor.ReportInterval = 500; Action <LightSensorReading> notifyLight = r => Console.WriteLine($"Light: {r.IlluminanceInLux} lx"); notifyLight(lightSensor.GetCurrentReading()); lightSensor.ReadingChanged += (o, e) => notifyLight(e.Reading); var compass = Compass.GetDefault(); compass.ReportInterval = 500; Action <CompassReading> notifyCompass = r => Console.WriteLine($"Compass: {r.HeadingMagneticNorth:N3} °"); notifyCompass(compass.GetCurrentReading()); compass.ReadingChanged += (o, e) => notifyCompass(e.Reading); Console.WriteLine("Press [Enter] to exit."); Console.ReadLine(); }
/// <summary> /// OnNavitatedTo /// </summary> /// <param name="e"></param> protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Keep the display in the On state while the app is running DisplayRequestSetting.RequestActive(); // Get capability to dim and brighten the display when needed BrightnessOverrideSetting = BrightnessOverride.GetForCurrentView(); if (BrightnessOverrideSetting.IsSupported) { BrightnessOverrideSetting.StartOverride(); } // Register for ambient light value changes LightSensorSetting = LightSensor.GetDefault(); if (LightSensorSetting != null) { LightSensorSetting.ReportInterval = Convert.ToUInt32(LightSensorReadingRateInMs.TotalMilliseconds); LightSensorSetting.ReadingChanged += LightSensor_ReadingChanged; } await LoadFrame(); }
/// <summary> /// Update Light Sensor readings event and update UI /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="object"/> instance containing the event data.</param> private void UpdateLightSensor(object sender, EventArgs e) { try { LightSensor light = LightSensor.GetDefault(); if (light != null) { SensorLabel.Text = LocRM.GetString("ALSReading") + ": " + light.GetCurrentReading().IlluminanceInLux.ToString(); int colorValue = (int)Math.Min(light.GetCurrentReading().IlluminanceInLux, 255); labelLight.ForeColor = Color.FromArgb(colorValue, colorValue, 0); } else { SensorLabel.Text = LocRM.GetString("NotFound"); _timer.Stop(); } } catch (Exception ex) { Log.LogError(ex.ToString()); _timer.Stop(); } }
private void ToggleSensors(SensorMessage sensorsMessage) { this.Sensors.SensorSwitches.Id = sensorsMessage.Id; foreach (var sensorItem in sensorsMessage.Sensors) { if (sensorItem.A != null) { sensorsMessage.Type = 'A'; if (Accelerometer.GetDefault() == null) { throw new UnsupportedSensorException("Accelerometer does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.A.Value.ToString() } }); this.Sensors.SensorSwitches.A = sensorItem.A.Value; } else if (sensorItem.G != null) { sensorsMessage.Type = 'G'; if (Gyrometer.GetDefault() == null) { throw new UnsupportedSensorException("Gyrometer does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.G.Value.ToString() } }); this.Sensors.SensorSwitches.G = sensorItem.G.Value; } else if (sensorItem.M != null) { sensorsMessage.Type = 'M'; if (Compass.GetDefault() == null) { throw new UnsupportedSensorException("Compass does not exist"); } this.Sensors.SensorSwitches.M = sensorItem.M.Value; App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.M.Value.ToString() } }); this.Sensors.SensorSwitches.M = sensorItem.M.Value; } else if (sensorItem.L != null) { sensorsMessage.Type = 'L'; this.Sensors.SensorSwitches.L = sensorItem.L.Value; App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.L.Value.ToString() } }); } else if (sensorItem.Q != null) { sensorsMessage.Type = 'Q'; if (OrientationSensor.GetDefault() == null) { throw new UnsupportedSensorException("OrientationSensor does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.Q.Value.ToString() } }); this.Sensors.SensorSwitches.Q = sensorItem.Q.Value; } else if (sensorItem.P != null) { sensorsMessage.Type = 'P'; if (LightSensor.GetDefault() == null) { throw new UnsupportedSensorException("LightSensor does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary <string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.P.Value.ToString() } }); this.Sensors.SensorSwitches.P = sensorItem.P.Value; } // outside of scope - applies to last only this.Sensors.SensorSwitches.Delta = sensorItem.Delta; this.Sensors.SensorSwitches.Interval = sensorItem.Interval; } this.Sensors.Start(); }
private async Task DeviceInfo(DeviceMessage devMessage) { var action = devMessage.Action.ToUpperInvariant(); switch (action) { case "CAPABILITIES": { var resultId = 0; var result = new StringBuilder(); if (Accelerometer.GetDefault() != null) { resultId += 1; result.Append("A"); } if (Gyrometer.GetDefault() != null) { resultId += 2; result.Append("G"); } var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { resultId += 4; result.Append("L"); } if (Compass.GetDefault() != null) { resultId += 8; result.Append("M"); } if (OrientationSensor.GetDefault() != null) { resultId += 16; result.Append("O"); } if (LightSensor.GetDefault() != null) { resultId += 32; result.Append("P"); } await this.SendResult( new DeviceResultMessage(devMessage) { ResultId = resultId, Result = result.ToString() }); break; } case "DATETIME": { var utcNow = DateTime.UtcNow; var now = DateTime.Now; await this.SendResult( new DeviceResultMessage(devMessage) { ResultD = (utcNow - new DateTime(1970, 1, 1)) .TotalSeconds, Result = utcNow.ToString("s") + "Z", Offset = TimeZoneInfo.Local.GetUtcOffset(now) .TotalMinutes }); break; } case "NAME": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult(new DeviceResultMessage(devMessage) { Result = deviceInfo.FriendlyName }); break; } case "OS": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult(new DeviceResultMessage(devMessage) { Result = deviceInfo.OperatingSystem }); break; } case "FWVER": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult( new DeviceResultMessage(devMessage) { Result = deviceInfo.SystemFirmwareVersion }); break; } case "HWVER": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult( new DeviceResultMessage(devMessage) { Result = deviceInfo.SystemHardwareVersion }); break; } case "PRODUCTNAME": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult( new DeviceResultMessage(devMessage) { Result = deviceInfo.SystemProductName }); break; } case "MANUFACTURER": { var deviceInfo = new EasClientDeviceInformation(); await this.SendResult( new DeviceResultMessage(devMessage) { Result = deviceInfo.SystemManufacturer }); break; } case "GET": { if (string.IsNullOrWhiteSpace(devMessage.Key)) { await this.SendResult(new DeviceResultMessage(devMessage) { ResultId = -2 }); return; } await this.SendResult( new DeviceResultMessage(devMessage) { Result = this.appSettings.GetValueOrDefault( devMessage.Message, devMessage.Key) }); break; } case "SET": { if (string.IsNullOrWhiteSpace(devMessage.Key)) { await this.SendResult(new DeviceResultMessage(devMessage) { ResultId = -2 }); return; } var original = this.appSettings.GetValueOrDefault(string.Empty, devMessage.Key); await this.SendResult( new DeviceResultMessage(devMessage) { ResultId = this.appSettings.AddOrUpdateValue( devMessage.Message, devMessage.Key) ? 0 : -1, Result = original }); this.appSettings.ReportChanged(devMessage.Key); break; } case "DELETE": { if (string.IsNullOrWhiteSpace(devMessage.Key)) { await this.SendResult(new DeviceResultMessage(devMessage) { ResultId = -2 }); return; } var result = this.appSettings.Remove(devMessage.Key); await this.SendResult(new DeviceResultMessage(devMessage) { ResultId = result ? 0 : 1 }); break; } } }
/// <summary> /// Determines whether an integrated ambient light sensor exists. /// </summary> /// <returns>True if exists</returns> public static bool AmbientLightSensorExists() { return(LightSensor.GetDefault() is not null); }
public MainPage() { this.InitializeComponent(); _lightSensor = LightSensor.GetDefault(); _lightSensor.ReadingChanged += OnLightSensorReadingChanged; }
private const uint baseMinimum = 100; //ms #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async void Start() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { if (SensorSwitches.A != null) { if (SensorSwitches.A.Value > 0) { if (accelerometer == null) { accelerometer = Accelerometer.GetDefault(); } if (accelerometer != null) { accelerometer.ReportInterval = Math.Max(Math.Max(baseMinimum, (uint)SensorSwitches.Interval), accelerometer.MinimumReportInterval); if (SensorSwitches.A.Value != 1) { accelerometer.ReadingChanged += NewAcc; } this[ACCELERATOR].Id = SensorSwitches.Id; this[ACCELERATOR].Delta = SensorSwitches.Delta; if (SensorSwitches.A.Value != 3) { SensorSwitches.A = null; NewAcc(accelerometer, null); } else { SensorSwitches.A = null; } } } else { if (accelerometer != null) { accelerometer.ReadingChanged -= NewAcc; NewAcc(null, null); } SensorSwitches.A = null; } } if (SensorSwitches.G != null) { if (SensorSwitches.G.Value > 0) { if (gyrometer == null) { gyrometer = Gyrometer.GetDefault(); } if (gyrometer != null) { gyrometer.ReportInterval = Math.Max(Math.Max(baseMinimum, (uint)SensorSwitches.Interval), gyrometer.MinimumReportInterval); if (SensorSwitches.G.Value != 1) { gyrometer.ReadingChanged += NewGyro; } this[GYROSCOPE].Id = SensorSwitches.Id; this[GYROSCOPE].Delta = SensorSwitches.Delta; if (SensorSwitches.G.Value != 3) { SensorSwitches.G = null; NewGyro(gyrometer, null); } else { SensorSwitches.G = null; } } } else { if (gyrometer != null) { gyrometer.ReadingChanged -= NewGyro; NewGyro(null, null); } SensorSwitches.G = null; } } if (SensorSwitches.M != null) { if (SensorSwitches.M.Value > 0) { if (compass == null) { compass = Compass.GetDefault(); } if (compass != null) { compass.ReportInterval = Math.Max(Math.Max(baseMinimum, (uint)SensorSwitches.Interval), compass.MinimumReportInterval); if (SensorSwitches.M.Value != 1) { compass.ReadingChanged += NewCom; } this[COMPASS].Id = SensorSwitches.Id; this[COMPASS].Delta = SensorSwitches.Delta; if (SensorSwitches.M.Value != 3) { SensorSwitches.M = null; NewCom(compass, null); } else { SensorSwitches.M = null; } } } else { if (compass != null) { compass.ReadingChanged -= NewCom; NewCom(null, null); } SensorSwitches.M = null; } } if (SensorSwitches.L != null) { if (SensorSwitches.L.Value > 0) { if (geolocator == null) { geolocator = new Geolocator(); } if (geolocator != null) { geolocator.ReportInterval = 30 * 60 * 1000; this[LOCATION].Id = SensorSwitches.Id; this[LOCATION].Delta = SensorSwitches.Delta; if (SensorSwitches.L.Value != 1) { geolocator.PositionChanged += NewLoc; } if (SensorSwitches.L.Value != 3) { SensorSwitches.L = null; NewLoc(geolocator, null); } else { SensorSwitches.L = null; } } } else { if (geolocator != null) { geolocator.PositionChanged -= NewLoc; NewLoc(null, null); } SensorSwitches.L = null; } } if (SensorSwitches.Q != null) { if (SensorSwitches.Q.Value > 0) { if (orientation == null) { orientation = OrientationSensor.GetDefault(); } if (orientation != null) { this[QUANTIZATION].Id = SensorSwitches.Id; this[QUANTIZATION].Delta = SensorSwitches.Delta; orientation.ReportInterval = Math.Max(Math.Max(baseMinimum, (uint)SensorSwitches.Interval), orientation.MinimumReportInterval); if (SensorSwitches.Q.Value != 1) { orientation.ReadingChanged += NewQuan; } if (SensorSwitches.Q.Value != 3) { SensorSwitches.Q = null; NewQuan(orientation, null); } else { SensorSwitches.Q = null; } } } else { if (orientation != null) { orientation.ReadingChanged -= NewQuan; NewQuan(null, null); } SensorSwitches.Q = null; } } if (SensorSwitches.P != null) { if (SensorSwitches.P.Value > 0) { if (lightSensor == null) { lightSensor = LightSensor.GetDefault(); } if (lightSensor != null) { this[LIGHTSENSOR].Id = SensorSwitches.Id; this[LIGHTSENSOR].Delta = SensorSwitches.Delta; lightSensor.ReportInterval = Math.Max(Math.Max(baseMinimum, (uint)SensorSwitches.Interval), lightSensor.MinimumReportInterval); if (SensorSwitches.P.Value != 1) { lightSensor.ReadingChanged += NewLight; } if (SensorSwitches.P.Value != 3) { SensorSwitches.P = null; NewLight(lightSensor, null); } else { SensorSwitches.P = null; } } } else { if (lightSensor != null) { lightSensor.ReadingChanged -= NewLight; NewQuan(null, null); } SensorSwitches.P = null; } } }
/// <summary> /// Initializes a new instance of the <see cref="LuxHelper"/> class. /// </summary> public LuxHelper() { this.sensor = LightSensor.GetDefault(); }