@@ -265,58 +265,53 @@ int8_t nicla::getBatteryPercentage(bool useLatchedValue) {
265
265
}
266
266
267
267
uint8_t nicla::getBatteryChargeLevel () {
268
- return getBatteryStatus () & BATTERY_CHARGE_MASK;
269
- }
270
-
271
- uint8_t nicla::getBatteryStatus () {
272
268
auto percent = getBatteryPercentage ();
273
- int res = BATTERY_UNKNOWN;
274
269
275
270
if (percent >= 98 ) {
276
- res = BATTERY_FULL;
271
+ return BATTERY_FULL;
277
272
} else if (percent >= 94 ){
278
- res = BATTERY_ALMOST_FULL;
273
+ return BATTERY_ALMOST_FULL;
279
274
} else if (percent >= 90 ){
280
- res = BATTERY_HALF;
275
+ return BATTERY_HALF;
281
276
} else if (percent >= 86 ){
282
- res = BATTERY_ALMOST_EMPTY;
277
+ return BATTERY_ALMOST_EMPTY;
283
278
} else if (percent < 86 && percent > 0 ) {
284
279
// < 84% is considered empty
285
- res = BATTERY_EMPTY;
286
- }
287
-
288
- if (_ntcEnabled) {
289
- // Extract bits 5 and 6 (TS_FAULT0 and TS_FAULT1)
290
- uint8_t temperatureSenseFault = _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_TS_CONTROL) >> 5 & 0b11 ;
291
-
292
- /*
293
- +------+-------------------------------------------------------------+
294
- | Bits | Description |
295
- +------+-------------------------------------------------------------+
296
- | 00 | Normal, No TS fault |
297
- | 01 | TS temp < TCOLD or TS temp > THOT (Charging suspended) |
298
- | 10 | TCOOL > TS temp > TCOLD (Charging current reduced by half) |
299
- | 11 | TWARM < TS temp < THOT (Charging voltage reduced by 140 mV) |
300
- +------+-------------------------------------------------------------+
301
- */
302
-
303
- if (temperatureSenseFault == 0 ){
304
- res |= BATTERY_TEMPERATURE_NORMAL;
305
- } else if (temperatureSenseFault == 1 ) {
306
- res |= BATTERY_TEMPERATURE_EXTREME;
307
- } else if (temperatureSenseFault == 2 ) {
308
- res |= BATTERY_TEMPERTURE_COOL;
309
- } else if (temperatureSenseFault == 3 ) {
310
- res |= BATTERY_TEMPERTURE_WARM;
311
- }
280
+ return BATTERY_EMPTY;
281
+ } else {
282
+ // Battery status could not be read
283
+ return BATTERY_UNKNOWN;
312
284
}
313
-
314
- return res;
315
285
}
316
286
317
287
uint8_t nicla::getBatteryTemperature () {
318
288
if (!_ntcEnabled) return BATTERY_TEMPERATURE_NORMAL;
319
- return getBatteryStatus () & BATTERY_TEMPERATURE_MASK;
289
+
290
+ // Extract bits 5 and 6 (TS_FAULT0 and TS_FAULT1)
291
+ uint8_t temperatureSenseFault = _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_TS_CONTROL) >> 5 & 0b11 ;
292
+
293
+ /*
294
+ +------+-------------------------------------------------------------+
295
+ | Bits | Description |
296
+ +------+-------------------------------------------------------------+
297
+ | 00 | Normal, No TS fault |
298
+ | 01 | TS temp < TCOLD or TS temp > THOT (Charging suspended) |
299
+ | 10 | TCOOL > TS temp > TCOLD (Charging current reduced by half) |
300
+ | 11 | TWARM < TS temp < THOT (Charging voltage reduced by 140 mV) |
301
+ +------+-------------------------------------------------------------+
302
+ */
303
+
304
+ if (temperatureSenseFault == 0 ){
305
+ return BATTERY_TEMPERATURE_NORMAL;
306
+ } else if (temperatureSenseFault == 1 ) {
307
+ return BATTERY_TEMPERATURE_EXTREME;
308
+ } else if (temperatureSenseFault == 2 ) {
309
+ return BATTERY_TEMPERTURE_COOL;
310
+ } else if (temperatureSenseFault == 3 ) {
311
+ return BATTERY_TEMPERTURE_WARM;
312
+ }
313
+
314
+ return BATTERY_TEMPERATURE_NORMAL;
320
315
}
321
316
322
317
0 commit comments