80
C H A P T E R 5
Scripting
script title. End users are free to supply a value or to accept the default
value. The
@default
instruction specifies this default value.
Because the script needs some time to set the camera up, we use that
time by giving the user something to read—for example, the usage of the
camera buttons during loupe mode:
print "Press MENU to cancel"
print "Zoom = magnification"
print "Shutter/2 = refocus"
This is good practice. When you allow for some user interaction, always
explain how to use the controls. Sometimes scripts are not used for a long
time, so the user might have forgotten how to operate the script.
rem init
if m < 1 then m = 3
Comment lines begin with the token
rem
. Comment lines are not executed
and do not affect the state of the camera. Their purpose is documentation.
Nevertheless, many comments can slow down a script. After each script
line (including comments), the CHDK pauses for 10 milliseconds to let the
camera do its work and look after user inputs. Newer CHDK builds, how-
ever, allow for larger comment blocks—they pause only once for up to
100 consecutive comment lines.
During initialization, you should check the validity of the parameters
and correct them as necessary. We set the input parameter to its default
value if the user entered an invalid value. A magnification of
0
is obviously
nonsense.
let s = 0
if m > 1 then s = 3
if m > 2 then s = 5
if m > 3 then s = 6
From the specified magnification, we compute the zoom step value. This
value will be used later for setting the zoom level. This section depends on
the camera model; different camera models have different zoom granular-
ity. While A-series cameras have 9 or 15 zoom steps, S-series cameras fea-
ture 129 steps. It would be possible to retrieve the number of zoom steps
from the camera and come up with a more general logic for selecting the
right zoom step, but for now we leave it at that for simplicity.
Summary of Contents for Camera
Page 1: ......
Page 2: ...The Canon Camera Hackers Manual ...
Page 3: ......
Page 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Page 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Page 25: ...16 CH APTER 3 ...
Page 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Page 213: ...204 CH APTER 6 ...
Page 253: ...244 AP PENDIX ...