Skip to content

Commit b90c690

Browse files
committed
Utilize bit-set to simplify field set/clear logic
Leveraging the fact that the Arduino C/C++ compiler defines "true" as 1 according to https://www.arduino.cc/reference/en/language/variables/constants/truefalse/
1 parent adfaa91 commit b90c690

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

examples/UPS/UPS.ino

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,17 @@ void loop() {
106106
iRemaining = (byte)(round((float)100*iBattSoc/1024));
107107
iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/100);
108108

109-
// Charging
110-
if(bCharging)
111-
iPresentStatus.CHARGING = 1;
112-
else
113-
iPresentStatus.CHARGING = 0;
114-
if(bACPresent)
115-
iPresentStatus.ACPRESENT = 1;
116-
else
117-
iPresentStatus.ACPRESENT = 0;
118-
if(iRemaining == iFullChargeCapacity)
119-
iPresentStatus.FULLCHARGE = 1;
120-
else
121-
iPresentStatus.FULLCHARGE = 0;
109+
// Charging
110+
iPresentStatus.CHARGING = bCharging;
111+
iPresentStatus.ACPRESENT = bACPresent;
112+
iPresentStatus.FULLCHARGE = (iRemaining == iFullChargeCapacity);
122113

123114
// Discharging
124115
if(bDischarging) {
125116
iPresentStatus.DISCHARGING = 1;
126117
// if(iRemaining < iRemnCapacityLimit) iPresentStatus.BELOWRCL = 1;
127118

128-
if(iRunTimeToEmpty < iRemainTimeLimit)
129-
iPresentStatus.RTLEXPIRED = 1;
130-
else
131-
iPresentStatus.RTLEXPIRED = 0;
119+
iPresentStatus.RTLEXPIRED = (iRunTimeToEmpty < iRemainTimeLimit);
132120

133121
}
134122
else {

0 commit comments

Comments
 (0)