Exemple #1
0
        public MainPage()
        {
            //Initialize all the things
            this.InitializeComponent();
            VoiceController.InitializeSpeechRecognizer();
            MirrorState.InitialMirrorState();
            _clockTimer            = new DispatcherTimer();
            _todaysWeatherTimer    = new DispatcherTimer();
            _tomorrowsWeatherTimer = new DispatcherTimer();
            _weeksWeatherTimer     = new DispatcherTimer();;
            _refreshRateTimer      = new DispatcherTimer();

            //Set the refresh rates on the timers
            _clockTimer.Interval            = TimeSpan.FromSeconds(ClockRefreshRate);
            _todaysWeatherTimer.Interval    = TimeSpan.FromSeconds(TodaysWeatherRefreshRate);
            _tomorrowsWeatherTimer.Interval = TimeSpan.FromHours(TomorrowsWeatherRefreshRate);
            _weeksWeatherTimer.Interval     = TimeSpan.FromHours(WeeksWeatherRefreshRate);
            _refreshRateTimer.Interval      = TimeSpan.FromMilliseconds(DisplayRefreshRate);

            //Set all the flags for updates to true at start
            _clockTicked            = true;
            _todaysWeatherTicked    = true;
            _tomorrowsWeatherTicked = true;
            _weeksWeatherTicked     = true;

            //Populate all weather information at the beginning
            WeatherLogic.UpdateTodaysWeather();
            WeatherLogic.UpdateTomorrowsWeather();
            WeatherLogic.UpdateThisWeeksWeather();

            //Start the program
            StartTimers();
            RefreshDisplay();
        }
Exemple #2
0
 private void UpdateTomorrowsWeatherDisplay()
 {
     WeatherLogic.UpdateTomorrowsWeather();
     if (MirrorState.IsConnectedToInternet())
     {
         TomorrowsWeatherLocationTextBlock.Text = WeatherLogic.GetCurrentLocation();
         TomorrowsWeatherLastUpdateDate.Text    = WeatherLogic.GetTomorrowsLastUpdateDay();
         Time6AM.Text                = WeatherLogic.Get6AMTime();
         Temp6AM.Text                = WeatherLogic.Get6AMTemp();
         Weather6AM.Source           = new BitmapImage(new Uri(WeatherLogic.Get6AMWeatherIcon()));
         Time9AM.Text                = WeatherLogic.Get9AMTime();
         Temp9AM.Text                = WeatherLogic.Get9AMTemp();
         Weather9AM.Source           = new BitmapImage(new Uri(WeatherLogic.Get9AMWeatherIcon()));
         Time12PM.Text               = WeatherLogic.Get12PMTime();
         Temp12PM.Text               = WeatherLogic.Get12PMTemp();
         Weather12PM.Source          = new BitmapImage(new Uri(WeatherLogic.Get12PMWeatherIcon()));
         Time3PM.Text                = WeatherLogic.Get3PMTime();
         Temp3PM.Text                = WeatherLogic.Get3PMTemp();
         Weather3PM.Source           = new BitmapImage(new Uri(WeatherLogic.Get3PMWeatherIcon()));
         Time6PM.Text                = WeatherLogic.Get6PMTime();
         Temp6PM.Text                = WeatherLogic.Get6PMTemp();
         Weather6PM.Source           = new BitmapImage(new Uri(WeatherLogic.Get6PMWeatherIcon()));
         Time9PM.Text                = WeatherLogic.Get9PMTime();
         Temp9PM.Text                = WeatherLogic.Get9PMTemp();
         Weather9PM.Source           = new BitmapImage(new Uri(WeatherLogic.Get9PMWeatherIcon()));
         TomorrowsHighTextBlock.Text = WeatherLogic.GetTomorrowsHighTemp();
         TomorrowsLowTextBlock.Text  = WeatherLogic.GetTomorrowsLowTemp();
     }
 }
