Beispiel #1
0
        private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("InvalidRequest"))
            {
                rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage);
            }

            else if (e.PropertyName.Equals("InvalidPin"))
            {
                rootPage.NotifyUser("Invalid password, access denied!", NotifyType.ErrorMessage);
            }

            // process ARGB Value
            if (e.PropertyName.Equals("Value"))
            {
                byte[] newColor = rootPage.Ble.lightBulbService.LightBulbColor.argb;
                rootPage.NotifyUser($"New color received: {newColor[0]} {newColor[1]} {newColor[2]} {newColor[3]}", NotifyType.StatusMessage);

                //initial check already in the characteristic, assuming [A R G B] here
                lightBulbBrush.Color = Windows.UI.Color.FromArgb(newColor[0], newColor[1], newColor[2], newColor[3]);
                LightBulb.ARGB(lightBulbBrush);
            }

            // password protected special scenario received
            else if (e.PropertyName.Equals("SpecialValue"))
            {
                byte specialEffects = rootPage.Ble.lightBulbService.LightBulbColor.specialEffectsScenario;
                rootPage.NotifyUser($"Correct PIN, new special effects scenario received: {specialEffects}", NotifyType.StatusMessage);

                //initial check already in the characteristic, assuming [A R G B] here
                if (specialEffects == 0x01)
                {
                    //Green
                    lightBulbBrush.Color = Windows.UI.Color.FromArgb(0xFF, 0x00, 0xFF, 0x00);
                    LightBulb.ARGB(lightBulbBrush);

                    //TextToSpeech.AutoPlay = true;
                    VoiceCongrats.SetSource(speechStream, speechStream.ContentType);
                    VoiceCongrats.Play();
                    // play Rick after the voice congrats finishes
                    VoiceCongrats.MediaEnded += RickRoll;

                    rootPage.NotifyCorrect(scenarioName);
                    Solved.Visibility       = Visibility.Visible;
                    ShowValidPin.Visibility = Visibility.Visible;
                    LightBulb.Checked(true);
                }
                else
                {
                    LightBulb.Off();
                    LightBulb.Checked(false);
                    Rick.Stop();
                    Rick.Visibility = Visibility.Collapsed;
                    colorTicker.Stop();
                }
            }
        }
Beispiel #2
0
        private void RickRoll(object Sender, RoutedEventArgs e)
        {
            Rick.Visibility = Visibility.Visible;
            Rick.Play();
            LightBulb.Checked(false);

            colorTicker          = new DispatcherTimer();
            colorTicker.Tick    += UpdateColor;
            colorTicker.Interval = new TimeSpan(0, 0, 0, 0, 250); // 4 x per second
            colorTicker.Start();
        }
Beispiel #3
0
        private void ServiceTTS_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("InvalidRequest"))
            {
                rootPage.NotifyUser("Invalid request! Did you send write command?", NotifyType.ErrorMessage);
            }

            //new characteristic value received
            if (e.PropertyName.Equals("Value"))
            {
                Debug.WriteLine($"Lightbulb service received from : {sender}");

                byte[] receivedWrite;
                CryptographicBuffer.CopyToByteArray(rootPage.Ble.lightBulbService.LightBulbTTS.Value, out receivedWrite);
                String receivedText = System.Text.Encoding.UTF8.GetString(receivedWrite);

                Debug.WriteLine($"TTS received value: {receivedText}");
                //remove excessive characters
                receivedText = Regex.Replace(receivedText, @"[^a-zA-Z0-9 -]", "");
                Debug.WriteLine($"TTS received value after removing special characters: {receivedText}");

                if (receivedText.Length == 0)
                {
                    rootPage.NotifyUser("Received TTS request, but no readable text value", NotifyType.ErrorMessage);
                }
                else
                {
                    var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => GenerateTTS(receivedText));
                    if (receivedText.StartsWith("Hello", StringComparison.OrdinalIgnoreCase))
                    {
                        if (isSolved == false)
                        {
                            isSolved = true;
                            rootPage.NotifyCorrect(scenarioName);
                            Solved.Visibility = Visibility.Visible;
                            LightBulb.Checked(true);
                        }
                    }
                    else
                    {
                        rootPage.NotifyUser($"Received TTS text: {receivedText}. How about saying hello?", NotifyType.StatusMessage);
                    }
                }
            }
        }
        private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("InvalidRequest"))
            {
                rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage);
            }

            else if (e.PropertyName.Equals("BlinkPassed"))
            {
                rootPage.NotifyCorrect(scenarioName);
                Solved.Visibility = Visibility.Visible;
                LightBulb.Checked(true);
                isSolved = true;
            }

            //new characteristic value received
            else if (e.PropertyName.Equals("Value"))
            {
                String receivedWrite = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value);

                // notify of every write until solved, otherwise it will overwrite the "congratulations" notification
                if (!isSolved)
                {
                    rootPage.NotifyUser("Write received: " + receivedWrite, NotifyType.StatusMessage);
                }

                if (receivedWrite.Equals("01"))
                {
                    LightBulb.On();
                }
                else if (receivedWrite.Equals("00"))
                {
                    LightBulb.Off();
                }
            }
        }