CHDK_DE Vorschauversion  Trunk Rev. 5715
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
ubasic.c-Dateireferenz
#include "camera_info.h"
#include "shot_histogram.h"
#include "levent.h"
#include "script.h"
#include "console.h"
#include "conf.h"
#include "lang.h"
#include "gui_lang.h"
#include "action_stack.h"
#include "shooting.h"
#include "sd_card.h"
#include "backlight.h"
#include "battery.h"
#include "temperature.h"
#include "clock.h"
#include "file_counter.h"
#include "lens.h"
#include "debug_led.h"
#include "keyboard.h"
#include "usb_remote.h"
#include "shutdown.h"
#include "sound.h"
#include "motion_detector.h"
#include "string.h"
#include "time.h"
#include "script_key_funcs.h"
#include "properties.h"
#include "ubasic.h"
#include "tokenizer.h"
+ Include-Abhängigkeitsdiagramm für ubasic.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  select_state
 
struct  for_state
 

Makrodefinitionen

#define DEBUG_PRINTF(...)
 
#define INCLUDE_OLD_GET__SYNTAX
 
#define MAX_STRINGLEN   40
 
#define MAX_GOSUB_STACK_DEPTH   10
 
#define MAX_IF_STACK_DEPTH   4
 
#define MAX_SELECT_STACK_DEPTH   4
 
#define MAX_WHILE_STACK_DEPTH   4
 
#define MAX_DO_STACK_DEPTH   4
 
#define MAX_FOR_STACK_DEPTH   4
 
#define MAX_VARNUM   52
 
#define YIELD_MAX_LINES_DEFAULT   1
 
#define YIELD_MAX_MS_DEFAULT   10
 

Funktionen

int ubasic_get_variable (int varnum)
 
void ubasic_set_variable (int varum, int value)
 
static int expr (void)
 
static void line_statement (void)
 
static void statement (void)
 
static int relation (void)
 
int ubasic_linenumber ()
 
int ubasic_init (const char *program, __attribute__((unused)) int is_ptp)
 
static int ubasic_get_key_arg ()
 
static void accept (int token)
 
static void accept_cr ()
 
static int varfactor (void)
 
static int shooting_get_near_limit_of_acceptable_sharpness ()
 
static int shooting_get_far_limit_of_acceptable_sharpness ()
 
static int shooting_get_depth_of_field ()
 
static int shooting_get_min_stack_distance ()
 
static int factor (void)
 
static int term (void)
 
static void jump_line (int linenum)
 
int jump_label (char *label)
 
static void goto_statement (void)
 
static void print_statement (void)
 
static void endif_statement (void)
 
static void if_statement (void)
 
static void else_statement (void)
 
static void dec_select_stack (void)
 
static void end_select_statement (void)
 
static void case_statement (void)
 
static void case_else_statement (void)
 
static void select_statement (void)
 
static void let_statement (void)
 
static void rem_statement (void)
 
static void cls_statement (void)
 
static void gosub_statement (void)
 
static void return_statement (void)
 
static void next_statement (void)
 
static void for_statement (void)
 
static void do_statement (void)
 
static void until_statement (void)
 
static void while_statement (void)
 
static void wend_statement (void)
 
static void end_statement (void)
 
static void click_statement (void)
 
static void press_statement (void)
 
static void release_statement (void)
 
static int action_stack_AS_UBASIC_SLEEP ()
 
static int sleep_delay (int delay)
 
static void sleep_statement (void)
 
static void shoot_statement (void)
 
static void set_console_layout (void)
 
static void set_console_autoredraw (void)
 
static void console_redraw_statement (void)
 
static void set_yield_statement ()
 
static void get_short_var_statement (int token, short(*func)(void))
 
static void get_int_var_statement (int token, int(*func)(void))
 
static void get_prop_statement ()
 
static void one_int_param_function (int token, void(*func)(int))
 
static void one_short_param_function (int token, void(*func)(short))
 
static void set_ev_statement ()
 
static void set_movie_status_statement ()
 
static void set_propcase_statement (int token, int prop)
 
static void set_mf_statement ()
 
static void set_focus_statement ()
 
static void set_led_statement ()
 
static void set_prop_statement ()
 
static void set_autostart_statement ()
 
static void set_capture_mode_canon_statement ()
 
static void reboot_statement ()
 
static void set_config_value_statement ()
 
static int action_stack_AS_UBASIC_WAIT_CLICK ()
 
static void wait_click_statement ()
 
static void is_key_statement (void)
 
static void set_exit_key_statement ()
 
static void get_config_value_statement ()
 
static void on_off_statement (int token, void(*on)(void), void(*off)(void))
 
static void shutdown_statement (void)
 
static void uB_set_av96 (int param)
 
static void uB_set_av96_direct (int param)
 
static void uB_set_tv96 (int param)
 
static void uB_set_tv96_direct (int param)
 
static void uB_set_sv96 (int param)
 
static void uB_set_nd_filter_state (int param)
 
static void uB_set_iso_real (int param)
 
static void md_get_cell_diff_statement ()
 
static void md_get_cell_val_statement ()
 
static void md_detect_motion_statement ()
 
static int _shot_histogram_set (int enable)
 
int ubasic_run (void)
 
void ubasic_end ()
 
void ubasic_set_as_ret (int md_ret)
 

Variablen

static char constprogram_ptr
 
static char string [MAX_STRINGLEN]
 
static short gosub_stack [MAX_GOSUB_STACK_DEPTH]
 
static int gosub_stack_ptr
 
static short if_stack [MAX_IF_STACK_DEPTH]
 
static int if_stack_ptr
 
static struct select_state select_stack [MAX_SELECT_STACK_DEPTH]
 
static int select_stack_ptr
 
static short while_stack [MAX_WHILE_STACK_DEPTH]
 
static int while_stack_ptr
 
static short do_stack [MAX_DO_STACK_DEPTH]
 
static int do_stack_ptr
 
static struct for_state for_stack [MAX_FOR_STACK_DEPTH]
 
static int for_stack_ptr
 
static int variables [MAX_VARNUM]
 
static int ended
 
static int ubasic_as_ret_var_num
 
static unsigned yield_max_lines
 
static unsigned yield_max_ms
 
static int flag_yield
 
int ubasic_error
 
const char * ubasic_errstrings [UBASIC_E_ENDMARK]
 

Makro-Dokumentation

#define DEBUG_PRINTF (   ...)

Definiert in Zeile 34 der Datei ubasic.c.

#define INCLUDE_OLD_GET__SYNTAX

Definiert in Zeile 80 der Datei ubasic.c.

#define MAX_DO_STACK_DEPTH   4

Definiert in Zeile 106 der Datei ubasic.c.

#define MAX_FOR_STACK_DEPTH   4

Definiert in Zeile 116 der Datei ubasic.c.

#define MAX_GOSUB_STACK_DEPTH   10

Definiert in Zeile 86 der Datei ubasic.c.

#define MAX_IF_STACK_DEPTH   4

Definiert in Zeile 90 der Datei ubasic.c.

#define MAX_SELECT_STACK_DEPTH   4

Definiert in Zeile 98 der Datei ubasic.c.

#define MAX_STRINGLEN   40

Definiert in Zeile 83 der Datei ubasic.c.

#define MAX_VARNUM   52

Definiert in Zeile 120 der Datei ubasic.c.

#define MAX_WHILE_STACK_DEPTH   4

Definiert in Zeile 102 der Datei ubasic.c.

#define YIELD_MAX_LINES_DEFAULT   1

Definiert in Zeile 138 der Datei ubasic.c.

#define YIELD_MAX_MS_DEFAULT   10

Definiert in Zeile 139 der Datei ubasic.c.

Dokumentation der Funktionen

static int _shot_histogram_set ( int  enable)
static

Definiert in Zeile 2237 der Datei ubasic.c.

2238 {
2239 #ifdef UBASIC_TEST
2240  return 0;
2241 #else
2242  return libshothisto->shot_histogram_set(enable);
2243 #endif
2244 }
static void accept ( int  token)
static

Definiert in Zeile 206 der Datei ubasic.c.

