--[[ (C)2012 rudi & msl, Version:0.5 look up max. distance value before infinity distance for CHDK and CHDK-DE @title SD min/max !default: 10km test distance @param a inf distance @default a 10000000 ]] pt=require("propcase") bs=require("binstr") function setup() --switch to record mode and manual focus local timeout if not get_mode() then set_record(1) timeout=10 repeat sleep(1000) timeout=timeout-1 until get_mode() or (timeout < 0) end if (post_levent_for_npt~=nil) and (get_focus_mode()==0) then post_levent_for_npt("PressSw1AndMF") timeout=10 repeat sleep(1000) timeout=timeout-1 until (get_focus_mode()==1) or (timeout < 0) end return (get_mode() and (get_focus_mode()==1)) end function focus(val) set_focus(val) sleep(2000) --[[ get_focus() ist ok but differnt distance in CHDK-DE (from lens) we need "to sensor" value at all a second set is needed to set propcase value to current focus value ]] set_focus(val) sleep(2000) return bs.getnum(get_prop_str(pt.SUBJECT_DIST1,4)) end -- alternative function for set_zoom() function set_zoom_lever(zoom_input) if zoom_input >= 0 and zoom_input < get_zoom_steps() then local zoom_is = get_zoom() if zoom_input ~= zoom_is then if zoom_input < zoom_is then press("zoom_out") repeat sleep(10) until get_zoom() <= zoom_input release("zoom_out") end if zoom_input > zoom_is then press("zoom_in") repeat sleep(10) until get_zoom() >= zoom_input release("zoom_in") end --set_zoom(zoom_input) --fine correction end end end function max_sd_test(init_dist, inf) local floop=false local fdist=false local max_dist=-1 local dist_test=init_dist local dist_step=init_dist while not(floop or (fdist and (dist == inf_dist))) do floop=(dist_step <= 1) dist_step=dist_step/2 dist=focus(dist_test) if (dist == inf_dist) then dist_test=dist_test-dist_step else if (dist == max_dist) then fdist=true end if (max_dist < dist) then max_dist=dist end dist_test=dist_test+dist_step end end return max_dist end function restore() if (post_levent_for_npt~=nil) and (get_focus_mode()==1) then post_levent_for_npt("PressSw1AndMF") sleep(1000) end --set_zoom(0) is dangerous if zoom position -> zoom max (hardware defect message on sx220) set_zoom_lever(0) sleep(500) if old_mode~=get_mode() then set_record(old_mode) end end --MAIN old_mode=get_mode() if setup() then set_zoom_lever(0) sleep(2000) min_dist=focus(1) inf_dist=focus(a) set_zoom_lever(get_zoom_steps()-1) sleep(2000) focus(1) print("testing, please wait ...") --start at half distance and put largest distance as referenz max_dist=max_sd_test(a/2,inf_dist) print("CAMERA_MIN_DIST",min_dist) print("CAMERA_MAX_DIST",max_dist+1) print("INFINITY_DIST ",inf_dist) restore() else if get_mode() then print("set camera to MF") else print("set camera to record and MF") end end