Skip to content

Instantly share code, notes, and snippets.

@pigeonhill
Last active May 13, 2023 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigeonhill/71b177b76b4d331baf3fa19488361584 to your computer and use it in GitHub Desktop.
Save pigeonhill/71b177b76b4d331baf3fa19488361584 to your computer and use it in GitHub Desktop.
--[[
@title QDFS
@chdk_version 1.7
#coc = 15 "CoC (um)" [5 30]
#brak = 0 "X bracket mode?" {ISO Tv HandH Auto->H Wind}
#b_val = 0 "X Bracketing Value" {Canon 1Ev 2Ev 3Ev 4Ev 5Ev}
#sleep_time = 0 "Delay (s)" [0 10]
#dis = 1 "Display" {#Bracks Focus}
#lensmag = 0 "Get Mag" {Off On Dynamic}
#reg = 1 "H/x Reg Dis" [1 3]
#offset = 1 "Console offset" [1 12]
#title = 1 "Title Line" {Off Full Exit}
#ettr_zero = 3 "ETTR zero count" [0 20]
#hhmin = 30 "HH Min Tv (1/x s)" [10 100]
Notes:
*
* This Quasi Depth of Field Scale script only runs on the M3 with the XIMR version of CHDK, ie CHDK 1.7
*
* The script provides visual feedback for manual deep focus bracketing, ie not for macro focus bracketing
* It also provides two, two exposure bracket options, from an ETTR exposure (ISO or Tv), a hand helding bracketing option, auto bracketing from...
* the shadows (set Ev to 2, 3 or 4), Wind bracketing and an option to use whatever Canon AEB is set
* The script first tests to see if a Canon AEB is set. If not the script then looks at the ISO/Tv ETTR bracketing options. Canon meaning whatever AEB is set on the Canon side, or not
* Repeatedly pressing the INFO button will cycle through the Canon screens, including the Canon histogram: which will be active via touch.
* Here you can change the AEB for example
* The script was mainly written for wide angle lenses and specifically the EF-M 11-22mm ;-)
* Although mainly EF-M lenses can be used, you can add other lenses, eg TS-E 24mm II
* An estimate of the front principal location can be found from subtracting the QDFS MFD (displayed in the console) from the Canon reported MFD
* Changing focal length will reset the DoF scale
* Switching out of ALT mode will exit the script
* Switching the console on in the script's menu will provide additional feedback, eg the lens stepper count and the Canon lower and upper focus bounds
* You can switch the console off by pressing the DOWN button
* Pressing the UP button will toggle between adjusting the shutter speed and ISO
* If you are focused beyond the hypefocal, the DoF Scale will display the infinity blur in microms (on the right of the DoF scale)
* The infinity blur info will disappear if you focus beyond the Canon 'data infinity', when you enter edit mode: using the LEFT, UP, RIGHT & DOWN buttons
* If selected, the number of brackets to the hyperfocal is also shown on the right, as you focus short of H/3
* If Focus is selected in the Display menu, then an ESTIMATE of the focus distance from the sensor is displayed: this can be compared to the Canon reported distance
* and the mag tuned as required
* Pressing the MENU button will toggle the bar on and off, eg as an aid to composing
* Pressing the INFO button will toggle through the various Canon displays
* Pressing the ZOOM-IN button will reset the realtive Ev feedback and show the current DoF on the top on the DoF scale
* A long press of the ZOOM-IN button will toggle between showing focus info on the right or % of the histogram in the top 1/3 stop
* Pressing the RIGHT button will ETTR, and pushing the LEFT button will ETTL. ETTR and ETTL thresholds can be changed in the code.
* If things don't look right either do a HS press, or change focal length to reset things or restart the script or the camera ;-)
* Further info on the script may be found on my blog, including dynamic focus calibration when the script is running
Release 1.403
photography.grayheron.net
April 2023
--]]
bi = get_buildinfo()
require "drawings"
props=require'propcase'
capmode = require("capmode")
tg = 242
bar = draw.add("rectf", 0, 0, 0, 0, tg,tg)
ndof = draw.add("rectf", 0, 0, 0, 0, tg,tg)
fdof = draw.add("rectf", 0, 0, 0, 0, tg,tg)
lastdof = draw.add("rectf", 0, 0, 0, 0, tg,tg)
line = draw.add("rectf", 0, 0, 0, 0, tg,tg)
hpos = draw.add("line", 0, 0, 0, 0, tg)
h3pos = draw.add("line", 0, 0, 0, 0, tg)
h5pos = draw.add("line", 0, 0, 0, 0, tg)
h7pos = draw.add("line", 0, 0, 0, 0, tg)
h9pos = draw.add("line", 0, 0, 0, 0, tg)
h10pos = draw.add("line", 0, 0, 0, 0, tg)
h0pos = draw.add("line", 0, 0, 0, 0, tg)
blur = draw.add("string",0,0,"",tg,tg)
nb = draw.add("string",0,0,"",tg,tg)
fp = draw.add("elpsf", 1, 1, 1, 1, tg, tg)
inf = draw.add("line", 0, 0, 0, 0, tg)
dot1 = draw.add("elpsf", 1, 1, 1, 1, tg, tg)
bar2 = draw.add("rectf", 0, 0, 0, 0, tg,tg)
cal = draw.add("string",0,0,"",tg,tg)
show = true
ettlmode = 0
show_ettr = 0
edit_update = false
X_state = {"ISO","Tv","HandH","Auto->H","Wind"}
B_state = {"Canon","1Ev","2Ev","3Ev","4Ev","5Ev"}
console_show = 1
set_console_autoredraw(1)
set_console_layout(0,0,45,3)
ref_s = get_prop(props.USER_TV)
del_ev = -(fmath.new(get_prop(props.USER_TV),96)-fmath.new(ref_s,96))
base_av = get_prop(props.USER_AV)
base_iso = get_iso_mode()
set_iso_mode(base_iso)
edit_mode = false
reset_lens = false
-- Check a few things first
if (bi.platform=="m3") and (bi.platsub=="101a") then
FocusSearchFar_FW = 0xfc43dfd9
FocusSearchNear_FW = 0xfc43dfff
FocusPositionWithLensCom = 0xfc5a85c7
shutter_trigger = "print"
elseif (bi.platform=="m3") and (bi.platsub=="120f") then
FocusSearchFar_FW = 0xfc43e349
FocusSearchNear_FW = 0xfc43e36f
FocusPositionWithLensCom = 0xfc5a8adf
shutter_trigger = "print"
elseif (bi.platform=="m3") and (bi.platsub=="121a") then
FocusSearchFar_FW = 0xfc43e379
FocusSearchNear_FW = 0xfc43e39f
FocusPositionWithLensCom = 0xfc5a8b0f
shutter_trigger = "print"
else
print("Only runs on the M3")
sleep(3000)
return -- exit
end
if capmode.get_name() ~= "M" then
print("Put camera in M mode")
sleep(3000)
return
end
if get_iso_mode() == 0 then
local test_X = get_prop(props.USER_TV)
wheel_right() -- check wheel is in Tv adjust mode
sleep(200)
if get_prop(props.USER_TV) == test_X then -- in ISO adjust mode
click("up") -- switch from ISO to Tv adjust mode
else -- in Tv mode, so exit Auto ISO
wheel_left()
sleep(200)
click("up")
sleep(200)
wheel_right()
sleep(200)
click("up")
end
end
if get_focus_mode() ~= 1 then -- switch to MF mode
click("left")
end
if get_gui_screen_width() == 360 then
hdmi = 0
else
hdmi = 60
end
if get_iso_mode() > 1 then -- give a warning
print("ISO > 100 : Press any key to continue")
wait_click()
end
set_draw_title_line(title)
-- Functions --
function get_focus_distance_lower() -- returns lower focus distance in mm, but note 'accuracy' is 1cm from Canon
local x=-1
if (bi.platform=="m3") and (bi.platsub=="101a") then
x=peek(0x00244918, 2)
elseif (bi.platform=="m3") and (bi.platsub=="120f") then
x=peek(0x0024495C, 2)
elseif (bi.platform=="m3") and (bi.platsub=="121a") then
x=peek(0x0024495C, 2)
elseif (bi.platform=="m10") then -- same address in 110d, 110f, 110g
x=peek(0x00272018, 2)
elseif (bi.platform=="m100") and (bi.platsub=="100a") then
x=peek(0x001FC7FC, 2)
else
print('Wrong platform')
end
if x == -1 then return -1 else return x*10 end -- in mm
end
function get_focus_distance_upper() -- returns upper focus distance in mm, but note 'accuracy' is 1cm from Canon
local x=-1
if (bi.platform=="m3") and (bi.platsub=="101a") then
x=peek(0x00244916, 2)
elseif (bi.platform=="m3") and (bi.platsub=="120f") then
x=peek(0x0024495A, 2)
elseif (bi.platform=="m3") and (bi.platsub=="121a") then
x=peek(0x0024495A, 2)
elseif (bi.platform=="m10") then -- same address in 110d, 110f, 110g
x=peek(0x00272016, 2)
elseif (bi.platform=="m100") and (bi.platsub=="100a") then
x=peek(0x001FC7FA, 2)
else
print('Wrong platform')
end
if x == -1 then return -1 else return x*10 end
end
function lens_name() -- does what it says
local pname = 0
if (bi.platform=="m3") then
if (bi.platsub == "101a") then
pname = 0x00244969
else
pname = 0x002449ad
end
elseif (bi.platform=="m10") then
pname = 0x272065
elseif (bi.platform=="m100") and (bi.platsub == "100a") then
pname = 0x1FC84E
end
local len = peek(pname-1,1)
local i = 0
local t = {}
while i < len do
local c = peek(pname + i, 1)
if c == 0 then break end
table.insert(t, string.char(c))
i = i + 1
end
local name = table.concat(t)
return name
end
function lens_cal() -- called at the start or when focal length changes: sets lens to MFD
local test_X = get_prop(props.USER_TV)
wheel_right() -- check wheel is in Tv adjust mode
sleep(500)
reset_lens = false
draw.clear()
draw.replace(bar,"rectf",hdmi,0,hdmi+360,20,"black","black")
draw.replace(cal,"string",hdmi+180-50,2,"Calibrating","white","black")
draw.overdraw()
local temp = 0
if get_prop(props.USER_TV) == test_X then -- in ISO adjust mode
wheel_left()
click("up") -- switch from ISO to Tv adjust mode
else
wheel_left()
end
repeat
temp = call_func_ptr(FocusPositionWithLensCom)
call_func_ptr(FocusSearchFar_FW)
sleep(50)
until temp == call_func_ptr(FocusPositionWithLensCom) -- make sure we are at 'infinity'
max_count = temp
local inf_dis = get_focus_distance_lower()
repeat -- to find some useful data
call_event_proc("EFLensCom.MoveFocus", -1, 1)
sleep(50)
until get_focus_distance_lower() < inf_dis
far_count = call_func_ptr(FocusPositionWithLensCom)+1
repeat
call_event_proc("EFLensCom.MoveFocus", -1, 1)
sleep(50)
until get_focus_distance_lower() < (H/reg):int() -- move to around the hyperfocal/reg
call_event_proc("EFLensCom.MoveFocus", 1, 1)
sleep(50)
local h_count = call_func_ptr(FocusPositionWithLensCom)
local h_dis = get_focus_distance_lower()
repeat
temp = call_func_ptr(FocusPositionWithLensCom)
call_func_ptr(FocusSearchNear_FW)
sleep(50)
until temp == call_func_ptr(FocusPositionWithLensCom) -- make sure we are at MFD
near_count = call_func_ptr(FocusPositionWithLensCom)
focus_count = near_count - far_count
MFD = get_focus_distance_lower()
mfd = MFD -- will be updated later
h_count = h_count-near_count + 1
mag = (F*(far_count-near_count))/((far_count-near_count-h_count)*(h_dis-2*F)) -- ignores hiatus and extension at this stage, ie get's things going
draw.clear()
dirty = true
show = true
end
function set_up()
dof = get_dofinfo()
F = fmath.new(dof.focal_length,1000) -- focal length in mm (real)
base_av = get_prop(props.USER_AV)
n = fmath.new(av96_to_aperture(base_av),1000) -- aperture number as a real
H = (1000*(F*F))/(n*coc) + F -- Relative to front principal
press("shoot_half")
repeat sleep(10) until get_shooting()
release("shoot_half")
repeat sleep(10) until (not get_shooting())
end
function lens_info()
if lens_name():sub(1,4) == "EF-M" then
return true
else -- lens not recognised
return false
end
end
function check_focus()
dof = get_dofinfo()
dirty = false
local test_count = call_func_ptr(FocusPositionWithLensCom) - near_count
repeat
test_count = call_func_ptr(FocusPositionWithLensCom) - near_count
sleep(10)
until test_count == call_func_ptr(FocusPositionWithLensCom) - near_count
local test_F = fmath.new(dof.focal_length,1000)
local test_n = fmath.new(av96_to_aperture(get_user_av96()),1000)
if test_F ~= F then
repeat
dof = get_dofinfo()
F = fmath.new(dof.focal_length,1000)
sleep(500)
dof = get_dofinfo()
test_F = fmath.new(dof.focal_length,1000)
until test_F == F
grabp = false
dirty = true
reset_lens = true
image = false
F = test_F
n = test_n
draw.remove(lastdof)
end
if test_n ~= n then
grabp = false
dirty = true
image = false
F = test_F
n = test_n
draw.remove(lastdof)
end
if test_count ~= focus_count then -- update things
dirty = true
focus_count = test_count
end
if lensmag == 2 and lensm ~= -1 then
mag = lensm
dirty = true
lensm = -1
end
H = 1000*(F*F)/(n*coc) + F
end
function update()
--if at 'infinity' then go into dynamic edit mode
pos = 0
k = 300-2*pos
draw.replace(bar,"rectf",hdmi+pos,0,hdmi+360,20,"black","black")
if call_func_ptr(FocusPositionWithLensCom) >= far_count then
edit_mode = true
qq = "Edit(L/U/R/D):"..B_state[b_val+1].."/"..coc.."um/"..X_state[brak+1].."/"..sleep_time.."s"
draw.replace(bar2,"rectf",hdmi+pos,0,hdmi+360,20,"black","black")
draw.replace(cal,"string",hdmi+pos+5,2,qq,"white","black")
return
else
edit_mode = false
draw.remove(cal)
draw.remove(bar2)
end
local J1 = far_count - near_count
if focus_count >= J1 then
u = fmath.new(810000,1)
else
u = (F*(J1 + J1*mag - mag*focus_count))/(mag*(J1-focus_count))
end
if (focus_count) <= (far_count - near_count) and not show_mag then
if u < H then
temp = H/u
print("#:"..(focus_count).."/"..max_count-near_count..", L/U:"..(get_focus_distance_lower()/10).."/"..(get_focus_distance_upper()/10).."cm, H/"..(temp):tostr(1)..", "..del_ev:tostr(1).."Ev")
else
temp = u/H
print("#:"..(focus_count).."/"..max_count-near_count..", L/U:"..(get_focus_distance_lower()/10).."/"..(get_focus_distance_upper()/10).."cm, "..(temp):tostr(1).."H"..", "..del_ev:tostr(1).."Ev")
end
elseif not show_mag then
print("#:"..(focus_count).."/"..max_count-near_count..", >INF"..", "..del_ev:tostr(1).."Ev")
end
mfd = (F*(J1 + J1*mag - mag*0))/(mag*(J1-0)) -- Min focus distance relative to the front principal
T = MFD - mfd
T = T - F - (F*F)/(mfd-F) -- hiatus estimate at MFD
x = F + (F*F)/(u-F) + T + u
halfdof = (mfd*k)/H
p = k - (mfd*k)/u
p = p:int()
halfdof = halfdof:int()
pj = p
fill = "grey_light"
if image then
if p == pdof then
fill = "yellow"
elseif p >= (pdof-2*halfdof) and p <= (pdof+2*halfdof) then
fill = "green"
else
fill = "red"
end
end
if (p-halfdof) <=0 then
draw.replace(ndof,"rectf",hdmi+pos+0,14,hdmi+pos+p,20,fill,fill)
else
draw.replace(ndof,"rectf",hdmi+pos+p-halfdof,14,hdmi+pos+p,20,fill,fill)
end
if u:int() > H:int() then
draw.replace(fdof,"rectf",hdmi+pos+p,14,hdmi+k,20,fill,fill)
else
draw.replace(fdof,"rectf",hdmi+pos+p,14,hdmi+pos+p+halfdof,20,fill,fill)
end
draw.replace(line,"rectf", hdmi+pos,10,hdmi+k,10,"white","white")
draw.replace(fp,"elpsf", hdmi+pos+p,17,2,2,"black","black")
local h1 = H:int()
draw.replace(h0pos,"line",hdmi+pos+0,0,hdmi+pos+0,20,"white")
p = (k - (mfd*k)/(H)):int()
if p >=0 then draw.replace(hpos,"line",hdmi+pos+p,0,hdmi+pos+p,20,"red") else draw.remove(hpos) end
p = (k - (mfd*k)/((H/2))):int()
if p >= 0 then draw.replace(h3pos,"line",hdmi+pos+p,3,hdmi+pos+p,17,"white") else draw.remove(h3pos) end
p = (k - (mfd*k)/((H/4))):int()
if p >= 0 then draw.replace(h5pos,"line",hdmi+pos+p,3,hdmi+pos+p,17,"white") else draw.remove(h5pos) end
p = (k - (mfd*k)/((H/8))):int()
if p >= 0 then draw.replace(h7pos,"line",hdmi+pos+p,3,hdmi+pos+p,17,"white") else draw.remove(h7pos) end
p = (k - (mfd*k)/((H/16))):int()
if p >= 0 then draw.replace(h9pos,"line",hdmi+pos+p,3,hdmi+pos+p,17,"white") else draw.remove(h9pos) end
p = (k - (mfd*k)/((H/32))):int()
if p >= 0 then draw.replace(h10pos,"line",hdmi+pos+p,3,hdmi+pos+p,17,"white") else draw.remove(h10pos) end
p = k
draw.replace(inf,"line",hdmi+pos+p,0,hdmi+pos+p,20,"white")
local qq = 0
if dis == 1 then
qq = ((x+5)/10):int().."cm"
draw.replace(blur,"string",hdmi+k+10,2,qq,"white","black")
elseif u:int() <= (H/3):int() and u:int() > 0 and dis == 0 then
qq = (H-u)/(2*u) + 1
qq = "#"..tostring(qq:int())
draw.replace(blur,"string",hdmi+k+10,2,qq,"white","black")
end
if u:int() >= H:int() then
qq = (1/2+((coc*H)/u)):int()
if qq >= 0 then
qq = tostring(qq).."um "
draw.replace(blur,"string",hdmi+k+10,2,qq,"white","black")
else
draw.remove(blur)
end
end
if show_ettr == 1 then
local histo={}
local total = 0
local stop3 = 0
histo,total=get_live_histo()
for i = 247,255,1 do stop3 = stop3 + histo[i] end -- get the total count in the top 1/10th of a stop
if stop3 - ettr_zero <= 0 then
qq = "0%"
elseif (100*stop3)/total == 0 then
qq = "#"..stop3
else
qq = tostring((100*stop3)/total).."%"
end
draw.replace(blur,"string",hdmi+k+10,2,qq,"white","black")
end
end
function check_overlaps()
if get_gui_screen_width() == 360 then
hdmi = 0
else
hdmi = 60
end
if grabp and image then
if u:int() > H:int() then
draw.replace(lastdof,"rectf",hdmi+pos+pdof-halfdof,0,hdmi+k,6,"grey_light","grey_light")
else
draw.replace(lastdof,"rectf",hdmi+pos+pdof-halfdof,0,hdmi+pos+pdof+halfdof,6,"grey_light","grey_light")
end
grabp = false
end
--dirty = false
end
function myshoot()
local prevcnt = hook_shoot.count()
local rawprevcnt = hook_raw.count()
press 'shoot_full_only'
repeat sleep(10) until prevcnt ~= hook_shoot.count()
release 'shoot_full_only'
repeat sleep(10) until rawprevcnt ~= hook_raw.count()
end
function snap() -- single image capture
press("shoot_half")
repeat sleep(10) until (get_shooting())
myshoot()
release("shoot_half")
repeat sleep(10) until (not get_shooting())
end
function take_bracket()
if brak == 0 then
local iso = get_iso_mode()
set_iso_mode(iso)
sleep(sleep_time*1000)
sleep(100)
snap()
local isov = iso
isov = isov + b_val*3
if isov > 16 then isov = 16 end
set_iso_mode(isov)
sleep(100)
snap()
set_iso_mode(iso)
elseif brak == 2 then -- try and take a handheld bracket set
s = get_prop(props.USER_TV)
local hhval = hhmin
if F:int() > hhmin then hhval = F:int() end
if tv96_to_usec(s) < 1000000/hhval then
print("HH Check OK")
sleep(sleep_time*1000)
snap()
set_tv96_direct(usec_to_tv96(1000000/hhval))
snap()
local iso = get_iso_mode()
if b_val == 4 then
isov = 1600
elseif b_val == 5 then
isov = 3200
else
isov = 800
end
set_iso_mode(isov)
set_tv96_direct(usec_to_tv96(1000000/hhval))
snap()
set_iso_mode(iso)
set_tv96_direct(s)
else
print("Adjust Xposure to <= 1/"..hhval.."s") -- don't take a handheld bracket set
sleep(3000)
end
elseif brak == 3 then -- auto bracket from the shadows
shot_histo_enable(1)
sleep(sleep_time*1000)
snap()
sleep(100)
local ev_step = b_val
if ev_step < 1 then ev_step = 1 end
if ev_step > 3 then ev_step = 3 end
local test=get_histo_range(988,1023) -- check the top 1/10 Ev part of the histogram
local step = 1
while test > 0 and (s + 96 * ev_step * step) <= 1152 do
set_tv96_direct(s + 96 * ev_step * step)
snap()
sleep(100)
test=get_histo_range(988,1023) -- check the top 1/10 Ev part of the histogram
step = step + 1
end
shot_histo_enable(0)
elseif brak == 4 then -- take a wind bracket
s = get_prop(props.USER_TV)
sleep(sleep_time*1000)
snap()
set_tv96_direct(s + 96 * b_val)
local isov = get_iso_mode()
set_iso_mode(isov + b_val*3)
snap()
set_tv96_direct(s)
set_iso_mode(isov)
else
local s = get_prop(props.TV)
sleep(sleep_time*1000)
snap()
set_tv96_direct(s - 96 * b_val)
snap()
end
end
function set_ETTR()
do
local histo={}
local total = 0
ref_s = get_prop(props.USER_TV)
histo,total=get_live_histo()
local total_count = total
total = 0
local max = #histo - 1
start = 247 -- top 1/10 stop
for i = start,max,1 do total = total + histo[i] end -- get the total count in the requested bins
local sl = 50
if total < ettr_zero then
repeat
wheel_left()
sleep(sl)
histo,total=get_live_histo()
total_count = total
total = 0
for i = start,max,1 do total = total + histo[i] end
until total >= ettr_zero or get_prop(props.USER_TV) <= -480
elseif total > ettr_zero then
repeat
wheel_right()
sleep(sl)
histo,total=get_live_histo()
total_count = total
total = 0
for i = start,max,1 do total = total + histo[i] end
until total <= ettr_zero or get_prop(props.USER_TV) >= 1052
end
s = get_prop(props.USER_TV)
return
end
end
function set_ETTL()
do
local histo={}
local total = 0
local sl = 100
local test_X = get_prop(props.USER_TV)
ref_s = test_X
if ettlmode == 1 then
local isov = get_iso_mode()
local i = 0
histo,total=get_live_histo()
local total_count = total
total = 0
for i = 0,25,1 do total = total + histo[i] end -- about -7.4 EV down from fully exposed: see https://scantips.com/lights/gamma3.html
if (100*total)/total_count > 10 then
repeat
wheel_right()
isov = get_iso_mode()
if isov > 16 then isov = 16 end
set_iso_mode(isov)
sleep(sl)
histo,total=get_live_histo()
total_count = total
total = 0
for i = 0,25,1 do total = total + histo[i] end
until (100*total)/total_count <= 10 or get_prop(props.USER_TV) <= -480 or isov >= 16
click("up")
end
else
histo,total=get_live_histo()
local total_count = total
total = 0
for i = 0,25,1 do total = total + histo[i] end -- get the total count in the requested bins (see https://scantips.com/lights/gamma3.html)
if (100*total)/total_count > 10 then
repeat
wheel_left()
histo,total=get_live_histo()
total_count = total
total = 0
for i = 0,25,1 do total = total + histo[i] end
until (100*total)/total_count <= 10 or get_prop(props.USER_TV) <= -480
elseif (100*total)/total_count < 10 then
repeat
wheel_right()
sleep(sl)
histo,total=get_live_histo()
total_count = total
total = 0
for i = 0,25,1 do total = total + histo[i] end
until (100*total)/total_count >= 10 or get_prop(props.USER_TV) >= 1052
end
end
s = get_prop(props.USER_TV)
return
end
end
function check_X()
del_ev = -(fmath.new(get_prop(props.USER_TV),96)-fmath.new(ref_s,96))
if get_prop(props.USER_TV) ~= s then
dirty = true
end
return
end
function check_buttons_etc()
wait_click(50) -- check for a button press
show_mag = false
if edit_mode then
edit_update = false
if is_key("right") then
brak = brak + 1
if brak > 4 then brak = 0 end
edit_update = true
elseif is_key("left") then
b_val = b_val + 1
if b_val > 5 then b_val = 0 end
edit_update = true
elseif is_key("up") then
coc = coc + 1
if coc > 30 then coc = 5 end
edit_update = true
elseif is_key("down") then
sleep_time = sleep_time + 1
if sleep_time > 10 then sleep_time = 0 end
edit_update = true
end
return
end
if is_key("set") and (lensmag == 1 or lensmag == 2) then
lensm = (F*(far_count-near_count))/((far_count-near_count-focus_count)*(get_focus_distance_lower() - (MFD-mfd) - F))
if lensmag == 2 then
mag = lensm
elseif lensmag == 1 then
print("Tuning Mag = "..lensm:tostr(4))
sleep(3000)
show_mag = true
end
image = false
grabp = false
dirty = true
draw.remove(lastdof)
elseif is_key("down") then -- toggle console on/off
console_show = 1 - console_show
if console_show == 0 then -- then switch off console display
set_console_layout(0,0,1,0)
print("")
set_console_autoredraw(-1)
else
set_console_autoredraw(1)
set_console_layout(0,offset-1,45,offset)
end
elseif is_key("up") then -- switich between Tv and ISO
click("up")
sleep(100)
dirty = true
elseif is_key("zoom_out") then -- toggle CHDK histogram on and off
if get_config_value(1060) == 0 then set_config_value(1060,1) else set_config_value(1060,0) end
elseif is_key("right") then -- ETTR requested
set_ETTR()
elseif is_key("left") then -- ETTL requested
set_ETTL()
elseif is_key(shutter_trigger) then
if b_val > 0 and get_prop(props.BRACKET_MODE) == 0 then
take_bracket()
else
snap()
end
last_count = focus_count
image = true
dirty = true
grabp = true
pdof = pj
elseif is_key("menu") then
if show then
draw_clear()
set_config_value(1060,0)
set_console_autoredraw(-1)
show = false
elseif not show then
draw.overdraw()
show = true
set_console_autoredraw(1)
end
elseif is_key("display") then
click("display")
dirty = true
elseif is_key("shoot_half") and get_alt_mode() then
dirty = true
end
if ecnt ~= get_exp_count() and not is_key(shutter_trigger) then
ecnt = get_exp_count()
last_count = focus_count
image = true
dirty = true
grabp = true
pdof = pj
end
if is_key("zoom_in") then
timer_start = get_tick_count()
while is_pressed("zoom_in") and get_tick_count()-timer_start < 2000 do
sleep(100)
end
if get_tick_count()-timer_start > 2000 then
show_ettr = 1 - show_ettr
dirty = true
else
last_count = focus_count
image = true
dirty = true
grabp = true
pdof = pj
s = get_prop(props.USER_TV)
ref_s = s
end
end
end
-- Main Section --
if lens_info() == false then -- then don't use
print("Lens not recognised")
sleep(3000)
return
end
show = true
grabp = false
set_up()
lens_cal()
lensm = -1
last_count = call_func_ptr(FocusPositionWithLensCom) - near_count
focus_count = last_count
if last_count ~= 0 or (mag*100):int() <= 0 then
print("Calibration failed: Try Again!")
sleep(3000)
return
end
s = get_prop(props.USER_TV)
ref_s = s
if offset == 0 then -- then switch off console display
set_console_layout(0,0,1,0)
print("")
set_console_autoredraw(-1)
else
set_console_autoredraw(1)
set_console_layout(0,offset-1,45,offset)
end
finish = false
image = false
ecnt = get_exp_count()
n = 0
show = true
sleep(100)
click("shoot_half")
repeat -- stay here
if get_alt_mode() then
if reset_lens then lens_cal() end -- focal length changed so recalibrate lens
check_focus()
check_buttons_etc()
check_X()
check_overlaps()
update()
if edit_update then draw.overdraw() end
if dirty then
draw.overdraw()
dirty = false
end
else
finish = true
end
sleep(100) -- adjust as required
if screen_needs_refresh() then dirty = true end
until finish -- exit script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment