--[[
@title AUTOEXP 3.0
@param n NumofShots
@default n 10000
@param d Delay
@default d 10
@param s Delay step (ms)
@default s 500
@param m Mode
@default m 0
@values m accurate fast
@param l Bv96 correction @ Bv = -500
@default l 0
@param h Bv96 correction @ Bv = +500
@default h 0
@param p Disable shoot
@default p 0
@range p 0 1
@param g Make log?
@default g 0
@range g 0 1
@param x Debbug info? -NOT-YET!-
@default x 0
@range x 0 1
--]]
--[[
Universal intervalometer version 3.0
This script is based on work of cyril42e (cyril42e@gmail.com)
[url]http://crteknologies.fr/wiki/doku.php/photo:chdk-scripts#night_shot[/url]
(I used his way to calculate shutter time)
Changed to intervalometer and converted to Lua by Pawel Tokarz aka Outslider
A lot of inspiration from the newest Waterwingzs version of yass:
[url]http://chdk.setepontos.com/index.php?topic=4920.msg99555#msg99555[/url]
--]]
--[[
Difference between modes:
- accurate mode:
*press half_shoot
*measure bv, calculate tv
*release half_shoot
*apply changes
*shoot
- fast mode:
*press half-shoot
*measure bv, calculate tv
*set_tv96_direct
*shoot without release of half-shutter
*release half_shoot - apply changes
--]]
--OK, set all global variables
TV_NEW=0
BV=0
PHOTO_NO=1
BV_COR=0
loop_step_start_time=0
time_to_wait=0
A=h-l
B=(l+h)/2
LOGFILE='A/SCRIPTS/AEXP3.LOG'
-- FUNCTIONS --
function init()
set_console_layout(0,0,25,6)
set_console_autoredraw(0)
end
function main()
if(m==0) then accurate_loop()
elseif(m==1) then fast_loop()
end
end
--debbug print function
function dprint(string)
if(x==1) then print(string) end
end
function print_data()
print("== PHOTO NO: "..PHOTO_NO.."/"..n)
print("Brightness: "..BV)
print("Shutter: "..seconds(TV_NEW).." s")
print("Correction: "..BV_COR)
print()
print("Time left: "..time_to_wait/1000+1)
log(" - time to wait: "..time_to_wait)
end
--function that prepares the camera for shooting
function make_camera_ready()
log(" -press shoot_half:"..get_tick_count())
press("shoot_half")
log(" -presd shoot_half:"..get_tick_count())
repeat
log(" - start sleep: "..get_tick_count())
sleep(50)
log(" - test get_sht: "..get_tick_count())
until get_shooting() == true
log(" - got shooting: "..get_tick_count())
end
function counter()
time_to_wait=1000*d-get_tick_count()+loop_step_start_time
log(" - start counter: "..get_tick_count())
log(" - time to wait*: "..time_to_wait)
repeat
time_to_wait=1000*d-get_tick_count()+loop_step_start_time
print_data();
sleep(s)
until time_to_wait<s
loop_step_start_time=get_tick_count()
end
--we start the main loop
function accurate_loop()
log("== LOOP STARTS NOW!!! ==")
repeat
log("== photo: "..PHOTO_NO.." ==")
loop_step_start_time=get_tick_count()
make_camera_ready()
log(" - rel shoot_half: "..get_tick_count())
release("shoot_half")
--we read Bv (luminance), Sv (ISO), Av (aperture) and current Tv (exposure time)
Bv=get_bv96()
Sv=get_sv96()
Av=get_av96()
Tv=get_tv96()
BV=Bv
BV_COR=Bv*A/1000+B
TV_NEW=Bv+Sv-Av-BV_COR
log(" - got exp params: "..get_tick_count())
log(" - Bv: "..Bv)
log(" - Sv: "..Sv)
log(" - Av: "..Av)
log(" - set Tv: "..TV_NEW)
log(" - set Tvs:"..seconds(TV_NEW))
set_tv96_direct(TV_NEW)
log(" - shoot: "..get_tick_count())
if(p==0) then
shoot()
end
counter()
PHOTO_NO=PHOTO_NO+1
until PHOTO_NO>n
end
function fast_loop()
log("== LOOP STARTS NOW!!! ==")
repeat
log("== photo: "..PHOTO_NO.." ==")
loop_step_start_time=get_tick_count()
make_camera_ready()
log(" - shoot: "..get_tick_count())
if(p==0) then
shoot()
end
log(" - rel shoot_half: "..get_tick_count())
release("shoot_half")
--we read Bv (luminance), Sv (ISO), Av (aperture) and current Tv (exposure time)
Bv=get_bv96()
Sv=get_sv96()
Av=get_av96()
Tv=get_tv96()
BV=Bv
BV_COR=Bv*A/1000+B
TV_NEW=Bv+Sv-Av-BV_COR
log(" - got exp params: "..get_tick_count())
log(" - Bv: "..Bv)
log(" - Sv: "..Sv)
log(" - Av: "..Av)
log(" - set Tv: "..TV_NEW)
log(" - set Tvs:"..seconds(TV_NEW))
set_tv96_direct(TV_NEW)
counter()
PHOTO_NO=PHOTO_NO+1
until PHOTO_NO>n
end
--from lapser's code:
--http://chdk.setepontos.com/index.php?topic=8742.new#new
function seconds(tv) -- for chdk 32 bit integer numbers
if(tlog==nil)then
tlog="000007015022029037044052059067075083091098106114122131139147155164172181189198207215224233242251260269278288297306316325335345354364374384394404414424435445456466477488498509520531542553565576587599610622634646658670682694706719731744756769782795808821834847861874888901915929943957971986"
end
pre="1/"
if(tv<=0)then
tv=-tv
pre=""
end
ti=(tv%96)*3+1 -- index into tlog
tv=(2^(tv/96))*(string.sub(tlog,ti,ti+2)+1000) -- time value in msec
ti=tv/1000 -- integer part
ts=string.format("%s%u.%03u",pre,ti,tv%1000) -- xx.xxx or 1/xx.xxx
if(ti>1)then -- truncate digits to reflect decimal precision
if(ti>149)then ti=-5
elseif(ti>14)then ti=-3
else ti=-2
end
ts=string.sub(ts,1,ti)
end
return ts
end
function log(string)
if(g==1) then
logfile_h=io.open(LOGFILE,"a+")
if (not logfile_h) then
print("Error opening logfile")
print("Press any key")
wait_click(0)
return
end
logfile_h:write(string)
logfile_h:write("\n")
logfile_h:close()
end
end
init()
main()