예제 #1
0
 private void SatSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (slidersAllowed)
     {
         PutEvents.ChangeSaturation(LightProperty.GetLightSource(((Slider)sender)), (int)((Slider)sender).Value);
     }
 }
예제 #2
0
 private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (slidersAllowed && !usingMega)
     {
         PutEvents.ChangeBrightness(LightProperty.GetLightSource((Slider)sender), (int)((Slider)sender).Value);
         UpdateMega();
     }
 }
예제 #3
0
 private void TileCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (slidersAllowed)
     {
         System.Windows.Controls.ComboBox tileRef = (System.Windows.Controls.ComboBox)sender;
         string    settingName = LightProperty.GetLightSource(tileRef);
         ComboItem temp        = (ComboItem)tileRef.SelectedItem;
         Properties.Settings.Default[settingName] = temp.idStore;
         CloseAfterSettings = true;
     }
 }
예제 #4
0
        private void Tile_Click(object sender, RoutedEventArgs e)
        {
            bool hardCoded;

            if (LightProperty.GetLightSource(((Tile)sender)).Substring(0, 6) == "scene_")
            {
                hardCoded = false;
            }
            else
            {
                hardCoded = true;
            }

            PutEvents.ChangeScene(LightProperty.GetLightSource(((Tile)sender)), hardCoded);
            SetInfo();
            FadeOut();
        }
