Add alarm 1 and 2 examples

pull/4/head
Diego Barrios Romero 2018-11-16 19:48:56 +01:00
parent d0bcb715ce
commit f53554b404
3 changed files with 42 additions and 0 deletions

View File

@ -21,5 +21,6 @@ fn main() {
// do something else... // do something else...
let seconds = rtc.get_seconds().unwrap(); let seconds = rtc.get_seconds().unwrap();
println!("Seconds: {}", seconds); println!("Seconds: {}", seconds);
let _dev = rtc.destroy_ds3231(); let _dev = rtc.destroy_ds3231();
} }

View File

@ -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();
}

View File

@ -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();
}