207 {
208  if(token != tokenizer_token()) {
209  DEBUG_PRINTF("Token not what was expected (expected %d, got %d)\n",
212  tokenizer_next();
213  ended = 1;
215  return;
216  }
217  DEBUG_PRINTF("Expected %d, got it\n", token);
218  tokenizer_next();
219 }
static void accept_cr ( )
static

Definiert in Zeile 222 der Datei ubasic.c.

223 {
224  while(tokenizer_token() != TOKENIZER_CR &&
226  tokenizer_next();
228 }
static int action_stack_AS_UBASIC_SLEEP ( )
static

Definiert in Zeile 1641 der Datei ubasic.c.

1642 {
1643  if (get_tick_count() >= action_top(2))
1644  {
1645  action_pop_func(1);
1646  return 1;
1647  }
1648  return 0;
1649 }
static int action_stack_AS_UBASIC_WAIT_CLICK ( )
static

Definiert in Zeile 1946 der Datei ubasic.c.

1947 {
1948  // Check key pressed or timeout
1950  {
1951  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1954  else
1956 
1957  action_pop_func(1);
1958  return 1;
1959  }
1960 
1961  return 0;
1962 }
static void case_else_statement ( void  )
static

Definiert in Zeile 1277 der Datei ubasic.c.

1278 {
1279  short case_goto = 0, case_gosub = 0;
1280  int cur_ln, gosub_ln = 0;
1281 
1283  if(select_stack_ptr > 0) {
1284  if (!select_stack[select_stack_ptr - 1].case_run) {
1285  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1286  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1287 //GOSUB - save curr linenumber
1288  cur_ln = tokenizer_line_number();
1289 //GOSUB
1290  statement();
1291 //GOSUB - save new linenumber, reset to curr linenumber
1292  if (case_gosub) {
1293  gosub_ln = tokenizer_line_number();
1294  jump_line(cur_ln+1);
1295  DEBUG_PRINTF("case_else_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1296  }
1297 //GOSUB
1298  DEBUG_PRINTF("case_else_statement: case_else execute\n");
1299  } else {
1300  DEBUG_PRINTF("case_else_statement: case_else jump; case_run: %d\n", select_stack[select_stack_ptr - 1].case_run);
1301  accept_cr();
1302  }
1303 //REM
1304  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1305 //REM
1306  if (case_goto) { dec_select_stack(); } else {
1307 //GOSUB test for end_select and set to gosub-linenumber
1309  DEBUG_PRINTF("ubasic.c: select_statement(): don't found end_select\n");
1310  ended = 1;
1312  } else {
1314  if (case_gosub) {
1316  jump_line(gosub_ln);
1317  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1318  }
1319  }
1320 //GOSUB
1321  }
1322  } else {
1323  DEBUG_PRINTF("case_else_statement: SELECT-Stack fault\n");
1324  ended = 1;
1326  }
1327 }
static void case_statement ( void  )
static

Definiert in Zeile 1187 der Datei ubasic.c.

1188 {
1189  int select_value, case_value_1, case_value_2, case_value_eq;
1190  short case_run, case_goto = 0, case_gosub = 0;
1191  int cur_ln, gosub_ln = 0;
1192 
1194  if(select_stack_ptr > 0) {
1195  select_value = select_stack[select_stack_ptr - 1].select_value;
1196  case_run = select_stack[select_stack_ptr - 1].case_run;
1197 
1198  if (!case_run) {
1199  case_value_1 = expr();
1200  case_value_eq = (select_value == case_value_1);
1201  if (case_value_eq) { DEBUG_PRINTF("case_statement: case_value_eq %d, case_value %d\n", case_value_eq, case_value_1); }
1202 
1203  if(tokenizer_token() == TOKENIZER_TO) {
1205  case_value_2 = expr();
1206  if (case_value_1 < case_value_2) {
1207  case_value_eq = ((select_value >= case_value_1) && (select_value <= case_value_2));
1208  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_1, case_value_2);
1209  } else {
1210  case_value_eq = ((select_value >= case_value_2) && (select_value <= case_value_1));
1211  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_2, case_value_1);
1212  }
1213  } else if (tokenizer_token() == TOKENIZER_COMMA) {
1214  do {
1216  if (case_value_eq) {
1217  case_value_2 = expr();
1218  } else {
1219  case_value_1 = expr();
1220  case_value_eq = (select_value == case_value_1);
1221  }
1222  } while (tokenizer_token() == TOKENIZER_COMMA);
1223  DEBUG_PRINTF("case_statement: case_value_eq %d, case_value_comma %d\n", case_value_eq, case_value_1);
1224  }
1225 
1227  if (case_value_eq) {
1228  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1229  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1230 //GOSUB - save curr linenumber
1231  cur_ln = tokenizer_line_number();
1232 //GOSUB
1233  statement();
1234 //GOSUB - save new linenumber, reset to curr linenumber
1235  if (case_gosub) {
1236  gosub_ln = tokenizer_line_number();
1237  jump_line(cur_ln+1);
1238  DEBUG_PRINTF("case_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1239  }
1240 //GOSUB
1241  DEBUG_PRINTF("case_statement: case execute\n");
1242  case_run = 1;
1243  select_stack[select_stack_ptr - 1].case_run = case_run;
1244  } else {
1245  DEBUG_PRINTF("case_statement: case jump; case_run: %d\n", case_run);
1246  accept_cr();
1247  }
1248  } else {accept_cr();}
1249 //REM
1250  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1251 //REM
1252  if (case_goto) { dec_select_stack(); } else {
1255  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case, case_else or end_select\n");
1256  ended = 1;
1258  } else {
1259 //GOSUB test for end_select and set to gosub-linenumber
1261  if (case_gosub) {
1263  jump_line(gosub_ln);
1264  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1265  }
1266  }
1267 //GOSUB
1268  }
1269  } else {
1270  DEBUG_PRINTF("case_statement: SELECT-Stack fail\n");
1271  ended = 1;
1273  }
1274 }
static void click_statement ( void  )
static

Definiert in Zeile 1597 der Datei ubasic.c.

1598 {
1599  int k;
1601  k = ubasic_get_key_arg();
1602  if (k > 0) {
1603  action_push_click(k);
1604  flag_yield=1;
1605  }
1606 
1607  DEBUG_PRINTF("End of click\n");
1608  accept_cr();
1609 }
static void cls_statement ( void  )
static

Definiert in Zeile 1385 der Datei ubasic.c.

1386 {
1388  console_clear();
1389  DEBUG_PRINTF("cls_statement\n");
1391 }
static void console_redraw_statement ( void  )
static

Definiert in Zeile 1716 der Datei ubasic.c.

1717 {
1719  console_redraw();
1720  accept_cr();
1721 }
static void dec_select_stack ( void  )
static

Definiert in Zeile 1161 der Datei ubasic.c.

1162 {
1163  if(select_stack_ptr > 0) {
1164  select_stack_ptr--;
1165  } else {
1166  DEBUG_PRINTF("select_statement: SELECT-Stack fail\n");
1167  ended = 1;
1169  }
1170 }
static void do_statement ( void  )
static

Definiert in Zeile 1499 der Datei ubasic.c.

1500 {
1505  do_stack_ptr++;
1506  } else {
1507  DEBUG_PRINTF("do_statement: do stack depth exceeded\n");
1508  ended = 1;
1510  }
1511 }
static void else_statement ( void  )
static

Definiert in Zeile 1095 der Datei ubasic.c.

1096 {
1097  int r=0, endif_cntr, f_nt;
1098 
1100  if(if_stack_ptr > 0) {
1101  r = if_stack[if_stack_ptr-1];
1102  }
1103  else{
1104  DEBUG_PRINTF("ubasic.c: else_statement(): else without if-statement\n");
1105  ended = 1;
1107  return;
1108  }
1109  DEBUG_PRINTF("else_statement: relation %d\n", r);
1110 
1111  if (tokenizer_token() == TOKENIZER_CR) {
1113  if(!r) {
1114  DEBUG_PRINTF("else_statement: result true\n");
1115  return;
1116  } else {
1117  DEBUG_PRINTF("else_statement: result false\n");
1118  endif_cntr=0;
1119  while(((tokenizer_token() != TOKENIZER_ENDIF )
1120  || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1121  f_nt=0;
1122  if( tokenizer_token() == TOKENIZER_IF) {
1123  endif_cntr+=1;
1124  }
1125  if( tokenizer_token() == TOKENIZER_THEN) {
1126  tokenizer_next();
1127  // then followed by CR -> multi line
1128  if (tokenizer_token() == TOKENIZER_CR) {
1129  f_nt=1;
1130  } else { // single line
1131  endif_cntr--;
1134  tokenizer_next();
1135  }
1137  DEBUG_PRINTF("ubasic.c: else_statement(): endif in singleline if-statement\n");
1138  ended = 1;
1140  return;
1141  }
1142  }
1143  }
1144  if( tokenizer_token() == TOKENIZER_ENDIF) { endif_cntr--; }
1145  if (!f_nt) { tokenizer_next(); }
1146  }
1147  }
1148  endif_statement();
1149  }else{
1150  DEBUG_PRINTF("ubasic.c: else_statement(): CR after ELSE expected\n");
1151  ended = 1;
1153  }
1154 }
static void end_select_statement ( void  )
static

Definiert in Zeile 1173 der Datei ubasic.c.

1174 {
1175  if(select_stack_ptr > 0) {
1178  dec_select_stack();
1179  } else {
1180  DEBUG_PRINTF("ubasic.c: end_select_statement(): end_select without select-statement\n");
1181  ended = 1;
1183  }
1184 }
static void end_statement ( void  )
static

