private async void GO_Click(object sender, RoutedEventArgs e) { //take a picture of the person giving the order var peopleIdentified = await TakePictureAndIdentifyAsync(); var result = await WebClientAccess.Order(CommandTextBox.Text); var pins = GetAuthorizedPins(result.Entity, peopleIdentified); foreach (var pin in pins) { switch (result.Intent) { case Intent.LightOn: pin.Write(GpioPinValue.Low); break; case Intent.LightOff: pin.Write(GpioPinValue.High); break; case Intent.None: default: break; } } CommandTextBox.Text = ""; CommandTextBox.Focus(FocusState.Keyboard); }
private async Task <IList <string> > TakePictureAndIdentifyAsync() { IList <string> peopleIdentified = new List <string>(); if (!isCameraInitialized) { await medCapture.InitializeAsync(); isCameraInitialized = true; } var imgFmt = ImageEncodingProperties.CreateJpeg(); var bmImage = new BitmapImage(); var fileName = Guid.NewGuid().ToString() + ".jpg"; var collisionOption = CreationCollisionOption.GenerateUniqueName; StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName, collisionOption); // captures and stores image file MessagesTextBox.Text = $"Taking picture\n"; await medCapture.CapturePhotoToStorageFileAsync(imgFmt, file); using (var strm = await file.OpenReadAsync()) { //start with clean list await bmImage.SetSourceAsync(strm); image.Source = bmImage; image.HorizontalAlignment = HorizontalAlignment.Center; strm.Seek(0); MessagesTextBox.Text = $"Sending pictue for detection\n"; peopleIdentified = await WebClientAccess.GetPeopleAsync(strm.AsStreamForRead()); } //delete image file await file.DeleteAsync(); return(peopleIdentified); }