Esempio n. 1
0
        public void HandleLuisResult(LuisResult result)
        {
            if (!result.Intents.Any())
            {
                return;
            }

            switch (result.Intents.First().Name)
            {
            case "ControlLED":

                if (result.Entities.Any(a => a.Key == "LedState"))
                {
                    string ledState = result.Entities.First(a => a.Key == "LedState").Value.First().Value;

                    if (ledState == "on")
                    {
                        if (result.Entities.Any(a => a.Key == "LedColor"))
                        {
                            string ledColor = result.Entities.First(a => a.Key == "LedColor").Value.First().Value;

                            SayAsync($"Turning on the {ledColor} light.");

                            switch (ledColor)
                            {
                            case "red":
                                _rgbLed.TurnOnLed(LedStatus.Red);
                                break;

                            case "green":
                                _rgbLed.TurnOnLed(LedStatus.Green);
                                break;

                            case "blue":
                                _rgbLed.TurnOnLed(LedStatus.Blue);
                                break;

                            case "purple":
                                _rgbLed.TurnOnLed(LedStatus.Purple);
                                break;
                            }
                        }
                    }
                    else if (ledState == "off")
                    {
                        SayAsync("Turning the light off.");
                        _rgbLed.TurnOffLed();
                    }
                }
                break;
            }
        }
Esempio n. 2
0
        private void DoDisco(object source, ElapsedEventArgs e)
        {
            Array     values    = Enum.GetValues(typeof(LedStatus));
            Random    random    = new Random();
            LedStatus randomBar = (LedStatus)values.GetValue(random.Next(values.Length - 1));

            _rgbLed.TurnOnLed(randomBar);
        }
Esempio n. 3
0
        private async void ProcessCurrentVideoFrame(ThreadPoolTimer timer)
        {
            if (_mediaCapture.CameraStreamState != Windows.Media.Devices.CameraStreamState.Streaming || !_frameProcessingSemaphore.Wait(0))
            {
                return;
            }

            if (!_motion)
            {
                Debug.WriteLine("No motion detected.");
                _frameProcessingSemaphore.Release();
                return;
            }

            try
            {
                var stream = new InMemoryRandomAccessStream();
                await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                MemoryStream memStream = await ConvertFromInMemoryRandomAccessStream(stream);

                Face[] result = await _faceServiceClient.DetectAsync(memStream, false, false, new[] { FaceAttributeType.Emotion });

                string displayText = $"{result.Length} faces found | {DateTime.Now.ToLongTimeString()}";

                if (result.Any())
                {
                    List <EmotionResult> emotions = new List <EmotionResult>
                    {
                        new EmotionResult()
                        {
                            Name = "Anger", Score = result.First().FaceAttributes.Emotion.Anger, LedStatus = LedStatus.Red
                        },
                        new EmotionResult()
                        {
                            Name = "Happiness", Score = result.First().FaceAttributes.Emotion.Happiness, LedStatus = LedStatus.Green
                        },
                        new EmotionResult()
                        {
                            Name = "Neutral", Score = result.First().FaceAttributes.Emotion.Neutral, LedStatus = LedStatus.Blue
                        }
                    };

                    displayText += string.Join(", ", emotions.Select(a => $"{a.Name}: {(a.Score * 100.0f).ToString("#0.00")}"));

                    _rgbLed.TurnOnLed(emotions.OrderByDescending(a => a.Score).First().LedStatus);
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusText.Text = displayText);

                Debug.WriteLine(displayText);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception with ProcessCurrentVideoFrame: " + ex);
            }
            finally
            {
                _frameProcessingSemaphore.Release();
            }
        }