private async void SetColour()
        {
            LifxColour colour = new LifxColour()
            {
                Hue        = (UInt16)HueSlider.Value,
                Saturation = (UInt16)SaturationSlider.Value,
                Luminosity = (UInt16)LuminositySlider.Value,
                Kelvin     = (UInt16)(KelvinSlider.Value)
            };

            foreach (LifxBulb bulb in StorageHelper.SelectedBulbs)
            {
                if (FadeTimeSlider.Value > 0)
                {
                    await bulb.SetWaveformCommand(0, 0, colour, Convert.ToUInt32(FadeTimeSlider.Value), 1f, 1, Waveform.Sine);
                }
                else
                {
                    await bulb.SetColorCommand(colour, 0);
                }

                bulb.Colour = colour;
            }

            StorageHelper.SaveToStorage();
        }
        void ColourListViewItem_Tapped(object sender, TappedRoutedEventArgs e)
        {
            TextBlock tappedColour = e.OriginalSource as TextBlock;

            if (tappedColour != null)
            {
                SetColour(LifxColour.ColorToLifxColour((Color)tappedColour.Tag));

                if (StorageHelper.LocalSettings.HasFlag(Settings.PivotOnColourChoice))
                {
                    MainPivot.SelectedIndex = 0;
                }
            }
            else
            {
                ListViewItem tappedColourItem = sender as ListViewItem;
                if (tappedColourItem != null)
                {
                    tappedColour = (tappedColourItem.Content as Grid).Children[2] as TextBlock;
                    SetColour(LifxColour.ColorToLifxColour((Color)tappedColour.Tag));

                    if (StorageHelper.LocalSettings.HasFlag(Settings.PivotOnColourChoice))
                    {
                        MainPivot.SelectedIndex = 0;
                    }
                }
            }
        }
 private void SetSliders(LifxColour colour)
 {
     UnBindValueChangedEventHandlers();
     HueSlider.Value        = colour.Hue;
     SaturationSlider.Value = colour.Saturation;
     LuminositySlider.Value = colour.Luminosity;
     KelvinSlider.Value     = colour.Kelvin;
     BindValueChangedEventHandlers();
 }
        private async void SetColour(LifxColour colour)
        {
            Helper.ShowProgressIndicator("Setting colour...");

            SetSliders(colour);

            foreach (LifxBulb bulb in StorageHelper.SelectedBulbs)
            {
                if (FadeColourAppBarButton.IsChecked.Value == true)
                {
                    await bulb.SetWaveformCommand(0, 0, colour, Convert.ToUInt32(FadeTimeSlider.Value), 1.0f, 1, Waveform.Sine);
                }
                else
                {
                    await bulb.SetColorCommand(colour, 0);
                }

                bulb.Colour = colour;
            }

            StorageHelper.SaveToStorage();
            Helper.HideProgressIndicator();
        }
Example #5
0
        private void PopulateList()
        {
            BulbListView.Items.Clear();

            BulbListView.Items.Add(new ListViewItem()
            {
                Margin = new Thickness {
                    Bottom = 12
                },
                Height = 50,
                VerticalContentAlignment = Windows.UI.Xaml.VerticalAlignment.Center,
                BorderBrush     = new SolidColorBrush(Colors.White),
                BorderThickness = new Thickness {
                    Bottom = 2
                },
                Content = new TextBlock()
                {
                    Margin = new Thickness {
                        Left = 8
                    },
                    FontSize = 26,
                    Text     = "all bulbs"
                }
            });

            foreach (ulong tag in StorageHelper.Tags)
            {
                ListViewItem tagsHeader = new ListViewItem()
                {
                    Margin = new Thickness {
                        Bottom = 12, Top = 8
                    },
                    Height = 50,
                    VerticalContentAlignment = Windows.UI.Xaml.VerticalAlignment.Center,
                    BorderBrush     = new SolidColorBrush(Colors.White),
                    BorderThickness = new Thickness {
                        Bottom = 1
                    },
                    Content = new TextBlock()
                    {
                        Margin = new Thickness {
                            Left = 4
                        },
                        FontSize = 22,
                        Text     = tag.ToString()
                    }
                };

                tagsHeader.Tapped += tagsHeader_Tapped;

                BulbListView.Items.Add(tagsHeader);

                foreach (LIFX_Net.LifxBulb bulb in StorageHelper.GetBulbs(tag))
                {
                    TextBlock bulbLabel = new TextBlock()
                    {
                        Margin = new Thickness {
                            Left = 46
                        },
                        FontSize          = 22,
                        VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center,
                        Text = bulb.Label
                    };

                    //bulbLabel.Inlines.Add(new Run() { Text = bulb.Label, Foreground = new SolidColorBrush(LifxColour.ToRgbColour(bulb.Colour)) });

                    TextBlock bulbPowerState = new TextBlock()
                    {
                        HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right,
                        Margin = new Thickness {
                            Right = 10
                        },
                        FontSize          = 22,
                        VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center,
                        Tag = bulb.UID
                    };

                    //Rectangle colourRectangle = new Rectangle()
                    //{
                    //    Fill = new SolidColorBrush(LifxColour.LifxColourToColor(bulb.Colour)),
                    //    HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left,
                    //    Margin = new Thickness { Left = 12 },
                    //    Height = 22,
                    //    Width = 22
                    //};

                    bulbPowerState.Inlines.Add(new Run()
                    {
                        Text       = bulb.IsOn.ToString(),
                        Foreground = bulb.IsOn == LifxPowerState.On ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Gray)
                    });
                    bulbPowerState.Tapped += bulbPowerState_Tapped;

                    Grid grid = new Grid()
                    {
                        Width = 300
                    };
                    grid.Children.Add(bulbLabel);
                    //grid.Children.Add(colourRectangle);
                    grid.Children.Add(bulbPowerState);

                    ListViewItem bulbItem = new ListViewItem()
                    {
                        Margin = new Thickness {
                            Left = 22, Top = 8, Bottom = 8
                        },
                        Height = 30,
                        VerticalContentAlignment = Windows.UI.Xaml.VerticalAlignment.Center,
                        Content         = grid,
                        BorderBrush     = new SolidColorBrush(LifxColour.LifxColourToColor(bulb.Colour)),
                        BorderThickness = new Thickness {
                            Left = 30
                        },
                    };

                    bulbItem.Tapped += bulbItem_Tapped;

                    BulbListView.Items.Add(bulbItem);
                }
            }
        }
