Ok, I have a project that uses a rotary encoder in the UI. The interface's response to encoder inputs is varying depending on the situation.
Also, I want my encoder logic to be in a dedicated library so I can use it in other projects.
Both these requirements mean that the actual result of the encoder's movement should be separate from the encoder logic functions.
Finally, the encoder logic is interrupt based. I'm pretty certain my current project would be fine if I polled, but again, I want an encoder library that is universal, so I want it fast enough for more MCU intensive projects.
My question is this. If I have my encoder ISRs return the result (Clockwise turn/ Counterclockwise), I would still have to pol to get that result, right? So maybe for instance, the ISR stores its return value in some global. I still need to periodically check that global, which amounts to polling again. Is this a valid method? My gut says the main reason for using interrupts is to not miss encoder events, but as long as that's working, I lose nothing by polling for the result in the global, right?
My other, less tasteful idea was to use some trick using a function pointer that can be assigned as needed to the current appropriate function needed for encoder results. I am not super in love with this notion though, because it seems like making what should be simple complicated.
How is this typically done?