Beispiel #1
0
        public MainPage()
        {
            this.InitializeComponent();

            ranOnLaunchInternetTasks        = false;
            currentNetworkConnectivityLevel = NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel();
            Window.Current.Activated       += Current_Activated;

            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;

            string deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;

            if (deviceFamily.Contains("Mobile"))
            {
                device = Device.Mobile;
            }
            else if (deviceFamily.Contains("Desktop"))
            {
                device = Device.Desktop;
            }
            else
            {
                device = Device.Other;
            }

            mediaPlayer              = new MediaPlayer();
            mediaPlayer.MediaEnded  += MediaPlayer_MediaEnded;
            mediaPlayer.MediaFailed += MediaPlayer_MediaFailed;
            mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
            httpClient           = new HttpClient();
            appleMovieDownloader = new AppleMovieDownloader(httpClient);
            sunrise          = DateTime.MinValue;
            sunset           = DateTime.MinValue;
            lastPositions    = new Queue <TimeSpan>();
            SpotifyHelper    = new SpotifyHelper();
            HueHelper        = new HueHelper();
            AirQualityHelper = new AirQualityHelper();
            CalendarHelper   = new CalendarHelper();

            rotationBuffer = 0;
            lightMode      = LightMode.Brightness;

            if (device == Device.Desktop)
            {
                dial = RadialController.CreateForCurrentView();
                dial.RotationResolutionInDegrees = 5;
                dial.UseAutomaticHapticFeedback  = false;
                dialConfig            = RadialControllerConfiguration.GetForCurrentView();
                menuItems             = new List <RadialControllerMenuItem>();
                isWindowFocused       = true;
                dial.ButtonClicked   += Dial_ButtonClicked;
                dial.RotationChanged += Dial_RotationChanged;
                dial.ControlAcquired += Dial_ControlAcquired;
                dial.ControlLost     += Dial_ControlLost;
            }
        }
Beispiel #2
0
        public DataJsonModel GetCurrentDataJson(Guid deviceId)
        {
            var result       = new DataJsonModel();
            var measurements = MeasurementsForDeviceFromHours(deviceId, 24).OrderBy(o => o.InsertDate);
            var current      = measurements.FirstOrDefault();

            if (current != null)
            {
                result.Last_data = new LastDataJsonModel
                {
                    LastUpdate        = (int)current.InsertDate.Value.UtcDateTime.Subtract(DateTime.UnixEpoch).TotalSeconds,
                    HeaterHumidity    = current.HeaterHumidity,
                    HeaterTemperature = current.HeaterTemperature,
                    Humidity          = current.Humidity,
                    Pm10        = current.Pm10,
                    Pm25        = current.Pm25,
                    Pressure    = current.Pressure,
                    Temperature = current.Temperature
                };
            }
            var last1h = measurements.Where(w => w.InsertDate >= DateTimeOffset.Now.AddHours(-1));

            if (last1h.Any())
            {
                var index = AirQualityHelper.FindLevel(AirQualityHelper.PM10Thresholds1h, last1h.Average(a => a.Pm10));
                result.Average_1h = new AverageDataJsonModel
                {
                    Pm25              = last1h.Average(a => a.Pm25),
                    Pm10              = last1h.Average(a => a.Pm10),
                    Temperature       = last1h.Average(a => a.Temperature),
                    Pressure          = last1h.Average(a => a.Pressure),
                    Humidity          = last1h.Average(a => a.Humidity),
                    HeaterTemperature = last1h.Average(a => a.HeaterTemperature),
                    HeaterHumidity    = last1h.Average(a => a.HeaterHumidity),
                    Index             = index.Name,
                    IndexNum          = index.Index
                };
            }
            if (measurements.Any())
            {
                var index = AirQualityHelper.FindLevel(AirQualityHelper.PM10Thresholds24h, measurements.Average(a => a.Pm10));
                result.Average_24h = new AverageDataJsonModel
                {
                    Pm25              = measurements.Average(a => a.Pm25),
                    Pm10              = measurements.Average(a => a.Pm10),
                    Temperature       = measurements.Average(a => a.Temperature),
                    Pressure          = measurements.Average(a => a.Pressure),
                    Humidity          = measurements.Average(a => a.Humidity),
                    HeaterTemperature = measurements.Average(a => a.HeaterTemperature),
                    HeaterHumidity    = measurements.Average(a => a.HeaterHumidity),
                    Index             = index.Name,
                    IndexNum          = index.Index
                };
            }
            return(result);
        }
Beispiel #3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            GeolocationAccessStatus accessStatus = await Geolocator.RequestAccessAsync();

            await RunOnLaunchInternetTasks();

            await HueHelper.Setup();

            if (device == Device.Desktop)
            {
                BuildDialMenu();
            }
            Task refreshLightStatus        = HueHelper.RefreshStatus();
            Task updateClockTask           = UpdateClockUI();
            Task checkFrozenVideo          = CheckFrozenVideo();
            Task processRotationBufferTask = ProcessRotationBuffer();

            _ = AirQualityHelper.Run();
            _ = CalendarHelper.Run();

            base.OnNavigatedTo(e);
        }