CHDK Wiki
No edit summary
No edit summary
Tag: sourceedit
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The script copied below is an accurate intervalometer that takes advantage of the latest features in CHDK 1.3.0 (or newer).
+
The script listed below is an accurate intervalometer that takes advantage of the latest features in CHDK 1.3.0 (or newer).
   
 
Should work on any CHDK supported Canon P&S camera.
 
Should work on any CHDK supported Canon P&S camera.
Line 6: Line 6:
 
#Accurate time interval based shooting
 
#Accurate time interval based shooting
 
#An option to turn the display off after the first or fifth shot.
 
#An option to turn the display off after the first or fifth shot.
#An option to lock focus when the script starts or to lock focus at infinity.
+
#An option to lock focus (or to lock focus at infinity) when the script starts .
  +
#An option to lock exposure when the script starts.
 
#The ability to stop the script by pressing any button.
 
#The ability to stop the script by pressing any button.
   
Line 14: Line 15:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
--[[
 
--[[
@title Intervalometer One
+
@title Time Lapse One
   
 
@param i Interval (sec)
 
@param i Interval (sec)
@default i 5
+
@default i 15
 
@range i 2 3600
 
@range i 2 3600
@param d Display Off Time
+
@param d Display Off Time
 
@default d 0
 
@default d 0
 
@values d Never 1_shot 5_shots
 
@values d Never 1_shot 5_shots
@param f Focus
+
@param f Focus
 
@default f 0
 
@default f 0
@values f None Locked Infinity
+
@values f Auto Locked Infinity
  +
@param e Exposure
  +
@default e 0
  +
@values e Auto Locked
 
--]]
 
--]]
   
 
interval = i*1000
function lock_focus()
 
  +
display_mode = d
if ( set_mf(1) == 0 ) then -- set MF mode
 
  +
focus_mode = f
set_aflock(1) -- fall back to AFL if set_mf fails
 
  +
exposure_mode = e
  +
  +
-- ========================== Useful Functions =================================
  +
 
function lock_focus()
 
if ( set_mf(1) == 0 ) then -- set MF mode
 
set_aflock(1) -- fall back to AFL if set_mf fails
 
end
 
end
 
end
end
 
   
function unlock_focus()
+
function unlock_focus()
set_mf(0)
+
set_mf(0)
set_aflock(0)
+
set_aflock(0)
end
+
end
   
function restore()
+
function restore()
if f > 0 then unlock_focus() end
+
if (exposure_mode == 1) then set_aelock(0) end
if d > 0 then set_lcd_display(1) end
+
if (focus_mode > 0 ) then unlock_focus() end
  +
if (display_mode > 0 ) then set_lcd_display(1) end
end
 
 
end
   
 
-- ========================== Main Program =================================
 
-- ========================== Main Program =================================
Line 51: Line 63:
 
print("CHDK 1.3.0 or higher required")
 
print("CHDK 1.3.0 or higher required")
 
else
 
else
  +
-- disable shutter button to allow orderly shutdown on any key press
 
-- setup CHDK so that shutter button does not halt the script
 
 
set_exit_key("no_key")
 
set_exit_key("no_key")
 
set_draw_title_line(0)
 
set_draw_title_line(0)
 
set_console_layout(1 ,5, 45, 12 )
 
set_console_layout(1 ,5, 45, 12 )
 
 
-- switch to shooting mode on start up
+
-- switch to shooting mode if necessary
 
if ( get_mode() == false ) then
 
if ( get_mode() == false ) then
sleep(1000)
 
set_record(1)
 
while ( get_mode() == false) do sleep(100) end
 
end
 
sleep(500)
 
 
-- set focus if requested
 
if f > 0 then lock_focus() end
 
if f==2 then
 
set_focus(50000)
 
 
sleep(1000)
 
sleep(1000)
 
set_record(1)
 
while ( get_mode() == false) do sleep(100) end
 
sleep(500)
 
end
 
end
   
-- loop until any key is pressed
+
-- enable ae lock or af lock if requested
  +
if (exposure_mode == 1) or (focus_mode > 0) then
  +
press("shoot_half")
  +
count = 0
  +
repeat
  +
sleep(50)
  +
count = count + 1
  +
until (get_shooting() == true ) or (count > 40 )
  +
if (exposure_mode == 1) then set_aelock(1) end
 
if (focus_mode > 0) then lock_focus() end
  +
release("shoot_half")
 
if (focus_mode == 2) then
  +
sleep(500)
 
set_focus(50000)
  +
sleep(1000)
  +
end
 
end
  +
  +
-- shoot and loop forever until any key pressed
 
shot_count = 1
 
shot_count = 1
 
next_time = get_tick_count()
 
next_time = get_tick_count()
 
repeat
 
repeat
 
if ( next_time <= get_tick_count() ) then
 
if ( next_time <= get_tick_count() ) then
print("Shot : "..shot_count)
+
print("Shot : "..shot_count)
shoot()
+
press("shoot_half")
if ((d == 1) and (shot_count == 2)) then set_lcd_display(0) end
+
if ( exposure_mode == 1) then
if ((d == 2) and (shot_count == 6)) then set_lcd_display(0) end
+
if ( focus_mode > 0 ) then
  +
sleep(500) -- ae and af locked
  +
else
  +
count = 0
  +
repeat
  +
sleep(50)
  +
count = count + 1
  +
until (get_focus_ok() == true ) or (count > 40 ) -- only ae locked
  +
end
  +
else
  +
count = 0
  +
repeat
  +
sleep(50)
  +
count = count + 1
  +
until (get_shooting() == true ) or (count > 40 ) -- only af locked or nothing locked
  +
end
  +
press("shoot_full")
  +
sleep(1000)
  +
release("shoot_full")
 
shot_count = shot_count + 1
 
shot_count = shot_count + 1
next_time = next_time + i*1000
+
if ((display_mode == 1) and (shot_count == 2)) then set_lcd_display(0) end
  +
if ((display_mode == 2) and (shot_count == 6)) then set_lcd_display(0) end
  +
next_time = next_time + interval
 
end
 
end
 
wait_click(100)
 
wait_click(100)
Line 88: Line 130:
 
restore()
 
restore()
 
end
 
end
 
 
   
 
</syntaxhighlight>
 
</syntaxhighlight>
  +
[[Category:Scripts]]

Revision as of 03:55, 19 December 2015

The script listed below is an accurate intervalometer that takes advantage of the latest features in CHDK 1.3.0 (or newer).

Should work on any CHDK supported Canon P&S camera.

Features

  1. Accurate time interval based shooting
  2. An option to turn the display off after the first or fifth shot.
  3. An option to lock focus (or to lock focus at infinity) when the script starts .
  4. An option to lock exposure when the script starts.
  5. The ability to stop the script by pressing any button.

Lua Script

TLapse1.lua : for CHDK v1.3.0 or greater (see note below)

--[[
@title Time Lapse One

@param     i Interval (sec)
  @default i 15
  @range   i 2 3600
@param     d Display Off Time
  @default d 0
  @values  d Never 1_shot 5_shots
@param     f Focus
  @default f 0
  @values  f Auto Locked Infinity
@param     e Exposure
  @default e 0
  @values  e Auto Locked
--]]

    interval      = i*1000
    display_mode  = d
    focus_mode    = f
    exposure_mode = e

--  ========================== Useful Functions ================================= 

    function lock_focus()
        if ( set_mf(1) == 0 ) then       -- set MF mode
            set_aflock(1)                -- fall back to AFL if set_mf fails
        end
    end

    function unlock_focus()
        set_mf(0)
        set_aflock(0)
    end

    function restore()
        if (exposure_mode == 1) then set_aelock(0) end
        if (focus_mode > 0    ) then unlock_focus() end
        if (display_mode > 0  ) then set_lcd_display(1) end
    end

--  ========================== Main Program ================================= 

bi=get_buildinfo()
version= tonumber(string.sub(bi.build_number,1,1))*100 + tonumber(string.sub(bi.build_number,3,3))*10 + tonumber(string.sub(bi.build_number,5,5))

if ( version < 130) then 
    print("CHDK 1.3.0 or higher required")
else
    -- disable shutter button to allow orderly shutdown on any key press
    set_exit_key("no_key")
    set_draw_title_line(0)    
    set_console_layout(1 ,5, 45, 12 )
    
    -- switch to shooting mode if necessary
    if ( get_mode() == false ) then
        sleep(1000)
        set_record(1)                 
        while ( get_mode() == false) do sleep(100) end
        sleep(500)   
    end

    -- enable ae lock or af lock if requested
    if (exposure_mode == 1) or (focus_mode > 0) then    
        press("shoot_half")     
        count = 0
        repeat  
            sleep(50)
            count = count + 1     
        until (get_shooting() == true ) or (count > 40 )
        if (exposure_mode == 1) then set_aelock(1) end
        if (focus_mode > 0)  then lock_focus() end
        release("shoot_half") 
        if (focus_mode == 2) then 
            sleep(500)
            set_focus(50000)  
            sleep(1000)
        end
    end
    
    -- shoot and loop forever until any key pressed
    shot_count = 1
    next_time = get_tick_count()
    repeat
        if ( next_time <= get_tick_count() ) then
            print("Shot : "..shot_count)   
            press("shoot_half")         
            if ( exposure_mode == 1) then 
                if ( focus_mode > 0 ) then 
                   sleep(500)                                         -- ae and af locked
                else
                    count = 0
                    repeat  
                        sleep(50)
                        count = count + 1 
                    until (get_focus_ok() == true ) or (count > 40 )  -- only ae locked
                end
            else
                count = 0
                repeat  
                    sleep(50)
                    count = count + 1      
                until (get_shooting() == true ) or (count > 40 )      -- only af locked or nothing locked
            end
            press("shoot_full")
            sleep(1000)
            release("shoot_full")
            shot_count = shot_count + 1 
            if ((display_mode == 1) and (shot_count == 2)) then set_lcd_display(0) end
            if ((display_mode == 2) and (shot_count == 6)) then set_lcd_display(0) end        
            next_time = next_time + interval
        end
        wait_click(100)
    until not(is_key("no_key"))
    restore()
end