5.7 Example scripts
143
The function
focus()
is called if the user wants to focus just once at the
beginning of the series. In this case, the focusing is performed by half-
pressing the shutter button. In the following
repeat
- loop we wait until the
camera becomes ready to shoot. The
sleep(1)
command in that loop is
recommended to give the camera processor some time to breathe. In
uBasic
that would not be necessary because the
uBasic
interpreter automatically
waits 10 msec after each line of code. This is not the case for
Lua
—probably
the main reason why
Lua
scripts are so much faster.
After focusing has finished, we lock the autofocus system and release
the shutter button. The camera will not try to refocus until the lock is re-
leased.
function focus()
press("shoot_half")
repeat
sleep(1)
until get_shooting()
set_aflock(1)
release("shoot_half")
end
Function
tohms()
converts milliseconds into the more readable format
h:m:s
. It does so by dividing the seconds subsequently by 60 and keeping
the remainders. Instead of using the operator
/
for division, we use the
function
idiv()
defined above:
function tohms(ticks)
local ts =
idiv((ticks + 50), 100)
local t = ts % 10
ts = idiv(ts, 10)
local s = ts % 60
ts = idiv(ts, 60)
local m = ts % 60
local h = idiv(ts, 60)
return h, m, s, t
end
All necessary functions are now implemented, and we can begin with the
main program. First, we print a short note to the user describing how to
abort the script. We then begin checking the parameters for valid values. If
a value is invalid, the parameter is reset to its default value.
We can compute the interval between two shots (
delay
) as discussed
above:
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 ...