Exemple #3
0
 private void UpdateWeeksWeatherForecastDisplay()
 {
     WeatherLogic.UpdateThisWeeksWeather();
     if (MirrorState.IsConnectedToInternet())
     {
         //WeeksWeatherLocationTextBlock.Text = WeatherLogic.GetCurrentLocation();
         ForecastDay1Date.Text      = WeatherLogic.GetDay1Date();
         ForecastDay1High.Text      = WeatherLogic.GetDay1HighTemp();
         ForecastDay1Low.Text       = WeatherLogic.GetDay1LowTemp();
         ForecastDay1Weather.Source = new BitmapImage(new Uri(WeatherLogic.GetDay1WeatherIcon()));
         ForecastDay2Date.Text      = WeatherLogic.GetDay2Date();
         ForecastDay2High.Text      = WeatherLogic.GetDay2HighTemp();
         ForecastDay2Low.Text       = WeatherLogic.GetDay2LowTemp();
         ForecastDay2Weather.Source = new BitmapImage(new Uri(WeatherLogic.GetDay2WeatherIcon()));
         ForecastDay3Date.Text      = WeatherLogic.GetDay3Date();
         ForecastDay3High.Text      = WeatherLogic.GetDay3HighTemp();
         ForecastDay3Low.Text       = WeatherLogic.GetDay3LowTemp();
         ForecastDay3Weather.Source = new BitmapImage(new Uri(WeatherLogic.GetDay3WeatherIcon()));
         ForecastDay4Date.Text      = WeatherLogic.GetDay4Date();
         ForecastDay4High.Text      = WeatherLogic.GetDay4HighTemp();
         ForecastDay4Low.Text       = WeatherLogic.GetDay4LowTemp();
         ForecastDay4Weather.Source = new BitmapImage(new Uri(WeatherLogic.GetDay4WeatherIcon()));
         ForecastDay5Date.Text      = WeatherLogic.GetDay5Date();
         ForecastDay5High.Text      = WeatherLogic.GetDay5HighTemp();
         ForecastDay5Low.Text       = WeatherLogic.GetDay5LowTemp();
         ForecastDay5Weather.Source = new BitmapImage(new Uri(WeatherLogic.GetDay5WeatherIcon()));
     }
 }
Exemple #4
0
 //Turn on the weather elements per MirrorState
 private void TurnOnWeather()
 {
     //If Main Weather display set to todays weather
     if (MirrorState.GetMainWeatherInfo().Equals(MirrorState.MAIN_WTHR_TODAY))
     {
         //Set todays weather visible and tomorrows weather collapsed
         TodaysWeather.Visibility    = Visibility.Visible;
         TomorrowsWeather.Visibility = Visibility.Collapsed;
     }
     //If Main Weather display set to tomorrows weather
     else
     {
         //Set todays weather collapsed and tomorrows weather visible
         TodaysWeather.Visibility    = Visibility.Collapsed;
         TomorrowsWeather.Visibility = Visibility.Visible;
     }
     //If the weeks weather is on
     if (MirrorState.IsWeeksWeatherOn())
     {
         //Set the weeks weather visible
         WeeksWeatherForecast.Visibility = Visibility.Visible;
     }
     //If the weeks weather is off
     else
     {
         //Set the weeks weather collapsed
         WeeksWeatherForecast.Visibility = Visibility.Collapsed;
     }
 }
 private static WeatherData ReadTodaysWeatherInformation()
 {
     try
     {
         //Request the JSON file from OpenWeatherMaps
         HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                             ($"http://api.openweathermap.org/data/2.5/weather?id=" + LocationCode + "&units=imperial&appID=6eeb0ae7137df453623bb2cb436db19a"));
         HttpClient client   = new HttpClient();
         var        response = client.SendAsync(request).Result;
         //Parse the object from the JSON and return it
         if (response.StatusCode == HttpStatusCode.OK)
         {
             var result = response.Content.ReadAsStringAsync().Result;
             var bytes  = Encoding.Unicode.GetBytes(result);
             using (MemoryStream stream = new MemoryStream(bytes))
             {
                 var serializer = new DataContractJsonSerializer(typeof(WeatherData));
                 var data       = (WeatherData)serializer.ReadObject(stream);
                 MirrorState.SetConnectedToInternet(true);
                 return(data);
             }
         }
         else
         {
             return(DefaultWeatherData());
         }
     }
     catch (Exception)
     {
         MirrorState.SetConnectedToInternet(false);
         return(null);
     }
 }
Exemple #6
0
 //------------------------------------------------------------------------------------------------
 //----------------------Modify XAML Elements For Each Weather Component---------------------------
 //------------------------------------------------------------------------------------------------
 private void UpdateTodaysWeatherDisplay()
 {
     WeatherLogic.UpdateTodaysWeather();
     if (MirrorState.IsConnectedToInternet())
     {
         TodaysWeatherTypeImage.Source       = new BitmapImage(new Uri(WeatherLogic.GetTodaysWeatherIcon()));
         TodaysWeatherLocationTextBlock.Text = WeatherLogic.GetCurrentLocation();
         TodaysWeatherTempTextBlock.Text     = WeatherLogic.GetTodaysTemperature();
         TodaysWeatherHiTempTextBlock.Text   = WeatherLogic.GetTodaysHiTemp();
         TodaysWeatherLowTempTextBlock.Text  = WeatherLogic.GetTodaysLowTemp();
         TodaysWeatherDate.Text = WeatherLogic.GetTodaysLastUpdateDay();
     }
 }