Definiert in Zeile 1590 der Datei ubasic.c.

1591 {
1593  ended = 1;
1594 }
static void endif_statement ( void  )
static

Definiert in Zeile 974 der Datei ubasic.c.

975 {
976  if(if_stack_ptr > 0) {
979  if_stack_ptr--;
980  } else {
981  DEBUG_PRINTF("ubasic.c: endif_statement(): endif without if-statement\n");
982  ended = 1;
984  }
985 }
static int expr ( void  )
static

Definiert in Zeile 806 der Datei ubasic.c.

807 {
808  int t1, t2;
809  int op;
810 
811  t1 = term();
812  op = tokenizer_token();
813  DEBUG_PRINTF("expr: token %d\n", op);
814  while(op == TOKENIZER_PLUS ||
815  op == TOKENIZER_MINUS ||
816  op == TOKENIZER_AND ||
817  op == TOKENIZER_LOR ||
818  op == TOKENIZER_XOR) {
819  tokenizer_next();
820  t2 = term();
821  DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
822  switch(op) {
823  case TOKENIZER_PLUS:
824  t1 = t1 + t2;
825  break;
826  case TOKENIZER_MINUS:
827  t1 = t1 - t2;
828  break;
829  case TOKENIZER_AND:
830  t1 = t1 & t2;
831  break;
832  case TOKENIZER_LOR:
833  t1 = t1 || t2;
834  break;
835  }
836  op = tokenizer_token();
837  }
838  DEBUG_PRINTF("expr: %d\n", t1);
839  return t1;
840 }
static int factor ( void  )
static

Definiert in Zeile 264 der Datei ubasic.c.

265 {
266  int r = 0;
267  tConfigVal configVal;
268 
269  DEBUG_PRINTF("factor: token %d\n", tokenizer_token());
270  switch(tokenizer_token()) {
271  case TOKENIZER_NUMBER:
272  r = tokenizer_num();
273  DEBUG_PRINTF("factor: number %d\n", r);
275  break;
276  case TOKENIZER_LEFTPAREN:
278  r = relation();
280  break;
281  case TOKENIZER_PLUS:
283  r = factor();
284  break;
285  case TOKENIZER_MINUS:
287  r = - factor();
288  break;
289  case TOKENIZER_LNOT:
291  r = ! relation();
292  break;
293  case TOKENIZER_GET_VBATT:
295  r = (unsigned short) stat_get_vbatt();
296  break;
298  {
300  struct tm *ttm;
301  ttm = get_localtime();
302  r = ttm->tm_hour * 3600 + ttm->tm_min * 60 + ttm->tm_sec;
303  }
304  break;
307  r = get_tick_count();
308  break;
309  case TOKENIZER_GET_MODE:
311  if (!camera_info.state.mode_play) r = 0;
312  if (camera_info.state.mode_play) r = 1;
314  break;
317  r = conf.raw_nr;
318  break;
319  case TOKENIZER_IS_KEY:
322  break;
326  break;
329 #ifdef UBASIC_TEST
330  r = 0;
331 #else
332  r = conf.script_startup;
333 #endif
334  break;
337  int usbpwr = 0 ;
338  if (tokenizer_token() != TOKENIZER_CR &&
340  usbpwr = expr();
341  }
342  r = get_usb_power(usbpwr);
343  break;
346  r = get_exposure_counter();
347  break;
351  break;
352  case TOKENIZER_RANDOM:
354  int min = expr();
355  int max = expr();
356  // shouldn't srand every time...
357  srand((int)shooting_get_bv96()+(unsigned short)stat_get_vbatt()+get_tick_count());
358  // wtf
359  action_push_delay(rand()%10);
360  flag_yield=1;
361  r = min + rand()%(max-min+1);
362  break;
365  r = get_movie_status();
366  break;
369  r = conf.platformid;
370  break;
374  break;
378  break;
382  break;
385  r = shooting_get_focus_ok();
386  break;
390  break;
394  break;
397  r = shooting_in_progress();
398  break;
401  r = shooting_is_flash();
402  break;
405  r = shooting_get_is_mode();
406  break;
407  case TOKENIZER_GET_EV:
410  break;
414  break;
418  break;
422  break;
425  r = zoom_points;
426  break;
430  {
431  r = 0;
432  }
433  else
434  {
436  {
437  r = 1;
438  }
439  else
440  {
441  r = 2;
442  }
443  }
444  break;
448  break;
449  case TOKENIZER_GET_TV96:
451  r = shooting_get_tv96();
452  break;
456  break;
460  break;
461  case TOKENIZER_GET_AV96:
463  r = shooting_get_av96();
464  break;
468  break;
472  break;
473  case TOKENIZER_GET_ZOOM:
475  r = shooting_get_zoom();
476  break;
477  case TOKENIZER_GET_FOCUS:
480  break;
484  break;
488  break;
489  case TOKENIZER_GET_DOF:
492  break;
496  break;
499  r = sd_over_modes() ;
500  break;
503  r = (int)shooting_get_iso_market();
504  break;
507  r = (int)shooting_get_iso_real();
508  break;
509  case TOKENIZER_GET_BV96:
511  r = (int)shooting_get_bv96();
512  break;
513  case TOKENIZER_GET_SV96:
515  r = (int)shooting_get_sv96_real();
516  break;
519  r = shooting_get_iso_mode();
520  break;
523  r = GetTotalCardSpaceKb();
524  break;
527  r = GetFreeCardSpaceKb();
528  break;
531  r = GetJpgCount();
532  break;
535  r = (camera_info.cam_has_video_button) ? 1 : 0;
536  break;
539  r = is_video_recording();
540  break;
543  r = GetRawCount();
544  break;
545  case TOKENIZER_GET_PROP:
547  int var = expr();
548  r = shooting_get_prop(var);
549  break;
552  int from = expr();
553  int to = expr();
554 #ifdef UBASIC_TEST
555  (void)from; (void)to;
556  r = 0;
557 #else
558  r = (unsigned short)libshothisto->shot_histogram_get_range(from, to);
559 #endif
560  break;
563  int temp = expr();
564  switch (temp)
565  {
566  case 0:
567  r = get_optical_temp();
568  break;
569  case 1:
570  r = get_ccd_temp();
571  break;
572  case 2:
573  r = get_battery_temp();
574  break;
575  default: // do something sane if given a bad index
576  r = 0;
577  }
578  break;
579  case TOKENIZER_GET_TIME:
581  int tmode = expr();
582  static struct tm *ttm;
583  ttm = get_localtime();
584  if (tmode==0) r = ttm->tm_sec;
585  else if (tmode==1) r = ttm->tm_min;
586  else if (tmode==2) r = ttm->tm_hour;
587  else if (tmode==3) r = ttm->tm_mday;
588  else if (tmode==4) r = ttm->tm_mon+1;
589  else if (tmode==5) r = 1900+ttm->tm_year;
590  break;
591  case TOKENIZER_GET_RAW:
593 #ifdef UBASIC_TEST
594  r = 1;
595 #else
596  r = conf.save_raw;
597 #endif
598  break;
599  // get CHDK capture mode value, or 0 if in playback or unknown (broken modemap)
600  // NOTE: different from get_mode, since this returns the actual value
605  else
606  r = 0;
607  break;
608  // check if CHDK capture mode exists in modemap of this camera
611  int modenum = expr();
612  if (shooting_mode_chdk2canon(modenum) == -1)
613  r = 0;
614  else
615  r = 1;
616  break;
620  break;
624  break;
627  int var1 = expr();
628  int var2 = expr();
629  if( conf_getValue(var1, &configVal) == CONF_VALUE) r = configVal.numb; else r = var2;
630  break;
633  int partNr = expr();
634  r = swap_partitions(partNr);
635  break;
636 
637  // APEX functions
641  break;
645  break;
649  break;
653  break;
657  break;
661  break;
665  break;
669  break;
672  r = shooting_get_tv96_from_shutter_speed((float)expr()/1000000.0);
673  break;
676  r = (int)(shooting_get_shutter_speed_from_tv96(expr()) * 1000000.0 + 0.5);
677  break;
680  int n = expr();
681  int d = expr();
682  r = shooting_get_tv96_from_shutter_speed((float)n/(float)d);
683  break;
687  break;
690  r=force_usb_state(expr()) ;
691  break;
694  r = (camera_info.state.gui_mode != 0);
695  break;
699  break;
703  break;
707  break;
711  break;
714  r = shooting_get_max_av96(); // NOTE -1 if not available, i.e. playback
715  break;
718  r = shooting_get_min_av96(); // NOTE -1 if not available, i.e. playback
719  break;
723  break;
727  break;
728  case TOKENIZER_GET_DIGIC:
731  break;
732  //ARM Begin
733 
734  default:
735  r = varfactor();
736  break;
737  }
738  return r;
739 }
static void for_statement ( void  )
static

