34
34
35
35
static Q_LOGGING_CATEGORY (CLASS_LC, " hw.dev.BQ27441" );
36
36
37
- BQ27441::BQ27441 (InterruptHandler *interruptHandler, const QString &i2cDevice, int i2cDeviceId, QObject *parent)
38
- : BatteryFuelGauge(" BQ27441 battery fuel gauge" , parent),
37
+ BQ27441::BQ27441 (InterruptHandler *interruptHandler, int capacity, const QString &i2cDevice, int i2cDeviceId,
38
+ QObject *parent)
39
+ : BatteryFuelGauge(" BQ27441 battery fuel gauge" , capacity, parent),
39
40
m_i2cDevice(i2cDevice),
40
41
m_i2cDeviceId(i2cDeviceId),
41
42
m_i2cFd(0 ) {
42
43
Q_ASSERT (interruptHandler);
43
44
Q_ASSERT (!i2cDevice.isEmpty ());
44
- qCDebug (CLASS_LC ()) << name () << i2cDevice << " with id:" << i2cDeviceId;
45
+ qCDebug (CLASS_LC ()) << name () << i2cDevice << " with id:" << i2cDeviceId << " , capacity: " << capacity ;
45
46
46
47
connect (interruptHandler, &InterruptHandler::interruptEvent, this , [&](int event) {
47
48
if (event == InterruptHandler::BATTERY) {
@@ -63,7 +64,7 @@ bool BQ27441::open() {
63
64
64
65
/* Initialize I2C */
65
66
bool initialized = false ;
66
- m_i2cFd = wiringPiI2CSetupInterface (qPrintable (m_i2cDevice), m_i2cDeviceId);
67
+ m_i2cFd = wiringPiI2CSetupInterface (qPrintable (m_i2cDevice), m_i2cDeviceId);
67
68
if (m_i2cFd == -1 ) {
68
69
qCCritical (CLASS_LC) << " Unable to open or select I2C device" << m_i2cDeviceId << " on" << m_i2cDevice;
69
70
} else {
@@ -96,23 +97,23 @@ const QLoggingCategory &BQ27441::logCategory() const { return CLASS_LC(); }
96
97
97
98
void BQ27441::updateBatteryValues () {
98
99
if (getDesignCapacity () != m_capacity) {
99
- qCDebug (CLASS_LC) << " Design capacity does not match." ;
100
-
101
100
// calibrate the gauge
102
- qCDebug (CLASS_LC) << " Fuel gauge calibration. Setting charge capacity to:" << m_capacity;
101
+ qCDebug (CLASS_LC) << " Design capacity does not match. Fuel gauge calibration. Setting charge capacity to:"
102
+ << m_capacity;
103
103
changeCapacity (m_capacity);
104
104
}
105
105
106
106
m_level = getStateOfCharge ();
107
107
emit levelChanged ();
108
- qCDebug (CLASS_LC ()) << " Battery level:" << m_level;
109
108
110
109
m_voltage = wiringPiI2CReadReg16 (m_i2cFd, BQ27441_COMMAND_VOLTAGE); // getVoltage();
111
- qCDebug (CLASS_LC ()) << " Battery voltage:" << m_voltage;
112
110
113
111
m_health = getStateOfHealth ();
112
+ if (CLASS_LC ().isDebugEnabled ()) {
113
+ qCDebug (CLASS_LC ()) << " Battery level:" << m_level << " %, battery voltage:" << m_voltage
114
+ << " mV, battery health:" << m_health;
115
+ }
114
116
emit healthChanged ();
115
- qCDebug (CLASS_LC ()) << " Battery health:" << m_health;
116
117
117
118
m_averagePower = static_cast <int >(
118
119
static_cast <int16_t >(wiringPiI2CReadReg16 (m_i2cFd, BQ27441_COMMAND_AVG_POWER))); // getAveragePower();
@@ -154,12 +155,13 @@ void BQ27441::updateBatteryValues() {
154
155
155
156
// calculate remaining battery life
156
157
float remainingLife = static_cast <float >(getRemainingCapacity ()) / static_cast <float >(abs (getAverageCurrent ()));
157
- m_remainingLife = (m_remainingLife + remainingLife) / 2 ;
158
+ m_remainingLife = (m_remainingLife + remainingLife) / 2 ;
158
159
emit remainingLifeChanged ();
159
160
160
- qCDebug (CLASS_LC ()) << " Average power" << m_averagePower << " mW" ;
161
- qCDebug (CLASS_LC ()) << " Average current" << getAverageCurrent () << " mA" ;
162
- qCDebug (CLASS_LC ()) << " Remaining battery life" << m_remainingLife << " h" ;
161
+ if (CLASS_LC ().isDebugEnabled ()) {
162
+ qCDebug (CLASS_LC ()) << " Average power" << m_averagePower << " mW, average current" << getAverageCurrent ()
163
+ << " mA, remaining battery life" << m_remainingLife << " h" ;
164
+ }
163
165
}
164
166
165
167
void BQ27441::begin () {
0 commit comments