I want to implement an RS485 absolute encoder, values 0-2048, on a canvas rapid door. The controller MCU that reads the encoder, which I will programm, may not be powered all the time, but it should be aware of door position on power on. Limit switches will not be installed. The door's movement will never translate to more than 360 degrees revolution on the encoder. It is expected that maximum movement will have a span of around 1600 values.
The installer will set the lowest and highest positions during a setup procedure: Move the door to its lowest position, store the encoder value, move the door to its highest position, store the encoder value, setup completed.
The lowest position can translate to any value on the encoder due to the fact that the canvas is fitted on the roll bar without knowledge of encoder position. So it can have a lowest position at encoder value of 100 or 1000 or 2000. This means that in normal movement, the value will wrap around 2048. Moreover the installer can fit the motor on the left or right side of the roll bar, so the encoder value might increment while the door goes up, or vice versa. To complicate matters even more, the door might move further from the lowest position, due to break heating, gear oil temperature change etc, so if its lowest value was 50, it could wrap over zero and reach a bottom value of 1950.
Considering the above description and scenarios where lowest (Lxxx) and highest (Hxxx) position have corresponding value pairs of: L200-H1400, L800-H300, L10-H1500 and the reverse movement of those L1400-H200, L300-H800, L1500-H10.
What algorithm - conditions would you use to stop the motor at the lowest and highest positions?