Cleanup of the 'nTxtbl' mess in core/kbd.c

  • 2 Replies
  • 821 Views
*

Offline philmoz

  • *****
  • 2936
    • Photos
  • Publish
    Cleanup of the 'nTxtbl' mess in core/kbd.c
    « on: 23 / June / 2011, 00:59:05 »
    Advertisements
    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:
    Code: [Select]
    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:
    Code: [Select]
    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.
    « Last Edit: 23 / June / 2011, 01:10:20 by philmoz »
    CHDK ports:
      sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
      g12 (1.00c, 1.00e, 1.00f & 1.00g)
      sx130is (1.01d & 1.01f)
      ixus310hs (1.00a & 1.01a)
      sx40hs (1.00d, 1.00g & 1.00i)
      g1x (1.00e, 1.00f & 1.00g)

    *

    Offline reyalp

    • ******
    • 9957
  • Publish
    Re: Cleanup of the 'nTxtbl' mess in core/kbd.c
    « Reply #1 on: 23 / June / 2011, 02:16:18 »
    Sounds good to :)

    edit:
    Caveat - that whole mess of remote code makes my head spin, so I can't claim to looked at any side effects of changing the values for the cameras with lots of zoom points.
    « Last Edit: 23 / June / 2011, 02:18:06 by reyalp »
    Don't forget what the H stands for.

  • Publish
    Re: Cleanup of the 'nTxtbl' mess in core/kbd.c
    « Reply #2 on: 23 / June / 2011, 05:56:38 »
    that whole mess of remote code makes my head spin


    That was copied from an early version of SDM.

    It is intended to support various still and video features for stereo photography.

    For CHDK, 'Alex scriptless remote' was added.

    For CHDK only, this could be made far simpler by eliminating stereo support.

     

    Related Topics