Example #6
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            SpeechRecognitionResult speechRecognitionResult = e.Parameter as SpeechRecognitionResult;

            string voiceCommandName = speechRecognitionResult.RulePath[0];
            string navigationTarget = speechRecognitionResult.SemanticInterpretation.Properties["NavigationTarget"][0];
            IReadOnlyDictionary <string, IReadOnlyList <string> > properties = speechRecognitionResult.SemanticInterpretation.Properties;
            UriBuilder    uri  = null;
            MessageDialog mbox = null;

            switch (voiceCommandName)
            {
            case "ChangeAllLightState":
            {
                StorageHelper.SelectedBulbs = StorageHelper.Bulbs;

                foreach (LifxBulb bulb in StorageHelper.SelectedBulbs)
                {
                    await bulb.SetPowerStateCommand(properties["LightState"][0]);
                }
            }
            break;

            case "ChaneOneLightState":
            case "ChangeOneLightStateAlternate":
            {
                StorageHelper.SelectedBulb = StorageHelper.GetBulb(properties["BulbName"][0], true);
                await StorageHelper.SelectedBulbs[0].SetPowerStateCommand(properties["LightState"][0]);
            }
            break;

            case "ChangeAllLightColour":
            {
                string colourname = properties["Colour"][0].Replace(" ", string.Empty);

                try
                {
                    StorageHelper.SelectedBulbs = StorageHelper.Bulbs;
                    LifxColour colour = LifxColour.ColorToLifxColour(colourname);

                    foreach (LifxBulb bulb in StorageHelper.SelectedBulbs)
                    {
                        bulb.Colour = colour;
                        await bulb.SetColorCommand(colour, 0);
                    }
                }
                catch (ColorNotFoundException)
                {
                    mbox = new MessageDialog(StorageHelper.ErrorMessages.GetString("ColourNotFound_Voice"), "Colour Not Found");
                }
            }
            break;

            case "ChangeOneLightColour":
            {
                string colourname = properties["Colour"][0].Replace(" ", string.Empty);
                string uriString  = string.Empty;

                try
                {
                    LifxColour colour = LifxColour.ColorToLifxColour(colourname);
                    StorageHelper.SelectedBulb = StorageHelper.GetBulb(properties["BulbName"][0], true);

                    await StorageHelper.SelectedBulbs[0].SetColorCommand(LifxColour.ColorToLifxColour(colourname), 0);

                    //uriString = typeof(VoiceCommandPage).ToString() + "?BulbName=" + properties["BulbName"][0] + "&Colour=" + colourname;
                    //uri = new UriBuilder(uriString);
                }
                catch (BulbNotFoundException)
                {
                    mbox = new MessageDialog(StorageHelper.ErrorMessages.GetString("BulbNotFound_Voice"), "Bulb Not Found");
                }
                catch (ColorNotFoundException)
                {
                    mbox = new MessageDialog(StorageHelper.ErrorMessages.GetString("ColourNotFound_Voice"), "Colour Not Found");
                }
            }
            break;

            default:
                break;
            }

            if (mbox != null)
            {
                await mbox.ShowAsync();
            }

            if (StorageHelper.LocalSettings.HasFlag(Settings.CloseOnVoiceCommand))
            {
                App.Current.Exit();
            }
            else
            {
                Frame rootFrame = new Frame();
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                Window.Current.Content = rootFrame;
                rootFrame.Navigate(typeof(MainPage), uri);
            }
        }