Closed
Description
Sorry if this has been asked earlier, I could not find an answer.
I was trying to implement a new type FilteredInputPin
. Which wraps an ordinary generic InputPin
but with some basic filtering added.
My plan was to implement InputPin
for FilteredInputPin
, every call to is_low
/is_high
would update its history and return the filters result. However that does not work since is_low
and is_high
both take shared references. Thus there is no way for me to update the filters history data.
Is this a use case that embedded-hal does not intend to support or is this an oversight? :)
Semi pseudo code:
struct FilteredInputPin<P> {
pin: P,
history: History,
}
impl<P: InputPin> InputPin for FilteredInputPin {
type Error = P::Error;
fn is_high(&self) -> Result<bool, Self::Error> {
let new_value = self.pin.is_high()?;
let result = self.history.update(new_value); // <--- Needs mutable access
Ok(result)
}
...
}
Metadata
Metadata
Assignees
Labels
No labels