Esempio n. 1
0
        private static LightColor ToLightColor(this LightStatusResponse lsr)
        {
            byte brightness = (byte)(lsr.Dimmer ?? 255);

            ColorTemperature?temperature = lsr.Mireds == null
                ? (ColorTemperature?)null
                : ColorTemperature.FromMireds((ushort)lsr.Mireds.Value);

            RgbColor?rgbColor = lsr.ColorHex == null
                ? (RgbColor?)null
                : RgbColor.FromHex((int)lsr.ColorHex);

            XyColor?xyColor = (lsr.ColorX == null) || (lsr.ColorY == null)
                ? (XyColor?)null
                : new XyColor((ushort)lsr.ColorX, (ushort)lsr.ColorY);

            HsColor?hsColor = (lsr.ColorHue == null) || (lsr.ColorSaturation == null)
                ? (HsColor?)null
                : new HsColor((ushort)lsr.ColorHue, (ushort)lsr.ColorSaturation);

            return(new LightColor(
                       brightness,
                       temperature,
                       rgbColor,
                       xyColor,
                       hsColor));
        }
Esempio n. 2
0
        public async Task <ColorTemperature> GetTemperatureInfo()
        {
            var response = await _nanoleafHttpClient.SendGetRequest("state/ct");

            ColorTemperature colorTemperatureInfo = JsonConvert.DeserializeObject <ColorTemperature>(response);

            return(colorTemperatureInfo);
        }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        float angle = transform.rotation.eulerAngles.x;

        angle                = Mathf.Sin(angle * Mathf.PI / 180);
        currentTemp          = Mathf.Lerp(sunriseTemp, noonTemp, angle);
        lightComponent.color = ColorTemperature.Color(currentTemp);
    }
Esempio n. 4
0
 public ViewModel()
 {
     // Set default colour to white, full brightness
     rgbColor    = new RGBColor(1.0f, 1.0f, 1.0f);
     hsvColor    = new HSVColor(0.0f, 0.0f, 1.0f);
     temperature = ColorTemperature.Neutral;
     brightness  = 1.0f;
     ColorChanged();
 }
Esempio n. 5
0
 public ViewModel()
 {
     // Set default colour to white, full brightness
     rgbColor = new RGBColor(1.0f, 1.0f, 1.0f);
     hsvColor = new HSVColor(0.0f, 0.0f, 1.0f);
     temperature = ColorTemperature.Neutral;
     brightness = 1.0f;
     ColorChanged();
 }
Esempio n. 6
0
 // Update is called once per frame
 void Update()
 {
     if (Quaternion.Angle(prevAngle, transform.rotation) > angleThreshold)
     {
         prevAngle = transform.rotation;
         float angle = transform.rotation.eulerAngles.x;
         angle                = Mathf.Sin(angle * Mathf.PI / 180);
         currentTemp          = Mathf.Lerp(sunriseTemp, noonTemp, angle);
         lightComponent.color = ColorTemperature.Color(currentTemp);
         DynamicGI.UpdateEnvironment();
     }
 }
