コード例 #1
0
            private void TestBrightness()
            {
                var(isGetSuccess, minimum, current, maximum) = MonitorConfiguration.GetBrightness(Handle, IsLowLevelSupported);
                var isValid = (minimum < maximum) && (minimum <= current) && (current <= maximum);

                GetBrightness = $"Success: {isGetSuccess}" + (isGetSuccess ? $", Valid: {isValid} (Minimum: {minimum}, Current: {current}, Maximum: {maximum})" : string.Empty);

                var difference = (uint)(DateTime.Now.Ticks % 6 + 5);                 // Integer from 5 to 10
                var expected   = difference;

                if (isGetSuccess && isValid)
                {
                    expected = (current - minimum > maximum - current) ? current - difference : current + difference;
                    expected = Math.Min(maximum, Math.Max(minimum, expected));
                }

                var isSetSuccess = MonitorConfiguration.SetBrightness(Handle, expected, IsLowLevelSupported);

                var(_, _, actual, _) = MonitorConfiguration.GetBrightness(Handle, IsLowLevelSupported);
                SetBrightness        = $"Success: {isSetSuccess}" + (isSetSuccess ? $", Match: {expected == actual} (Expected: {expected}, Actual: {actual})" : string.Empty);

                if (isSetSuccess)
                {
                    MonitorConfiguration.SetBrightness(Handle, current, IsLowLevelSupported);
                }
            }
コード例 #2
0
            private void TestBrightness()
            {
                var(success, _, current, maximum) = MonitorConfiguration.GetBrightness(Handle, IsLowLevelSupported);
                GetBrightness = success;

                SetBrightness = MonitorConfiguration.SetBrightness(Handle, Math.Min(maximum, current + 5), IsLowLevelSupported);
                if (SetBrightness)
                {
                    MonitorConfiguration.SetBrightness(Handle, current, IsLowLevelSupported);
                }
            }
コード例 #3
0
ファイル: DdcMonitorItem.cs プロジェクト: usaone/Monitorian
        public override bool SetBrightness(int brightness)
        {
            if ((brightness < 0) || (100 < brightness))
            {
                throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
            }

            var buffer = (uint)Math.Round(brightness / 100D * (_maximum - _minimum) + _minimum, MidpointRounding.AwayFromZero);

            if (MonitorConfiguration.SetBrightness(_handle, buffer, _useLowLevel))
            {
                this.Brightness = brightness;
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public override AccessResult SetBrightness(int brightness)
        {
            if (brightness is < 0 or > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
            }

            var buffer = (uint)Math.Round(brightness / 100D * (_maximumBrightness - _minimumBrightness) + _minimumBrightness, MidpointRounding.AwayFromZero);

            var result = MonitorConfiguration.SetBrightness(_handle, buffer, _capability.IsHighLevelBrightnessSupported);

            if (result.Status == AccessStatus.Succeeded)
            {
                this.Brightness = brightness;
            }
            return(result);
        }