3434
3535static Q_LOGGING_CATEGORY (CLASS_LC, " hw.dev.BQ27441" );
3636
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),
3940 m_i2cDevice(i2cDevice),
4041 m_i2cDeviceId(i2cDeviceId),
4142 m_i2cFd(0 ) {
4243 Q_ASSERT (interruptHandler);
4344 Q_ASSERT (!i2cDevice.isEmpty ());
44- qCDebug (CLASS_LC ()) << name () << i2cDevice << " with id:" << i2cDeviceId;
45+ qCDebug (CLASS_LC ()) << name () << i2cDevice << " with id:" << i2cDeviceId << " , capacity: " << capacity ;
4546
4647 connect (interruptHandler, &InterruptHandler::interruptEvent, this , [&](int event) {
4748 if (event == InterruptHandler::BATTERY) {
@@ -63,7 +64,7 @@ bool BQ27441::open() {
6364
6465 /* Initialize I2C */
6566 bool initialized = false ;
66- m_i2cFd = wiringPiI2CSetupInterface (qPrintable (m_i2cDevice), m_i2cDeviceId);
67+ m_i2cFd = wiringPiI2CSetupInterface (qPrintable (m_i2cDevice), m_i2cDeviceId);
6768 if (m_i2cFd == -1 ) {
6869 qCCritical (CLASS_LC) << " Unable to open or select I2C device" << m_i2cDeviceId << " on" << m_i2cDevice;
6970 } else {
@@ -96,23 +97,23 @@ const QLoggingCategory &BQ27441::logCategory() const { return CLASS_LC(); }
9697
9798void BQ27441::updateBatteryValues () {
9899 if (getDesignCapacity () != m_capacity) {
99- qCDebug (CLASS_LC) << " Design capacity does not match." ;
100-
101100 // 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;
103103 changeCapacity (m_capacity);
104104 }
105105
106106 m_level = getStateOfCharge ();
107107 emit levelChanged ();
108- qCDebug (CLASS_LC ()) << " Battery level:" << m_level;
109108
110109 m_voltage = wiringPiI2CReadReg16 (m_i2cFd, BQ27441_COMMAND_VOLTAGE); // getVoltage();
111- qCDebug (CLASS_LC ()) << " Battery voltage:" << m_voltage;
112110
113111 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+ }
114116 emit healthChanged ();
115- qCDebug (CLASS_LC ()) << " Battery health:" << m_health;
116117
117118 m_averagePower = static_cast <int >(
118119 static_cast <int16_t >(wiringPiI2CReadReg16 (m_i2cFd, BQ27441_COMMAND_AVG_POWER))); // getAveragePower();
@@ -154,12 +155,13 @@ void BQ27441::updateBatteryValues() {
154155
155156 // calculate remaining battery life
156157 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 ;
158159 emit remainingLifeChanged ();
159160
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+ }
163165}
164166
165167void BQ27441::begin () {
0 commit comments