private static void DetermineWorkloads()
        {
            BatteryStatus     batteryStatus   = PowerManager.BatteryStatus;
            int               remainingCharge = PowerManager.RemainingChargePercent;
            PowerSupplyStatus powerStatus     = PowerManager.PowerSupplyStatus;
            PowerSourceKind   powerSource     = PowerManager.PowerSourceKind;

            if ((powerSource == PowerSourceKind.DC &&
                 batteryStatus == BatteryStatus.Discharging &&
                 remainingCharge < 25) ||
                (powerSource == PowerSourceKind.AC &&
                 powerStatus == PowerSupplyStatus.Inadequate))
            {
                // The device is not in a good battery/power state,
                // so we should pause any non-critical work.
                PauseNonCriticalWork();
            }
            else if ((batteryStatus != BatteryStatus.Discharging && remainingCharge > 75) &&
                     powerStatus != PowerSupplyStatus.Inadequate)
            {
                // The device is in good battery/power state,
                // so let's kick of some high-power work.
                StartPowerIntensiveWork();
            }
        }
        private static void PowerManager_PowerSupplyStatusChanged(object sender, object e)
        {
            PowerSupplyStatus powerStatus = PowerManager.PowerSupplyStatus;

            OutputMessage($"Power supply status changed: {powerStatus}");
            DetermineWorkloads();
        }
Exemple #3
0
            string _serial_number;                          // The best approximation of the battery serial number

            public BatteryStateMsg(JSONNode msg)
            {
                _header                  = new std_msgs.HeaderMsg(msg["header"]);
                _voltage                 = msg["voltage"].AsFloat;
                _current                 = msg["current"].AsFloat;
                _charge                  = msg["charge"].AsFloat;
                _capacity                = msg["capacity"].AsFloat;
                _design_capacity         = msg["design_capacity"].AsFloat;
                _percentage              = msg["percentage"].AsFloat;
                _power_supply_status     = (PowerSupplyStatus)msg["power_supply_status"].AsInt;
                _power_supply_health     = (PowerSupplyHealth)msg["power_supply_health"].AsInt;
                _power_supply_technology = (PowerSupplyTechnology)msg["power_supply_technology"].AsInt;
                _present                 = msg["present"].AsBool;

                JSONArray cell_voltages_temp = msg["cell_voltage"].AsArray;

                _cell_voltage = new float[cell_voltages_temp.Count];
                for (int i = 0; i < _cell_voltage.Length; i++)
                {
                    _cell_voltage[i] = cell_voltages_temp[i].AsFloat;
                }

                _location      = msg["location"].Value;
                _serial_number = msg["serial_number"].Value;
            }
        public void pwrIcon(PowerSupplyStatus status)
        {
            switch (status)
            {
            case PowerSupplyStatus.Inadequate:
                //strPowerLineStatus = "Device is running on battery";
                //pwrStateIcon.Text = $"";
                break;

            case PowerSupplyStatus.Adequate:
                //strPowerLineStatus = "Device is plugged in";
                //pwrStateIcon.Text = $"";
                break;

            case PowerSupplyStatus.NotPresent:
                //strPowerLineStatus = "Power Status: Unknown";
                //pwrStateIcon.Text = $"";
                break;
            }
        }
Exemple #5
0
        public void pwrIcon(PowerSupplyStatus status)
        {
            switch (status)
            {
            case PowerSupplyStatus.Inadequate:
                Debug.WriteLine("PowerSupply inadequete.");
                //strPowerLineStatus = "Device is running on battery";
                //pwrStateIcon.Text = $"";
                break;

            case PowerSupplyStatus.Adequate:
                Debug.WriteLine("PowerSupply adequete.");
                //strPowerLineStatus = "Device is plugged in";
                //pwrStateIcon.Text = $"";
                break;

            case PowerSupplyStatus.NotPresent:
                Debug.WriteLine("There should be zero reasons you're seeing this.");
                //strPowerLineStatus = "Power Status: Unknown";
                //pwrStateIcon.Text = $"";
                break;
            }
        }