Exemple #7
0
        //Refresh all the display elements
        private void RefreshDisplay()
        {
            //Determine if the mirror is on or off and
            //adjust display elements accordingly
            if (MirrorState.IsMirrorOn())
            {
                ClockTxtBlock.Visibility = Visibility.Visible;
                if (MirrorState.IsWeatherOn() && MirrorState.IsConnectedToInternet())
                {
                    TurnOnWeather();
                }
            }
            else
            {
                ClockTxtBlock.Visibility = Visibility.Collapsed;
                TurnOffWeather();
            }

            if (!MirrorState.IsConnectedToInternet())
            {
                TurnOffWeather();
            }

            //Refresh each element if it ticked since last refresh
            //Refresh clock
            if (_clockTicked)
            {
                ClockTxtBlock.Text = DateTime.Now.ToString(@"h\:mm");
                _clockTicked       = false;
            }
            //Refresh today's weather
            if (_todaysWeatherTicked)
            {
                UpdateTodaysWeatherDisplay();
                _todaysWeatherTicked = false;
            }
            //Refresh tomorrow's weather
            if (_tomorrowsWeatherTicked)
            {
                UpdateTomorrowsWeatherDisplay();
                _tomorrowsWeatherTicked = false;
            }
            //Refresh the weeks weather forecast
            if (_weeksWeatherTicked)
            {
                UpdateWeeksWeatherForecastDisplay();
                _weeksWeatherTicked = false;
            }
        }
 //Logic to hide the appropriate weather element when a voice command is given
 private static void HideWeatherDisplay(string timeFrame)
 {
     if (timeFrame.Equals(WEATHER_WEEKS))
     {
         MirrorState.SetWeeksWeatherOn(false);
     }
     else if (timeFrame.Equals(WEATHER_TODAY))
     {
         MirrorState.SetWeatherOn(true);
     }
     else if (timeFrame.Equals(WEATHER_TOMORROW))
     {
         MirrorState.SetMainWeatherInfo(MirrorState.MAIN_WTHR_TODAY);
     }
     else
     {
         Debug.WriteLine("Unknown Time Frame for Show Weather command.");
     }
 }
        //Handle appropriate voice commands
        private static void RecognizerResultGenerated(SpeechContinuousRecognitionSession session,
                                                      SpeechContinuousRecognitionResultGeneratedEventArgs args)
        {
            // Output debug strings
            Debug.WriteLine(args.Result.Status);
            Debug.WriteLine(args.Result.Text);

            Debug.WriteLine(args.Result.Constraint.Tag);

            int count = args.Result.SemanticInterpretation.Properties.Count;

            Debug.WriteLine("Count: " + count);
            Debug.WriteLine("Tag: " + args.Result.Constraint.Tag);

            // Check for different tags and set variables for logic based on commands
            String target = args.Result.SemanticInterpretation.Properties.ContainsKey(TAG_TARGET)
                ? args.Result.SemanticInterpretation.Properties[TAG_TARGET][0].ToString()
                : "";

            String cmd = args.Result.SemanticInterpretation.Properties.ContainsKey(TAG_CMD)
                ? args.Result.SemanticInterpretation.Properties[TAG_CMD][0].ToString()
                : "";

            String timeFrame = args.Result.SemanticInterpretation.Properties.ContainsKey(TAG_TIME_FRAME)
                ? args.Result.SemanticInterpretation.Properties[TAG_TIME_FRAME][0].ToString()
                : "";

            //Logic based on what commands were said.
            //Turn Mirror On
            if (cmd.Equals(COMMAND_ON))
            {
                MirrorState.SetMirrorOn(true);
            }
            //Turn Mirror Off
            else if (cmd.Equals(COMMAND_OFF))
            {
                MirrorState.SetMirrorOn(false);
            }
            //Show Weather Element specified
            else if (cmd.Equals(COMMAND_SHOW))
            {
                if (target.Equals(TARGET_WEATHER))
                {
                    ShowWeatherDisplay(timeFrame);
                }
                else
                {
                    Debug.WriteLine("Invalid Target for 'Show' Command");
                }
            }
            //Hide weather element specified
            else if (cmd.Equals(COMMAND_HIDE))
            {
                if (target.Equals(TARGET_WEATHER))
                {
                    HideWeatherDisplay(timeFrame);
                }
                else
                {
                    Debug.WriteLine("Invalid Target for 'Show' Command");
                }
            }
            else
            {
                Debug.WriteLine("Unknown Voice Command");
            }
        }