Definiert in Zeile 1463 der Datei ubasic.c.

1464 {
1465  int for_variable, to, step;
1466 
1468  for_variable = tokenizer_variable_num();
1471  ubasic_set_variable(for_variable, expr());
1473  to = expr();
1474  step = 1;
1475  if (tokenizer_token() != TOKENIZER_CR) {
1477  step = expr();
1478  }
1480 
1483  for_stack[for_stack_ptr].for_variable = for_variable;
1486  DEBUG_PRINTF("for_statement: new for, var %d to %d\n",
1487  for_stack[for_stack_ptr].for_variable,
1488  for_stack[for_stack_ptr].to);
1489 
1490  for_stack_ptr++;
1491  } else {
1492  DEBUG_PRINTF("for_statement: for stack depth exceeded\n");
1493  ended = 1;
1495  }
1496 }
static void get_config_value_statement ( )
static

Definiert in Zeile 2033 der Datei ubasic.c.

2034 {
2035  int var, var1, var2;
2036  tConfigVal configVal;
2038  var = expr();
2039  var1 = expr();
2040  var2 = tokenizer_variable_num();
2042  if( conf_getValue(var, &configVal) == CONF_VALUE ) {
2043  ubasic_set_variable(var2, configVal.numb);
2044  } else {
2045  ubasic_set_variable(var2, var1);
2046  }
2047  accept_cr();
2048 }
static void get_int_var_statement ( int  token,
int(*)(void)  func 
)
static

Definiert in Zeile 1749 der Datei ubasic.c.

1750 {
1751  int var;
1752  accept(token);
1753  var = tokenizer_variable_num();
1755  ubasic_set_variable(var, func());
1756  accept_cr();
1757 }
static void get_prop_statement ( )
static

Definiert in Zeile 1759 der Datei ubasic.c.

1760 {
1761  int var, var1;
1763  var = expr();
1764  var1 = tokenizer_variable_num();
1767 
1768  accept_cr();
1769 }
static void get_short_var_statement ( int  token,
short(*)(void)  func 
)
static

Definiert in Zeile 1738 der Datei ubasic.c.

1739 {
1740  int var;
1741  accept(token);
1742  var = tokenizer_variable_num();
1744  ubasic_set_variable(var, func());
1745  accept_cr();
1746 }
static void gosub_statement ( void  )
static

Definiert in Zeile 1394 der Datei ubasic.c.

1395 {
1398  tokenizer_string(string, sizeof(string));
1399  do {
1400  tokenizer_next();
1401  } while(tokenizer_token() != TOKENIZER_CR);
1404 /* tokenizer_line_number_inc();*/
1406  gosub_stack_ptr++;
1407  jump_label(string);
1408  } else {
1409  DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n");
1410  ended = 1;
1412  }
1413  } else {
1414  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
1415  ended = 1;
1417  }
1418 }
static void goto_statement ( void  )
static

Definiert in Zeile 930 der Datei ubasic.c.

931 {
934  tokenizer_string(string, sizeof(string));
935  tokenizer_next();
936  jump_label(string);
937  } else {
938  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
939  ended = 1;
941  }
942 }
static void if_statement ( void  )
static

Definiert in Zeile 988 der Datei ubasic.c.

989 {
990  int r, else_cntr,endif_cntr,f_nt,f_sl;
991 
993  DEBUG_PRINTF("if_statement: get_relation\n");
994  r = relation();
995  DEBUG_PRINTF("if_statement: relation %d\n", r);
997  if (ended) {
998  return;
999  }
1000 
1001  if (tokenizer_token() == TOKENIZER_CR) {
1002  // CR after then -> multiline IF-Statement
1004  if_stack[if_stack_ptr] = r;
1005  if_stack_ptr++;
1006  } else {
1007  DEBUG_PRINTF("if_statement: IF-stack depth exceeded\n");
1008  ended = 1;
1010  return;
1011  }
1012  DEBUG_PRINTF("if_statement: stack_ptr %d\n", if_stack_ptr);
1014  if(r) {
1015  DEBUG_PRINTF("if_statement: result true\n");
1016  return;
1017  }else {
1018  DEBUG_PRINTF("if_statement: result false\n");
1019 
1020  else_cntr=endif_cntr=0; // number of else/endif possible in current nesting
1021  f_nt=f_sl=0; // f_nt flag for additional next token, f_fs flag single line
1022 
1024  || else_cntr || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1025  f_nt=0;
1026  // nested if
1027  if( tokenizer_token() == TOKENIZER_IF) {
1028  else_cntr+=1;
1029  endif_cntr+=1;
1030  f_sl=0;
1031  DEBUG_PRINTF("IF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1032  }
1033  if( tokenizer_token() == TOKENIZER_THEN) {
1034  f_nt=1;
1035  tokenizer_next();
1036  DEBUG_PRINTF("THEN: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1037  if (tokenizer_token() != TOKENIZER_CR) { f_sl=1; }
1038  DEBUG_PRINTF("THEN_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1039  }
1040  if(tokenizer_token() == TOKENIZER_ELSE) {
1041  else_cntr--;
1042  DEBUG_PRINTF("ELSE: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1043  if (else_cntr<0) {
1044  DEBUG_PRINTF("ubasic.c: if_statement(): else without if-statement\n");
1045  ended = 1;
1047  return;
1048  }
1049  }
1050  if(!f_sl && (tokenizer_token() == TOKENIZER_ENDIF)) {
1051  endif_cntr--;
1052  if (endif_cntr != else_cntr) else_cntr--;
1053  DEBUG_PRINTF("ENDIF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1054  } else {
1055  if (f_sl && (tokenizer_token() == TOKENIZER_CR)) {
1056  f_sl=0;
1057  endif_cntr--;
1058  if (endif_cntr != else_cntr) else_cntr--;
1059  DEBUG_PRINTF("ENDIF_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1060  }else{
1062  DEBUG_PRINTF("ubasic.c: if_statement(): endif in singleline if-statement\n");
1063  ended = 1;
1065  return;
1066  }
1067  }
1068  }
1069  if (!f_nt) { tokenizer_next(); }
1070  }
1071  if(tokenizer_token() == TOKENIZER_ELSE) { return; }
1072  }
1073  endif_statement();
1074  }else {
1075  // Singleline IF-Statement
1076  if(r) {
1077  statement();
1078  } else {
1079  do {
1080  tokenizer_next();
1081  } while(tokenizer_token() != TOKENIZER_ELSE &&
1084  if(tokenizer_token() == TOKENIZER_ELSE) {
1086  statement();
1087  } else {
1089  }
1090  }
1091  }
1092 }
static void is_key_statement ( void  )
static

Definiert in Zeile 1995 der Datei ubasic.c.

1996 {
1997  int var;
1999  var = tokenizer_variable_num();
2002  DEBUG_PRINTF("End of is_key\n");
2003  accept_cr();
2004 }
int jump_label ( char *  label)

Definiert in Zeile 901 der Datei ubasic.c.

902 {
903  char currLabel[MAX_STRINGLEN];
905  currLabel[0] = 0;
907  tokenizer_next();
908  if (tokenizer_token() == TOKENIZER_LABEL) {
909  tokenizer_label(currLabel, sizeof(currLabel));
910  tokenizer_next();
911  if(strcmp(label, currLabel) == 0) {
913  DEBUG_PRINTF("jump_linenum: Found line %d\n", tokenizer_line_number());
914  break;
915  }
916  }
917  }
920  DEBUG_PRINTF("Label %s not found", label);
922  }
923  return 0;
924  } else {
925  return 1;
926  }
927 }
static void jump_line ( int  linenum)
static

Definiert in Zeile 888 der Datei ubasic.c.

889 {
891  while(tokenizer_line_number() != linenum) {
892  tokenizer_next();
893  }
894  /* swallow the CR that would be read next */
896 
897 }
static void let_statement ( void  )
static

Definiert in Zeile 1362 der Datei ubasic.c.

1363 {
1364 
1365  int var;
1366 
1367  var = tokenizer_variable_num();
1368 
1371  ubasic_set_variable(var, expr());
1372  DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
1373  accept_cr();
1374 }
static void line_statement ( void  )
static

Definiert in Zeile 2672 der Datei ubasic.c.

2673 {
2674  /* line numbers have been removed */
2675  DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_line_number());
2676  /* current_linenum = tokenizer_num();*/
2677 #if 0
2678  if (tokenizer_token() == TOKENIZER_LABEL) {
2679 #ifdef DEBUG
2680  tokenizer_label(string, sizeof(string));
2681  DEBUG_PRINTF("line_statement: label: %s\n", string );
2682 #endif
2685  return;
2686  }
2687 #endif
2688  /* reyalp - eat up to 100 labels or rems at a time so they don't cost 10ms each */
2689  int count = 100;
2690  do {
2691  int r=tokenizer_token();
2692  if ( r == TOKENIZER_LABEL ) {
2693  /* hit limit and we are on a label, return */
2694  if( count == 1 )
2695  return;
2696 #ifdef DEBUG
2697  tokenizer_label(string, sizeof(string));
2698  DEBUG_PRINTF("line_statement: label: %s\n", string );
2699 #endif
2702  }
2703  else if ( r == TOKENIZER_REM ) {
2704  rem_statement();
2705  }
2706  else {
2707  break;
2708  }
2709  } while(--count);
2710  statement();
2711  return;
2712 }
static void md_detect_motion_statement ( )
static

Definiert in Zeile 2142 der Datei ubasic.c.

2143 {
2144  int columns;
2145  int rows;
2146  int pixel_measure_mode;
2147  int detection_timeout;
2148  int measure_interval;
2149  int threshold;
2150  int draw_grid=0;
2151  int clipping_region_mode=0;
2152  int clipping_region_row1=0;
2153  int clipping_region_column1=0;
2154  int clipping_region_row2=0;
2155  int clipping_region_column2=0;
2156  int parameters=0;
2157  int pixels_step=1;
2158  int msecs_before_trigger=0;
2159 
2161 
2162  columns=expr();tokenizer_next();
2163 
2164  rows=expr();tokenizer_next();
2165 
2166  pixel_measure_mode=expr();tokenizer_next();
2167 
2168  detection_timeout=expr();tokenizer_next();
2169 
2170  measure_interval=expr();tokenizer_next();
2171 
2172  threshold=expr();tokenizer_next();
2173 
2174  draw_grid=expr();tokenizer_next();
2175 
2177 
2179 
2181  // eat COMA
2182  // tokenizer_next();
2183  }
2184 
2186  tokenizer_next();
2187  clipping_region_mode = expr();
2188  }
2190  tokenizer_next();
2191  clipping_region_column1 = expr();
2192  }
2194  tokenizer_next();
2195  clipping_region_row1 = expr();
2196  }
2198  tokenizer_next();
2199  clipping_region_column2 = expr();
2200  }
2202  tokenizer_next();
2203  clipping_region_row2 = expr();
2204  }
2206  tokenizer_next();
2207  parameters = expr();
2208  }
2210  tokenizer_next();
2211  pixels_step = expr();
2212  }
2213 
2215  tokenizer_next();
2216  msecs_before_trigger = expr();
2217  }
2218 
2219  accept_cr();
2220 
2221 #ifdef UBASIC_TEST
2222  // TODO: add something here for ubasic_test
2223 #else
2225  columns, rows, pixel_measure_mode, detection_timeout,
2226  measure_interval, threshold, draw_grid,
2227  clipping_region_mode,
2228  clipping_region_column1, clipping_region_row1,
2229  clipping_region_column2, clipping_region_row2,
2230  parameters, pixels_step, msecs_before_trigger);
2231 #endif
2232 
2233  flag_yield=1;
2234 }
static void md_get_cell_diff_statement ( )
static

Definiert in Zeile 2102 der Datei ubasic.c.

2103 {
2104  int var, col, row;
2106 
2107  col=expr();tokenizer_next();
2108 
2109  row=expr();tokenizer_next();
2110 
2111  var = tokenizer_variable_num();
2113  accept_cr();
2114 
2115 #ifdef UBASIC_TEST
2116  // TODO: add something here for ubasic_test
2117 #else
2119 #endif
2120 }
static void md_get_cell_val_statement ( )
static

Definiert in Zeile 2122 der Datei ubasic.c.

2123 {
2124  int var, col, row;
2126 
2127  col=expr();tokenizer_next();
2128 
2129  row=expr();tokenizer_next();
2130 
2131  var = tokenizer_variable_num();
2133  accept_cr();
2134 
2135 #ifdef UBASIC_TEST
2136  // TODO: add something here for ubasic_test
2137 #else
2139 #endif
2140 }
static void next_statement ( void  )
static

Definiert in Zeile 1435 der Datei ubasic.c.

1436 {
1437  int var, value;
1438 
1440  var = tokenizer_variable_num();
1442  if(for_stack_ptr > 0 &&
1443  var == for_stack[for_stack_ptr - 1].for_variable) {
1444  value = ubasic_get_variable(var) + for_stack[for_stack_ptr - 1].step;
1445  ubasic_set_variable(var, value);
1446 
1447  if(((for_stack[for_stack_ptr - 1].step > 0) && (value <= for_stack[for_stack_ptr - 1].to)) ||
1448  ((for_stack[for_stack_ptr - 1].step < 0) && (value >= for_stack[for_stack_ptr - 1].to)))
1449  jump_line(for_stack[for_stack_ptr - 1].line_after_for);
1450  else {
1451  for_stack_ptr--;
1453  }
1454  } else {
1455  DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var);
1456  ended = 1;
1458  }
1459 
1460 }
static void on_off_statement ( int  token,
void(*)(void)  on,
void(*)(void)  off 
)
static

Definiert in Zeile 2050 der Datei ubasic.c.

2051 {
2052  accept(token);
2053  if (expr() > 0) on();
2054  else off();
2055  accept_cr();
2056 }
static void one_int_param_function ( int  token,
void(*)(int)  func 
)
static

Definiert in Zeile 1774 der Datei ubasic.c.

1775 {
1776  accept(token);
1777  func(expr());
1778  accept_cr();
1779 }
static void one_short_param_function ( int  token,
void(*)(short)  func 
)
static

Definiert in Zeile 1782 der Datei ubasic.c.

1783 {
1784  accept(token);
1785  func(expr());
1786  accept_cr();
1787 }
static void press_statement ( void  )
static

Definiert in Zeile 1612 der Datei ubasic.c.

1613 {
1614  int k;
1616  k = ubasic_get_key_arg();
1617  if (k > 0) {
1618  action_push_press(k);
1619  flag_yield=1;
1620  }
1621  DEBUG_PRINTF("End of press\n");
1622  accept_cr();
1623 }
static void print_statement ( void  )
static

Definiert in Zeile 945 der Datei ubasic.c.

946 {
947  static char buf[128];
948 
949  buf[0]=0;
951  do {
952  DEBUG_PRINTF("Print loop\n");
954  tokenizer_string(string, sizeof(string));
955  sprintf(buf+strlen(buf), "%s", string);
956  tokenizer_next();
957  } else if(tokenizer_token() == TOKENIZER_COMMA) {
958  strcat(buf, " ");
959  tokenizer_next();
960  } else if(tokenizer_token() == TOKENIZER_SEMICOLON) {
961  tokenizer_next();
962  } else {
963  sprintf(buf+strlen(buf), "%d", expr());
964  }
966  script_console_add_line((long)buf);
967  DEBUG_PRINTF("End of print\n");
968  accept_cr();
969 }
static void reboot_statement ( )
static

Definiert in Zeile 1916 der Datei ubasic.c.

1916  {
1919  tokenizer_string(string, sizeof(string));
1920  tokenizer_next();
1921  reboot(string);
1922  } else {
1923  reboot(NULL);
1924  }
1925 }
static int relation ( void  )
static

Definiert in Zeile 843 der Datei ubasic.c.

844 {
845  int r1, r2;
846  int op;
847 
848  r1 = expr();
849  op = tokenizer_token();
850  DEBUG_PRINTF("relation: token %d\n", op);
851  while(op == TOKENIZER_LAND) {
852  tokenizer_next();
853  r2 = expr();
854  DEBUG_PRINTF("relation: %d %d %d\n", r1, op, r2);
855  switch(op) {
856  case TOKENIZER_LAND:
857  r1 = r1 && r2;
858  break;
859  }
860  op = tokenizer_token();
861  }
862  return r1;
863 }
static void release_statement ( void  )
static

Definiert in Zeile 1626 der Datei ubasic.c.

1627 {
1628  int k;
1630  k = ubasic_get_key_arg();
1631  if (k > 0) {
1633  flag_yield=1;
1634  }
1635  DEBUG_PRINTF("End of release\n");
1636  accept_cr();
1637 }
static void rem_statement ( void  )
static

Definiert in Zeile 1377 der Datei ubasic.c.

1378 {
1380  DEBUG_PRINTF("rem_statement\n");
1382 }
static void return_statement ( void  )
static

Definiert in Zeile 1421 der Datei ubasic.c.

1422 {
1424  if(gosub_stack_ptr > 0) {
1425  gosub_stack_ptr--;
1427  } else {
1428  DEBUG_PRINTF("return_statement: non-matching return\n");
1429  ended = 1;
1431  }
1432 }
static void select_statement ( void  )
static

Definiert in Zeile 1330 der Datei ubasic.c.

1331 {
1332 
1333  int select_value;
1334 
1336  select_value = expr();
1338 //REM
1339  while (tokenizer_token() == TOKENIZER_REM) {statement();}
1340 //REM
1341 
1343  select_stack[select_stack_ptr].select_value = select_value;
1345  DEBUG_PRINTF("select_statement: new select, value %d\n",select_stack[select_stack_ptr].select_value);
1346  select_stack_ptr++;
1347  if (tokenizer_token() != TOKENIZER_CASE) {
1348  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case-statement\n");
1349  ended = 1;
1351  }
1352  else { case_statement(); }
1353  } else {
1354  DEBUG_PRINTF("select_statement: SELECT-stack depth exceeded\n");
1355  ended = 1;
1357  }
1358 }
static void set_autostart_statement ( )
static

Definiert in Zeile 1892 der Datei ubasic.c.

1893 {
1894  int to;
1896  to = expr();
1897 #ifndef UBASIC_TEST
1898  if (to >= 0 && to <= 3) conf.script_startup=to;
1899  conf_save();
1900 #endif
1901  accept_cr();
1902 }
static void set_capture_mode_canon_statement ( )
static

Definiert in Zeile 1904 der Datei ubasic.c.

1905 {
1906  int to;
1908  to = expr();
1909  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
1910  if( to < 0)
1911  to &= 0xFFFF;
1913  accept_cr();
1914 }
static void set_config_value_statement ( )
static

Definiert in Zeile 1927 der Datei ubasic.c.

1928 {
1929  int id, value;
1930  tConfigVal configVal = {0};
1931 
1933  id = expr();
1934  value = expr();
1935  if( conf_getValue(id, &configVal) == CONF_VALUE ) {
1936  configVal.numb = value;
1937  configVal.isNumb = 1;
1938  conf_setValue(id, configVal);
1939  }
1940  accept_cr();
1941 }
static void set_console_autoredraw ( void  )
static

Definiert in Zeile 1709 der Datei ubasic.c.

1710 {
1713  accept_cr();
1714 }
static void set_console_layout ( void  )
static

Definiert in Zeile 1697 der Datei ubasic.c.

1698 {
1699  int x1,y1,x2,y2;
1701  x1 = expr();
1702  y1 = expr();
1703  x2 = expr();
1704  y2 = expr();
1705  console_set_layout(x1,y1,x2,y2);
1706  accept_cr();
1707 }
static void set_ev_statement ( )
static

Definiert in Zeile 1808 der Datei ubasic.c.

1809  {
1810  int to;
1812  to = expr();
1815  accept_cr();
1816  }
static void set_exit_key_statement ( )
static

Definiert in Zeile 2006 der Datei ubasic.c.

2007 {
2008  int k;
2011  {
2012  tokenizer_string(string, sizeof(string));
2013  k = script_keyid_by_name(string);
2014  if (k <= 0)
2015  {
2017  ended = 1 ;
2018  }
2019  else
2020  {
2021  script_set_terminate_key(k,string);
2022  }
2023  }
2024  else
2025  {
2026  DEBUG_PRINTF("ubasic.c: set_exit_key no key specified\n");
2027  ended = 1;
2029  }
2030  accept_cr() ;
2031 }
static void set_focus_statement ( )
static

Definiert in Zeile 1842 der Datei ubasic.c.

1843 {
1845  int sd = expr();
1846  // if sd override not available now, fail immediately without calling set_focus
1847  // to avoid unexpected results with SET_LATER
1848  if(shooting_can_focus()) {
1849  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
1850  // in AF lock or MF (canon or set by MF functions), set focus now
1853  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
1854  {
1856  }
1857  else
1858  {
1859  // in an AF mode, set later
1861  }
1862  }
1863  accept_cr();
1864 }
static void set_led_statement ( )
static

Definiert in Zeile 1866 der Datei ubasic.c.

1867 {
1868  int to, to1, to2;
1870  to = expr();
1871  to1 = expr();
1872  to2 = 200;
1874  to2 = expr();
1875  }
1876  camera_set_led(to, to1, to2);
1877  accept_cr();
1878 }
static void set_mf_statement ( )
static

Definiert in Zeile 1834 der Datei ubasic.c.

1835 {
1837  if (expr() > 0) DoMFLock();
1838  else UnlockMF();
1839  accept_cr();
1840 }
static void set_movie_status_statement ( )
static

Definiert in Zeile 1818 der Datei ubasic.c.

1819 {
1822  accept_cr();
1823 }
static void set_prop_statement ( )
static

Definiert in Zeile 1880 der Datei ubasic.c.

1881 {
1882  int to, to1;
1884  to = expr();
1885  to1 = expr();
1886  shooting_set_prop(to, to1);
1887  accept_cr();
1888 }
static void set_propcase_statement ( int  token,
int  prop 
)
static

Definiert in Zeile 1826 der Datei ubasic.c.

1827 {
1828  accept(token);
1829  shooting_set_prop(prop, expr());
1830  accept_cr();
1831 }
static void set_yield_statement ( )
static

Definiert in Zeile 1723 der Datei ubasic.c.

1724 {
1726  int val = expr();
1728  val = expr();
1730  accept_cr();
1731 }
static void shoot_statement ( void  )
static

Definiert in Zeile 1681 der Datei ubasic.c.

1682 {
1684  ubasic_as_ret_var_num = -1;
1685  if (tokenizer_token() != TOKENIZER_CR)
1686  {
1689  }
1690  action_push_shoot(1);
1691  flag_yield=1;
1692  DEBUG_PRINTF("End of shoot\n");
1693  accept_cr();
1694 }
static int shooting_get_depth_of_field ( )
static

Definiert in Zeile 252 der Datei ubasic.c.

253 {
256 }
static int shooting_get_far_limit_of_acceptable_sharpness ( )
static

Definiert in Zeile 246 der Datei ubasic.c.

247 {
250 }
static int shooting_get_min_stack_distance ( )
static

Definiert in Zeile 258 der Datei ubasic.c.

static int shooting_get_near_limit_of_acceptable_sharpness ( )
static

Definiert in Zeile 240 der Datei ubasic.c.

241 {
244 }
static void shutdown_statement ( void  )
static

Definiert in Zeile 2059 der Datei ubasic.c.

