CHDK ManualEdit

CHDK User Manual : Scripting (program your camera)

CHDK Scripting LinksEdit

CHDK Scripts CHDK Scripting
Script Commands Script Commands Stub
User Written Scripts Property Case Values

uBASIC LinksEdit

uBASIC Tutorial Scratchpad

Lua LinksEdit

Lua Lua Syntax
Lua Reference Lua PTP Scripting
Lua Draw & Lua Drawing Native Function Calls
Lua Development Environment Lua 5.1 Reference Manual
Script Shooting Hooks One Page CHDK Lua Reference Card

Script Header DocumentationEdit

The Script Header Tutorial - The Script Header

All Scripting FunctionsEdit


Lens Functions
Function Link Lua uBASIC Description
get_focus YYgets current focus distance in mm
get_focus_mode YYreturns focus mode, 0=auto, 1=MF, 3=inf., 4=macro, 5=supermacro
get_focus_ok YYreturns 0=focus not ok, 1=ok if get_focus_state<>0 and get_shooting=1
get_focus_state YYreturns focus status, > 0 focus successful, =0 not successful, < 0 MF
get_IS_mode YYget image stabilization mode
get_zoom YYreturns current zoom position
get_zoom_steps YYreturns the number of zoom steps supported by the camera
get_sd_over_modes YYreturns a bit field value indicating when subject distance override will work with this camera.
set_mf YYlock/unlock Canon manual focus (MF) mode.
set_aflock YYblocks the camera firmware from making focus adjustments
set_focus YYsets current focus distance in mm
set_zoom YYsets the current zoom position
set_zoom_rel YYmoves zoom position a relative amount
set_zoom_speed YYsets zoom speed (only works on some cameras)
Depth of Field
Function Link Lua uBASIC Description
get_dofinfo Y -get DOF table (uBASIC commands below)
get_dof -Yget the depth of sharpness in mm
get_far_limit -Yget the far acceptable sharpness distance
get_near_limit -Yget near acceptable sharpness distance
get_focal_length -Yget current lens focal length
get_hyp_dist -Yget hyperfocal distance
Exposure Functions
Function Link Lua uBASIC Description
get_av NYobsolete - replaced with get_user_av_id
get_av96 YYgets APEX96 aperature value
get_bv96 YYgets APEX96 luminance value
get_ev YYget exposure adjustment amount
get_iso NYobsolete - replaced with get_iso_mode
get_iso_market YYget inflated marketing ISO value
get_iso_mode YYobtain ISO mode
get_iso_real YYget actual ISO value
get_nd_present YYreturns whether camera has an ND filter (and / or diaphragm )
get_sv96 YYgets APEX96 ISO sensitivity setting
get_tv96 YYgets APEX96 exposure time
get_user_av_id YYgets M mode override APEX96 aperature value by index
get_user_av96 YYgets APEX96 aperature value
get_user_tv_id YYgets M mode override APEX96 exposure time by index
get_user_tv96 YYgets M mode override APEX96 exposure value
set_aelock YYsets automatic exposure lock (AEL) ( CHDK 1.3.0 or newer)
set_av NYobsolete - replaced with set_user_av_by_id
set_av_rel NYobsolete - replaced with set_user_ac_by_id_rel
set_av96 YYsets the APEX96 aperature value
set_av96_direct YYsets the APEX96 aperature value (bypass validation check)
set_ev YYsets exposure adjustment amount
set_iso NYobsolete - replaced with set_iso_mode
set_iso_mode YYsets propcase PROPCASE_ISO_MODE
set_iso_real YYsets the sv96 override value base on ISO sensitivity value
set_nd_filter YYmoves neutral density filter into or out of the optical path
set_sv96 YYset APEX96 ISO sensitivity value
set_tv NYobsolete - replaced with set_user_tv_by_id
set_tv_rel NYobsolete - replaced with set_user_tv_by_id_rel
set_tv96 YYset APEX96 exposure time
set_tv96_direct YYset APEX96 exposure time (bypass validity checks)
set_user_av_by_id YYset user override APEX96 aperature by index (M mode only)
set_user_av_by_id_rel YYset user override APEX96 aperature by index relative (M mode only)
set_user_av96 YYset user override APEX96 aperature (M mode only)
set_user_tv_by_id YYset user override APEX96 exposure time index (M mode only)
set_user_tv_by_id_rel YYset user override APEX96 exposure time index offset (M mode only)
set_user_tv96 YYset user override APEX96 exposure time (M mode only)
get_live_histo YN Get a histogram of the live viewport
APEX96 Conversion Note : CHDK 1.3.0 or greater
Function Link Lua uBASIC Description
iso_to_sv96 YYconverts ISO into sv96 units
sv96_to_iso YYconverts sv96 units to ISO
iso_real_to_market YYconverts ISO value from real to market
iso_market_to_real YYconverts ISO value from real to market
sv96_real_to_market YYconverts sv96 value from real to market
sv96_market_to_real YYconverts sv96 value from market to real
aperture_to_av96 YYconverts f-stop to av96 units
av96_to_aperture YYconverts av96 value to f-stop
usec_to_tv96 YYconverts shutter speed to tv96 units
tv96_to_usec YYconverts tv96 value to shutter speed
seconds_to_tv96 YYconverts fractional value to tv96 units
Camera Functions
Function Link Lua uBASIC Description
get_capture_mode NYgets current camera Program mode setting
get_display_mode NYreturns state of LCD display info
get_drive_mode YYreturns shutter drive mode (single, continuous, timer )
get_flash_mode YYreturns flash mode (flash auto, flash on, flash off)
get_flash_params_count YNreturns # of flash memory parameters available in camera
get_flash_ready YYreturns status indicating if flash is ready to fire
get_meminfo YNget camera memory information
get_mode YYreturns whether record mode or playback mode is active
get_movie_status YYgets state of video recording (off,on,paused)
get_orientation_sensor YYget camera rotation sensor value
get_parameter_data YNget data from camera\'s flash memory
get_prop YYget PropertyCase value as short integer
get_prop_str YNget the value of a PropertyCase as a string
get_propset YYget the propset number for this camera
get_quality NYreturns the current capture quality setting in Canon grades
get_resolution NYreturns the current capture resolution setting in Canon grades
get_shooting YYindicates that half_press is active, exposure is set and focusing is completed (see also get_focus_ok)
get_temperature YYreturns specified temperature sensor value
get_vbatt YYget current battery charge state
get_video_button YYreturns whether on not the camera has a video button
get_video_details YNreturns a struct with viewport configuration info
get_video_recording YYreturn whether video is recording or not
is_capture_mode_valid YYcheck if CHDK mode number is valid for this camera
play_sound Y*plays the specified sound sequence (uBASIC use playsound)
reboot YYrestart the camera
restore YYspecifies the routine called before a script terminates
set_capture_mode YYset capture mode by CHDK mode number
set_capture_mode_canon YYset capture mode by PROPCASE_SHOOTING_MODE value
set_led YYturns on or off the selected camera LED
set_movie_status YYallow video recording to pause, unpause and stop
set_prop YYset PropertyCase value as short integer
set_prop_str YNused to set arbitraty sized propcases in Lua
set_quality NYset the quality (in Canon grades),
set_record YYset playback or record mode
set_resolution NYSet the resolution (in Canon grades)
shut_down YYturns the camera off
Keypad & Switches
Function Link Lua uBASIC Description
click YYpress and release a key
is_key YYdetemines if specified key was pressed
is_pressed YYdetermines if specified key is being pressed
press YYactivates the specified camera button
release YYreleases the specified camera button
shoot YYtakes a picture
wait_click YYwaits for any camera button to be pressed
wheel_left YYsimulates moving jog dial wheel to the left
wheel_right YYsimulates moving jog dial wheel to the right
set_exit_key YYchanges the key used to terminate the script (CHDK 1.3.0 or greater)
SD Card Functions
Function Link Lua uBASIC Description
get_disk_size YYreturns size of SD card
get_exp_count YY return number of shots in a session
get_image_dir YN get current image directory
file_browser YNactivate SD card file browser on LCD screen
get_free_disk_space YYreturn space left on SD card
get_jpg_count YYreturn number of JPG shots left on SD card
get_partitionInfo YNget partition information from the SD card
set_file_attributes YNset file attributes of file on SD card
swap_partitions YYchanges the partition order if SD card has multiple partitions
Script Status Functions
Function Link Lua uBASIC Description
autostarted YYchecks if script was autostarted
end NYterminate uBASIC program execution
get_autostart YYreads the conf.script_autostart
get_day_seconds YYreturn number of seconds since midnight
get_tick_count YYgets time in tic units (milliseconds) since camera startup
get_time YYreturns elements of the camera\'s current date / time setting
set_autostartYYwrite conf.script_autostart (0=off, 1=on, 2=once)
set_yield YYcontrol how much of the Camera CPU time is used by scripting engine
sleep YYhalts program execution for specified number of milliseconds
Firmware Interface
Function Link Lua uBASIC Description
call_event_proc(name,...) YNcalls a registered event procedure.
call_func_ptr(fptr,...) YNcall ARM or Thumb function in camera RAM or ROM
get_levent_def YNlookup levent definition by event's name string or id number
get_levent_def_by_index YNlookup levent definition by index in logical event table
get_levent_index YNreturns the index of the given event
post_levent_for_npt YNTriggers a LogicalEvent in the Canon firmware.
post_levent_to_ui YNTriggers a LogicalEvent in the canon firmware.
set_levent_active YN<needs a definition>
set_levent_script_mode YN<needs a definition>
Display & Text Console
Function Link Lua uBASIC Description
set_backlight YYturns the LCD screen backlight on or off
set_lcd_display YYturns the LCD screen on or off (CHDK 1.3.0 or greater)
set_draw_title_lineYYturns the CHDK title line on or off  (CHDK 1.3.0 or greater)
get_draw_title_lineYYreturns the current CHDK title state  (CHDK 1.3.0 or greater)
cls YYclear console screen
console_redraw YYmanually refresh/rewrite the script console
print YYdisplays a line of text on console area of LCD screen
print_screen YYcauses text written to screen to also be written to file on the SD card
set_console_autoredraw YYenable or disable automatic rewrite/refresh of the console
set_console_layout YYsets the dimensions the LCD message console
LCD Graphics
Function Link Lua uBASIC Description YNLua drawing module
draw_ellipse YNdraws an ellipse on LCD screen
draw_ellipse YNdraws an ellipse on LCD screen
draw_ellipse_filled YNdraws a filled ellipse on LCD screen
draw_line YNdraw a line on LCD screen
draw_pixel YNdraws a single pixel on LCD screen
draw_rect YNdraws a rectangle on LCD screen
draw_rect_filled YNdraws a filled rectangle on LCD screen
draw_string YNprints a text string on LCD screen
textbox YNinput text function for Lua scripts
get_gui_screen_width YN get screen width
get_gui_screen_height YN get screen height
Function Link Lua uBASIC Description
get_raw YYreturn status of RAW disabled or enabled
get_raw_count YYreturn number of RAW shots that will fit on remaining SD card space
get_raw_nr YYreturn state of dark frame subtraction (noise reduction) override (auto, off, on )
get_raw_support YY return whether or not current capture mode supports RAW
raw_merge_add_file YNadds a RAW file to the current merge process
raw_merge_end YNends a RAW merge process on the camera
raw_merge_start YNbegins a RAW merge process on the camera
set_raw YYenables or disables the storage of RAW images
set_raw_develop YNdevelop RAW image on next shot
set_raw_nr YY set CHDK dark frame subtraction (noise reduction) override
CHDK Functionality
Function Link Lua uBASIC Description
enter_alt YYactivates CHDK mode (CHDK 1.3.0 or greater for uBASIC support)
exit_alt YYexits CHDK mode
get_alt_mode YYreturns whether CHDK is in ALT mode or not (CHDK 1.3.0 or greater)
get_buildinfo YNreturn info about CHDK version running on the camera
get_config_value YYget currently selected state of CHDK menu item
set_config_autosave YN on/off for the autosave function of the CHDK configuration (CHDK 1.3.0 or greater)
load_config_file YNloads a CHDK configuration file (CHDK 1.3.0 or greater)
save_config_file YNsaves a CHDK configuration file (CHDK 1.3.0 or greater)
get_histo_range YYreturn % if values in given range on histogram
get_platform_idNYget the camera's platform ID value
set_config_value YYsets specified CHDK config value to specified value
shot_histo_enable YYenables creation of histogram data from a shot
Function Link Lua uBASIC Description
bitand(a, b) YNreturns bitwise logical AND of two variables
bitnot(a) YNreturns bitwise inversion of a variable
bitor(a, b) YNreturns bitwise logical OR of two variables
bitshl(a) YNreturns logical shift left of a variable
bitshri(a) YNreturns logical right of a variable (top bit stays in same state afterwards)
bitshru(a) YNreturns logical right of a variable (top bit = 0 afterwards)
bitxor(a, b) YNreturns logical exclusive or of two variables
peek YNreads from specified camera memory address
poke YNwrites to specified camera memory address
Motion Detection
Function Link Lua uBASIC Description
md_detect_motion YYwaits for a change in specified screen cells caused by motion
md_get_cell_diff YYgets change in motion detect level in specified cell
md_get_cell_val YYgets signal level in specified cell
md_af_on_time YYenable AF led for MD response testing
USB Port Interface
Function Link Lua uBASIC Description
get_usb_power YYget status of USB remote ( current level, pulse width, pulse count, etc )
set_remote_timing YYenables high precision USB remote timing
read_usb_msg YNread a message from the CHDK ptp usb interface
write_usb_msg YNwrite a message via the CHDK ptp interface
usb_msg_table_to_stringYN User-definable callback used convert tables to string for write_usb_msg and PTP return
switch_mode_usb YNset playback or record mode while PTP USB connected
usb_force_active YYforce camera to believe USB 5V pin is active
usb_sync_wait YYcauses camera to wait for sync signal on next shot (CHDK 1.4.0 or newer)
Tone Curves
Function Link Lua uBASIC Description
get_curve_file YNLua commands to control tone curves
get_curve_state YNLua commands to control tone curves
set_curve_file YNload a tone curve file
set_curve_state YNenable/disable the use of a tone curve file
imath functions
Function Link Lua uBASIC Description
imath.scale YNconstant = 1000
imath.pi2 YNconstant = 6283
imath.pi YNconstant = 3142
imath.pi_2 YNconstant = 1517
imath.muldiv YNa*b/c
imath.mul YNa*b
imath.div YNa/b
imath.rad YNrad -> deg
imath.deg YNdeg -> rad
imath.sinr YNsin(rad)
imath.cosr YNcos(rad)
imath.tanr YNtan(rad)
imath.asinr YNarcsin(rad)
imath.acosr YNarccos(rad)
imath.atanr YNarctan(rad)
imath.polr YNr, rad_alpha = pol(x, y)
imath.recr YNx, y = rec(r, rad_alpha)
imath.sind YNsin(deg)
imath.cosd YNcos(deg)
imath.tand YNtan(deg)
imath.asind YNarcsin(deg)
imath.acosd YNarccos(deg)
imath.atand YNarctan(deg)
imath.pold YNr, deg_alpha = pol(x, y)
imath.recd YNx, y = rec(r, deg_alpha)
imath.pow YNx^y
imath.log YNlog(x)
imath.log2 YNlog2(x)
imath.log10 YNlog10(x)
imath.sqrt YNsquare root YNinteger
imath.frac YN fractal
imath.ceil YN ceil
imath.floor YNfloor
imath.round YNround