Pass variablue per value

pull/4/head
Diego Barrios Romero 2018-11-16 17:50:06 +01:00
parent 4674d06546
commit f971786c0d
3 changed files with 8 additions and 8 deletions

View File

@ -121,7 +121,7 @@ where
let mut data = [ Register::ALARM1_SECONDS,
decimal_to_packed_bcd(when.second) | match_mask[0],
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]];
self.iface.write_data(&mut data)
}
@ -139,7 +139,7 @@ where
let mut data = [ Register::ALARM1_SECONDS,
decimal_to_packed_bcd(when.second) | match_mask[0],
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];
self.iface.write_data(&mut data)
}
@ -155,7 +155,7 @@ where
let match_mask = get_matching_mask_alarm2(matching);
let mut data = [ Register::ALARM2_MINUTES,
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]];
self.iface.write_data(&mut data)
}
@ -171,7 +171,7 @@ where
let match_mask = get_matching_mask_alarm2(matching);
let mut data = [ Register::ALARM2_MINUTES,
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];
self.iface.write_data(&mut data)
}

View File

@ -126,7 +126,7 @@ where
///
/// Will return an `Error::InvalidInputData` if the hours are out of range.
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)
}
@ -201,7 +201,7 @@ where
let mut payload = [Register::SECONDS,
decimal_to_packed_bcd(datetime.second),
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.day),
month, year];

View File

@ -17,8 +17,8 @@ fn packed_bcd_to_decimal(bcd: u8) -> u8 {
(bcd >> 4) * 10 + (bcd & 0xF)
}
fn hours_to_register<E>(hours: &Hours) -> Result<u8, Error<E>> {
match *hours {
fn hours_to_register<E>(hours: Hours) -> Result<u8, Error<E>> {
match hours {
Hours::H24(h) if h > 23 => Err(Error::InvalidInputData),
Hours::H24(h) => Ok(decimal_to_packed_bcd(h)),
Hours::AM(h) if h < 1 || h > 12 => Err(Error::InvalidInputData),