Example #1
0
void Plugin::handlePlatformStarted ()
{
    connect (PL_,
             SIGNAL (batteryInfoUpdated (Liznoo::BatteryInfo)),
             this,
             SLOT (handleBatteryInfo (Liznoo::BatteryInfo)));

    QTimer *timer = new QTimer (this);
    connect (timer,
             SIGNAL (timeout ()),
             this,
             SLOT (handleUpdateHistory ()));
    timer->start (3000);
}
Example #2
0
	void PlatformWinAPI::handleBatteryStateChanged (int newPercentage)
	{
		//TODO(DZhon): Rewrite using Win32_Battery WMI Class.

		qDebug() << tr ("New battery state detected") << ": [" << newPercentage << "]";

		SYSTEM_POWER_STATUS powerStatus;
		BOOL retCode = GetSystemPowerStatus (&powerStatus);

		Q_ASSERT (retCode);

		BatteryInfo info;		

		info.TimeToEmpty_ = powerStatus.BatteryLifeTime;
		info.Percentage_ = newPercentage;

		emit batteryInfoUpdated (info);
	}
Example #3
0
	void DBusConnector::requeryDevice (const QString& id)
	{
		QDBusInterface face ("org.freedesktop.UPower",
				id,
				"org.freedesktop.UPower.Device",
				SB_);
		if (face.property ("Type").toInt () != 2)
			return;

		BatteryInfo info;
		info.ID_ = id;
		info.Percentage_ = face.property ("Percentage").toInt ();
		info.TimeToFull_ = face.property ("TimeToFull").toLongLong ();
		info.TimeToEmpty_ = face.property ("TimeToEmpty").toLongLong ();
		info.Voltage_ = face.property ("Voltage").toDouble ();
		info.Energy_ = face.property ("Energy").toDouble ();
		info.EnergyFull_ = face.property ("EnergyFull").toDouble ();
		info.DesignEnergyFull_ = face.property ("EnergyFullDesign").toDouble ();
		info.EnergyRate_ = face.property ("EnergyRate").toDouble ();
		info.Technology_ = TechIdToString (face.property ("Technology").toInt ());
		info.Temperature_ = 0;

		emit batteryInfoUpdated (info);
	}
Example #4
0
	void FreeBSDPlatform::update ()
	{
		int batteries = 0;
		if (!ACPIfd_)
			return;

		ioctl (ACPIfd_, ACPIIO_BATT_GET_UNITS, &batteries);
		for (int i = 0; i < batteries; i++)
		{
			acpi_battery_ioctl_arg arg;
			BatteryInfo info;
			int units = 0, capacity = 0, designCapacity = 0, percentage = 0, rate = 0, voltage = 0, remaining_time = 0;
			bool valid = false;
			arg.unit = i;
			if (ioctl (ACPIfd_, ACPIIO_BATT_GET_BIF, &arg) >= 0)
			{
				info.ID_ = QString("%1 %2 %3")
								.arg (arg.bif.model)
								.arg (arg.bif.serial)
								.arg (arg.bif.oeminfo);
				info.Technology_ = arg.bif.type;
				units = arg.bif.units;
				capacity = arg.bif.lfcap;
				designCapacity = arg.bif.dcap;
			}
			arg.unit = i;
			if (ioctl (ACPIfd_, ACPIIO_BATT_GET_BATTINFO, &arg) >= 0)
			{
				percentage = arg.battinfo.cap;
				rate = arg.battinfo.rate;
				remaining_time = arg.battinfo.min * 60;
			}
			arg.unit = i;
			if (ioctl (ACPIfd_, ACPIIO_BATT_GET_BST, &arg) >= 0)
			{
				voltage = arg.bst.volt;
				if ((arg.bst.state & ACPI_BATT_STAT_INVALID) != ACPI_BATT_STAT_INVALID &&
					arg.bst.state != ACPI_BATT_STAT_NOT_PRESENT)
					valid = true;
			}

			info.Percentage_ = percentage;
			info.Voltage_ = voltage / 1000.0;
			info.EnergyRate_ = rate / 1000.0;
			info.EnergyFull_ = capacity / 1000.0;
			info.DesignEnergyFull_ = designCapacity / 1000.0;
			if (units == ACPI_BIF_UNITS_MA)
			{
				info.EnergyRate_ *= info.Voltage_;
				info.EnergyFull_ *= info.Voltage_;
				info.DesignEnergyFull_ *= info.Voltage_;
			}

			info.Energy_ = info.EnergyFull_ * percentage / 100;

			if (valid)
			{
				if ((arg.bst.state & ACPI_BATT_STAT_DISCHARG) != 0)
				{
					info.TimeToFull_ = 0;
					info.TimeToEmpty_ = remaining_time;
				}
				else if ((arg.bst.state & ACPI_BATT_STAT_CHARGING) != 0)
				{
					info.TimeToEmpty_ = 0;
					info.TimeToFull_ = (info.EnergyFull_ - info.Energy_) / info.EnergyRate_ * 3600;
				}
				emit batteryInfoUpdated (info);
			}
		}
	}