diff --git a/src/ds323x/configuration.rs b/src/ds323x/configuration.rs index 7973f9e..2a8f1a8 100644 --- a/src/ds323x/configuration.rs +++ b/src/ds323x/configuration.rs @@ -34,20 +34,14 @@ where /// Enable the 32kHz output. pub fn enable_32khz_output(&mut self) -> Result<(), Error> { - // avoid clearing alarm flags - let status = self.status | BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F; - self.iface.write_register(Register::STATUS, status)?; - self.status = status; - Ok(()) + let status = self.status | BitFlags::EN32KHZ; + self.write_status_without_clearing_alarm(status) } /// Disable the 32kHz output. pub fn disable_32khz_output(&mut self) -> Result<(), Error> { - // avoid clearing alarm flags - let status = self.status & !BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F; - self.iface.write_register(Register::STATUS, status)?; - self.status = status; - Ok(()) + let status = self.status & !BitFlags::EN32KHZ; + self.write_status_without_clearing_alarm(status) } /// Set the aging offset. @@ -102,4 +96,12 @@ where self.control = control; Ok(()) } + + pub(crate) fn write_status_without_clearing_alarm(&mut self, status: u8) -> Result<(), Error> { + // avoid clearing alarm flags + let new_status = status | BitFlags::ALARM2F | BitFlags::ALARM1F; + self.iface.write_register(Register::STATUS, new_status)?; + self.status = status; + Ok(()) + } }