5.2 uBasic
79
as soon as you load another script, the new script will run at start-up, so it
is necessary to reload
flashoff.lua
before switching off.
Many scripts can be configured with parameters. These parameters are
defined in the header section of the script. After the script has been loaded,
they are listed in the bottom section of the CHDK
Script
menu. The param-
eter values shown there can be modified with the
LEFT
,
RIGHT,
and
FUNC/
SET
keys. If a script has many parameters, it can be tedious to set up all the
parameters before running the script. The CHDK therefore offers the pos-
sibility to store frequently used parameter combinations in parameter sets.
Ten of those sets exist (0–9). By modifying the value of the menu entry
Parameters set,
you can easily switch among different parameter combina-
tions.
5.2
uBasic
The original
uBasic
interpreter was written by the Swedish programmer
Adam Dunkels
. He said, “I’ve always wanted to write a really small BASIC
interpreter. So I sat down for an hour or two and did it.” It’s probably true.
uBasic
is tiny, and there are only a few commands to learn. The original
uBasic
interpreter didn’t even understand labels—instead you specified
line numbers as
GOTO
targets, just like in the days of the legendary C64.
Labels were later added by
Pablo d’Angelo
who is also the main contributor
for the
Hugin panorama stitcher
.
So, let’s jump right into another small script and see how
uBasic
looks
these days. (A more systematic introduction into
uBasic
is given in the fol-
lowing sections.) The following script implements an electronic
magnify-
ing glass
by switching the camera into the
Digital Macro
mode and setting
a predefined magnification level. Also, most of the info texts are hidden
from the display.
@title
Digital Magnifier
@param m Initial Magnification
@default m 3
This is the header section of the script. The title will appear at the bottom
of the display after the script is loaded. You should avoid using more than
24 characters; otherwise, the title would override the
<ALT>
indicator.
The title declaration is followed by the declaration of the parameters
providing input to the script. With the
@param
instruction, you specify a
variable name and a parameter description. Variable names for parameters
always consist of a single lower case letter. In newer CHDK versions, you
can have variable names from
a
–
z
, in older versions only
a
–
j
. The parame-
ter description is shown in the script menu (
ALT
>
FUNC/SET
) below the
Figure 5-1
The CHDK
Script
menu. The upper half
is used for general script configuration,
such as script loading, delaying the
execution of the script for a specified
number of 1/10 secs, resetting to the
default parameter values, and
switching and saving parameter sets.
The lower half is reserved for the script
parameters. Here are some of the
parameters from the motion detection
script discussed in section 5.7.3
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 ...