2059  {
2062  accept_cr();
2063 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 1651 der Datei ubasic.c.

1652 {
1653  /* delay of -1 signals indefinite (actually 1 day) delay */
1654  if (delay == -1)
1655  delay = 86400000;
1656 
1657  if (delay > 0)
1658  return delay + get_tick_count();
1659 
1660  return 0;
1661 }
static void sleep_statement ( void  )
static

Definiert in Zeile 1664 der Datei ubasic.c.

1665 {
1667 
1668  int delay = sleep_delay(expr());
1669  if (delay > 0)
1670  {
1671  action_push(delay);
1673  }
1674 
1675  flag_yield=1;
1676  DEBUG_PRINTF("End of sleep\n");
1677  accept_cr();
1678 }
static void statement ( void  )
static

Definiert in Zeile 2249 der Datei ubasic.c.

2250 {
2252 
2253  token = tokenizer_token();
2254 
2255  switch(token) {
2256  // aelock
2257  case TOKENIZER_SET_AELOCK:
2259  break;
2260  // aflock
2261  case TOKENIZER_SET_AFLOCK:
2263  break;
2264 
2267  break;
2268  case TOKENIZER_PRINT:
2269  print_statement();
2270  break;
2271 
2272  case TOKENIZER_SLEEP:
2273  sleep_statement();
2274  break;
2275  case TOKENIZER_CLICK:
2276  click_statement();
2277  break;
2278  case TOKENIZER_PRESS:
2279  press_statement();
2280  break;
2281  case TOKENIZER_RELEASE:
2283  break;
2284  case TOKENIZER_SHOOT:
2285  shoot_statement();
2286  break;
2289  break;
2292  break;
2295  break;
2296 #ifdef INCLUDE_OLD_GET__SYNTAX
2297  case TOKENIZER_GET_TV96:
2299  break;
2302  break;
2305  break;
2306  case TOKENIZER_GET_AV96:
2308  break;
2311  break;
2314  break;
2315  case TOKENIZER_GET_ZOOM:
2317  break;
2318  case TOKENIZER_GET_FOCUS:
2320  break;
2323  break;
2326  break;
2327  case TOKENIZER_GET_DOF:
2329  break;
2332  break;
2335  break;
2338  break;
2339  case TOKENIZER_GET_BV96:
2341  break;
2342  case TOKENIZER_GET_SV96:
2344  break;
2347  break;
2348  case TOKENIZER_GET_VBATT:
2349  get_int_var_statement(token, (int (*)(void))stat_get_vbatt);
2350  break;
2352  get_int_var_statement(token, (int (*)(void))GetTotalCardSpaceKb);
2353  break;
2355  get_int_var_statement(token, (int (*)(void))GetFreeCardSpaceKb);
2356  break;
2358  get_int_var_statement(token, (int (*)(void))GetJpgCount);
2359  break;
2361  get_int_var_statement(token, (int (*)(void))GetRawCount);
2362  break;
2363  case TOKENIZER_GET_PROP:
2365  break;
2366 #endif
2369  break;
2370  case TOKENIZER_SET_TV96:
2372  break;
2373  case TOKENIZER_PLAY_SOUND:
2374  one_int_param_function(token, (void (*)(int))play_sound);
2375  break;
2378  break;
2381  break;
2384  break;
2387  break;
2388  case TOKENIZER_SET_AV96:
2390  break;
2391 
2394  break;
2397  break;
2400  break;
2401 
2404  break;
2405 
2406  case TOKENIZER_SET_ZOOM:
2408  break;
2411  break;
2414  break;
2415  case TOKENIZER_SET_FOCUS:
2417  break;
2418  case TOKENIZER_SET_MF:
2419  set_mf_statement();
2420  break;
2421 
2422 /*
2423  case TOKENIZER_SET_ISO_MARKET:
2424  one_int_param_function(token, shooting_set_iso_market);
2425  break;
2426  case TOKENIZER_SET_ISO_DL_F_B:
2427  one_int_param_function(token, shooting_set_iso_real_delta_from_base);
2428  break;
2429 */
2430  //ARM End
2431 
2434  break;
2435  case TOKENIZER_SET_SV96:
2437  break;
2438 
2441  break;
2442 
2443  case TOKENIZER_SET_PROP:
2445  break;
2446  case TOKENIZER_SET_LED:
2448  break;
2449 
2450  case TOKENIZER_SET_EV:
2451  set_ev_statement();
2452  break;
2453 
2456  break;
2459  break;
2460  case TOKENIZER_SET_QUALITY:
2462  break;
2463 
2464  case TOKENIZER_WAIT_CLICK:
2466  break;
2467  case TOKENIZER_IS_KEY:
2468  is_key_statement();
2469  break;
2472  break;
2473 
2474  case TOKENIZER_WHEEL_LEFT:
2475  accept(token);
2476  JogDial_CCW();
2477  accept_cr();
2478  break;
2479  case TOKENIZER_WHEEL_RIGHT:
2480  accept(token);
2481  JogDial_CW();
2482  accept_cr();
2483  break;
2484 
2485  case TOKENIZER_IF:
2486  if_statement();
2487  break;
2488  case TOKENIZER_ELSE:
2489  else_statement();
2490  break;
2491  case TOKENIZER_ENDIF:
2492  endif_statement();
2493  break;
2494  case TOKENIZER_SELECT:
2495  select_statement();
2496  break;
2497  case TOKENIZER_CASE:
2498  case_statement();
2499  break;
2500  case TOKENIZER_CASE_ELSE:
2502  break;
2503  case TOKENIZER_GOTO:
2504  goto_statement();
2505  break;
2506  case TOKENIZER_GOSUB:
2507  gosub_statement();
2508  break;
2509  case TOKENIZER_RETURN:
2510  return_statement();
2511  break;
2512  case TOKENIZER_FOR:
2513  for_statement();
2514  break;
2515  case TOKENIZER_NEXT:
2516  next_statement();
2517  break;
2518  case TOKENIZER_DO:
2519  do_statement();
2520  break;
2521  case TOKENIZER_UNTIL:
2522  until_statement();
2523  break;
2524  case TOKENIZER_WHILE:
2525  while_statement();
2526  break;
2527  case TOKENIZER_WEND:
2528  wend_statement();
2529  break;
2530  case TOKENIZER_END:
2531  end_statement();
2532  break;
2533  case TOKENIZER_LET:
2535  /* Fall through. */
2536  case TOKENIZER_VARIABLE:
2537  let_statement();
2538  break;
2539  case TOKENIZER_REM:
2540  rem_statement();
2541  break;
2542  case TOKENIZER_CLS:
2543  cls_statement();
2544  break;
2545  case TOKENIZER_SET_RAW:
2546  accept(token);
2547  conf.save_raw = expr();
2548  accept_cr();
2549  break;
2550  case TOKENIZER_SET_RAW_NR:
2551  accept(token);
2552  conf.raw_nr = expr();
2553  accept_cr();
2554  break;
2557  break;
2558  case TOKENIZER_EXIT_ALT:
2559  accept(token);
2560  exit_alt();
2561  accept_cr();
2562  break;
2563  case TOKENIZER_ENTER_ALT:
2564  accept(token);
2565  enter_alt(1);
2566  accept_cr();
2567  break;
2568  case TOKENIZER_SHUT_DOWN:
2572  break;
2575  break;
2577  accept(token);
2579  accept_cr();
2580  break;
2581 
2582  // >> mx3 . motion detector
2585  break;
2588  break;
2591  break;
2592  // << mx3 . motion_detector
2593 
2595  accept(token);
2598  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
2599  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
2600  // clear previous values
2602  camera_info.perf.af_led.min = 0xFFFFFFFF;
2603  } else {
2604  camera_info.perf.md_af_tuning = 0; // Disable MD testing
2605  }
2606  accept_cr();
2607  break;
2608 
2610  one_int_param_function(token, (void (*)(int))_shot_histogram_set);
2611  break;
2612 
2613  case TOKENIZER_SET_RECORD:
2615  break;
2616 
2618  one_int_param_function(token, (void (*)(int))shooting_set_mode_chdk);
2619  break;
2620 
2623  break;
2624 
2625  case TOKENIZER_REBOOT:
2626  reboot_statement();
2627  break;
2628 
2631  break;
2632 
2635  break;
2636  case TOKENIZER_SET_YIELD:
2638  break;
2639 
2642 #ifdef UBASIC_TEST
2643  // TODO: add something here for ubasic_test
2644 #else
2645  if (expr()) usb_sync_wait_flag = 1;
2646  else usb_sync_wait_flag = 0;
2647 #endif
2648  accept_cr();
2649  break;
2650 
2653 #ifdef UBASIC_TEST
2654  // TODO: add something here for ubasic_test
2655 #else
2656  int hpenable= expr();
2657  if ( hpenable > 0) start_usb_HPtimer(hpenable);
2658  else stop_usb_HPtimer();
2659 #endif
2660  accept_cr();
2661  break;
2662 
2663  default:
2664  DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
2665  ended = 1;
2667  }
2668 }
static int term ( void  )
static

Definiert in Zeile 742 der Datei ubasic.c.

743 {
744  int f1, f2;
745  int op;
746 
747  f1 = factor();
748  op = tokenizer_token();
749  DEBUG_PRINTF("term: token %d\n", op);
750  while(op == TOKENIZER_ASTR ||
751  op == TOKENIZER_SLASH ||
752  op == TOKENIZER_LT ||
753  op == TOKENIZER_GT ||
754  op == TOKENIZER_GE ||
755  op == TOKENIZER_LE ||
756  op == TOKENIZER_NE ||
757  op == TOKENIZER_EQ ||
758  op == TOKENIZER_XOR ||
759  op == TOKENIZER_OR ||
760  op == TOKENIZER_MOD) {
761  tokenizer_next();
762  f2 = factor();
763  DEBUG_PRINTF("term: %d %d %d\n", f1, op, f2);
764  switch(op) {
765  case TOKENIZER_ASTR:
766  f1 = f1 * f2;
767  break;
768  case TOKENIZER_SLASH:
769  f1 = f1 / f2;
770  break;
771  case TOKENIZER_MOD:
772  f1 = f1 % f2;
773  break;
774  case TOKENIZER_LT:
775  f1 = f1 < f2;
776  break;
777  case TOKENIZER_GT:
778  f1 = f1 > f2;
779  break;
780  case TOKENIZER_EQ:
781  f1 = f1 == f2;
782  break;
783  case TOKENIZER_NE:
784  f1 = f1 != f2;
785  break;
786  case TOKENIZER_LE:
787  f1 = f1 <= f2;
788  break;
789  case TOKENIZER_GE:
790  f1 = f1 >= f2;
791  break;
792  case TOKENIZER_OR:
793  f1 = f1 | f2;
794  break;
795  case TOKENIZER_XOR:
796  f1 = f1 ^ f2;
797  break;
798  }
799  op = tokenizer_token();
800  }
801  DEBUG_PRINTF("term: %d\n", f1);
802  return f1;
803 }
static void uB_set_av96 ( int  param)
static

Definiert in Zeile 2065 der Datei ubasic.c.

2065  {
2067  return ;
2068 }
static void uB_set_av96_direct ( int  param)
static

Definiert in Zeile 2070 der Datei ubasic.c.

2070  {
2072  return ;
2073 }
static void uB_set_iso_real ( int  param)
static

Definiert in Zeile 2095 der Datei ubasic.c.

2095  {
2097  return ;
2098 }
static void uB_set_nd_filter_state ( int  param)
static

Definiert in Zeile 2090 der Datei ubasic.c.