Esempio n. 7
0
        private Color GetBackgroundColor(int temperature, int brightness)
        {
            // get color gamma adjustment
            var gamma = ColorTemperature.GetColorProfile(temperature);

            return(new Color()
            {
                A = byte.MaxValue,
                R = (byte)(byte.MaxValue * gamma.Red),
                G = (byte)(byte.MaxValue * gamma.Green),
                B = (byte)(byte.MaxValue * gamma.Blue),
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static ColorTemperature NormalizeColorForAllowedColorRange(this ColorTemperature color, LightType lightType)
        {
            switch (lightType)
            {
            case LightType.Color:
                return(Math.Min(MaxAllowedColorTemperatureForWhiteAndColorLights, Math.Max(color, MinAllowedColorTemperatureForWhiteAndColorLights)));

            case LightType.WhiteAmbiance:
                return(Math.Min(MaxAllowedColorTemperatureForWhiteAmbianceLights, Math.Max(color, MinAllowedColorTemperatureForWhiteAndColorLights)));

            case LightType.WhiteOnly:
                return(null);

            default:
                throw new ArgumentException($"Unsupported light type '{lightType}'.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static bool IsInAllowedColorRange(this ColorTemperature colorTemperature, LightType lightType)
        {
            switch (lightType)
            {
            case LightType.Color:
                return(colorTemperature <= MaxAllowedColorTemperatureForWhiteAndColorLights && colorTemperature >= MinAllowedColorTemperatureForWhiteAndColorLights);

            case LightType.WhiteAmbiance:
                return(colorTemperature <= MaxAllowedColorTemperatureForWhiteAmbianceLights && colorTemperature >= MinAllowedColorTemperatureForWhiteAndColorLights);

            case LightType.WhiteOnly:
                return(false);

            default:
                throw new ArgumentException($"Unsupported light type '{lightType}'.");
            }
        }
Esempio n. 10
0
        private void UpdateGamma()
        {
            // Determine if an update is needed
            var isUpdateNeeded =
                CurrentColorTemperature != TargetColorTemperature || // target temperature not reached yet
                IsEnabled && _settingsService.IsGammaPollingEnabled; // gamma polling

            // If update is not needed - return
            if (!isUpdateNeeded)
            {
                return;
            }

            // Determine if gamma change should be smooth
            var isSmooth = _settingsService.IsGammaSmoothingEnabled && !IsCyclePreviewEnabled;

            // If smooth - advance towards target temperature in small steps
            if (isSmooth)
            {
                // Calculate difference
                var diff = TargetColorTemperature.Value - CurrentColorTemperature.Value;

                // Calculate delta
                var delta = 30.0 * Math.Sign(diff);
                if (Math.Abs(delta) > Math.Abs(diff))
                {
                    delta = diff;
                }

                // Set new color temperature
                CurrentColorTemperature = new ColorTemperature(CurrentColorTemperature.Value + delta);
            }
            // Otherwise - just snap to target temperature
            else
            {
                CurrentColorTemperature = TargetColorTemperature;
            }

            // Update gamma
            _winApiService.SetGamma(CurrentColorTemperature);
        }
Esempio n. 11
0
        private static ColorBalance GetColorBalance(ColorTemperature temperature)
        {
            // Algorithm taken from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/

            double GetRed()
            {
                if (temperature.Value > 6600)
                {
                    return(Math.Pow(temperature.Value / 100 - 60, -0.1332047592) * 329.698727446 / 255);
                }

                return(1);
            }

            double GetGreen()
            {
                if (temperature.Value > 6600)
                {
                    return(Math.Pow(temperature.Value / 100 - 60, -0.0755148492) * 288.1221695283 / 255);
                }

                return((Math.Log(temperature.Value / 100) * 99.4708025861 - 161.1195681661) / 255);
            }

            double GetBlue()
            {
                if (temperature.Value >= 6600)
                {
                    return(1);
                }

                if (temperature.Value <= 1900)
                {
                    return(0);
                }

                return((Math.Log(temperature.Value / 100 - 10) * 138.5177312231 - 305.0447927307) / 255);
            }

            return(new ColorBalance(GetRed(), GetGreen(), GetBlue()));
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="now"></param>
        /// <returns></returns>
        public TimeSpan GetThreadSleepDuration(DateTime now)
        {
            List <KeyValuePair <DateTime, int> > pairs = GetSortedTimesAndColorTemperaturePairs(now);

            TimeSpan currentTimeSpan = new TimeSpan(
                0,
                now.Hour,
                now.Minute,
                now.Second);

            TimeSpan startingTimeSpan = new TimeSpan(
                0,
                pairs[0].Key.Hour,
                pairs[0].Key.Minute,
                pairs[0].Key.Second);

            TimeSpan endingTimeSpan = new TimeSpan(
                pairs[0].Key.Day == pairs[1].Key.Day ? 0 : 1, // when time spans multiple days handle in a month/year agnostic manner
                pairs[1].Key.Hour,
                pairs[1].Key.Minute,
                pairs[1].Key.Second);

            if (startingTimeSpan == endingTimeSpan)
            {
                throw new ArgumentException($"Thw two provided time values of '{startingTimeSpan.ToString()}' should not match.");
            }

            if (pairs[0].Key > pairs[1].Key)
            {
                throw new ArgumentException($"Invalid provided TimeSpan values. Start time should be less than end time.");
            }

            TimeSpan sleepDuration;

            if (pairs[0].Value == pairs[1].Value)
            {
                sleepDuration  = pairs[1].Key - now;
                sleepDuration += TimeSpan.FromMilliseconds(1000 - sleepDuration.Milliseconds);
            }
            else
            {
                double percentComplete = (currentTimeSpan.TotalSeconds - startingTimeSpan.TotalSeconds) / (endingTimeSpan.TotalSeconds - startingTimeSpan.TotalSeconds);

                int    totalIntervals          = Math.Abs(pairs[0].Value - pairs[1].Value);
                double secondsBetweenIntervals = Math.Abs((endingTimeSpan - startingTimeSpan).TotalSeconds) / totalIntervals;
                secondsBetweenIntervals = Convert.ToInt32(Math.Ceiling(secondsBetweenIntervals * percentComplete));

                if (secondsBetweenIntervals == 0)
                {
                    secondsBetweenIntervals = 1;
                }

                sleepDuration = TimeSpan.FromSeconds(secondsBetweenIntervals);
            }

            ColorTemperature currentColorTemperature = GetColorTemperature(now);

            // Account for updating the test hook between retrieving color temperature values
            //if (_today.HasValue)
            //{
            //    if (Today.Day != (now + sleepDuration).Day)
            //    {
            //        // Make sure we only update once
            //        Today = Today.AddDays(1);
            //    }
            //}

            ColorTemperature nextColorTemperature = GetColorTemperature(now + sleepDuration);

            if (currentColorTemperature == nextColorTemperature)
            {
                return(sleepDuration + GetThreadSleepDuration(now + sleepDuration));
            }

            return(sleepDuration);
        }
Esempio n. 13
0
    IEnumerator DrawParticles()
    {
        while (true)
        {
            foreach (var item in flowTypes)
            {
                if (!flowParticles.ContainsKey(item.Key))
                {
                    var child = transform.Find(item.Key.ToString());
                    if (child == null)
                    {
                        if (!warningGiven.Contains(item.Key))
                        {
                            Debug.LogError("No particle system for " + item.Key);
                            warningGiven.Add(item.Key);
                        }
                        continue;
                    }
                    var particle = child.GetComponent <ParticleSystem>();
                    if (particle == null)
                    {
                        if (!warningGiven.Contains(item.Key))
                        {
                            Debug.LogError("Malformed particle system for " + item.Key);
                            warningGiven.Add(item.Key);
                        }
                        continue;
                    }
                    flowParticles[item.Key] = particle;
                }
                foreach (var particle in item.Value)
                {
                    if (!GameMap.IsInVisibleArea(particle.pos))
                    {
                        continue;
                    }
                    var emitParams = new ParticleSystem.EmitParams();
                    emitParams.position = GameMap.DFtoUnityTileCenter(particle.pos);
                    Color color = Color.white;
                    switch (item.Key)
                    {
                    case FlowType.Dragonfire:
                        color = ColorTemperature.Color(Mathf.Lerp(dragonColorTempMin, dragonColorTempMax, particle.density / 100.0f));
                        break;

                    case FlowType.Miasma:
                    case FlowType.Steam:
                    case FlowType.Mist:
                    case FlowType.Smoke:
                    case FlowType.MagmaMist:
                    case FlowType.CampFire:
                    case FlowType.Fire:
                    case FlowType.OceanWave:
                    case FlowType.SeaFoam:
                        color = Color.white;
                        break;

                    case FlowType.ItemCloud:
                        color = ContentLoader.GetColor(particle.item, particle.material);
                        flowParticles[item.Key].customData.SetVector(ParticleSystemCustomData.Custom1, 0, new ParticleSystem.MinMaxCurve(ImageManager.Instance.GetItemTile(particle.item)));
                        flowParticles[item.Key].customData.SetVector(ParticleSystemCustomData.Custom1, 1, new ParticleSystem.MinMaxCurve(ContentLoader.GetPatternIndex(particle.material)));
                        break;

                    case FlowType.MaterialGas:
                    case FlowType.MaterialVapor:
                    case FlowType.MaterialDust:
                    case FlowType.Web:
                    default:
                        color = ContentLoader.GetColor(particle.material);
                        break;
                    }
                    if (item.Key == FlowType.ItemCloud)
                    {
                        if (UnityEngine.Random.Range(0, 100) > particle.density)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        color.a = particle.density / 100f;
                    }
                    emitParams.startColor           = color;
                    emitParams.applyShapeToPosition = true;
                    flowParticles[item.Key].Emit(emitParams, 1);
                }
            }
            yield return(new WaitForSeconds(updateRate));
        }
    }
Esempio n. 14
0
 public static extern bool GetMonitorColorTemperature(
     [In] HandleRef hMonitor,
     [Out] out ColorTemperature pctCurrentColorTemperature
     );
Esempio n. 15
0
 public void SetGamma(ColorTemperature temperature) => _gammaManager.SetGamma(GetColorBalance(temperature));
        /// <summary>
        ///
        /// </summary>
        private void PopulateColorTemperature()
        {
            //
            iComboBoxColorTemperature.Items.Clear();
            //
            if (iCheckBoxColorTemperatureUnlock.Checked)
            {
                // Unlock mode provides all choices
                // This was designed to be able to test Dell monitors not reporting capabilities properly
                foreach (ColorTemperature t in Enum.GetValues(typeof(ColorTemperature)))
                {
                    iComboBoxColorTemperature.Items.Add(t);
                }

                return;
            }

            PhysicalMonitor  pm      = CurrentPhysicalMonitor();
            ColorTemperature current = pm.ColorTemperature;

            //
            iComboBoxColorTemperature.Items.Add(ColorTemperature.Unknown);

            // Add supported color temperature to our combo box
            // For those Dell monitors not reporting supported color temperature we added the current check
            // That makes sure the current profile is in the combo box

            if (pm.SupportsColorTemperature4000K || current == ColorTemperature.K4000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K4000);
            }

            if (pm.SupportsColorTemperature5000K || current == ColorTemperature.K5000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K5000);
            }

            if (pm.SupportsColorTemperature6500K || current == ColorTemperature.K6500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K6500);
            }

            if (pm.SupportsColorTemperature7500K || current == ColorTemperature.K7500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K7500);
            }

            if (pm.SupportsColorTemperature8200K || current == ColorTemperature.K8200)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K8200);
            }

            if (pm.SupportsColorTemperature9300K || current == ColorTemperature.K9300)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K9300);
            }

            if (pm.SupportsColorTemperature10000K || current == ColorTemperature.K10000)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K10000);
            }

            if (pm.SupportsColorTemperature11500K || current == ColorTemperature.K11500)
            {
                iComboBoxColorTemperature.Items.Add(ColorTemperature.K11500);
            }
        }