Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Oct 11, 2020
1 parent 08422b6 commit 4343171
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/booster_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,20 @@ impl BoosterChannels {
///
/// # Args
/// * `channel` - The channel to perform the action on.
/// * `func` - A function called with the channel selected and with the channel and the ADC3 peripheral passed as arguments.
/// * `func` - A function called with the channel selected and
/// with the channel and the ADC3 peripheral passed as arguments.
pub fn map<F, R>(&mut self, channel: Channel, func: F) -> Result<R, Error>
where
F: FnOnce(&mut RfChannel, &mut hal::adc::Adc<hal::stm32::ADC3>) -> Result<R, Error>,
{
let mux = &mut self.mux;
let adc = &mut self.adc;
let ch = &mut self.channels[channel as usize];
ch.as_mut().ok_or(Error::NotPresent).and_then(|ch| {
mux.select_bus(Some(channel.into())).unwrap();
func(ch, adc)
})
self.channels[channel as usize]
.as_mut()
.ok_or(Error::NotPresent)
.and_then(|ch| {
mux.select_bus(Some(channel.into())).unwrap();
func(ch, adc)
})
}
}
2 changes: 1 addition & 1 deletion src/mqtt_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn handle_channel_update(message: &[u8], channels: &mut BoosterChannels) -> Stri
Ok("Channel saved")
}
})
.map_or_else(|e| Response::error(e), |m| Response::okay(m))
.map_or_else(Response::error, Response::okay)
}

/// Handle a request to read a property of an RF channel.
Expand Down

0 comments on commit 4343171

Please sign in to comment.