Skip to content

Commit 36333e8

Browse files
committed
nicla-system: Replace battery temperature with enum.
1 parent 9b9c616 commit 36333e8

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

libraries/Nicla_System/examples/NiclaSenseME_BatteryStatus/NiclaSenseME_BatteryStatus.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ bool updateBatteryLevel(bool enforceNewReading = false) {
4545
return false;
4646
}
4747

48-
String getBatteryTemperatureDescription(int status) {
48+
String getBatteryTemperatureDescription(BatteryTemperature status) {
4949
switch (status) {
50-
case BATTERY_TEMPERATURE_NORMAL:
50+
case BatteryTemperature::Normal:
5151
return "Normal";
52-
case BATTERY_TEMPERATURE_EXTREME:
52+
case BatteryTemperature::Extreme:
5353
return "Extreme";
54-
case BATTERY_TEMPERTURE_COOL:
54+
case BatteryTemperature::Cool:
5555
return "Cool";
56-
case BATTERY_TEMPERTURE_WARM:
56+
case BatteryTemperature::Warm:
5757
return "Warm";
5858
default:
5959
return "Unknown";

libraries/Nicla_System/src/Nicla_System.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ enum class BatteryChargeLevel {
2828
};
2929

3030
// 2 bits are used to indicate the battery temperature
31-
#define BATTERY_TEMPERATURE_MASK 0b00011000
32-
#define BATTERY_TEMPERATURE_NORMAL (0 << 4)
33-
#define BATTERY_TEMPERATURE_EXTREME (1 << 4)
34-
#define BATTERY_TEMPERTURE_COOL (2 << 4)
35-
#define BATTERY_TEMPERTURE_WARM (3 << 4)
31+
enum class BatteryTemperature {
32+
Normal = 0b00,
33+
Extreme = 0b01,
34+
Cool = 0b10,
35+
Warm = 0b11
36+
};
3637

3738
class nicla {
3839

@@ -111,10 +112,10 @@ class nicla {
111112
* @note If the battery doesn't have a negative temperature coefficient (NTC) thermistor, the temperature is always "Normal".
112113
* This is not determined automatically and needs to be set using the setBatteryNTCEnabled() function.
113114
* @see setBatteryNTCEnabled()
114-
* @return uint8_t The battery temperature represented by one of the following constants:
115-
* BATTERY_TEMPERATURE_NORMAL, BATTERY_TEMPERATURE_EXTREME, BATTERY_TEMPERTURE_COOL, BATTERY_TEMPERTURE_WARM
115+
* @return BatteryTemperature The battery temperature represented by one of the following constants:
116+
* BatteryTemperature::Normal, BatteryTemperature::Extreme, BatteryTemperature::Cool, BatteryTemperature::Warm
116117
*/
117-
static uint8_t getBatteryTemperature();
118+
static BatteryTemperature getBatteryTemperature();
118119

119120
/**
120121
* @brief Returns potential battery faults retrieved from the fault register.

0 commit comments

Comments
 (0)