As far as I can make out the nTxtbl and ZSTEP_TABLE_SIZE stuff in core/kbd.c is used for remote switches to determine the allowed zoom point values for the camera.
Zoom points are the physical positions of the zoom stepper motor, not the zoom focus length. Zoom point 0 being at the widest end of the zoom range.
The zoom points go from 0 to zoom_points - 1, where zoom_points is a variable defined in platform/camera/main.c for each camera.
For cameras with only a few zoom points the nTxtbl array contains all the values from 0 to zoom_points - 1 and ZSTEP_TABLE_SIZE will be equal to zoom_points.
For cameras with a large number of zoom points the nTxtbl array holds a subset of values that step through the zoom_points range and ZSTEP_TABLE_SIZE is the number of elements in nTxtbl.
The mess comes from all the 'defined(CAMERA_xxx)' stuff used to set these up for each camera.
It occurred to me that we could just as easily calculate this at run time as below.
1. replace ZSTEP_TABLE_SIZE with this function:
int zstep_table_size()
{
// For cameras with a small number of zoom points return the number of zoom points
// otherwise return a fixed size of 9 (see below)
if (zoom_points <= 15) return zoom_points;
else return 9;
}
2. replace each use of the nTxtbl array with this function:
int nTxtbl(int i)
{
// Assumption:- 0 <= i < zstep_table_size()
// For cameras with a small number of zoom points return the zoom point number
// otherwise return the i/8'th value between 0 and zoom_points, this gives us 9 possible values from 0 to zoom_points
// e.g. i = 0 --> return 0
// i = 1 --> return 1 * (zoom_points-1) / 8
// ...
// i = 7 --> return 7 * (zoom_points-1) / 8
// i = 8 --> return 8 * (zoom_points-1) / 8 == (zoom_points - 1)
if (zoom_points <= 15) return i;
else return ((i * 2 * (zoom_points-1) + 1) / 16);
}
For cameras with a small number of zoom points (<= 15) this returns the same values as currently.
For the others this returns a slightly different set of values; but since the code doesn't seem to care about the actual values it should achieve the same end result.
Any comments or suggestions on this would be appreciated.
Phil.