|
5.2 uBasic 79as soon as you load another script, the new script will run at start-up, so itis necessary to reload flashoff.lua before switching off.Many scripts can be configured with parameters. These parameters aredefined in the header section of the script. After the script has been loaded,they are listed in the bottom section of the CHDK Script menu. The param-eter values shown there can be modified with the LEFT, RIGHT, and FUNC/SET keys. If a script has many parameters, it can be tedious to set up all theparameters before running the script. The CHDK therefore offers the pos-sibility to store frequently used parameter combinations in parameter sets.Ten of those sets exist (0–9). By modifying the value of the menu entryParameters set, you can easily switch among different parameter combina-tions.5.2 uBasicThe original uBasic interpreter was written by the Swedish programmerAdam Dunkels. He said, “I’ve always wanted to write a really small BASICinterpreter. So I sat down for an hour or two and did it.” It’s probably true.uBasic is tiny, and there are only a few commands to learn. The originaluBasic interpreter didn’t even understand labels—instead you specifiedline numbers as GOTO targets, just like in the days of the legendary C64.Labels were later added by Pablo d’Angelo who is also the main contributorfor the Hugin panorama stitcher.So, let’s jump right into another small script and see how uBasic looksthese days. (A more systematic introduction into uBasic is given in the fol-lowing sections.) The following script implements an electronic magnify-ing glass by switching the camera into the Digital Macro mode and settinga predefined magnification level. Also, most of the info texts are hiddenfrom the display.@title Digital Magnifier@param m Initial Magnification@default m 3This is the header section of the script. The title will appear at the bottomof the display after the script is loaded. You should avoid using more than24 characters; otherwise, the title would override the indicator.The title declaration is followed by the declaration of the parametersproviding input to the script. With the @param instruction, you specify avariable name and a parameter description. Variable names for parametersalways consist of a single lower case letter. In newer CHDK versions, youcan have variable names from a–z, in older versions only a–j. The parame-ter description is shown in the script menu (ALT > FUNC/SET) below theFigure 5-1The CHDK Script menu. The upper halfis used for general script configuration,such as script loading, delaying theexecution of the script for a specifiednumber of 1/10 secs, resetting to thedefault parameter values, andswitching and saving parameter sets.The lower half is reserved for the scriptparameters. Here are some of theparameters from the motion detectionscript discussed in section 5.7.3 PreviousNext |