mirror of https://github.com/eldruin/ds323x-rs
Add alarm 1 and 2 examples
parent
d0bcb715ce
commit
f53554b404
|
@ -21,5 +21,6 @@ fn main() {
|
|||
// do something else...
|
||||
let seconds = rtc.get_seconds().unwrap();
|
||||
println!("Seconds: {}", seconds);
|
||||
|
||||
let _dev = rtc.destroy_ds3231();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//! Set the Alarm1 to each week on a week day at a specific time
|
||||
extern crate linux_embedded_hal as hal;
|
||||
extern crate ds323x;
|
||||
use ds323x::{ Ds323x, Hours, WeekdayAlarm1, Alarm1Matching };
|
||||
|
||||
fn main() {
|
||||
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
|
||||
let mut rtc = Ds323x::new_ds3232(dev);
|
||||
let alarm1 = WeekdayAlarm1 {
|
||||
weekday: 1,
|
||||
hour: Hours::H24(7),
|
||||
minute: 2,
|
||||
second: 15
|
||||
};
|
||||
rtc.set_alarm1_weekday(alarm1, Alarm1Matching::AllMatch).unwrap();
|
||||
|
||||
let _dev = rtc.destroy_ds3232();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//! Set the Alarm2 to each day at the same time and enable interrupts on output.
|
||||
//!
|
||||
//! The INT/SQW output pin will be set to 1 when it the alarm matches.
|
||||
|
||||
extern crate linux_embedded_hal as hal;
|
||||
extern crate ds323x;
|
||||
use ds323x::{ Ds323x, Hours, DayAlarm2, Alarm2Matching };
|
||||
|
||||
fn main() {
|
||||
let dev = hal::Spidev::open("/dev/spidev0.0").unwrap();
|
||||
let chip_select = hal::Pin::new(24);
|
||||
let mut rtc = Ds323x::new_ds3234(dev, chip_select);
|
||||
let alarm2 = DayAlarm2 {
|
||||
day: 1, // does not matter given the chosen matching
|
||||
hour: Hours::AM(11),
|
||||
minute: 2
|
||||
};
|
||||
rtc.set_alarm2_day(alarm2, Alarm2Matching::HoursAndMinutesMatch).unwrap();
|
||||
rtc.use_int_sqw_output_as_interrupt().unwrap();
|
||||
rtc.enable_alarm2_interrupts().unwrap();
|
||||
|
||||
let (_dev, _chip_select_pin) = rtc.destroy_ds3234();
|
||||
}
|
Loading…
Reference in New Issue