You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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? :)
Yes I think a Cell would probably be completely fine. Have actually never used gotten around to using a Cell, but that does indeed seem to be a sufficient solution here since my History type would probably just be something like a
structFilteredInputPin<P>{pin:P,history:Cell<History>,}impl<P:InputPin>InputPinforFilteredInputPin{typeError = P::Error;fnis_high(&self) -> Result<bool,Self::Error>{let new_value = self.pin.is_high()?;let history = self.history.get();// <-- Cell::get makes a copy of the history, assuming History: Copylet(new_history, result) = history.update(new_value);// <--- creates a new History object plus the resultself.history.set(new_history);// <-- Overwrite cells contents with new historyOk(result)}
...
}
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 genericInputPin
but with some basic filtering added.My plan was to implement
InputPin
forFilteredInputPin
, every call tois_low
/is_high
would update its history and return the filters result. However that does not work sinceis_low
andis_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:
The text was updated successfully, but these errors were encountered: