コード例 #1
0
ファイル: TimeKeeper.cs プロジェクト: jvanegmond/mlux
        private void TimeKeeperMainThread()
        {
            var cancel = _cancelSource.Token;

            while (true)
            {
                var relTime  = TimeUtil.GetRelativeTime(TimeProvider.Now);
                var previous = _profile.Previous(TimeProvider.Now);
                var next     = _profile.Next(TimeProvider.Now);

                var brightness  = (int)LinearNodeInterpolation.Interpolate(relTime, previous, next, NodeProperty.Brightness);
                var temperature = (int)LinearNodeInterpolation.Interpolate(relTime, previous, next, NodeProperty.ColorTemperature);
                temperature -= temperature % 10;

                _allMonitors.SetBrightness(brightness);
                _allMonitors.SetTemperature(temperature);

                CurrentChanged?.Invoke(this, EventArgs.Empty);
                NodeElapsed?.Invoke(this, EventArgs.Empty);

                var result = WaitHandle.WaitAny(new[] { cancel.WaitHandle, _runNow }, TimeSpan.FromSeconds(1));

                if (result == 0)
                {
                    break;              // Stop
                }
            }
        }
コード例 #2
0
 public void InterpolateTest1()
 {
     Assert.AreEqual(10, LinearNodeInterpolation.Interpolate(10, 20, 0));
     Assert.AreEqual(12, LinearNodeInterpolation.Interpolate(10, 20, 0.25));
     Assert.AreEqual(15, LinearNodeInterpolation.Interpolate(10, 20, 0.5));
     Assert.AreEqual(17, LinearNodeInterpolation.Interpolate(10, 20, 0.75));
     Assert.AreEqual(20, LinearNodeInterpolation.Interpolate(10, 20, 1));
 }
コード例 #3
0
        public void GetRelTimePercentageTest3()
        {
            var start = TimeSpan.FromHours(22);
            var end   = TimeSpan.FromHours(6);

            Assert.AreEqual(0, LinearNodeInterpolation.GetRelTimePercentage(TimeSpan.FromHours(22), start, end));
            Assert.AreEqual(0.25, LinearNodeInterpolation.GetRelTimePercentage(TimeSpan.FromHours(0), start, end));
            Assert.AreEqual(0.5, LinearNodeInterpolation.GetRelTimePercentage(TimeSpan.FromHours(2), start, end));
            Assert.AreEqual(0.75, LinearNodeInterpolation.GetRelTimePercentage(TimeSpan.FromHours(4), start, end));
            Assert.AreEqual(1, LinearNodeInterpolation.GetRelTimePercentage(TimeSpan.FromHours(6), start, end));
        }
コード例 #4
0
ファイル: SettingsGraph.xaml.cs プロジェクト: jvanegmond/mlux
        private void UpdateFirstLast(TimeNodeView lastNode, TimeNodeView firstNode)
        {
            var brightness  = (int)LinearNodeInterpolation.Interpolate(TimeSpan.Zero, lastNode.UnderlyingNode, firstNode.UnderlyingNode, NodeProperty.Brightness);
            var temperature = (int)LinearNodeInterpolation.Interpolate(TimeSpan.Zero, lastNode.UnderlyingNode, firstNode.UnderlyingNode, NodeProperty.ColorTemperature);

            SetGradientStop(TimeSpan.Zero, brightness, temperature, BackgroundBrush.GradientStops[0]);
            SetGradientStop(TimeSpan.FromDays(1), brightness, temperature, BackgroundBrush.GradientStops[1]);

            var firstLine = GraphCanvas.Children.OfType <Line>().First(_ => _.Name == "FirstLine");
            var lastLine  = GraphCanvas.Children.OfType <Line>().First(_ => _.Name == "LastLine");

            var brightnessPercentage     = ((double)brightness - TimeProfile.MinBrightness) / (TimeProfile.MaxBrightness - TimeProfile.MinBrightness);
            var brightnessAbsoluteHeight = (1d - brightnessPercentage) * GraphCanvas.ActualHeight;

            firstLine.Y1 = brightnessAbsoluteHeight;
            lastLine.Y2  = brightnessAbsoluteHeight;
            lastLine.X2  = GraphCanvas.ActualWidth;
        }