Wikia

CHDK Wiki

UBASIC/uBASIC syntax

Talk0
565pages on
this wiki

< UBASIC

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

Camera scripting using uBASICEdit

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 ManualEdit

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

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

Variables: Upper and lower case Latin letters from A-Z and a-z as 32-bit signed integers (-2147483648 to +2147483647).

Labels: This version of uBasic does not 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 are ready for processing and specified time in menu has elapsed.
  • sleep <number>
Delay for <number> in 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 depth of 4 nested for loops is allowed. Ten 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, an error message with line number in which the error occured is shown in the upper left corner of the display.

Using labels and gosubEdit

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.
A simple program that captures 3 images with increased ISO settings might 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
Advertisement | Your ad here

Around Wikia's network

Random Wiki