Ejemplo n.º 1
0
        void bulbItem_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (!powerStateTapped)
            {
                TextBlock bulbItem = e.OriginalSource as TextBlock;

                if (bulbItem != null)
                {
                    StorageHelper.SelectedBulb = StorageHelper.GetBulb(bulbItem.Text, true);
                    Frame.Navigate(typeof(MainPage), typeof(BulbSelector).ToString());
                }
            }
            else
            {
                powerStateTapped = false;
            }
        }
Ejemplo n.º 2
0
        async void Instance_PanControllerFound(object sender, LifxPanController e)
        {
            StorageHelper.StorePanController(e);

            foreach (LifxBulb bulb in e.Bulbs)
            {
                LifxLightStatusMessage lightstatusmessage = await StorageHelper.GetBulb(bulb.UID).GetLightStatusCommand();

                if (lightstatusmessage != null)
                {
                    StorageHelper.GetBulb(lightstatusmessage.ReceivedData.TargetMac).Label  = lightstatusmessage.Label;
                    StorageHelper.GetBulb(lightstatusmessage.ReceivedData.TargetMac).Tags   = lightstatusmessage.Tags;
                    StorageHelper.GetBulb(lightstatusmessage.ReceivedData.TargetMac).IsOn   = lightstatusmessage.PowerState;
                    StorageHelper.GetBulb(lightstatusmessage.ReceivedData.TargetMac).Colour = new LifxColour()
                    {
                        Hue        = lightstatusmessage.Hue,
                        Luminosity = lightstatusmessage.Lumnosity,
                        Saturation = lightstatusmessage.Saturation,
                        Kelvin     = lightstatusmessage.Kelvin
                    };

                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        NextPageButton.IsEnabled      = true;
                        LooksGoodTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        BulbListBox.Visibility        = Windows.UI.Xaml.Visibility.Visible;
                        BulbListBox.Items.Add(new ListBoxItem()
                        {
                            Content = (lightstatusmessage.Label + " - " + LifxHelper.ByteArrayToString(lightstatusmessage.ReceivedData.TargetMac)) as string
                        });
                    });
                }
            }

            StorageHelper.SaveToStorage();

            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                Helper.HideProgressIndicator();
            });
        }
Ejemplo n.º 3
0
        async void bulbPowerState_Tapped(object sender, TappedRoutedEventArgs e)
        {
            powerStateTapped = true;

            TextBlock powerTextBlock = sender as TextBlock;

            if (powerTextBlock != null)
            {
                LifxBulb bulb = StorageHelper.GetBulb(powerTextBlock.Tag as Byte[]);
                LIFX_Net.Messages.LifxPowerStateMessage psm = await bulb.SetPowerStateCommand(powerTextBlock.Text == LifxPowerState.On.ToString()?LifxPowerState.Off : LifxPowerState.On);

                powerTextBlock.Inlines.Clear();
                powerTextBlock.Inlines.Add(new Run()
                {
                    Text       = psm.PowerState.ToString(),
                    Foreground = psm.PowerState == LifxPowerState.On ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Gray)
                });

                bulb.IsOn = psm.PowerState;
                StorageHelper.SaveToStorage();
            }
        }
Ejemplo n.º 4
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);
            }
        }