CHDK Wiki
mNo edit summary
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
#<span style="line-height:21px;">Switch to playback mode between shots.</span>
 
#<span style="line-height:21px;">Switch to playback mode between shots.</span>
 
#<span style="line-height:21px;">Enter sleep mode between shots (on cameras with a "short cut" button)</span>
 
#<span style="line-height:21px;">Enter sleep mode between shots (on cameras with a "short cut" button)</span>
Testing indicates that the using the first two methods will extend battery life about 20%.  The other three methods can double or even quadtriple battery life.
+
Testing indicates that the using the first two methods will extend battery life about 20%.  The other three methods can double or even quadruple battery life.
   
Discussion thread for this script is here : [http://chdk.setepontos.com/index.php?topic=9049 Battery Intervalometer]​ .  Save it with .lua file extension - something like '''battery.lua'''
+
Discussion thread for this script is here : [http://chdk.setepontos.com/index.php?topic=9049 Battery Intervalometer]​ .  Save it with .lua file extension - something like '''miser2.lua'''
   
  +
<syntaxhighlight lang="lua">
--[[
 
  +
--[[
@title Battery Intervalometer 5.5
 
  +
@title Battery Miser 6.1
@param s Interval (sec)
 
  +
@param s Interval (sec)
@default s 60
 
  +
@default s 60
@param b Turn Backlight Off
 
  +
@param b Turn Backlight Off
@default b 0
 
@range b 0 1
+
@default b 0
  +
@range b 0 1
@param d Turn Display Off
 
  +
@param d Turn Display Off
@default d 0
 
@range d 0 1
+
@default d 0
  +
@range d 0 1
@param p Wait in Playback Mode
 
  +
@param p Wait in Playback Mode
@default p 0
 
@range p 0 1
+
@default p 0
  +
@range p 0 1
@param a Enable AF Lock
 
  +
@param k Use shortcut key to sleep
@default a 0
 
@range a 0 1
+
@default k 0
  +
@range k 0 1
@param l Log to File
 
  +
@param a Enable AF Lock
@default l 1
 
@range l 0 1
+
@default a 0
  +
@range a 0 1
@param r Lens Retract Delay (sec)
 
  +
@param l Log to File
@default r 60
 
  +
@default l 1
@param v Batttery Stop Voltage (mV)
 
  +
@range l 0 1
@default v 1000
 
  +
@param r Lens Retract Delay (sec)
@range v 0 10000
 
  +
@default r 60
--]]
 
  +
@param v Batttery Stop Voltage (mV)
 
  +
@default v 1000
props=require("propcase")
 
  +
@range v 0 10000
 
  +
--]]
function restore()
 
  +
set_backlight(1)
 
  +
props=require("propcase")
set_aflock(0)
 
  +
end
 
  +
shortcut_key="print" -- edit this if using shortcut key to enter sleep mode
 
  +
sleep_mode=false
function log_to_file( string )
 
  +
if ( l == 1 ) then
 
  +
print_screen(-10)
 
  +
function restore()
print(string)
 
print_screen(false)
+
set_backlight(1)
else
+
set_aflock(0)
print(string)
+
sleep_disable()
end
+
end
  +
end
 
  +
function sleep_enable()
 
  +
if( sleep_mode==false) then
function switch_mode( m ) -- change between shooting and playback mode
 
if ( m == 1 ) then
+
print("enter sleep mode via shortcut")
if ( get_mode() == false ) then
+
press(shortcut_key)
  +
sleep(2000)
print("switching to record mode")
 
set_record(1)
+
release(shortcut_key)
  +
sleep_mode=true
while ( get_mode() == false ) do
 
  +
end
sleep(100)
 
end
+
end
  +
  +
function sleep_disable()
  +
if( sleep_mode==true) then
  +
print("exit sleep mode via shortcut")
  +
press(shortcut_key)
  +
sleep(2000)
  +
release(shortcut_key)
  +
sleep_mode=false
  +
end
  +
end
  +
  +
  +
function log_to_file( string )
  +
if ( l == 1 ) then
  +
print_screen(-10)
  +
print(string)
  +
print_screen(false)
  +
else
  +
print(string)
  +
end
  +
end
  +
  +
  +
function switch_mode( m ) -- change between shooting and playback mode
  +
if ( m == 1 ) then
  +
if ( get_mode() == false ) then
  +
print("switching to record mode")
  +
set_record(1)
  +
while ( get_mode() == false ) do
  +
sleep(100)
  +
end
  +
end
  +
else
  +
if ( get_mode() == true ) then
  +
print("switching to playback mode")
  +
set_record(0)
  +
while ( get_mode() == true ) do
  +
sleep(100)
  +
end
 
end
 
end
else
+
end
  +
end
if (( get_mode() == true ) and ( p == 1 )) then
 
  +
print("switching to playback mode")
 
  +
function display_off() -- turn off display by pressing DISP button
set_record(0)
 
  +
print("blanking display")
while ( get_mode() == true ) do
 
  +
count=5
sleep(100)
 
  +
disp_save = get_prop(props.DISPLAY_MODE)
end
 
end
+
repeat
  +
disp = get_prop(props.DISPLAY_MODE)
  +
if ( disp ~= 2 ) then
  +
click("display")
  +
sleep(500)
  +
end
  +
count=count-1
  +
until ((disp==2) or (count==0))
  +
if ( count>0 ) then
  +
print("display blanked")
  +
else
  +
print("unable to blank the display")
  +
end
  +
end
  +
  +
set_console_layout(0,0,45,12)
  +
  +
if ( l==1 ) then
  +
print_screen(-10)
  +
print(" ")
  +
print("============================================")
  +
print(os.date("%d.%m.%y %X"))
  +
print("interval=",s,"retract=",r,"AFL=",a)
  +
print("backlight=",b,"playback_idle=",p)
  +
print("display off=",d, "vbatt cutout=", v)
  +
print("sleep mode=",k,"logging=",d)
  +
print("============================================")
  +
print_screen(false)
  +
end
  +
  +
sleep(2000)
  +
  +
shotcount=0
  +
interval=s*1000
  +
retract=r*1000
  +
b=1-b
  +
  +
  +
switch_mode(1)
  +
  +
if( a == 1 ) then -- focus lock ?
  +
press( "shoot_half" )
  +
while ( get_shooting() == true ) do
  +
sleep(100)
 
end
 
end
  +
release("shoot_half")
end
 
  +
set_aflock(1)
 
  +
print( "--focus locked")
set_console_layout(0,0,45,12)
 
  +
sleep(500)
 
  +
end
if ( l==1 ) then
 
  +
print_screen(-10)
 
  +
if ( d==1 ) then -- turn display off ?
print(" ")
 
  +
if( p==1 ) then
print("============================================")
 
print(os.date("%d.%m.%y %X"))
+
print("**Warning: Wait in Playback mode")
  +
print("**conflicts with Display Off mode.")
print("interval=",s,"retract=",r,"AFL=",a)
 
  +
print("**Disabling Playback Idle mode")
print("backlight=",b,"playback_idle=",p)
 
  +
sleep(2000)
print("display off=",d, "vbatt cutout=", v)
 
print("logging=",d)
+
p=0
  +
end
print("============================================")
 
print_screen(false)
+
display_off()
  +
sleep(5000)
end
 
  +
end
 
  +
sleep(2000)
 
  +
 
  +
battery = get_vbatt()
shotcount=0
 
  +
nextshot=get_tick_count()
interval=s*1000
 
  +
start=nextshot
retract=r*1000
 
  +
abort = false
b=1-b
 
  +
 
  +
switch_mode(1)
 
  +
-- intervalometer loop starts here
 
  +
if( a == 1 ) then -- focus lock ?
 
  +
repeat
press( "shoot_half" )
 
  +
switch_mode(1)
while ( get_shooting() == true ) do
 
  +
print("short wait =", (nextshot-get_tick_count())/1000 )
sleep(100)
 
  +
while (nextshot > get_tick_count()) do
end
 
release("shoot_half")
+
set_backlight(b)
set_aflock(1)
 
print( "--focus locked")
 
 
sleep(500)
 
sleep(500)
end
+
end
  +
 
  +
shotcount = shotcount + 1
if ( d==1 ) then -- turn display off ?
 
if( p==1 ) then
+
tic = get_tick_count()-start
  +
nextshot = nextshot + interval
print("**Warning: Wait in Playback mode")
 
  +
lens_retract = get_tick_count() + retract
print("**conflicts with Display Off mode.")
 
  +
log_to_file(string.format("shot:%d %2.2d:%2.2d %d.%2.2dV", shotcount, tic/3600000, (tic%3600000)/60000, battery/1000, (battery%1000)/10))
print("**Disabling Playback Idle mode")
 
  +
sleep(2000)
 
  +
if (k==1) then sleep_disable() end
p=0
 
  +
end
 
  +
shoot()
print("blanking display")
 
  +
sleep(2000)
 
count=5
+
sleep(200)
  +
disp_save = get_prop(props.DISPLAY_MODE)
 
  +
if( p==1) then switch_mode(0) end
repeat
 
  +
disp = get_prop(props.DISPLAY_MODE)
 
if ( disp ~= 2 ) then
+
if (k==1) then sleep_enable() end
  +
click("display")
 
  +
print( "next shot wait ..", (nextshot-get_tick_count())/1000 )
sleep(500)
 
end
+
repeat
  +
if( (p==1) and (lens_retract < (get_tick_count()+2000) )) then
count=count-1
 
  +
switch_mode(1)
until ((disp==2) or (count==0))
 
if ( count>0 ) then
+
switch_mode(0)
  +
lens_retract = get_tick_count() + retract
print("display blanked")
 
else
+
end
print("unable to blank the display")
 
end
 
sleep(5000)
 
end
 
 
battery = get_vbatt()
 
nextshot=get_tick_count()
 
start=nextshot
 
abort = false
 
 
-- intervalometer loop starts here
 
 
repeat
 
switch_mode(1)
 
print("short wait =", (nextshot-get_tick_count())/1000 )
 
while (nextshot > get_tick_count()) do
 
 
set_backlight(b)
 
set_backlight(b)
  +
battery = (get_vbatt() + (battery*15)) / 16
sleep(500)
 
  +
if ( battery < v ) then abort=true end
end
 
  +
if ( is_pressed("menu")) then abort=true end
 
shotcount = shotcount + 1
+
sleep(100)
tic = get_tick_count()-start
+
until ((nextshot < (get_tick_count()+3000) ) or abort)
  +
until ( abort )
nextshot = nextshot + interval
 
  +
lens_retract = get_tick_count() + retract
 
  +
-- all done - user abort or battery below limit
log_to_file(string.format("shot:%d %2.2d:%2.2d %d.%2.2dV", shotcount, tic/3600000, (tic%3600000)/60000, battery/1000, (battery%1000)/10))
 
  +
 
  +
if( battery < v ) then
shoot()
 
  +
log_to_file("battery limit reached")
 
  +
else
sleep(200)
 
  +
log_to_file("user abort")
 
  +
end
switch_mode(0)
 
  +
print( "next shot wait ..", (nextshot-get_tick_count())/1000 )
 
repeat
+
if ( d==1 ) then
  +
print("unblanking display")
if( lens_retract < (get_tick_count()+2000) ) then
 
  +
count=5
switch_mode(1)
 
  +
repeat
switch_mode(0)
 
  +
disp = get_prop(props.DISPLAY_MODE)
lens_retract = get_tick_count() + retract
 
end
+
if ( disp ~= disp_save) then
set_backlight(b)
+
click("display")
  +
sleep(500)
battery = (get_vbatt() + (battery*15)) / 16
 
  +
end
if ( battery < v ) then abort=true end
 
  +
count=count-1
if ( is_pressed("menu")) then abort=true end
 
  +
until ((disp==disp_save) or (count==0))
sleep(100)
 
  +
end
until ((nextshot < (get_tick_count()+3000) ) or abort)
 
  +
restore()
until ( abort )
 
  +
 
  +
-- all done - user abort or battery below limit
 
  +
</syntaxhighlight>
 
if( battery < v ) then
 
log_to_file("battery limit reached")
 
else
 
log_to_file("user abort")
 
end
 
 
if ( d==1 ) then
 
print("unblanking display")
 
count=5
 
repeat
 
disp = get_prop(props.DISPLAY_MODE)
 
if ( disp ~= disp_save) then
 
click("display")
 
sleep(500)
 
end
 
count=count-1
 
until ((disp==disp_save) or (count==0))
 
end
 
restore()
 
<span style="line-height:13.981481552124023px;white-space:pre;"> 
 
</span>
 
 
[[Category:Intervalometer]]
 
[[Category:Intervalometer]]
 
[[Category:Scripts]]
 
[[Category:Scripts]]

Latest revision as of 16:57, 6 April 2013

This script was written to demonstrate and test the various methods known to extend battery life when using an intervalometer (time lapse) script.  These are :

  1. Lock the autofocus.
  2. Turn the backlight off.
  3. Turn the display off (on camera that supports that - typically models with an OVF)\
  4. Switch to playback mode between shots.
  5. Enter sleep mode between shots (on cameras with a "short cut" button)

Testing indicates that the using the first two methods will extend battery life about 20%.  The other three methods can double or even quadruple battery life.

Discussion thread for this script is here : Battery Intervalometer​ .  Save it with .lua file extension - something like miser2.lua

--[[
@title Battery Miser 6.1
@param s Interval (sec)
@default s 60
@param b Turn Backlight Off
@default b 0
@range b 0 1
@param d Turn Display Off
@default d 0
@range d 0 1
@param p Wait in Playback Mode
@default p 0
@range p 0 1
@param k Use shortcut key to sleep
@default k 0
@range k 0 1
@param a Enable AF Lock
@default a 0
@range a 0 1
@param l Log to File
@default l 1
@range l 0 1
@param r Lens Retract Delay (sec)
@default r 60
@param v Batttery Stop Voltage (mV)
@default v 1000
@range v 0 10000
--]]

props=require("propcase")

shortcut_key="print"   -- edit this if using shortcut key to enter sleep mode
sleep_mode=false


function restore()
    set_backlight(1)
    set_aflock(0)
    sleep_disable()
end

function sleep_enable()
  if( sleep_mode==false) then
      print("enter sleep mode via shortcut")
      press(shortcut_key)
      sleep(2000)
      release(shortcut_key)
      sleep_mode=true
  end
end
  
function sleep_disable()
  if( sleep_mode==true) then
      print("exit sleep mode via shortcut")
      press(shortcut_key)
      sleep(2000)
      release(shortcut_key)
      sleep_mode=false
  end
end
  

function log_to_file( string )
   if ( l == 1 ) then
      print_screen(-10)
         print(string)
      print_screen(false)
   else
     print(string)
   end
end


function switch_mode( m )   -- change between shooting and playback mode
   if ( m == 1 ) then
      if ( get_mode() == false ) then
         print("switching to record mode")
         set_record(1)
         while ( get_mode() == false ) do
            sleep(100)
         end
      end
   else
      if ( get_mode() == true ) then
         print("switching to playback mode")
         set_record(0)
         while ( get_mode() == true ) do
            sleep(100)
         end
       end
   end
end

function display_off()   -- turn off display by pressing DISP button
   print("blanking display")
   count=5
   disp_save = get_prop(props.DISPLAY_MODE)   
   repeat
      disp = get_prop(props.DISPLAY_MODE)   
      if ( disp ~= 2 ) then
          click("display")
          sleep(500)
      end
      count=count-1
   until ((disp==2) or (count==0))
   if ( count>0 ) then 
       print("display blanked")
   else
       print("unable to blank the display")
   end
end

set_console_layout(0,0,45,12)

if ( l==1 ) then
   print_screen(-10)
   print("  ")
   print("============================================")
   print(os.date("%d.%m.%y  %X"))
   print("interval=",s,"retract=",r,"AFL=",a)
   print("backlight=",b,"playback_idle=",p)
   print("display off=",d, "vbatt cutout=", v)
   print("sleep mode=",k,"logging=",d)
   print("============================================")
   print_screen(false)
end

sleep(2000)

shotcount=0
interval=s*1000
retract=r*1000
b=1-b


switch_mode(1)

if( a == 1 ) then            -- focus lock ?
    press( "shoot_half" )
    while ( get_shooting() == true ) do
      sleep(100)
    end
    release("shoot_half")
    set_aflock(1)
    print( "--focus locked")
    sleep(500)
end

if ( d==1 ) then             -- turn display off ?
   if( p==1 ) then 
	print("**Warning: Wait in Playback mode")
	print("**conflicts with Display Off mode.")
        print("**Disabling Playback Idle mode")
        sleep(2000)
        p=0
   end
   display_off()
   sleep(5000)
end


battery = get_vbatt()
nextshot=get_tick_count()
start=nextshot
abort = false


-- intervalometer loop starts here

repeat 
   switch_mode(1)
   print("short wait =", (nextshot-get_tick_count())/1000 )
   while (nextshot > get_tick_count()) do
     set_backlight(b)
     sleep(500)
   end

   shotcount = shotcount + 1
   tic  = get_tick_count()-start
   nextshot = nextshot + interval
   lens_retract = get_tick_count() + retract
   log_to_file(string.format("shot:%d %2.2d:%2.2d %d.%2.2dV", shotcount, tic/3600000, (tic%3600000)/60000, battery/1000, (battery%1000)/10))

   if (k==1) then sleep_disable() end

   shoot()

   sleep(200)

   if( p==1) then switch_mode(0) end

   if (k==1) then sleep_enable() end

   print( "next shot wait ..", (nextshot-get_tick_count())/1000 )
   repeat
      if( (p==1) and (lens_retract < (get_tick_count()+2000) )) then
         switch_mode(1)
         switch_mode(0)
         lens_retract = get_tick_count() + retract
      end
      set_backlight(b)
      battery = (get_vbatt() + (battery*15)) / 16
      if ( battery < v ) then abort=true end
      if ( is_pressed("menu")) then abort=true end
      sleep(100)
   until ((nextshot < (get_tick_count()+3000) ) or abort)
until ( abort )

-- all done - user abort or battery below limit

if( battery < v ) then
   log_to_file("battery limit reached")
else
   log_to_file("user abort")
end

if ( d==1 ) then
   print("unblanking display")
   count=5
   repeat
      disp = get_prop(props.DISPLAY_MODE)
      if ( disp ~= disp_save) then
         click("display")
         sleep(500)
      end
      count=count-1
   until ((disp==disp_save) or (count==0))
end
restore()