@@ -266,35 +266,81 @@ uint8_t SFE_MAX1704X::getStatus(void)
266266 return (statusReg & 0x7F ); // Highest bit is don't care
267267}
268268
269- bool SFE_MAX1704X::isReset (void )
269+ bool SFE_MAX1704X::isReset (bool clear )
270270{
271271 uint8_t status = getStatus ();
272- return (status & MAX1704x_STATUS_RI);
272+ bool flag = (status & MAX1704x_STATUS_RI) > 0 ;
273+ if (flag && clear) // Clear the flag if requested
274+ {
275+ // Clear the aligned bit in the status register
276+ clearStatusRegBits (MAX1704x_STATUS_RI << 8 );
277+ }
278+ return (flag);
273279}
274- bool SFE_MAX1704X::isVoltageHigh (void )
280+ bool SFE_MAX1704X::isVoltageHigh (bool clear )
275281{
276282 uint8_t status = getStatus ();
277- return (status & MAX1704x_STATUS_VH);
283+ bool flag = (status & MAX1704x_STATUS_VH) > 0 ;
284+ if (flag && clear) // Clear the flag if requested
285+ {
286+ // Clear the aligned bit in the status register
287+ clearStatusRegBits (MAX1704x_STATUS_VH << 8 );
288+ }
289+ return (flag);
278290}
279- bool SFE_MAX1704X::isVoltageLow (void )
291+ bool SFE_MAX1704X::isVoltageLow (bool clear )
280292{
281293 uint8_t status = getStatus ();
282- return (status & MAX1704x_STATUS_VL);
294+ bool flag = (status & MAX1704x_STATUS_VL) > 0 ;
295+ if (flag && clear) // Clear the flag if requested
296+ {
297+ // Clear the aligned bit in the status register
298+ clearStatusRegBits (MAX1704x_STATUS_VL << 8 );
299+ }
300+ return (flag);
283301}
284- bool SFE_MAX1704X::isVoltageReset (void )
302+ bool SFE_MAX1704X::isVoltageReset (bool clear )
285303{
286304 uint8_t status = getStatus ();
287- return (status & MAX1704x_STATUS_VR);
305+ bool flag = (status & MAX1704x_STATUS_VR) > 0 ;
306+ if (flag && clear) // Clear the flag if requested
307+ {
308+ // Clear the aligned bit in the status register
309+ clearStatusRegBits (MAX1704x_STATUS_VR << 8 );
310+ }
311+ return (flag);
288312}
289- bool SFE_MAX1704X::isLow (void )
313+ bool SFE_MAX1704X::isLow (bool clear )
290314{
291315 uint8_t status = getStatus ();
292- return (status & MAX1704x_STATUS_HD);
316+ bool flag = (status & MAX1704x_STATUS_HD) > 0 ;
317+ if (flag && clear) // Clear the flag if requested
318+ {
319+ // Clear the aligned bit in the status register
320+ clearStatusRegBits (MAX1704x_STATUS_HD << 8 );
321+ }
322+ return (flag);
293323}
294- bool SFE_MAX1704X::isChange (void )
324+ bool SFE_MAX1704X::isChange (bool clear )
295325{
296326 uint8_t status = getStatus ();
297- return (status & MAX1704x_STATUS_SC);
327+ bool flag = (status & MAX1704x_STATUS_SC) > 0 ;
328+ if (flag && clear) // Clear the flag if requested
329+ {
330+ // Clear the aligned bit in the status register
331+ clearStatusRegBits (MAX1704x_STATUS_SC << 8 );
332+ }
333+ return (flag);
334+ }
335+
336+ // Clear the specified bit in the MAX17048/49 status register (PRIVATE)
337+ // This requires the bits in mask to be correctly aligned.
338+ // MAX1704x_STATUS_RI etc. will need to be shifted left by 8 bits to become aligned.
339+ uint8_t SFE_MAX1704X::clearStatusRegBits (uint16_t mask)
340+ {
341+ uint16_t statusReg = read16 (MAX17048_STATUS);
342+ statusReg &= ~mask; // Clear the specified bits
343+ return (write16 (statusReg, MAX17048_STATUS)); // Write the contents back again
298344}
299345
300346uint8_t SFE_MAX1704X::clearAlert ()
0 commit comments