예제 #5
0
        public bool slidersAllowed = false; //Prevents SetInfo from changing the actual light states

        public void InitSceneInfo()         //This should probably be a lot shorter. Break down into smaller/reusable bits.
        {
            slidersAllowed = false;
            int i = 1;

            //Set slider data
            foreach (string lightLabel in Storage.groupData.lights)
            {
                if (i <= 5)
                {
                    string labelName     = String.Format("SliderName{0}", i);
                    string briSliderName = String.Format("BriSlider{0}", i);
                    string hueSliderName = String.Format("HueSlider{0}", i);
                    string satSliderName = String.Format("SatSlider{0}", i);
                    System.Windows.Controls.Label nameRef = (System.Windows.Controls.Label) this.FindName(labelName);
                    Slider sliderRef  = (Slider)this.FindName(briSliderName);
                    Slider sliderRef2 = (Slider)this.FindName(hueSliderName);
                    Slider sliderRef3 = (Slider)this.FindName(satSliderName);


                    LightProperty.SetLightSource(nameRef, lightLabel);
                    LightProperty.SetLightSource(sliderRef, lightLabel);
                    LightProperty.SetLightSource(sliderRef2, lightLabel);
                    LightProperty.SetLightSource(sliderRef3, lightLabel);

                    nameRef.Content  = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "name" });
                    sliderRef.Value  = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "bri" });
                    sliderRef2.Value = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "hue" });
                    sliderRef3.Value = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "sat" });
                    if (JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "on" }) == true && !Effects.effectsOn)
                    {
                        sliderRef.IsEnabled  = true;
                        sliderRef.Opacity    = 0.85;
                        sliderRef2.IsEnabled = true;
                        sliderRef2.Opacity   = 0.85;
                        sliderRef3.IsEnabled = true;
                        sliderRef3.Opacity   = 0.85;
                    }
                    i++;
                }
            }

            //Set current scene
            this.SceneCombo.Items.Add(new ComboItem("New scene", ""));
            this.SceneCombo.SelectedIndex = 0;

            i = 1;
            foreach (dynamic scene in Storage.sceneData)
            {
                this.SceneCombo.Items.Add(new ComboItem(JsonParser.Read(Storage.sceneData, new string[] { scene.Key, "name" }), scene.Key));
                if (SceneEdit.IsSceneMatch(scene.Key))
                {
                    this.SceneCombo.SelectedIndex = i;
                }
                i++;
            }

            //Populate group settings
            this.GroupCombo.Items.Clear();
            this.GroupCombo.Items.Add(new ComboItem("All lights", "0"));
            this.GroupCombo.SelectedIndex = 0;
            i = 1;
            foreach (dynamic group in Storage.latestData.groups)
            {
                this.GroupCombo.Items.Add(new ComboItem(JsonParser.Read(Storage.latestData, new string[] { "groups", group.Key, "name" }), group.Key));
                if (group.Key == Properties.Settings.Default.bridgeGroup)
                {
                    this.GroupCombo.SelectedIndex = i;
                }
                i++;
            }

            //Populate light dropdowns
            for (int n = 1; n <= 5; n++)
            {
                string   comboName = String.Format("GroupLight{0}", n);
                ComboBox comboRef  = (ComboBox)this.FindName(comboName);

                if (n != 1)
                {
                    comboRef.Items.Add(new ComboItem("None", ""));
                }

                foreach (dynamic light in Storage.latestData.lights)
                {
                    string jsonName      = JsonParser.Read(light.Value, new string[] { "name" });
                    string jsonModel     = JsonParser.Read(light.Value, new string[] { "modelid" });
                    string friendlyModel = "Unknown light type";

                    if (jsonModel.Contains("LCT"))
                    {
                        friendlyModel = "hue";
                    }
                    else if (jsonModel.Contains("LLC"))
                    {
                        friendlyModel = "LivingColors";
                    }
                    else if (jsonModel.Contains("LWB"))
                    {
                        friendlyModel = "hue lux";
                    }
                    else if (jsonModel.Contains("LWL"))
                    {
                        friendlyModel = "LivingWhites";
                    }
                    else if (jsonModel.Contains("LST"))
                    {
                        friendlyModel = "LightStrips";
                    }

                    string name = String.Format("{0} ({1})", jsonName, friendlyModel);
                    comboRef.Items.Add(new ComboItem(name, light.Key));

                    if (Storage.groupData.lights.Length >= n)
                    {
                        if (Storage.groupData.lights[n - 1] == light.Key)
                        {
                            comboRef.SelectedIndex = comboRef.Items.Count - 1;
                        }
                    }
                }

                if (comboRef.SelectedIndex == -1)
                {
                    comboRef.SelectedIndex = 0;
                }
            }

            //Populate auto-effect dropdown
            DefaultCombo.Items.Add(new ComboItem("None", "", 0));
            DefaultCombo.SelectedIndex = 0;
            i = 1;

            DefaultCombo.Items.Add(new ComboItem("Ambient mode", "ambient", 1));
            if (Properties.Settings.Default.autoEffect == 1)               //There's probably a cleaner way to handle this.
            {
                if (Properties.Settings.Default.autoName == "ambient")
                {
                    DefaultCombo.SelectedIndex = i;
                }
            }
            i++;

            DefaultCombo.Items.Add(new ComboItem("Daylight mode", "daylight", 1));
            if (Properties.Settings.Default.autoEffect == 1)
            {
                if (Properties.Settings.Default.autoName == "daylight")
                {
                    DefaultCombo.SelectedIndex = i;
                }
            }
            i++;

            foreach (dynamic scene in Storage.defaultScenes)
            {
                DefaultCombo.Items.Add(new ComboItem(JsonParser.Read(Storage.defaultScenes, new string[] { scene.Key, "name" }), scene.Key, -2));
                if (Properties.Settings.Default.autoEffect == -2)
                {
                    if (scene.Key == Properties.Settings.Default.autoName)
                    {
                        DefaultCombo.SelectedIndex = i;
                    }
                }
                i++;
            }
            foreach (dynamic scene in Storage.sceneData)
            {
                DefaultCombo.Items.Add(new ComboItem(JsonParser.Read(Storage.sceneData, new string[] { scene.Key, "name" }), scene.Key, -1));
                if (Properties.Settings.Default.autoEffect == -1)
                {
                    if (scene.Key == Properties.Settings.Default.autoName)
                    {
                        DefaultCombo.SelectedIndex = i;
                    }
                }
                i++;
            }

            //Populate various app setting dropdowns
            int    sunrise  = SunriseEquation.JulianToTime(SunriseEquation.sunrise);
            int    sunset   = SunriseEquation.JulianToTime(SunriseEquation.sunset);
            string regional = String.Format(
                "Regional (sunrise at {0}:{1}, sunset at {2}:{3})",
                (sunrise / 60).ToString("D2"),
                (sunrise % 60).ToString("D2"),
                (sunset / 60).ToString("D2"),
                (sunset % 60).ToString("D2"));

            AppCombo2.Items.Add(regional);
            AppCombo2.Items.Add("Equinox (sunrise at 06:00, sunset at 18:00)");

            sunrise = SunriseEquation.JulianToTime(SunriseEquation.startup);
            sunset  = SunriseEquation.JulianToTime(SunriseEquation.startup + 0.5);
            string startup = String.Format(
                "Startup (sunrise at {0}:{1}, sunset at {2}:{3})",
                (sunrise / 60).ToString("D2"),
                (sunrise % 60).ToString("D2"),
                (sunset / 60).ToString("D2"),
                (sunset % 60).ToString("D2"));

            AppCombo2.Items.Add(startup);

            AppCombo2.SelectedIndex = Albedo.Properties.Settings.Default.daylightSetting;

            if (Albedo.Properties.Settings.Default.ambientTransition == 80)
            {
                AppCombo1.SelectedIndex = 0;
            }
            else if (Albedo.Properties.Settings.Default.ambientTransition == 40)
            {
                AppCombo1.SelectedIndex = 1;
            }
            else if (Albedo.Properties.Settings.Default.ambientTransition == 10)
            {
                AppCombo1.SelectedIndex = 2;
            }

            slidersAllowed = true;
        }
