@@ -17,7 +17,7 @@ const char STRING_SERIAL[] PROGMEM = "UPS10";
17
17
const byte bDeviceChemistry = IDEVICECHEMISTRY;
18
18
const byte bOEMVendor = IOEMVENDOR;
19
19
20
- uint16_t iPresentStatus = 0 , iPreviousStatus = 0 ;
20
+ PresentStatus iPresentStatus = {} , iPreviousStatus = {} ;
21
21
22
22
byte bRechargable = 1 ;
23
23
byte bCapacityMode = 2 ; // units are in %%
@@ -109,56 +109,44 @@ void loop() {
109
109
iRemaining = (byte)(round ((float )100 *iBattSoc/1024 ));
110
110
iRunTimeToEmpty = (uint16_t )round ((float )iAvgTimeToEmpty*iRemaining/100 );
111
111
112
- // Charging
113
- if (bCharging)
114
- bitSet (iPresentStatus,PRESENTSTATUS_CHARGING);
115
- else
116
- bitClear (iPresentStatus,PRESENTSTATUS_CHARGING);
117
- if (bACPresent)
118
- bitSet (iPresentStatus,PRESENTSTATUS_ACPRESENT);
119
- else
120
- bitClear (iPresentStatus,PRESENTSTATUS_ACPRESENT);
121
- if (iRemaining == iFullChargeCapacity)
122
- bitSet (iPresentStatus,PRESENTSTATUS_FULLCHARGE);
123
- else
124
- bitClear (iPresentStatus,PRESENTSTATUS_FULLCHARGE);
112
+ // Charging
113
+ iPresentStatus.CHARGING = bCharging;
114
+ iPresentStatus.ACPRESENT = bACPresent;
115
+ iPresentStatus.FULLCHARGE = (iRemaining == iFullChargeCapacity);
125
116
126
117
// Discharging
127
118
if (bDischarging) {
128
- bitSet ( iPresentStatus,PRESENTSTATUS_DISCHARGING) ;
129
- // if(iRemaining < iRemnCapacityLimit) bitSet( iPresentStatus,PRESENTSTATUS_BELOWRCL) ;
119
+ iPresentStatus. DISCHARGING = 1 ;
120
+ // if(iRemaining < iRemnCapacityLimit) iPresentStatus.BELOWRCL = 1 ;
130
121
131
- if (iRunTimeToEmpty < iRemainTimeLimit)
132
- bitSet (iPresentStatus, PRESENTSTATUS_RTLEXPIRED);
133
- else
134
- bitClear (iPresentStatus, PRESENTSTATUS_RTLEXPIRED);
122
+ iPresentStatus.RTLEXPIRED = (iRunTimeToEmpty < iRemainTimeLimit);
135
123
136
124
}
137
125
else {
138
- bitClear ( iPresentStatus,PRESENTSTATUS_DISCHARGING) ;
139
- bitClear ( iPresentStatus, PRESENTSTATUS_RTLEXPIRED) ;
126
+ iPresentStatus. DISCHARGING = 0 ;
127
+ iPresentStatus. RTLEXPIRED = 0 ;
140
128
}
141
129
142
130
// Shutdown requested
143
131
if (iDelayBe4ShutDown > 0 ) {
144
- bitSet ( iPresentStatus, PRESENTSTATUS_SHUTDOWNREQ) ;
132
+ iPresentStatus. SHUTDOWNREQ = 1 ;
145
133
Serial.println (" shutdown requested" );
146
134
}
147
135
else
148
- bitClear ( iPresentStatus, PRESENTSTATUS_SHUTDOWNREQ) ;
136
+ iPresentStatus. SHUTDOWNREQ = 0 ;
149
137
150
138
// Shutdown imminent
151
- if ((iPresentStatus & ( 1 << PRESENTSTATUS_SHUTDOWNREQ) ) ||
152
- (iPresentStatus & ( 1 << PRESENTSTATUS_RTLEXPIRED) )) {
153
- bitSet ( iPresentStatus, PRESENTSTATUS_SHUTDOWNIMNT) ;
139
+ if ((iPresentStatus. SHUTDOWNREQ ) ||
140
+ (iPresentStatus. RTLEXPIRED )) {
141
+ iPresentStatus. SHUTDOWNIMNT = 1 ;
154
142
Serial.println (" shutdown imminent" );
155
143
}
156
144
else
157
- bitClear ( iPresentStatus, PRESENTSTATUS_SHUTDOWNIMNT) ;
145
+ iPresentStatus. SHUTDOWNIMNT = 0 ;
158
146
159
147
160
148
161
- bitSet ( iPresentStatus ,PRESENTSTATUS_BATTPRESENT) ;
149
+ iPresentStatus. BATTPRESENT = 1 ;
162
150
163
151
164
152
0 commit comments