Exemple #1
0
        public bool SetBrightness(int brightness)
        {
            if ((brightness < 0) || (100 < brightness))
            {
                throw new ArgumentOutOfRangeException(nameof(brightness), "The brightness must be within 0 to 100.");
            }

            lock (_lock)
            {
                if (_isRemovable)
                {
                    brightness = ArraySearch.GetNearest(_brightnessLevels, (byte)brightness);

                    if (MSMonitor.SetBrightness(DeviceInstanceId, brightness))
                    {
                        this.Brightness = brightness;
                        return(true);
                    }
                }
                else
                {
                    if (PowerManagement.SetActiveSchemeBrightness(brightness))
                    {
                        this.Brightness = brightness;
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemple #2
0
        public bool UpdateBrightness(int brightness = -1)
        {
            lock (_lock)
            {
                if (_isRemovable)
                {
                    this.Brightness = (0 <= brightness)
                                                ? brightness
                                                : MSMonitor.GetBrightness(DeviceInstanceId);
                }
                else
                {
                    this.Brightness = PowerManagement.GetActiveSchemeBrightness();

                    if (LightSensor.AmbientLightSensorExists)
                    {
                        this.BrightnessAdjusted = (0 <= brightness)
                                                        ? brightness
                                                        : MSMonitor.GetBrightness(DeviceInstanceId);
                    }
                }
                return(0 <= this.Brightness);
            }
        }