void Initialize() { onboardLed = new RgbPwmLed(device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue, 3.3f, 3.3f, 3.3f, Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); onboardLed.StartPulse(Color.Red); analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); displayController = new WeatherView(); Device.InitWiFiAdapter().Wait(); onboardLed.StartPulse(Color.Blue); var result = Device.WiFiAdapter.Connect(Secrets.WIFI_NAME, Secrets.WIFI_PASSWORD); if (result.ConnectionStatus != ConnectionStatus.Success) { throw new Exception($"Cannot connect to network: {result.ConnectionStatus}"); } onboardLed.StartPulse(Color.Green); }
private static void CreateDailyView(List <Weather> weatherList, HashSet <IGrouping <DateTime, Weather> > uniqueDates, List <WeatherView> weatherViewList) { Parallel.ForEach(uniqueDates, (date) => { WeatherView indoorView = new WeatherView(); WeatherView outdoorView = new WeatherView(); indoorView.Date = date.Key; indoorView.Location = "Inne"; indoorView.WeatherList = weatherList.Where(d => d.Date.Date.Equals(date.Key) && d.Location.Contains("Inne")).ToList(); outdoorView.Date = date.Key; outdoorView.Location = "Ute"; outdoorView.WeatherList = weatherList.Where(d => d.Date.Date.Equals(date.Key) && d.Location.Contains("Ute")).ToList(); //Calculate Average and mould risk indoorView.AverageHumidity = indoorView.WeatherList.Average(t => t.Humidity); indoorView.AverageTemperature = indoorView.WeatherList.Average(t => t.Temperature); indoorView.MouldRisk = CalculateMouldRisk(indoorView); outdoorView.AverageHumidity = outdoorView.WeatherList.Average(t => t.Humidity); outdoorView.AverageTemperature = outdoorView.WeatherList.Average(t => t.Temperature); outdoorView.MouldRisk = CalculateMouldRisk(outdoorView); weatherViewList.Add(indoorView); weatherViewList.Add(outdoorView); }); }
public IEnumerable <string> Handle(string input, Match match, IListener listener) { var weather = new Weather(); WeatherView.Create(weather); yield return(weather.ToString()); }
private async Task Resume() { // Save index before update int index = TextForecastControl.SelectedIndex; // Check pin tile status CheckTiles(); if (wLoader.GetWeather()?.IsValid() == true) { Weather weather = wLoader.GetWeather(); // Update weather if needed on resume if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(location, this, this); await RefreshWeather(false); } else { // Check weather data expiration if (!int.TryParse(weather.ttl, out int ttl)) { ttl = Settings.DefaultInterval; } TimeSpan span = DateTimeOffset.Now - weather.update_time; if (span.TotalMinutes > ttl) { await RefreshWeather(false); } else { WeatherView.UpdateView(wLoader.GetWeather()); Shell.Instance.HamburgerButtonColor = WeatherView.PendingBackgroundColor; if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { // Mobile StatusBar.GetForCurrentView().BackgroundColor = WeatherView.PendingBackgroundColor; } else { // Desktop var titlebar = ApplicationView.GetForCurrentView().TitleBar; titlebar.BackgroundColor = WeatherView.PendingBackgroundColor; titlebar.ButtonBackgroundColor = titlebar.BackgroundColor; } } } } // Set saved index from before update // Note: needed since ItemSource is cleared and index is reset if (index == 0) // Note: UWP Mobile Bug { TextForecastControl.SelectedIndex = index + 1; } TextForecastControl.SelectedIndex = index; }
private void CreateWeatherView() { if (weatherView == null) { weatherView = new WeatherView(); weatherView.UpdateStatus += weatherView_UpdateStatus; panelsGrid.Children.Add(weatherView); weatherView.UpdateLayout(); } }
public override void Init(IModule module) { base.Init(module); viewScript = InstantiateView <WeatherView>(path); _weatherController = new WeatherController(); _weatherController.WeatherView = (WeatherView)viewScript; RegisterView(viewScript); RegisterController(_weatherController); _weatherController.Start(); }
private void t_Tick_fade(object sender, EventArgs e) { if (this.Opacity < 0.01) { tn.Enabled = false; WeatherView wt = new WeatherView(); wt.Show(); wt.startFadeinTimer(); this.Close(); } this.Opacity -= 0.05; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var weatherView = new WeatherView(); var weatherPresenter = new WeatherPresenter(); weatherView.Presenter = weatherPresenter; weatherPresenter.View = weatherView; Application.Run(weatherView); }
private static void UsingWebRequest() { //var request = new HttpWebRequest() // var url = "https://randomuser.me/api/"; var cityname = "London"; var url_info = $"http://api.openweathermap.org/data/2.5/forecast?q={cityname}&units=metric&appid=744ef013a49f618d4320751b1af097a8"; var request = WebRequest.CreateHttp(url_info); var responce = request.GetResponse(); var stream = responce.GetResponseStream(); var sr = new StreamReader(stream); var data = sr.ReadToEnd(); var user = JsonConvert.DeserializeObject <WeatherRoot>(data); w = new WeatherView() { currentweather = new WeatherDay() { Temperature = user.list.FirstOrDefault().main.temp } }; //Console.WriteLine($"City: { user.city.name }"); //Console.WriteLine($"Clouds: { user.list.FirstOrDefault().clouds.all }"); //Console.WriteLine($"Visibility: { user.list.FirstOrDefault().visibility }"); //Console.WriteLine($"Visibility: { user.list.FirstOrDefault().weather.FirstOrDefault().description }"); //Console.WriteLine($"Dt_txt: { user.list.FirstOrDefault().dt_txt }"); //Console.WriteLine($"Temp: { user.list.FirstOrDefault().main.temp }"); var info = user.list.FirstOrDefault().weather.FirstOrDefault().icon; //var picturename = "03d.png"; var picturename = info + ".png"; var url_image = $"http://openweathermap.org/img/wn/{picturename}";//[email protected] WebClient webClient = new WebClient(); var data_picture = webClient.DownloadData(url_image); var temp = url_image.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var filename = temp[temp.Count() - 1]; File.WriteAllBytes(filename, data_picture); }
void Initialize() { onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); displayController = new WeatherView(); onboardLed.StartPulse(Color.Green); }
/* * return the model object "WeatherDays" */ public WeatherDays getThatList(WeatherView weather) { WeatherDays weatherStruct = new WeatherDays(); List <double> newList = new List <double>(); newList.Add(Convert.ToDouble(weather.january)); newList.Add(Convert.ToDouble(weather.february)); newList.Add(Convert.ToDouble(weather.march)); newList.Add(Convert.ToDouble(weather.april)); newList.Add(Convert.ToDouble(weather.may)); newList.Add(Convert.ToDouble(weather.june)); newList.Add(Convert.ToDouble(weather.july)); newList.Add(Convert.ToDouble(weather.august)); newList.Add(Convert.ToDouble(weather.september)); newList.Add(Convert.ToDouble(weather.october)); newList.Add(Convert.ToDouble(weather.november)); newList.Add(Convert.ToDouble(weather.december)); weatherStruct.setDays(newList); weatherStruct.setFeature(weather.feature); return(weatherStruct); }
public void OnWeatherLoaded(LocationData location, Weather weather) { // Save index before update int index = TextForecastControl.SelectedIndex; if (weather?.IsValid() == true) { wm.UpdateWeather(weather); WeatherView.UpdateView(weather); if (wm.SupportsAlerts) { if (weather.weather_alerts != null && weather.weather_alerts.Count > 0) { // Alerts are posted to the user here. Set them as notified. Task.Run(async() => { await WeatherAlertHandler.SetasNotified(location, weather.weather_alerts); }); } // Show/Hide Alert panel if (WeatherView.Extras.Alerts.Count > 0) { FrameworkElement alertButton = AlertButton; if (alertButton == null) { alertButton = FindName(nameof(AlertButton)) as FrameworkElement; } ResizeAlertPanel(); alertButton.Visibility = Visibility.Visible; } else { FrameworkElement alertButton = AlertButton; if (alertButton != null) { alertButton.Visibility = Visibility.Collapsed; } } } else { FrameworkElement alertButton = AlertButton; if (alertButton != null) { alertButton.Visibility = Visibility.Collapsed; } } // Update home tile if it hasn't been already if (Settings.HomeData.Equals(location) && (TimeSpan.FromTicks(DateTime.Now.Ticks - Settings.UpdateTime.Ticks).TotalMinutes > Settings.RefreshInterval) || !WeatherTileCreator.TileUpdated) { Task.Run(async() => await WeatherUpdateBackgroundTask.RequestAppTrigger()); } else if (SecondaryTileUtils.Exists(location.query)) { WeatherTileCreator.TileUpdater(location, weather); } // Shell Shell.Instance.HamburgerButtonColor = WeatherView.PendingBackgroundColor; if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { // Mobile StatusBar.GetForCurrentView().BackgroundColor = WeatherView.PendingBackgroundColor; } else { // Desktop var titlebar = ApplicationView.GetForCurrentView().TitleBar; titlebar.BackgroundColor = WeatherView.PendingBackgroundColor; titlebar.ButtonBackgroundColor = titlebar.BackgroundColor; } } // Set saved index from before update // Note: needed since ItemSource is cleared and index is reset if (index == 0) // Note: UWP Mobile Bug { TextForecastControl.SelectedIndex = index + 1; } TextForecastControl.SelectedIndex = index; if (WeatherView.Extras.HourlyForecast.Count >= 1) { HourlyForecastPanel.Visibility = Visibility.Visible; } else { HourlyForecastPanel.Visibility = Visibility.Collapsed; } if (WeatherView.Extras.TextForecast.Count >= 1) { ForecastSwitch.Visibility = Visibility.Visible; } else { ForecastSwitch.Visibility = Visibility.Collapsed; } if (!String.IsNullOrWhiteSpace(WeatherView.Extras.Chance)) { if (!Settings.API.Equals(WeatherAPI.MetNo)) { if (!DetailsWrapGrid.Children.Contains(PrecipitationPanel)) { DetailsWrapGrid.Children.Insert(0, PrecipitationPanel); ResizeDetailItems(); } PrecipitationPanel.Visibility = Visibility.Visible; } else { DetailsWrapGrid.Children.Remove(PrecipitationPanel); ResizeDetailItems(); } int precipCount = PrecipitationPanel.Children.Count; int atmosCount = AtmospherePanel.Children.Count; if (Settings.API.Equals(WeatherAPI.OpenWeatherMap) || Settings.API.Equals(WeatherAPI.MetNo)) { if (ChanceItem != null) { PrecipitationPanel.Children.Remove(ChanceItem); } FrameworkElement cloudinessItem = CloudinessItem; if (cloudinessItem == null) { cloudinessItem = FindName(nameof(CloudinessItem)) as FrameworkElement; } if (cloudinessItem != null && !AtmospherePanel.Children.Contains(cloudinessItem)) { AtmospherePanel.Children.Insert(2, cloudinessItem); } } else { FrameworkElement chanceItem = ChanceItem; if (chanceItem == null) { chanceItem = FindName(nameof(ChanceItem)) as FrameworkElement; } if (chanceItem != null && !PrecipitationPanel.Children.Contains(chanceItem)) { PrecipitationPanel.Children.Insert(2, chanceItem); } if (CloudinessItem != null) { AtmospherePanel.Children.Remove(CloudinessItem); } } if (precipCount != PrecipitationPanel.Children.Count || atmosCount != AtmospherePanel.Children.Count) { ResizeDetailItems(); } } else { DetailsWrapGrid.Children.Remove(PrecipitationPanel); if (CloudinessItem != null) { AtmospherePanel.Children.Remove(CloudinessItem); } ResizeDetailItems(); } LoadingRing.IsActive = false; }
public App() { // The root page of your application MainPage = new WeatherView(); }
/// <summary> /// Sets the weather control /// </summary> /// <param name="weather">The current weather</param> private void SetWeatherControl(WeatherMainModel weather) { Dispatcher.Invoke(() => WeatherView.SetWeather(weather)); }
private static double CalculateMouldRisk(WeatherView view) { return((view.AverageHumidity - 78) * (view.AverageTemperature / 15) / 0.22); }