Operation: Standard Calibration UI
The button is used to calibrate the servo input range so that modules can use servo data reliably. The reason you need to calibrate this input is to accommodate different transmitters. If you've read my Servos 101 note you know that while it is a convention that "neutral" is about 1500 uSecs and full retract is 1000 uSecs and full extension is 2000 uSecs, there is no hard and fast standard for these values. Transmitters come with trim pots and adjustments to allow you to get the motion you need from your model, and on real servos you can use a servo horn to adjust how much actuation a push rod can do. In the electronic domain however we don't have servo horns. However we do have the ability to do math :-)
All the software modules that use servos define a "factory" setting of 1072 uSecs for full off, 1522 uSecs for Neutral, and 1922 uSecs for full on. This corresponds to the default Futaba settings and as I use a Futaba 3PJS in most of my work with these it works out. But what about tuning that number to something your transmitter actually is putting out? That is where the "button UI" comes into its own.
I wrote some code that implement a simple button state machine as follows:
Figure 1. Button State Machine
As you can see its activated when the button is pressed and held on for more than .5 seconds. This first barrier is to prevent false entry into the calibration phase. Once it has been held for at least half a second and released, the gizmo loops while it simply monitors the servo signal coming in. During this looping it is blinking the "CAL" LED to indicate that it is in this state.
The goal here was to let a single individual calibrate the unit. Once in calibration mode, you go back, pick up your transmitter and work the stick/wheel whatever of the desired channel from one limit to the other. When that is done you return the stick/wheel to neutral (often you can just let it go and it will spring return) and then you go back to the gizmo and push the button again.
At that second push, the transmitter is sending neutral so that is what is noted for neutral, then a scaling factor is computed for both the (neutral -> min) range, and for the (neutral -> max) range. Those scaling factors are stored for later use and the routine exits back into "normal" mode.