Esempio n. 1
0
        private async void Timer_Tick(object sender, object e)
        {
            try
            {
                //emotion api calling
                float humidity    = BMP280.GetHumidity();
                float temperature = BMP280.GetTemperature();

                Scores scores = await client.RecognizeAsync(Person[PersonIndex]);

                HappyModel model = new HappyModel(Store[StoreIndex].StoreName, temperature, humidity,
                                                  Store[StoreIndex].Longitude.ToString(),
                                                  Store[StoreIndex].Latitude.ToString(),
                                                  scores);

                DisplayModel(model);

                //Image setting
                Image       img         = sender as Image;
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(Person[PersonIndex]);

                imgPerson.Source = bitmapImage;


                //Map Setting
                Windows.Devices.Geolocation.BasicGeoposition geo = new Windows.Devices.Geolocation.BasicGeoposition();
                geo.Latitude  = Store[StoreIndex].Latitude;
                geo.Longitude = Store[StoreIndex].Longitude;

                Windows.UI.Xaml.Controls.Maps.MapIcon icon = new Windows.UI.Xaml.Controls.Maps.MapIcon();
                icon.Location = new Windows.Devices.Geolocation.Geopoint(geo);
                icon.NormalizedAnchorPoint = new Point(1, 1);
                icon.Title = Store[StoreIndex].StoreName;

                mapStoreLocation.MapElements.Clear();
                mapStoreLocation.MapElements.Add(icon);

                await mapStoreLocation.TrySetViewAsync(new Windows.Devices.Geolocation.Geopoint(geo), 18, 0, 0, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow);

                //IoTHubProxy data sending
                try
                {
                    IoTProxy.SendMessage(model);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("IoTHub======" + ex.Message);
                }

                PersonIndex++;
                StoreIndex++;


                //Init index
                if (PersonIndex == Person.Count() - 1)
                {
                    PersonIndex = 0;
                }
                if (StoreIndex == Store.Count() - 1)
                {
                    StoreIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("System======" + ex.Message);
            }
        }