I modified script_shoot_hook_run(int hook) to provide an interval timer. Here's how you activate it in Lua:
hook_shoot.set(-interval)
So to set a 2 second interval, you'd call it like this:
hook_shoot.set(-2000)
I also added the option to enable the hook without a timeout (infinite timeout):
hook_raw.set(-1)
To return the enter and exit times for a hook, I modified script_shoot_hook_count(int hook) to return those values in addition to the count. Here's the Lua call:
count,henter,hexit=hook_shoot.count()
Here are the changes to the file, script_shoot_hook.c
//lapser begin
extern int get_tick_count();
void script_shoot_hook_run(int hook)
{
int timeout=hooks[hook].timeout;
int tickdone = get_tick_count();
hooks[hook].enter = tickdone;
hooks[hook].count++;
// only mark hook active if it was set
if(timeout != 0){
// notify rawop when in raw hook, so it can update valid raw status
// and values that might change between shots
if(hook == SCRIPT_SHOOT_HOOK_RAW) {
rawop_update_hook_status(1);
}
hooks[hook].active = 1;
if(timeout > 0)tickdone += timeout; //normal timeout >0
else tickdone = hooks[hook].exit - timeout; //interval timeout <0
while(((timeout==-1)||(get_tick_count()<tickdone)) && hooks[hook].active) {
msleep(10);
}
if(hook == SCRIPT_SHOOT_HOOK_RAW) {
rawop_update_hook_status(0);
}
hooks[hook].active = 0;
}
hooks[hook].exit = get_tick_count();
}
//lapser end
*********** also changed this function at the end of the file
//lapser begin
int icalled=0; //called 3 times from luascript.c
//return number of times hook has been called (for this script),
// plus enter and exit tick counts
int script_shoot_hook_count(int hook)
{
icalled++;
if(icalled == 1)return hooks[hook].count;
if(icalled == 2)return hooks[hook].enter; //tick count entered hook
icalled=0;
return hooks[hook].exit; //tick count exited hook (i.e. shutter open tick)
}
I also needed to make a 2 line change in luascript.c
static int luaCB_shoot_hook_count( lua_State* L )
{
int hook = lua_tonumber( L, lua_upvalueindex(1) );
lua_pushnumber(L,script_shoot_hook_count(hook));
//return 1;
lua_pushnumber(L,script_shoot_hook_count(hook));//lapser hook enter time
lua_pushnumber(L,script_shoot_hook_count(hook));//lapser hook exit time
return 3; //lapser
}
That's all that's needed. All of my changes are backwards compatible, so they won't affect any existing scripts.
Here's the test script, "Itest.lua"
--[[
@title Interval Test
@chdk_version 1.5.0
#interval=20 "Interval (sec*10)"
#nshots=15 "# Shots (0: no limit)"
]]
--logger s: one line sent to log file (set fname before first call)
bi=get_buildinfo()
fname="A/CHDK/LOGS/"..bi.platform..os.date("_%y%m%d_%H%M_Itest.log")
function logger(s)
if slog==nil then -- first call opens file
if s==nil then return end -- don't open empty file
flog=io.open(fname,"ab")
slog={}
nlog=0
end
if s~=nil then
nlog=nlog+1
slog[nlog]=s
else
for i=1,nlog do
flog:write(slog[i],"\n")
end
flog:close()
slog=nil
end
end
function ksleep(t)
wait_click(t)
if not is_key("no_key") then
done=true
end
end
if(interval<1)then interval=1 end
interval=interval*100 -- convert to msec
--bi=get_buildinfo()
logger("Itest "..os.date())
logger(string.format("Camera:%s f/w:%s platformID:%s bit/pixel:%d",
bi.platform,bi.platsub,bi.platformid,rawop.get_bits_per_pixel()))
logger(string.format("version:%s %s built on %s %s",
bi.version,bi.build_number,bi.build_date,bi.build_time))
logger(string.format("Interval=%d",interval))
logger(string.format("Nshots=%d",nshots))
cls()
set_console_autoredraw(-1)
set_draw_title_line(0)
osd=get_config_value(1)
set_config_value(1, 0)
-- don't set hook_shoot until in raw hook after 1st shot (no delay before 2nd shot)
hook_raw.set(-1) -- no timeout
done=false
logger() -- write log so far to SD card
logger("Shot# Interval Late Early Rdelay Rdiff") -- reopens log file
sleep(1000)
press("shoot_half")
repeat sleep(10) until get_shooting()
press("shoot_full_only")
tlast=get_tick_count()
repeat
while not hook_raw.is_ready() do ksleep(10) end
hook_shoot.set(-interval) -- allows changing interval between shots
tnow1=get_tick_count()
count,tnow,hexit=hook_raw.count() -- tnow=raw hook enter tick
count,henter,hexit=hook_shoot.count()
logger(string.format("%5d%9d%8d%8d%8d%8d",
count, hexit-tlast, hexit-tlast-interval, hexit-henter, tnow-hexit, tnow1-tnow))
tlast=hexit
if done or count==nshots then
release("shoot_full")
done=true
end
hook_raw.continue()
until done
logger() -- print log and close file
set_config_value(1,osd)
To compile, save the attached files into the modules folder. The Itest.lua test script is attached to my next post.