Skip to content

Commit 7e5e789

Browse files
committed
nicla-system: Add function to check if board runs on battery.
1 parent a7e10f6 commit 7e5e789

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

libraries/Nicla_System/examples/NiclaSenseME_BatteryStatus/NiclaSenseME_BatteryStatus.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ void loop()
222222
bool isCharging = nicla::getOperatingStatus() == OperatingStatus::Charging;
223223
Serial.print("Battery is charging: ");
224224
Serial.println(isCharging ? "Yes" : "No");
225+
226+
bool runsOnBattery = nicla::runsOnBattery();
227+
Serial.print("Runs on battery: ");
228+
Serial.println(runsOnBattery ? "Yes" : "No");
229+
225230

226231
Serial.println("----------------------");
227232
}

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ bool nicla::enableCharging(uint16_t mA, bool disableNtc)
153153
return _pmic.getFastChargeControlRegister() == _fastChargeRegisterData;
154154
}
155155

156+
bool nicla::runsOnBattery() {
157+
return _pmic.runsOnBattery(BQ25120A_ADDRESS);
158+
}
159+
156160
uint8_t nicla::getBatteryFaults() {
157161
// Skips the mask bits (4 LSBs)
158162
return (_pmic.getFaultsRegister() >> 4) & 0b1111;

libraries/Nicla_System/src/Nicla_System.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class nicla {
6161
*/
6262
static bool enableCharging(uint16_t mA = 20, bool disableNtc = true);
6363

64+
/**
65+
* @brief Determines if the board is charged from the battery.
66+
*
67+
* @return true If the board is powered from the battery. False, when powered from USB / VIN.
68+
*/
69+
static bool runsOnBattery();
70+
6471
/**
6572
* @brief Enables or disables the negative temperature coefficient (NTC) thermistor.
6673
* NTCs are used to prevent the batteries from being charged at temperatures that are too high or too low.

0 commit comments

Comments
 (0)