eldruin / ds323x-rs

Platform-agnostic Rust driver for the DS3231, DS3232 and DS3234 extremely accurate real-time clocks (RTC).
Apache License 2.0
13 stars 7 forks source link

Methods returning types from `chrono` panic if the device is uninitialized #6

Closed eldruin closed 3 years ago

eldruin commented 3 years ago

When the device is still uninitialized, it is possible that the values in the registers result in invalid input data for the chrono data types. In these cases, chrono methods panic:

This applies at least to methods get_date(), get_time() and get_datetime(). This can be solved by adding a new error variant named something similar to InvalidDeviceState and using the _opt variants of the methods to create chrono data types.

eldruin commented 3 years ago

I have fixed this in version 0.4.0. In such cases Error::InvalidDeviceState will be returned. Closing.

cc: @jamesmunns