mirror of https://github.com/eldruin/ds323x-rs
Pass variablue per value
parent
4674d06546
commit
f971786c0d
|
@ -121,7 +121,7 @@ where
|
||||||
let mut data = [ Register::ALARM1_SECONDS,
|
let mut data = [ Register::ALARM1_SECONDS,
|
||||||
decimal_to_packed_bcd(when.second) | match_mask[0],
|
decimal_to_packed_bcd(when.second) | match_mask[0],
|
||||||
decimal_to_packed_bcd(when.minute) | match_mask[1],
|
decimal_to_packed_bcd(when.minute) | match_mask[1],
|
||||||
hours_to_register(&when.hour)? | match_mask[2],
|
hours_to_register(when.hour)? | match_mask[2],
|
||||||
decimal_to_packed_bcd(when.date) | match_mask[3]];
|
decimal_to_packed_bcd(when.date) | match_mask[3]];
|
||||||
self.iface.write_data(&mut data)
|
self.iface.write_data(&mut data)
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ where
|
||||||
let mut data = [ Register::ALARM1_SECONDS,
|
let mut data = [ Register::ALARM1_SECONDS,
|
||||||
decimal_to_packed_bcd(when.second) | match_mask[0],
|
decimal_to_packed_bcd(when.second) | match_mask[0],
|
||||||
decimal_to_packed_bcd(when.minute) | match_mask[1],
|
decimal_to_packed_bcd(when.minute) | match_mask[1],
|
||||||
hours_to_register(&when.hour)? | match_mask[2],
|
hours_to_register(when.hour)? | match_mask[2],
|
||||||
decimal_to_packed_bcd(when.weekday) | match_mask[3] | BitFlags::WEEKDAY];
|
decimal_to_packed_bcd(when.weekday) | match_mask[3] | BitFlags::WEEKDAY];
|
||||||
self.iface.write_data(&mut data)
|
self.iface.write_data(&mut data)
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ where
|
||||||
let match_mask = get_matching_mask_alarm2(matching);
|
let match_mask = get_matching_mask_alarm2(matching);
|
||||||
let mut data = [ Register::ALARM2_MINUTES,
|
let mut data = [ Register::ALARM2_MINUTES,
|
||||||
decimal_to_packed_bcd(when.minute) | match_mask[0],
|
decimal_to_packed_bcd(when.minute) | match_mask[0],
|
||||||
hours_to_register(&when.hour)? | match_mask[1],
|
hours_to_register(when.hour)? | match_mask[1],
|
||||||
decimal_to_packed_bcd(when.date) | match_mask[2]];
|
decimal_to_packed_bcd(when.date) | match_mask[2]];
|
||||||
self.iface.write_data(&mut data)
|
self.iface.write_data(&mut data)
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ where
|
||||||
let match_mask = get_matching_mask_alarm2(matching);
|
let match_mask = get_matching_mask_alarm2(matching);
|
||||||
let mut data = [ Register::ALARM2_MINUTES,
|
let mut data = [ Register::ALARM2_MINUTES,
|
||||||
decimal_to_packed_bcd(when.minute) | match_mask[0],
|
decimal_to_packed_bcd(when.minute) | match_mask[0],
|
||||||
hours_to_register(&when.hour)? | match_mask[1],
|
hours_to_register(when.hour)? | match_mask[1],
|
||||||
decimal_to_packed_bcd(when.weekday) | match_mask[2] | BitFlags::WEEKDAY];
|
decimal_to_packed_bcd(when.weekday) | match_mask[2] | BitFlags::WEEKDAY];
|
||||||
self.iface.write_data(&mut data)
|
self.iface.write_data(&mut data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ where
|
||||||
///
|
///
|
||||||
/// Will return an `Error::InvalidInputData` if the hours are out of range.
|
/// Will return an `Error::InvalidInputData` if the hours are out of range.
|
||||||
pub fn set_hours(&mut self, hours: Hours) -> Result<(), Error<E>> {
|
pub fn set_hours(&mut self, hours: Hours) -> Result<(), Error<E>> {
|
||||||
let value = hours_to_register(&hours)?;
|
let value = hours_to_register(hours)?;
|
||||||
self.iface.write_register(Register::HOURS, value)
|
self.iface.write_register(Register::HOURS, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ where
|
||||||
let mut payload = [Register::SECONDS,
|
let mut payload = [Register::SECONDS,
|
||||||
decimal_to_packed_bcd(datetime.second),
|
decimal_to_packed_bcd(datetime.second),
|
||||||
decimal_to_packed_bcd(datetime.minute),
|
decimal_to_packed_bcd(datetime.minute),
|
||||||
hours_to_register(&datetime.hour)?,
|
hours_to_register(datetime.hour)?,
|
||||||
decimal_to_packed_bcd(datetime.weekday),
|
decimal_to_packed_bcd(datetime.weekday),
|
||||||
decimal_to_packed_bcd(datetime.day),
|
decimal_to_packed_bcd(datetime.day),
|
||||||
month, year];
|
month, year];
|
||||||
|
|
|
@ -17,8 +17,8 @@ fn packed_bcd_to_decimal(bcd: u8) -> u8 {
|
||||||
(bcd >> 4) * 10 + (bcd & 0xF)
|
(bcd >> 4) * 10 + (bcd & 0xF)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hours_to_register<E>(hours: &Hours) -> Result<u8, Error<E>> {
|
fn hours_to_register<E>(hours: Hours) -> Result<u8, Error<E>> {
|
||||||
match *hours {
|
match hours {
|
||||||
Hours::H24(h) if h > 23 => Err(Error::InvalidInputData),
|
Hours::H24(h) if h > 23 => Err(Error::InvalidInputData),
|
||||||
Hours::H24(h) => Ok(decimal_to_packed_bcd(h)),
|
Hours::H24(h) => Ok(decimal_to_packed_bcd(h)),
|
||||||
Hours::AM(h) if h < 1 || h > 12 => Err(Error::InvalidInputData),
|
Hours::AM(h) if h < 1 || h > 12 => Err(Error::InvalidInputData),
|
||||||
|
|
Loading…
Reference in New Issue