Canon Camera Hackers Manual page 151

Camera hackers manual berthold daum
Table of Contents

Advertisement

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
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
other key, we loop around and wait for the remaining time.
function sleep_until(ticks)
repeat
local sleep_time =
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
SET
ticks - get_tick_count()
key. By doing so, we have the ability to
SET
key, we return true. For any

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents