--[[ ******************************** Licence: GPL (c) msl 2012-2014 Thx elektronikfreak, rudi, waterwingz, Werner_O v2.1.700 ******************************** @title AvPlus v2 @param a Verzoegerung [s] @default a 2 @range a 0 10 @param d Hilfe bei Start @default d 1 @range d 0 1 ]] if tonumber(string.sub(string.gsub(get_buildinfo().build_number, "%p", ""), 0, 3)) < 130 then error("CHDK 1.3.0 or higher required") end prop = require "propcase" osd = require "gen/cnf_osd" require "drawings" --parameter delay = a * 1000 starthelp = d == 1 and true or false --definitions FONT_W = 8 --font width FONT_H = 16 --font high SCREEN_W = get_gui_screen_width() SCREEN_H = get_gui_screen_height() APEX = 32 --factor for ev96, tv96, av96 calculation EV_LIMIT = 6 --limit for ev correction in 1/3 steps AV96_MIN = 176 --F2.0 AV96_MAX = 784 --F16.0 hyp_foc = false focus_state= 0 tv96 = get_tv96() tv96_calc = tv96 av96 = get_av96() ev = get_ev()/APEX draw_y = SCREEN_H - FONT_H --bottom line xscale = 2 --x scaling draw string idx = 2 idx_max = 3 lang = get_prop(get_propset() == 1 and 196 or 61)/256 == 1 and 2 or 1 --language 1=en, 2=de state = {} state[1] = {"exposure correction", "aperture setting", "focus type selection"} state[2] = {"Belichtungskorrektur", "Blende einstellen", "Fokusart wählen"} str_no_record_mode = {} str_no_record_mode[1] = "No record mode!" str_no_record_mode[2] = "Kein Aufnahme-Modus!" str_script_version = "AvPlus Version 2.1" --functions function half_press() set_ev(ev * APEX) set_av96_direct(av96) local count = 0 local timeout = false if hyp_foc then --if hyperfocal then go into mf mode if set_mf(1) == 1 then --if mf is true then set hyperfocal distance sleep(500) set_focus(hyp_dist) end end press("shoot_half") repeat sleep(50) count = count + 1 if count > 40 then timeout = true end until get_shooting() or timeout bv96 = get_bv96() av96 = get_av96() sv96 = get_sv96() tv96 = get_tv96() focus_state = get_focus_state() tv96_calc = bv96 + sv96 - av96 --calculates real Tv repeat --wait for either full press or release wait_click(100) if is_key("shoot_full") then full_press() end until not is_pressed("shoot_half") release("shoot_half") repeat sleep(50) until not get_shooting() if hyp_foc then set_mf(0) end end function full_press() if focus_state == 0 and hyp_foc == false then --abort if focus not ok & no selection of hyperfocal distance return else set_tv96_direct(tv96_calc) sleep(delay) --delay time for shooting press("shoot_full") repeat sleep(200) until not is_pressed("shoot_full") release("shoot_full") end end function calc_hyp_dist() --calculates recent hyperfocal distance in dependence of focal length and av local dof = get_dofinfo() local fl = dof.focal_length --((fl/coc)*fl)/av is better than (fl*fl)/(av*coc) local hyp = (imath.div(imath.mul(imath.div(fl, dof.coc), fl), av96_to_aperture(av96)) + fl +500)/imath.scale return hyp end function print_tv(val) --look up for exposure string local i = 1 local tv_str = {"n/a", "2048\"", "1625\"", "1290\"", "1024\"", "812\"", "645\"", "512\"", "406\"", "322\"", "256\"", "203\"", "161\"", "128\"", "101\"", "80\"", "64\"", "50\"", "40\"", "32\"", "25\"", "20\"", "15\"", "13\"", "10\"", "8\"", "6\"", "5\"", "4\"", "3\"2", "2\"5", "2\"", "1\"6", "1\"3", "1\"", "0\"8", "0\"6", "0\"5", "0\"4", "0\"3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320","1/400", "1/500","1/640","1/800","1/1000","1/1250","1/1600","1/2000","1/2500","1/3200","1/4000","1/5000","1/6400","1/8000","Hi"} local tv_ref = {-1056,-1024, -992, -960, -928, -896, -864, -832, -800, -768, -736, -704, -672, -640, -608, -576, -544, -512, -480, -448, -416, -384, -352, -320, -288, -256, -224, -192, -160, -128, -96, -64, -32, 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800, 832, 864, 896, 928, 960, 992, 1024, 1056, 1088, 1120, 1152, 1184, 1216, 1248, 1280} while (i <= #tv_ref) and (val > tv_ref[i]-1) do i=i+1 end return tv_str[i] end function print_av(val) --calculates aperture string local av = av96_to_aperture(val) return ("F"..av/1000).."."..((av%1000)/100) end function draw_third_string(x, y, val, clt, clb, xsc, ysc) --draws 3 as denominator for Ev values local third = "" local i = val < 0 and "-" or "" if math.abs(val) > 2 then i = i..tostring(math.abs(val/3)) end if val == 0 then i = "0" end if val >= 0 then x = x + 8 end draw.add("string", x, y, i, clt, clb, xsc, ysc) if val%3 ~= 0 then x = x + #i * 8 *xsc if math.abs(val%3) == 1 then third = "\185" end if math.abs(val%3) == 2 then third = "\178" end draw.add("string", x , y-1, third, clt, clb, xsc, ysc) draw.add("string", x , y+9, "\179", clt, clb, xsc, ysc) draw.add("line" , x+1, y+7, x+7*xsc, y+7, clt) end end function print_dist(dist) --formated focus distance value local str_dist = "n/a" if dist < 0 then str_dist = "inf." elseif dist < 1000 then str_dist = string.format(".%03d" , dist) elseif dist < 10000 then str_dist = string.format("%d.%02d", dist/1000, (dist%1000)/ 10) elseif dist < 100000 then str_dist = string.format("%2d.%d" , dist/1000, (dist%1000)/100) elseif dist >=100000 then str_dist = string.format("%4d" , dist/1000) end return str_dist end function draw_values() local cl = focus_state == 0 and "red" or "green" local x = SCREEN_W == 480 and 62 or 2 local f1 = not hyp_foc and "\16f %s" or " f %s" local f2 = hyp_foc and "\16h %s" or " h %s" draw.add("rectf", x-2, draw_y-FONT_H, x+360, SCREEN_H, "black", "black") if idx == 1 then draw.add("rectf", x , draw_y-FONT_H, x+48 , SCREEN_H, "grey", "grey") end if idx == 2 then draw.add("rectf", x+156, draw_y-FONT_H, x+156+(#print_av(av96)*FONT_W*xscale)+3, SCREEN_H, "grey", "grey") end draw_third_string(x, draw_y - FONT_H/2, ev, cl, idx == 1 and "grey" or "black", xscale, 1) draw.add("string", x+ 60, draw_y-FONT_H/2, string.format("%s" , print_tv(tv96_calc)) , cl, "black", xscale, 1) draw.add("string", x+160, draw_y-FONT_H/2, print_av(av96) , cl, idx == 2 and "grey" or "black", xscale, 1) draw.add("string", x+246, draw_y-FONT_H , string.format(f1 , print_dist(get_dofinfo().focus)), cl, idx == 3 and "grey" or "black", xscale, 1) draw.add("string", x+246, draw_y , string.format(f2 , print_dist(hyp_dist)) , cl, idx == 3 and "grey" or "black", xscale, 1) draw.add("string", x+180-#state[lang][idx]/2*FONT_W, draw_y-FONT_H*2, state[lang][idx], "white", "trans") end function draw_help() draw.clear() local help_str = {} help_str[1] = {"Help "..str_script_version,"FULL PRESS : shoot","HALF PRESS : check exposure", "\017 \016 : change function", "\030 \031 : change value", "MENU : exit", "FUNC/SET : help on/off", "green focus ok, red focus not ok", "If red shoot only with", "hyperfocal distance available."} help_str[2] = {"HILFE "..str_script_version,"Auslöser voll : Foto","Auslöser halb : überprüfen", "\017 \016 : Auswahl Funktion", "\030 \031 : Einstellungen", "MENU : Skript beenden", "FUNC/SET : Hilfe an/aus", "grün Fokus ok, rot Fokus nicht ok", "Bei rot Auslösung nur mit", "hyperfokaler Distanz möglich."} local w = 18 local x = (SCREEN_W/2) - (w*2/2*FONT_W) local y = draw_y - (FONT_H *3) - (#help_str[lang] * FONT_H) local i = 0 local fg, str, inx local osd_chdk_icons = get_config_value(osd.show_osd) local osd_chdk_values = get_config_value(osd.show_values) if osd_chdk_icons > 0 then set_config_value(osd.show_osd, 0) end if osd_chdk_values > 0 then set_config_value(osd.show_values, 0) end while i < #help_str[lang] do i=i+1 str = string.rep(" ", w)..(help_str[lang][i])..string.rep(" ", w) inx = string.find(str,":") if inx ~= nil then draw.add("string", x, y+i*FONT_H, string.sub(str, inx-w , inx+w) , "blue", "white") else fg = i == 1 and "red" or "black" draw.add("string", x, y+i*FONT_H, string.sub(str, (#str/2)-w, (#str/2)+w), fg, "white") end end repeat draw.overdraw() wait_click(800) until is_key("set") or is_key("menu") if osd_chdk_icons > 0 then set_config_value(osd.show_osd, 1) end if osd_chdk_values > 0 then set_config_value(osd.show_values, osd_chdk_values) end draw.clear() end function restore() if get_focus_mode == 1 then set_mf(0) end set_draw_title_line(1) end --main script if get_mode() then cls() set_draw_title_line(0) --disables script title and ALT text set_exit_key("no_key") --disables all keys for abort, also shutter if starthelp then draw_help() end --displaying help screen after script start half_press() --first shoot info repeat av_min = get_prop(prop.MIN_AV) --min. useable av depending on focal length if av96 < av_min then av96 = av_min end --check min. possible av hyp_dist = calc_hyp_dist() --calculates hyperfocal distance draw.clear() --deletes drawing objects draw_values() --draws drawing objects with recent values repeat draw.redraw() --redraws drawing objects wait_click(800) until not is_key("no_key") if is_key("shoot_half") then --shoot info if av96 < av_min then av96 = av_min end half_press() elseif is_key("left") then if idx > 1 then idx = idx - 1 else idx = idx_max end elseif is_key("right") then if idx < idx_max then idx = idx + 1 else idx = 1 end elseif is_key("up") then if idx == 1 then if ev < EV_LIMIT then ev = ev + 1 end --increase ev elseif idx == 2 then av96 = av96 + APEX --increase av if av96 > AV96_MAX then av96 = AV96_MAX end if av96 < av_min then av96 = av_min end half_press() elseif idx == 3 then hyp_foc = not hyp_foc --toggle focus/hyperfocal end elseif is_key("down") then if idx == 1 then if ev > (EV_LIMIT * -1) then ev = ev - 1 end --decrease ev elseif idx == 2 then av96 = av96 - APEX --decrease av if av96 < AV96_MIN then av96 = AV96_MIN end if av96 < av_min then av96 = av_min end half_press() elseif idx == 3 then hyp_foc = not hyp_foc --toggle focus/hyperfocal end elseif is_key("set") then draw_help() --displaying help screen elseif is_key("zoom_in") then press("zoom_in") while is_pressed("zoom_in") do sleep(20) end release("zoom_in") elseif is_key("zoom_out") then press("zoom_out") while is_pressed("zoom_out") do sleep(20) end release("zoom_out") end until is_key("menu") else print(str_no_record_mode[lang]) sleep(2000) end restore()