17 #include <QDBusInterface>
25 const QString UPOWER_SERVICE = QStringLiteral("org.freedesktop.UPower");
26 const QString UPOWER_OBJECT = QStringLiteral("org.freedesktop.UPower.
Device");
31 std::string device_path = config.check(
"device_path",
32 Value(
"/org/freedesktop/UPower/devices/battery_BAT0"),
33 "Battery device path (as returned by 'upower -e', for example '/org/freedesktop/UPower/devices/battery_BAT0')").asString();
35 m_interface =
new QDBusInterface(UPOWER_SERVICE, QString(device_path.c_str()), UPOWER_OBJECT, QDBusConnection::systemBus());
36 if (!m_interface->isValid()) {
37 yCError(UPOWERBATTERY) <<
"Interface not found";
53 voltage = m_interface->property(
"Voltage").toDouble();
59 auto energyrate = m_interface->property(
"EnergyRate").toDouble();
60 auto voltage = m_interface->property(
"Voltage").toDouble();
61 auto state = m_interface->property(
"State").toUInt();
62 current = energyrate / voltage;
63 if (current > 0 && state == 1 ) {
71 charge = m_interface->property(
"Percentage").toInt();
78 auto st = m_interface->property(
"State").toUInt();
79 auto wl = m_interface->property(
"WarningLevel").toUInt();
82 case 1 : [[fallthrough]];
89 case 1 : [[fallthrough]];
96 case 4 : [[fallthrough]];
100 case 0 : [[fallthrough]];
111 case 0 : [[fallthrough]];
122 temperature = m_interface->property(
"Temperature").toDouble();
128 info = QStringLiteral(
"Vendor: %1, Model: %2, Serial: %3")
129 .arg(m_interface->property(
"Vendor").toString())
130 .arg(m_interface->property(
"Model").toString())
131 .arg(m_interface->property(
"Serial").toString())
133 yCDebug(UPOWERBATTERY) << info;
upowerBattery: A device to view the battery of a linux laptop in YARP using the yarp::dev::IBattery i...
bool getBatteryCurrent(double ¤t) override
Get the instantaneous current measurement.
bool getBatteryStatus(Battery_status &status) override
get the battery status
bool close() override
Close the DeviceDriver.
bool getBatteryTemperature(double &temperature) override
get the battery temperature
bool getBatteryCharge(double &charge) override
get the battery status of charge
bool getBatteryVoltage(double &voltage) override
Get the instantaneous voltage measurement.
bool getBatteryInfo(std::string &info) override
get the battery hardware characteristics (e.g.
@ BATTERY_CRITICAL_WARNING
A base class for nested structures that can be searched.
A single value (typically within a Bottle).
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
An interface to the operating system, including Port based communication.
yarp::robotinterface::Device Device
The main, catch-all namespace for YARP.