ds323x-rs/examples/linux.rs

27 lines
635 B
Rust
Raw Normal View History

2019-05-16 17:18:07 +00:00
extern crate ds323x;
2018-10-28 09:32:41 +00:00
extern crate embedded_hal;
extern crate linux_embedded_hal;
2019-05-16 17:18:07 +00:00
use ds323x::{DateTime, Ds323x, Hours};
2018-10-28 09:32:41 +00:00
use linux_embedded_hal::I2cdev;
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut rtc = Ds323x::new_ds3231(dev);
2018-11-16 16:36:15 +00:00
let datetime = DateTime {
2019-05-16 17:18:07 +00:00
year: 2018,
month: 8,
day: 20,
weekday: 4,
hour: Hours::H24(19),
minute: 59,
second: 58,
};
2018-11-16 16:36:15 +00:00
rtc.set_datetime(&datetime).unwrap();
// do something else...
let seconds = rtc.get_seconds().unwrap();
println!("Seconds: {}", seconds);
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
}