예제 #6
0
        public void SetInfo()
        {
            slidersAllowed = false;
            int i = 1;

            string username = Platform.ReadSetting("bridgeUserName");

            if (username.Contains("albedo"))
            {
                return;
            }

            //Populate Lights tab
            foreach (string lightLabel in Storage.groupData.lights)
            {
                if (i <= 5)
                {
                    string labelName  = String.Format("SliderName{0}", i);
                    string sliderName = String.Format("Slider{0}", i);
                    System.Windows.Controls.Label nameRef = (System.Windows.Controls.Label) this.FindName(labelName);
                    Slider sliderRef = (Slider)this.FindName(sliderName);

                    LightProperty.SetLightSource(nameRef, lightLabel);
                    LightProperty.SetLightSource(sliderRef, lightLabel);

                    nameRef.Content = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "name" });
                    sliderRef.Value = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "bri" });
                    if (JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state", "on" }) == true && !Effects.effectsOn)
                    {
                        sliderRef.IsEnabled  = true;
                        sliderRef.Opacity    = 0.85;
                        MegaSlider.IsEnabled = true;
                        MegaSlider.Opacity   = 0.85;
                    }
                    i++;
                }
            }
            UpdateMega();

            //Set effect switches
            if (Effects.effectsOn)
            {
                switch (Effects.effectMode)
                {
                case "test":
                    break;

                case "ambient":
                    this.AmbientSwitch.IsChecked = true;
                    break;

                case "daylight":
                    this.DaylightSwitch.IsChecked = true;
                    break;
                }
            }


            //Populate group settings
            this.GroupCombo.Items.Clear();
            this.GroupCombo.Items.Add(new ComboItem("All lights", "0"));
            this.GroupCombo.SelectedIndex = 0;
            i = 1;
            foreach (dynamic group in Storage.latestData.groups)
            {
                this.GroupCombo.Items.Add(new ComboItem(JsonParser.Read(Storage.latestData, new string[] { "groups", group.Key, "name" }), group.Key));
                if (group.Key == Properties.Settings.Default.bridgeGroup)
                {
                    this.GroupCombo.SelectedIndex = i;
                }
                i++;
            }

            //Populate scene settings
            for (int i2 = 1; i2 <= 8; i2++)
            {
                string comboName   = String.Format("Tile{0}Combo", i2);
                string settingName = String.Format("customSelected{0}", i2);
                System.Windows.Controls.ComboBox comboRef = (System.Windows.Controls.ComboBox) this.FindName(comboName);

                comboRef.Items.Clear();
                comboRef.Items.Add(new ComboItem("None", ""));
                comboRef.SelectedIndex = 0;
                i = 1;
                foreach (dynamic scene in Storage.defaultScenes)
                {
                    comboRef.Items.Add(new ComboItem(JsonParser.Read(Storage.defaultScenes, new string[] { scene.Key, "name" }), scene.Key));
                    if (scene.Key == (string)Properties.Settings.Default[settingName])
                    {
                        comboRef.SelectedIndex = i;
                    }
                    i++;
                }
                foreach (dynamic scene in Storage.sceneData)
                {
                    comboRef.Items.Add(new ComboItem(JsonParser.Read(Storage.sceneData, new string[] { scene.Key, "name" }), scene.Key));
                    if (scene.Key == (string)Properties.Settings.Default[settingName])
                    {
                        comboRef.SelectedIndex = i;
                    }
                    i++;
                }
            }

            //Populate Scenes tab
            for (int i2 = 1; i2 <= 8; i2++)
            {
                Tile   tileRef  = (Tile)this.FindName(String.Format("Tile{0}", i2));
                string tileName = (string)Properties.Settings.Default[String.Format("customSelected{0}", i2)];
                if (tileName != "")
                {
                    if (JsonParser.Read(Storage.sceneData, new string[] { tileName }) != null)
                    {
                        tileRef.Title = JsonParser.Read(Storage.sceneData, new string[] { tileName, "name" });
                        LightProperty.SetLightSource(tileRef, tileName);
                        dynamic tileColor = Storage.tileColors((int)JsonParser.Read(Storage.sceneData, new string[] { tileName, "tilecolor" }));

                        tileRef.Background  = new BrushConverter().ConvertFromString(tileColor.background);
                        tileRef.BorderBrush = new BrushConverter().ConvertFromString(tileColor.border);
                        if (tileColor.blackText)
                        {
                            Brush black = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                            tileRef.Foreground = black;
                        }
                    }
                    else if (JsonParser.Read(Storage.defaultScenes, new string[] { tileName }) != null)
                    {
                        tileRef.Title = JsonParser.Read(Storage.defaultScenes, new string[] { tileName, "name" });
                        LightProperty.SetLightSource(tileRef, tileName);
                        dynamic tileColor = Storage.tileColors((int)JsonParser.Read(Storage.defaultScenes, new string[] { tileName, "tilecolor" }));

                        tileRef.Background  = new BrushConverter().ConvertFromString(tileColor.background);
                        tileRef.BorderBrush = new BrushConverter().ConvertFromString(tileColor.border);
                        if (tileColor.blackText)
                        {
                            Brush black = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                            tileRef.Foreground = black;
                        }
                    }
                    else
                    {
                        Properties.Settings.Default[String.Format("customSelected{0}", i2)] = "";
                        tileRef.IsEnabled = false;
                    }
                }
                else
                {
                    tileRef.IsEnabled = false;
                }
            }

            slidersAllowed = true;
        }