private void UpdateBatteryImage() { Single batteryLevel = BatteryMonitor.GetBatteryLevel(); Boolean flag = BatteryMonitor.IsBatteryCharging(); if (batteryLevel < 0.02f) { this.batteryImage.sprite = this.battery1Sprite; } else if (batteryLevel < 0.1f) { this.batteryImage.sprite = this.battery10Sprite; } else if (batteryLevel < 0.2f) { this.batteryImage.sprite = this.battery20Sprite; } else if (batteryLevel < 0.3f) { this.batteryImage.sprite = this.battery30Sprite; } else if (batteryLevel < 0.4f) { this.batteryImage.sprite = this.battery40Sprite; } else if (batteryLevel < 0.5f) { this.batteryImage.sprite = this.battery50Sprite; } else if (batteryLevel < 0.6f) { this.batteryImage.sprite = this.battery60Sprite; } else if (batteryLevel < 0.7f) { this.batteryImage.sprite = this.battery70Sprite; } else if (batteryLevel < 0.8f) { this.batteryImage.sprite = this.battery80Sprite; } else if (batteryLevel < 0.9f) { this.batteryImage.sprite = this.battery90Sprite; } else { this.batteryImage.sprite = this.battery100Sprite; } if (flag) { this.batteryChargeImage.gameObject.SetActive(true); } else { this.batteryChargeImage.gameObject.SetActive(false); } }
public void EnableBatteryMonitor() { if (_batteryMonitor != null) { return; } _batteryMonitor = new BatteryMonitor(); _batteryMonitor.PropertyChanged += BatteryMonitorOnPropertyChanged; UpdateBatteryStatus(); }
public void DisableBatteryMonitor() { if (_batteryMonitor == null) { return; } _batteryMonitor.PropertyChanged -= BatteryMonitorOnPropertyChanged; _batteryMonitor.Stop(); _batteryMonitor = null; UpdateBatteryStatus(); }
public IEnumerable <TabletBatteryMonitorResponse> GetAverageTabletBatteryUsage(List <TabletBatteryMonitorRequest> metrics) { var result = new List <TabletBatteryMonitorResponse>(); if (metrics != null && metrics.Any()) { var batteryMonitor = new BatteryMonitor(); var filtered_metrics = batteryMonitor.Filter(metrics); foreach (var item in filtered_metrics) { if (item.Value.Count == 1) { result.Add(new TabletBatteryMonitorResponse(item.Key, "unknown")); continue; } item.Value.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp)); result.Add(new TabletBatteryMonitorResponse(item.Key, batteryMonitor.GetAverageForDevice(item.Value))); } } return(result); }
public static bool StartupProcess() { // Profile our initialization Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // Fire up our server if (!StartServer()) { if (!arg_replace) { Logger.Log.Error("Could not set up the listener for beagrep requests. " + "There is probably another beagrepd instance running. " + "Use --replace to replace the running service"); Environment.Exit(1); } ReplaceExisting(); } // Set up out-of-process indexing LuceneQueryable.IndexerHook = new LuceneQueryable.IndexerCreator(RemoteIndexer.NewRemoteIndexer); Config config = Conf.Get(Conf.Names.DaemonConfig); // Initialize synchronization to keep the indexes local if PathFinder.StorageDir // is on a non-block device, or if BEAGREP_SYNCHRONIZE_LOCALLY is set if ((!SystemInformation.IsPathOnBlockDevice(PathFinder.StorageDir) && config.GetOption(Conf.Names.IndexSynchronization, true)) || Environment.GetEnvironmentVariable("BEAGREP_SYNCHRONIZE_LOCALLY") != null) { IndexSynchronization.Initialize(); } // Start the query driver. Logger.Log.Debug("Starting QueryDriver"); QueryDriver.Start(); // Start our battery monitor so we can shut down the // scheduler if needed. BatteryMonitor.Init(); bool initially_on_battery = !BatteryMonitor.UsingAC && !config.GetOption(Conf.Names.IndexOnBattery, false); // Start the Global Scheduler thread if (!arg_disable_scheduler) { if (!initially_on_battery) { Logger.Log.Debug("Starting Scheduler thread"); Scheduler.Global.Start(); } else { Log.Debug("Beagrep started on battery, not starting scheduler thread"); } } // Start our Inotify threads Inotify.Start(); // Test if the FileAdvise stuff is working: This will print a // warning if not. The actual advice calls will fail silently. FileAdvise.TestAdvise(); #if ENABLE_AVAHI zeroconf = new Beagrep.Daemon.Network.Zeroconf(); #endif Conf.WatchForUpdates(); stopwatch.Stop(); Logger.Log.Debug("Daemon initialization finished after {0}", stopwatch); SystemInformation.LogMemoryUsage(); if (arg_indexing_test_mode) { Thread.Sleep(1000); // Ugly paranoia: wait a second for the backends to settle. Logger.Log.Debug("Running in indexing test mode"); Scheduler.Global.EmptyQueueEvent += OnEmptySchedulerQueue; Scheduler.Global.Add(null); // pulse the scheduler } return(false); }
public static Int32 GetBatteryPercent() { return((Int32)(100f * BatteryMonitor.GetBatteryLevel())); }