@@ -34,6 +34,7 @@ class SensorBattery: public Sensor {
34
34
int8_t _battery_pin = -1 ;
35
35
float _battery_volts_per_bit = 0.003363075 ;
36
36
float _battery_adj_factor = 1.0 ;
37
+ bool _send_battery_level = true ;
37
38
38
39
public:
39
40
SensorBattery (uint8_t child_id = BATTERY_CHILD_ID): Sensor(-1 ) {
@@ -74,6 +75,11 @@ class SensorBattery: public Sensor {
74
75
_battery_adj_factor = value;
75
76
};
76
77
78
+ // if true call sendBatteryLevel() in addition to send the measured voltage back (default: true)
79
+ void setSendBatteryLevel (bool value) {
80
+ _send_battery_level = value;
81
+ };
82
+
77
83
// define what to do during loop
78
84
void onLoop (Child* child) {
79
85
// measure the battery
@@ -91,13 +97,15 @@ class SensorBattery: public Sensor {
91
97
}
92
98
volt = volt * _battery_adj_factor;
93
99
child->setValue (volt);
94
- // calculate the percentage
95
- int percentage = ((volt - _battery_min) / (_battery_max - _battery_min)) * 100 ;
96
- if (percentage > 100 ) percentage = 100 ;
97
- if (percentage < 0 ) percentage = 0 ;
98
- // report battery level percentage
99
- sendBatteryLevel (percentage);
100
- nodeManager.sleepBetweenSend ();
100
+ if (_send_battery_level) {
101
+ // calculate the percentage
102
+ int percentage = ((volt - _battery_min) / (_battery_max - _battery_min)) * 100 ;
103
+ if (percentage > 100 ) percentage = 100 ;
104
+ if (percentage < 0 ) percentage = 0 ;
105
+ // report battery level percentage
106
+ if (_send_battery_level) sendBatteryLevel (percentage);
107
+ nodeManager.sleepBetweenSend ();
108
+ }
101
109
};
102
110
103
111
#if NODEMANAGER_OTA_CONFIGURATION == ON
0 commit comments