2090  {
2092  return ;
2093 }
static void uB_set_sv96 ( int  param)
static

Definiert in Zeile 2085 der Datei ubasic.c.

2085  {
2087  return ;
2088 }
static void uB_set_tv96 ( int  param)
static

Definiert in Zeile 2075 der Datei ubasic.c.

2075  {
2077  return ;
2078 }
static void uB_set_tv96_direct ( int  param)
static

Definiert in Zeile 2080 der Datei ubasic.c.

2080  {
2082  return ;
2083 }
void ubasic_end ( void  )

Definiert in Zeile 2779 der Datei ubasic.c.

2779  {
2780 }
static int ubasic_get_key_arg ( )
static

Definiert in Zeile 195 der Datei ubasic.c.

195  {
196  int k;
197  tokenizer_string(string, sizeof(string));
198  tokenizer_next();
199  k = script_keyid_by_name(string);
200  if (k <= 0)
202  return k;
203 }
int ubasic_get_variable ( int  varnum)

Definiert in Zeile 2770 der Datei ubasic.c.

2771 {
2772  if(varnum >= 0 && varnum < MAX_VARNUM) {
2773  return variables[varnum];
2774  }
2775  return 0;
2776 }
int ubasic_init ( const char *  program,
__attribute__((unused)) int  is_ptp 
)

Definiert in Zeile 180 der Datei ubasic.c.

181 {
182  program_ptr = program;
183  flag_yield = 0;
185  tokenizer_init(program);
186  ended = 0;
190  return 1;
191 }
int ubasic_linenumber ( )

Definiert in Zeile 173 der Datei ubasic.c.

174 {
175  return tokenizer_line_number();
176 }
int ubasic_run ( void  )

Definiert in Zeile 2714 der Datei ubasic.c.

2715 {
2716  unsigned start_tick = get_tick_count();
2717  unsigned lines = 0;
2718  flag_yield = 0;
2719 
2720  do
2721  {
2722  if ( ended || tokenizer_finished() )
2723  {
2724  DEBUG_PRINTF("uBASIC program finished\n");
2725  if (ubasic_error)
2726  {
2727  // Generate error message
2728  char buf[100];
2729  const char *msg;
2731  {
2733  }
2734  else
2735  {
2737  }
2738  sprintf(buf, "uBASIC:%d %s ", ubasic_linenumber(), msg);
2739  // Show error message
2740  script_console_add_error((long)buf);
2742  return SCRIPT_RUN_ERROR;
2743  }
2744  // Show 'Finished' message
2746  return SCRIPT_RUN_ENDED;
2747  }
2748 
2749  line_statement();
2750 
2751  // Return control to CHDK only if external processing required
2752  if ( flag_yield )
2753  return SCRIPT_RUN_RUNNING;
2754 
2755  lines++;
2756  } while (lines < yield_max_lines && get_tick_count() - start_tick < yield_max_ms);
2757 
2758  return SCRIPT_RUN_RUNNING;
2759 }
void ubasic_set_as_ret ( int  md_ret)

Definiert in Zeile 2784 der Datei ubasic.c.

2785 {
2786  if (ubasic_as_ret_var_num >= 0)
2788 }
void ubasic_set_variable ( int  varum,
int  value 
)

Definiert in Zeile 2762 der Datei ubasic.c.

2763 {
2764  if(varnum >= 0 && varnum < MAX_VARNUM) {
2765  variables[varnum] = value;
2766  }
2767 }
static void until_statement ( void  )
static

Definiert in Zeile 1514 der Datei ubasic.c.

1515 {
1516  int r;
1517 
1519  r = relation();
1520  if(do_stack_ptr > 0) {
1521  if(!r) {
1523  } else {
1524  do_stack_ptr--;
1525  accept_cr();
1526  }
1527  } else {
1528  DEBUG_PRINTF("until_statement: unmatched until\n");
1529  ended = 1;
1531  }
1532 }
static int varfactor ( void  )
static

Definiert in Zeile 231 der Datei ubasic.c.

232 {
233  int r;
234  DEBUG_PRINTF("varfactor: obtaining %d from variable %d\n", variables[tokenizer_variable_num()], tokenizer_variable_num());
237  return r;
238 }
static void wait_click_statement ( )
static

Definiert in Zeile 1964 der Datei ubasic.c.

1965 {
1967 
1968  int delay = -1;
1970  {
1971  delay = expr();
1972  if (delay == 0) delay = -1;
1973  }
1974  delay = sleep_delay(delay);
1975 
1976  accept_cr();
1977 
1978  // Reset 'clicked' key if it has not changed since last time
1980  {
1982  }
1983 
1984  // Set up for wait or click testing
1985  action_push(delay);
1987 
1988  // Check for short delay or key already pressed by calling action stack routine once now
1990  {
1991  flag_yield=1;
1992  }
1993 }
static void wend_statement ( void  )
static

Definiert in Zeile 1577 der Datei ubasic.c.

1578 {
1580  if(while_stack_ptr > 0) {
1582  } else {
1583  DEBUG_PRINTF("wend_statement: unmatched wend\n");
1584  ended = 1;
1586  }
1587 }
static void while_statement ( void  )
static

Definiert in Zeile 1535 der Datei ubasic.c.

1536 {
1537  int r, while_cntr;
1538 
1543  while_stack_ptr++;
1544  }
1545  } else {
1546  DEBUG_PRINTF("while_statement: while stack depth exceeded\n");
1547  ended = 1;
1549  return;
1550  }
1551 
1552  r = relation();
1553  if(while_stack_ptr > 0) {
1554  if(!r) {
1555  while_cntr=0;
1556  while((tokenizer_token() != TOKENIZER_WEND || while_cntr ) &&
1558  if (tokenizer_token() == TOKENIZER_WHILE) while_cntr+=1;
1559  if (tokenizer_token() == TOKENIZER_WEND) while_cntr-=1;
1560  tokenizer_next();
1561  }
1562  while_stack_ptr--;
1563 
1565  accept(TOKENIZER_CR);
1566  } else {
1567  accept_cr();
1568  }
1569  } else {
1570  DEBUG_PRINTF("while_statement: unmatched wend\n");
1571  ended = 1;
1573  }
1574 }

Variablen-Dokumentation

short do_stack[MAX_DO_STACK_DEPTH]
static

Definiert in Zeile 107 der Datei ubasic.c.

int do_stack_ptr
static

Definiert in Zeile 108 der Datei ubasic.c.

int ended
static

Definiert in Zeile 123 der Datei ubasic.c.

int flag_yield
static

Definiert in Zeile 146 der Datei ubasic.c.

struct for_state for_stack[MAX_FOR_STACK_DEPTH]
static

Definiert in Zeile 117 der Datei ubasic.c.

int for_stack_ptr
static

Definiert in Zeile 118 der Datei ubasic.c.

short gosub_stack[MAX_GOSUB_STACK_DEPTH]
static

Definiert in Zeile 87 der Datei ubasic.c.

int gosub_stack_ptr
static

Definiert in Zeile 88 der Datei ubasic.c.

short if_stack[MAX_IF_STACK_DEPTH]
static

Definiert in Zeile 91 der Datei ubasic.c.

int if_stack_ptr
static

Definiert in Zeile 92 der Datei ubasic.c.

char const* program_ptr
static

Definiert in Zeile 82 der Datei ubasic.c.

struct select_state select_stack[MAX_SELECT_STACK_DEPTH]
static

Definiert in Zeile 99 der Datei ubasic.c.

int select_stack_ptr
static

Definiert in Zeile 100 der Datei ubasic.c.

char string[MAX_STRINGLEN]
static

Definiert in Zeile 84 der Datei ubasic.c.

int ubasic_as_ret_var_num
static

Definiert in Zeile 126 der Datei ubasic.c.

int ubasic_error

Definiert in Zeile 148 der Datei ubasic.c.

const char* ubasic_errstrings[UBASIC_E_ENDMARK]
Initialisierung:
=
{
"No err",
"Parse err",
"Unk stmt",
"Unk key",
"Unk label",
"gosub: Stack ful",
"bad return",
"if: Stack ful",
"bad endif",
"select: Stack ful",
"bad end_select",
"for: Stack ful",
"bad next",
"do: Stack ful",
"bad until",
"while: Stack ful",
"bad wend",
"Unk err"
}

Definiert in Zeile 149 der Datei ubasic.c.

int variables[MAX_VARNUM]
static

Definiert in Zeile 121 der Datei ubasic.c.

short while_stack[MAX_WHILE_STACK_DEPTH]
static

Definiert in Zeile 103 der Datei ubasic.c.

int while_stack_ptr
static

Definiert in Zeile 104 der Datei ubasic.c.

unsigned yield_max_lines
static

Definiert in Zeile 141 der Datei ubasic.c.

unsigned yield_max_ms
static

Definiert in Zeile 143 der Datei ubasic.c.