ds323x-rs/examples/linux.rs

15 lines
431 B
Rust
Raw Permalink Normal View History

2020-05-02 09:36:42 +00:00
use ds323x::{Ds323x, NaiveDate, Rtcc};
2020-07-10 20:24:29 +00:00
use linux_embedded_hal::I2cdev;
2018-10-28 09:32:41 +00:00
fn main() {
2020-07-10 20:24:29 +00:00
let dev = I2cdev::new("/dev/i2c-1").unwrap();
2018-10-28 09:32:41 +00:00
let mut rtc = Ds323x::new_ds3231(dev);
2020-05-02 09:36:42 +00:00
let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
2018-11-16 16:36:15 +00:00
rtc.set_datetime(&datetime).unwrap();
// do something else...
2020-05-02 09:36:42 +00:00
let time = rtc.get_time().unwrap();
println!("Time: {}", time);
2018-11-16 18:48:56 +00:00
2018-11-16 18:42:47 +00:00
let _dev = rtc.destroy_ds3231();
2018-10-28 09:32:41 +00:00
}