Esempio n. 1
0
        /// <inheritdoc />
        public void StopCyclePreview()
        {
            _cyclePreviewTimer.IsEnabled = false;
            IsPreviewModeEnabled         = false;

            Debug.WriteLine("Canceled cycle preview", GetType().Name);
            CyclePreviewEnded?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 2
0
        public TemperatureService(ISettingsService settingsService, IGammaService gammaService)
        {
            _settingsService = settingsService;
            _gammaService    = gammaService;

            // Polling timer
            _pollingTimer       = new Timer();
            _pollingTimer.Tick += (sender, args) => UpdateGamma();

            // Temperature update timer
            _temperatureUpdateTimer       = new SyncedTimer();
            _temperatureUpdateTimer.Tick += (sender, args) =>
            {
                Tick?.Invoke(this, EventArgs.Empty);
                if (!_temperatureSmoother.IsActive)
                {
                    UpdateTemperature(true);
                }
            };

            // Cycle preview timer
            _cyclePreviewTimer       = new Timer(TimeSpan.FromMilliseconds(15));
            _cyclePreviewTimer.Tick += (sender, args) =>
            {
                CyclePreviewTime = CyclePreviewTime.Add(TimeSpan.FromHours(0.05));
                Tick?.Invoke(this, EventArgs.Empty);
                IsPreviewModeEnabled = true;
                UpdateTemperature(true);

                // Ending condition
                if ((CyclePreviewTime - DateTime.Now).TotalHours >= 24)
                {
                    _cyclePreviewTimer.IsEnabled = false;
                    IsPreviewModeEnabled         = false;
                    Debug.WriteLine("Ended cycle preview", GetType().Name);
                    CyclePreviewEnded?.Invoke(this, EventArgs.Empty);
                }
            };

            // Helpers
            _temperatureSmoother           = new ValueSmoother();
            _temperatureSmoother.Finished += (sender, args) => UpdateTemperature(true); // snap

            // System events
            SystemEvents.PowerModeChanged       += SystemPowerModeChanged;
            SystemEvents.DisplaySettingsChanged += SystemDisplaySettingsChanged;

            // Settings
            _settingsService.PropertyChanged += SettingsServicePropertyChanged;
            UpdateConfiguration();

            // Init
            _temperature = _settingsService.DefaultMonitorTemperature;
        }