File indexing completed on 2024-05-12 04:01:50
0001 /* 0002 SPDX-FileCopyrightText: 2006-2007 Kevin Ottens <ervin@kde.org> 0003 SPDX-FileCopyrightText: 2012 Lukas Tinkl <ltinkl@redhat.com> 0004 SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef SOLID_BATTERY_H 0010 #define SOLID_BATTERY_H 0011 0012 #include <solid/solid_export.h> 0013 0014 #include <solid/deviceinterface.h> 0015 0016 namespace Solid 0017 { 0018 class BatteryPrivate; 0019 class Device; 0020 0021 /** 0022 * This device interface is available on batteries. 0023 */ 0024 class SOLID_EXPORT Battery : public DeviceInterface 0025 { 0026 Q_OBJECT 0027 Q_PROPERTY(bool present READ isPresent NOTIFY presentStateChanged) 0028 Q_PROPERTY(BatteryType type READ type CONSTANT) 0029 Q_PROPERTY(int chargePercent READ chargePercent NOTIFY chargePercentChanged) 0030 Q_PROPERTY(int capacity READ capacity NOTIFY capacityChanged) 0031 Q_PROPERTY(bool rechargeable READ isRechargeable CONSTANT) 0032 Q_PROPERTY(bool powerSupply READ isPowerSupply NOTIFY powerSupplyStateChanged) 0033 Q_PROPERTY(ChargeState chargeState READ chargeState NOTIFY chargeStateChanged) 0034 Q_PROPERTY(qlonglong timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged) 0035 Q_PROPERTY(qlonglong timeToFull READ timeToFull NOTIFY timeToFullChanged) 0036 Q_PROPERTY(double energy READ energy NOTIFY energyChanged) 0037 Q_PROPERTY(double energyFull READ energyFull NOTIFY energyFullChanged) 0038 Q_PROPERTY(double energyFullDesign READ energyFullDesign NOTIFY energyFullDesignChanged) 0039 Q_PROPERTY(double energyRate READ energyRate NOTIFY energyRateChanged) 0040 Q_PROPERTY(double voltage READ voltage NOTIFY voltageChanged) 0041 Q_PROPERTY(double temperature READ temperature NOTIFY temperatureChanged) 0042 Q_PROPERTY(Technology technology READ technology CONSTANT) 0043 Q_PROPERTY(QString serial READ serial CONSTANT) 0044 Q_PROPERTY(qlonglong remainingTime READ remainingTime NOTIFY remainingTimeChanged) 0045 Q_DECLARE_PRIVATE(Battery) 0046 friend class Device; 0047 0048 public: 0049 /** 0050 * This enum type defines the type of the device holding the battery 0051 * 0052 * - PdaBattery : A battery in a Personal Digital Assistant 0053 * - UpsBattery : A battery in an Uninterruptible Power Supply 0054 * - PrimaryBattery : A primary battery for the system (for example laptop battery) 0055 * - MouseBattery : A battery in a mouse 0056 * - KeyboardBattery : A battery in a keyboard 0057 * - KeyboardMouseBattery : A battery in a combined keyboard and mouse 0058 * - CameraBattery : A battery in a camera 0059 * - PhoneBattery : A battery in a phone 0060 * - MonitorBattery : A battery in a monitor 0061 * - GamingInputBattery : A battery in a gaming input device (for example a wireless game pad) 0062 * - BluetoothBattery: A generic Bluetooth device battery (if its type isn't known, a Bluetooth 0063 * mouse would normally show up as a MouseBattery), @since 5.54 0064 * - TabletBattery : A battery in a graphics tablet or pen, @since 5.88 0065 * - HeadphoneBattery : A battery in a headphone, @since 6.0 0066 * - HeadsetBattery : A battery in a headset, @since 6.0 0067 * - TouchpadBattery : A battery in a touchpad. This is how the Dualsense Wireless Controller is categorized @since 6.0 0068 * - UnknownBattery : A battery in an unknown device 0069 */ 0070 enum BatteryType { 0071 UnknownBattery, 0072 PdaBattery, 0073 UpsBattery, 0074 PrimaryBattery, 0075 MouseBattery, 0076 KeyboardBattery, 0077 KeyboardMouseBattery, 0078 CameraBattery, 0079 PhoneBattery, 0080 MonitorBattery, 0081 GamingInputBattery, 0082 BluetoothBattery, 0083 TabletBattery, 0084 HeadphoneBattery, 0085 HeadsetBattery, 0086 TouchpadBattery, 0087 }; 0088 Q_ENUM(BatteryType) 0089 0090 /** 0091 * This enum type defines charge state of a battery 0092 * 0093 * - NoCharge : Battery charge is stable, not charging or discharging or 0094 * the state is Unknown 0095 * - Charging : Battery is charging 0096 * - Discharging : Battery is discharging 0097 * - FullyCharged: The battery is fully charged; a battery not necessarily 0098 * charges up to 100% 0099 */ 0100 enum ChargeState { NoCharge, Charging, Discharging, FullyCharged }; 0101 Q_ENUM(ChargeState) 0102 0103 /** 0104 * Technology used in the battery 0105 * 0106 * 0: Unknown 0107 * 1: Lithium ion 0108 * 2: Lithium polymer 0109 * 3: Lithium iron phosphate 0110 * 4: Lead acid 0111 * 5: Nickel cadmium 0112 * 6: Nickel metal hydride 0113 */ 0114 enum Technology { 0115 UnknownTechnology = 0, 0116 LithiumIon, 0117 LithiumPolymer, 0118 LithiumIronPhosphate, 0119 LeadAcid, 0120 NickelCadmium, 0121 NickelMetalHydride, 0122 }; 0123 Q_ENUM(Technology) 0124 0125 private: 0126 /** 0127 * Creates a new Battery object. 0128 * You generally won't need this. It's created when necessary using 0129 * Device::as(). 0130 * 0131 * @param backendObject the device interface object provided by the backend 0132 * @see Solid::Device::as() 0133 */ 0134 SOLID_NO_EXPORT explicit Battery(QObject *backendObject); 0135 0136 public: 0137 /** 0138 * Destroys a Battery object. 0139 */ 0140 ~Battery() override; 0141 0142 /** 0143 * Get the Solid::DeviceInterface::Type of the Battery device interface. 0144 * 0145 * @return the Battery device interface type 0146 * @see Solid::DeviceInterface::Type 0147 */ 0148 static Type deviceInterfaceType() 0149 { 0150 return DeviceInterface::Battery; 0151 } 0152 0153 /** 0154 * Indicates if this battery is currently present in its bay. 0155 * 0156 * @return true if the battery is present, false otherwise 0157 */ 0158 bool isPresent() const; 0159 0160 /** 0161 * Retrieves the type of device holding this battery. 0162 * 0163 * @return the type of device holding this battery 0164 * @see Solid::Battery::BatteryType 0165 */ 0166 Solid::Battery::BatteryType type() const; 0167 0168 /** 0169 * Retrieves the current charge level of the battery normalised 0170 * to percent. 0171 * 0172 * @return the current charge level normalised to percent 0173 */ 0174 int chargePercent() const; 0175 0176 /** 0177 * Retrieves the battery capacity normalised to percent, 0178 * meaning how much energy can it hold compared to what it is designed to. 0179 * The capacity of the battery will reduce with age. 0180 * A capacity value less than 75% is usually a sign that you should renew your battery. 0181 * 0182 * @since 4.11 0183 * @return the battery capacity normalised to percent 0184 */ 0185 int capacity() const; 0186 0187 /** 0188 * Indicates if the battery is rechargeable. 0189 * 0190 * @return true if the battery is rechargeable, false otherwise (one time usage) 0191 */ 0192 bool isRechargeable() const; 0193 0194 /** 0195 * Indicates if the battery is powering the machine. 0196 * 0197 * @return true if the battery is powersupply, false otherwise 0198 */ 0199 bool isPowerSupply() const; 0200 0201 /** 0202 * Retrieves the current charge state of the battery. It can be in a stable 0203 * state (no charge), charging or discharging. 0204 * 0205 * @return the current battery charge state 0206 * @see Solid::Battery::ChargeState 0207 */ 0208 Solid::Battery::ChargeState chargeState() const; 0209 0210 /** 0211 * Time (in seconds) until the battery is empty. 0212 * 0213 * @return time until the battery is empty 0214 * @since 5.0 0215 */ 0216 qlonglong timeToEmpty() const; 0217 0218 /** 0219 * Time (in seconds) until the battery is full. 0220 * 0221 * @return time until the battery is full 0222 * @since 5.0 0223 */ 0224 qlonglong timeToFull() const; 0225 0226 /** 0227 * Retrieves the technology used to manufacture the battery. 0228 * 0229 * @return the battery technology 0230 * @see Solid::Battery::Technology 0231 */ 0232 Solid::Battery::Technology technology() const; 0233 0234 /** 0235 * Amount of energy (measured in Wh) currently available in the power source. 0236 * 0237 * @return amount of battery energy in Wh 0238 */ 0239 double energy() const; 0240 0241 /** 0242 * Amount of energy (measured in Wh) the battery has when it is full. 0243 * 0244 * @return amount of battery energy when full in Wh 0245 * @since 5.7 0246 */ 0247 double energyFull() const; 0248 0249 /** 0250 * Amount of energy (measured in Wh) the battery should have by design hen it is full. 0251 * 0252 * @return amount of battery energy when full by design in Wh 0253 * @since 5.7 0254 */ 0255 double energyFullDesign() const; 0256 0257 /** 0258 * Amount of energy being drained from the source, measured in W. 0259 * If positive, the source is being discharged, if negative it's being charged. 0260 * 0261 * @return battery rate in Watts 0262 * 0263 */ 0264 double energyRate() const; 0265 0266 /** 0267 * Voltage in the Cell or being recorded by the meter. 0268 * 0269 * @return voltage in Volts 0270 */ 0271 double voltage() const; 0272 0273 /** 0274 * The temperature of the battery in degrees Celsius. 0275 * 0276 * @return the battery temperature in degrees Celsius 0277 * @since 5.0 0278 */ 0279 double temperature() const; 0280 0281 /** 0282 * The serial number of the battery 0283 * 0284 * @return the serial number of the battery 0285 * @since 5.0 0286 */ 0287 QString serial() const; 0288 0289 /** 0290 * Retrieves the current estimated remaining time of the system batteries 0291 * 0292 * @return the current global estimated remaining time in seconds 0293 * @since 5.8 0294 */ 0295 qlonglong remainingTime() const; 0296 0297 Q_SIGNALS: 0298 /** 0299 * This signal is emitted if the battery gets plugged in/out of the 0300 * battery bay. 0301 * 0302 * @param newState the new plugging state of the battery, type is boolean 0303 * @param udi the UDI of the battery with thew new plugging state 0304 */ 0305 void presentStateChanged(bool newState, const QString &udi); 0306 0307 /** 0308 * This signal is emitted when the charge percent value of this 0309 * battery has changed. 0310 * 0311 * @param value the new charge percent value of the battery 0312 * @param udi the UDI of the battery with the new charge percent 0313 */ 0314 void chargePercentChanged(int value, const QString &udi); 0315 0316 /** 0317 * This signal is emitted when the capacity of this battery has changed. 0318 * 0319 * @param value the new capacity of the battery 0320 * @param udi the UDI of the battery with the new capacity 0321 * @since 4.11 0322 */ 0323 void capacityChanged(int value, const QString &udi); 0324 0325 /** 0326 * This signal is emitted when the power supply state of the battery 0327 * changes. 0328 * 0329 * @param newState the new power supply state, type is boolean 0330 * @param udi the UDI of the battery with the new power supply state 0331 * @since 4.11 0332 */ 0333 void powerSupplyStateChanged(bool newState, const QString &udi); 0334 0335 /** 0336 * This signal is emitted when the charge state of this battery 0337 * has changed. 0338 * 0339 * @param newState the new charge state of the battery, it's one of 0340 * the type Solid::Battery::ChargeState 0341 * @see Solid::Battery::ChargeState 0342 * @param udi the UDI of the battery with the new charge state 0343 */ 0344 void chargeStateChanged(int newState, const QString &udi = QString()); 0345 0346 /** 0347 * This signal is emitted when the time until the battery is empty 0348 * has changed. 0349 * 0350 * @param time the new remaining time 0351 * @param udi the UDI of the battery with the new remaining time 0352 * @since 5.0 0353 */ 0354 void timeToEmptyChanged(qlonglong time, const QString &udi); 0355 0356 /** 0357 * This signal is emitted when the time until the battery is full 0358 * has changed. 0359 * 0360 * @param time the new remaining time 0361 * @param udi the UDI of the battery with the new remaining time 0362 * @since 5.0 0363 */ 0364 void timeToFullChanged(qlonglong time, const QString &udi); 0365 0366 /** 0367 * This signal is emitted when the energy value of this 0368 * battery has changed. 0369 * 0370 * @param energy the new energy value of the battery 0371 * @param udi the UDI of the battery with the new energy value 0372 */ 0373 void energyChanged(double energy, const QString &udi); 0374 0375 /** 0376 * This signal is emitted when the energy full value of this 0377 * battery has changed. 0378 * 0379 * @param energy the new energy full value of the battery 0380 * @param udi the UDI of the battery with the new energy full value 0381 */ 0382 void energyFullChanged(double energy, const QString &udi); 0383 0384 /** 0385 * This signal is emitted when the energy full design value of this 0386 * battery has changed. 0387 * 0388 * @param energy the new energy full design value of the battery 0389 * @param udi the UDI of the battery with the new energy full design value 0390 */ 0391 void energyFullDesignChanged(double energy, const QString &udi); 0392 0393 /** 0394 * This signal is emitted when the energy rate value of this 0395 * battery has changed. 0396 * 0397 * If positive, the source is being discharged, if negative it's being charged. 0398 * 0399 * @param energyRate the new energy rate value of the battery 0400 * @param udi the UDI of the battery with the new charge percent 0401 */ 0402 void energyRateChanged(double energyRate, const QString &udi); 0403 0404 /** 0405 * This signal is emitted when the voltage in the cell has changed. 0406 * 0407 * @param voltage the new voltage of the cell 0408 * @param udi the UDI of the battery with the new voltage 0409 * @since 5.0 0410 */ 0411 void voltageChanged(double voltage, const QString &udi); 0412 0413 /** 0414 * This signal is emitted when the battery temperature has changed. 0415 * 0416 * @param temperature the new temperature of the battery in degrees Celsius 0417 * @param udi the UDI of the battery with the new temperature 0418 * @since 5.0 0419 */ 0420 void temperatureChanged(double temperature, const QString &udi); 0421 0422 /** 0423 * This signal is emitted when the estimated battery remaining time changes. 0424 * 0425 * @param time the new remaining time 0426 * @param udi the UDI of the battery with the new remaining time 0427 * @since 5.8 0428 */ 0429 void remainingTimeChanged(qlonglong time, const QString &udi); 0430 }; 0431 } 0432 0433 #endif