142
C H A P T E R 5
Scripting
environment such as a PC, the operator
/
denotes a floating-point division.
Because an integer division is what we want, and because it is more conve-
nient to debug scripts on a PC, we use
idiv()
instead of
/
throughout the
script.
function idiv(a,b)
return (a-(a % b))/b
end
pcall(function()
require("chdklib")
end
)
props = require("propcase")
function set_display_mode(mode)
while get_prop(
props.DISPLAY_MODE) ~= mode do
click("display")
sleep(100)
end
end
The implementation of the next function,
sleep_until()
, could be trivial:
simply calling the
sleep()
command and specifying the interval between
now and the target time. But here, we want to do a bit more and allow the
user to abort the script with the
SET
key. By doing so, we have the ability to
restore the focus and display settings, which we cannot do if the user
aborts with the shutter button.
Therefore, we use the command
wait_click()
instead and specify the
interval (
sleep_time
) as a timeout. When this timeout happens, function
is_pressed()
returns
“
no_key”. We then return
false
because the user
does not want to abort. If the user clicks the
SET
key, we return
true
. For any
other key, we loop around and wait for the remaining time.
function sleep_until(ticks)
repeat
local sleep_time =
ticks - get_tick_count()
if sleep_time <= 0 then
return false
end
wait_click(sleep_time)
if is_pressed("set") then
return true
end
until is_pressed("no_key")
return false
end
Содержание Camera
Страница 1: ......
Страница 2: ...The Canon Camera Hackers Manual ...
Страница 3: ......
Страница 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Страница 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Страница 25: ...16 CH APTER 3 ...
Страница 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Страница 213: ...204 CH APTER 6 ...
Страница 253: ...244 AP PENDIX ...