Wikia

CHDK Wiki

Changes: UBASIC/uBASIC syntax

Edit

Back to page

(added link to scripting cross reference page)
m
Line 7: Line 7:
 
The camera is now completely scriptable with uBASIC programs that simulate pressing keys
 
The camera is now completely scriptable with uBASIC programs that simulate pressing keys
   
{{tagb|→}} See also the '''[[CHDK_Scripting_Cross_Reference_Page|Scripting Cross Reference Page]]''' for the complete list of CHDK scripting commands for Lua and uBasic.
 
   
 
===uBASIC Syntax short manual===
 
===uBASIC Syntax short manual===
Line 33: Line 32:
   
 
See the [[uBASIC/TutorialScratchpad|Scripting Tutorial]] for more complete explanation and use of all commands.
 
See the [[uBASIC/TutorialScratchpad|Scripting Tutorial]] for more complete explanation and use of all commands.
  +
  +
{{tagb|→}} See also the '''[[CHDK_Scripting_Cross_Reference_Page|Scripting Cross Reference Page]]''' for the complete list of CHDK scripting commands for Lua and uBasic.
   
 
(Note: Newer versions of CHDK allow for saving scripts in a /CHDK/SCRIPTS/ sub-folder. This makes for easier selection and loading of different scripts. They may have a more descriptive name, but they must end with the .bas extension. Also, some features (button commands and menu selections) between the A-Series and Sx IS cameras are slightly different. Scripts may need to be slightly modified to run on one line of camera or the other. If you write and share scripts with others it would help if you make note somewhere of which camera your particular script was written for, or if it will run on all of them.)
 
(Note: Newer versions of CHDK allow for saving scripts in a /CHDK/SCRIPTS/ sub-folder. This makes for easier selection and loading of different scripts. They may have a more descriptive name, but they must end with the .bas extension. Also, some features (button commands and menu selections) between the A-Series and Sx IS cameras are slightly different. Scripts may need to be slightly modified to run on one line of camera or the other. If you write and share scripts with others it would help if you make note somewhere of which camera your particular script was written for, or if it will run on all of them.)

Revision as of 21:21, May 27, 2012

!!! This text has to be updated !!!

Camera scripting using uBASIC

The CHDK includes a slightly modified version of the uBASIC interpreter written by Adam Dunkels, http://www.sics.se/~adam/ubasic/

The camera is now completely scriptable with uBASIC programs that simulate pressing keys


uBASIC Syntax short manual

Keywords: let, if, then, else, for, to, next, goto, gosub, return, end.

Special keywords: click, press, release, shoot, sleep.

Variables: lower latin letter from a to z. 32 bit signed integer (-2147483648 to +2147483647).


Labels: This version of uBasic doesn't support line numbers. Instead, labels are used. A label must be the only statement in a line and start with a colon(:).

Special keywords syntax:

  • click "button_name", press "button_name", release "button_name"
where button_name can be one of: up, down, left, right, set, shoot_half, shoot_full, zoom_in, zoom_out, menu, display, print, erase. Corresponding button is "clicked" (pressed and released).
  • S-series buttons: iso, flash, mf, macro, video, timer
  • shoot
Take a picture. Procedure will return when first raw data will be ready for processing and specified time in menu had elapsed.
  • sleep <number>
Delay for <number> ms. Timer resolution is around 10-30 ms.

See the Scripting Tutorial for more complete explanation and use of all commands.

See also the Scripting Cross Reference Page for the complete list of CHDK scripting commands for Lua and uBasic.

(Note: Newer versions of CHDK allow for saving scripts in a /CHDK/SCRIPTS/ sub-folder. This makes for easier selection and loading of different scripts. They may have a more descriptive name, but they must end with the .bas extension. Also, some features (button commands and menu selections) between the A-Series and Sx IS cameras are slightly different. Scripts may need to be slightly modified to run on one line of camera or the other. If you write and share scripts with others it would help if you make note somewhere of which camera your particular script was written for, or if it will run on all of them.)

Default script follows:

sleep 1000
if a<1 then let a=2
if b<1 then let b=3
for s=1 to a
  shoot
  for n=1 to b
    click "right"
  next n
next s
shoot
end

Note that values of variables a, b and c are set to values you can choose from the Alt. Conf. menu.

Maximum script size is 8K. A maximum of 4 nested for loops is allowed. 10 nested gosub calls are possible. (Clarification needed here -- maximum nested DEPTH of for loops is 4? and specific to GOSUBs, maximum nested *DEPTH* is 10 ?)

If execution/parse error occurs message with line number is shown in the upper left corner of the display.

Using labels and gosub

For complex programming tasks, it is often helpful to split the program into smaller subroutines that can be called with the gosub command. You can jump to labels using the gosub statements. Due to a known bug, you might need to add a space char right after the label (":label "), otherwise you might get an "Unk Label"-error. -> Should be fixed in build #66.
A simple program that captures 3 images with increased ISO settings would look like this:

 shoot
 for i=1 to 3
   gosub "incISO"
   shoot
 next i
 for i=1 to 3
   gosub "decISO"
 next i
 end

 :incISO
   click "menu"
   [some more clicks]
   return

 :decISO
   click "menu"
   [some more clicks]
   return

Around Wikia's network

Random Wiki