I got my continuous mode interval timer working pretty well by adding a delay in raw_savefile() right after build_shot_histogram(). But this happens AFTER the shot, and you really want to time the interval from the start of the shot. I've been looking for a way to do this for awhile, but I think I finally found it.
There's already a hook that happens immediately before the shot. It looks like the purpose of this hook is to turn off dark frames, which is one of the most useful features of CHDK for night shots. But I also discovered that I can put my interval timer delay at the end of this function. It works!
With the delay right before the shutter opens, it should be almost perfectly accurate, since it doesn't depend on the shutter speed, or file save time. Delaying after the shot is not accurate when the shutter time or file save time changes between shots.
I recently discovered that in continuous drive mode, the last picture taken is displayed on the screen, instead of the screen going blank for the entire exposure (with review mode off). But while delaying in raw_savefile(), the picture isn't ready to show, so the picture before it shows on the screen during the delay. Moving the delay to right before the next shot solves this problem. The screen shows the shot just taken while waiting to take the next shot.
The delay only happens when a script is active, and the script called "set_shot_interval(delay)." But the delay happens in any mode, not just continuous. After setting a shot interval, each new shot will delay until the time between the new shot and the last shot exceeds that interval, even if you use a new half_press, or the shoot() function. A simple time lapse script would be:
set_shot_interval(10000) -- 10 seconds
repeat shoot() until false
When the script is terminated by pressing the shutter button, script.c calls set_shot_interval(0), and the delay is cancelled. The last picture will then be taken immediately.
void __attribute__((naked,noinline)) capt_seq_hook_set_nr()
{
asm volatile("STMFD SP!, {R0-R12,LR}\n");
switch (core_get_noise_reduction_value()){
case NOISE_REDUCTION_AUTO_CANON:
// leave it alone
...
raw_shot_delay(); //wait delay interval, if any, before continuing shot ******************
shutter_open_time=_time((void*)0);
shutter_open_tick_count = get_tick_count();
asm volatile("LDMFD SP!, {R0-R12,PC}\n");
}
I also added a double shot option to use with shot metering in continuous mode. It's activated with set_shot_interval(-2). After this, every other shot will have no delay.
Since shot metering takes place after the shot, the new exposure can't be applied until the next shot. If the shots are far apart, say 1 or 2 minutes, then the metering may not be accurate since the scene might change. So for long shot intervals, this option takes a "metering" shot, followed by a correctly exposed shot derived from the metering shot.