CHDK_DE Vorschauversion  Trunk Rev. 5833
 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 2245 der Datei ubasic.c.

2246 {
2247 #ifdef UBASIC_TEST
2248  return 0;
2249 #else
2250  return libshothisto->shot_histogram_set(enable);
2251 #endif
2252 }
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 1649 der Datei ubasic.c.

1650 {
1651  if (get_tick_count() >= action_top(2))
1652  {
1653  action_pop_func(1);
1654  return 1;
1655  }
1656  return 0;
1657 }
static int action_stack_AS_UBASIC_WAIT_CLICK ( )
static

Definiert in Zeile 1954 der Datei ubasic.c.

1955 {
1956  // Check key pressed or timeout
1958  {
1959  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1962  else
1964 
1965  action_pop_func(1);
1966  return 1;
1967  }
1968 
1969  return 0;
1970 }
static void case_else_statement ( void  )
static

Definiert in Zeile 1285 der Datei ubasic.c.

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

Definiert in Zeile 1195 der Datei ubasic.c.

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

Definiert in Zeile 1605 der Datei ubasic.c.

1606 {
1607  int k;
1609  k = ubasic_get_key_arg();
1610  if (k > 0) {
1611  action_push_click(k);
1612  flag_yield=1;
1613  }
1614 
1615  DEBUG_PRINTF("End of click\n");
1616  accept_cr();
1617 }
static void cls_statement ( void  )
static

Definiert in Zeile 1393 der Datei ubasic.c.

1394 {
1396  console_clear();
1397  DEBUG_PRINTF("cls_statement\n");
1399 }
static void console_redraw_statement ( void  )
static

Definiert in Zeile 1724 der Datei ubasic.c.

1725 {
1727  console_redraw();
1728  accept_cr();
1729 }
static void dec_select_stack ( void  )
static

Definiert in Zeile 1169 der Datei ubasic.c.

1170 {
1171  if(select_stack_ptr > 0) {
1172  select_stack_ptr--;
1173  } else {
1174  DEBUG_PRINTF("select_statement: SELECT-Stack fail\n");
1175  ended = 1;
1177  }
1178 }
static void do_statement ( void  )
static

Definiert in Zeile 1507 der Datei ubasic.c.

1508 {
1513  do_stack_ptr++;
1514  } else {
1515  DEBUG_PRINTF("do_statement: do stack depth exceeded\n");
1516  ended = 1;
1518  }
1519 }
static void else_statement ( void  )
static

Definiert in Zeile 1103 der Datei ubasic.c.

1104 {
1105  int r=0, endif_cntr, f_nt;
1106 
1108  if(if_stack_ptr > 0) {
1109  r = if_stack[if_stack_ptr-1];
1110  }
1111  else{
1112  DEBUG_PRINTF("ubasic.c: else_statement(): else without if-statement\n");
1113  ended = 1;
1115  return;
1116  }
1117  DEBUG_PRINTF("else_statement: relation %d\n", r);
1118 
1119  if (tokenizer_token() == TOKENIZER_CR) {
1121  if(!r) {
1122  DEBUG_PRINTF("else_statement: result true\n");
1123  return;
1124  } else {
1125  DEBUG_PRINTF("else_statement: result false\n");
1126  endif_cntr=0;
1127  while(((tokenizer_token() != TOKENIZER_ENDIF )
1128  || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1129  f_nt=0;
1130  if( tokenizer_token() == TOKENIZER_IF) {
1131  endif_cntr+=1;
1132  }
1133  if( tokenizer_token() == TOKENIZER_THEN) {
1134  tokenizer_next();
1135  // then followed by CR -> multi line
1136  if (tokenizer_token() == TOKENIZER_CR) {
1137  f_nt=1;
1138  } else { // single line
1139  endif_cntr--;
1142  tokenizer_next();
1143  }
1145  DEBUG_PRINTF("ubasic.c: else_statement(): endif in singleline if-statement\n");
1146  ended = 1;
1148  return;
1149  }
1150  }
1151  }
1152  if( tokenizer_token() == TOKENIZER_ENDIF) { endif_cntr--; }
1153  if (!f_nt) { tokenizer_next(); }
1154  }
1155  }
1156  endif_statement();
1157  }else{
1158  DEBUG_PRINTF("ubasic.c: else_statement(): CR after ELSE expected\n");
1159  ended = 1;
1161  }
1162 }
static void end_select_statement ( void  )
static

Definiert in Zeile 1181 der Datei ubasic.c.

1182 {
1183  if(select_stack_ptr > 0) {
1186  dec_select_stack();
1187  } else {
1188  DEBUG_PRINTF("ubasic.c: end_select_statement(): end_select without select-statement\n");
1189  ended = 1;
1191  }
1192 }
static void end_statement ( void  )
static

Definiert in Zeile 1598 der Datei ubasic.c.

1599 {
1601  ended = 1;
1602 }
static void endif_statement ( void  )
static

Definiert in Zeile 982 der Datei ubasic.c.

983 {
984  if(if_stack_ptr > 0) {
987  if_stack_ptr--;
988  } else {
989  DEBUG_PRINTF("ubasic.c: endif_statement(): endif without if-statement\n");
990  ended = 1;
992  }
993 }
static int expr ( void  )
static

Definiert in Zeile 814 der Datei ubasic.c.

815 {
816  int t1, t2;
817  int op;
818 
819  t1 = term();
820  op = tokenizer_token();
821  DEBUG_PRINTF("expr: token %d\n", op);
822  while(op == TOKENIZER_PLUS ||
823  op == TOKENIZER_MINUS ||
824  op == TOKENIZER_AND ||
825  op == TOKENIZER_LOR ||
826  op == TOKENIZER_XOR) {
827  tokenizer_next();
828  t2 = term();
829  DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
830  switch(op) {
831  case TOKENIZER_PLUS:
832  t1 = t1 + t2;
833  break;
834  case TOKENIZER_MINUS:
835  t1 = t1 - t2;
836  break;
837  case TOKENIZER_AND:
838  t1 = t1 & t2;
839  break;
840  case TOKENIZER_LOR:
841  t1 = t1 || t2;
842  break;
843  }
844  op = tokenizer_token();
845  }
846  DEBUG_PRINTF("expr: %d\n", t1);
847  return t1;
848 }
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;
715  break;
719  break;
722  r = shooting_get_max_av96(); // NOTE -1 if not available, i.e. playback
723  break;
726  r = shooting_get_min_av96(); // NOTE -1 if not available, i.e. playback
727  break;
731  break;
735  break;
736  case TOKENIZER_GET_DIGIC:
739  break;
740  //ARM Begin
741 
742  default:
743  r = varfactor();
744  break;
745  }
746  return r;
747 }
static void for_statement ( void  )
static

Definiert in Zeile 1471 der Datei ubasic.c.

1472 {
1473  int for_variable, to, step;
1474 
1476  for_variable = tokenizer_variable_num();
1479  ubasic_set_variable(for_variable, expr());
1481  to = expr();
1482  step = 1;
1483  if (tokenizer_token() != TOKENIZER_CR) {
1485  step = expr();
1486  }
1488 
1491  for_stack[for_stack_ptr].for_variable = for_variable;
1494  DEBUG_PRINTF("for_statement: new for, var %d to %d\n",
1495  for_stack[for_stack_ptr].for_variable,
1496  for_stack[for_stack_ptr].to);
1497 
1498  for_stack_ptr++;
1499  } else {
1500  DEBUG_PRINTF("for_statement: for stack depth exceeded\n");
1501  ended = 1;
1503  }
1504 }
static void get_config_value_statement ( )
static

Definiert in Zeile 2041 der Datei ubasic.c.

2042 {
2043  int var, var1, var2;
2044  tConfigVal configVal;
2046  var = expr();
2047  var1 = expr();
2048  var2 = tokenizer_variable_num();
2050  if( conf_getValue(var, &configVal) == CONF_VALUE ) {
2051  ubasic_set_variable(var2, configVal.numb);
2052  } else {
2053  ubasic_set_variable(var2, var1);
2054  }
2055  accept_cr();
2056 }
static void get_int_var_statement ( int  token,
int(*)(void)  func 
)
static

Definiert in Zeile 1757 der Datei ubasic.c.

1758 {
1759  int var;
1760  accept(token);
1761  var = tokenizer_variable_num();
1763  ubasic_set_variable(var, func());
1764  accept_cr();
1765 }
static void get_prop_statement ( )
static

Definiert in Zeile 1767 der Datei ubasic.c.

1768 {
1769  int var, var1;
1771  var = expr();
1772  var1 = tokenizer_variable_num();
1775 
1776  accept_cr();
1777 }
static void get_short_var_statement ( int  token,
short(*)(void)  func 
)
static

Definiert in Zeile 1746 der Datei ubasic.c.

1747 {
1748  int var;
1749  accept(token);
1750  var = tokenizer_variable_num();
1752  ubasic_set_variable(var, func());
1753  accept_cr();
1754 }
static void gosub_statement ( void  )
static

Definiert in Zeile 1402 der Datei ubasic.c.

1403 {
1406  tokenizer_string(string, sizeof(string));
1407  do {
1408  tokenizer_next();
1409  } while(tokenizer_token() != TOKENIZER_CR);
1412 /* tokenizer_line_number_inc();*/
1414  gosub_stack_ptr++;
1415  jump_label(string);
1416  } else {
1417  DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n");
1418  ended = 1;
1420  }
1421  } else {
1422  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
1423  ended = 1;
1425  }
1426 }
static void goto_statement ( void  )
static

Definiert in Zeile 938 der Datei ubasic.c.

939 {
942  tokenizer_string(string, sizeof(string));
943  tokenizer_next();
944  jump_label(string);
945  } else {
946  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
947  ended = 1;
949  }
950 }
static void if_statement ( void  )
static

Definiert in Zeile 996 der Datei ubasic.c.

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

Definiert in Zeile 2003 der Datei ubasic.c.

2004 {
2005  int var;
2007  var = tokenizer_variable_num();
2010  DEBUG_PRINTF("End of is_key\n");
2011  accept_cr();
2012 }
int jump_label ( char *  label)

Definiert in Zeile 909 der Datei ubasic.c.

910 {
911  char currLabel[MAX_STRINGLEN];
913  currLabel[0] = 0;
915  tokenizer_next();
916  if (tokenizer_token() == TOKENIZER_LABEL) {
917  tokenizer_label(currLabel, sizeof(currLabel));
918  tokenizer_next();
919  if(strcmp(label, currLabel) == 0) {
921  DEBUG_PRINTF("jump_linenum: Found line %d\n", tokenizer_line_number());
922  break;
923  }
924  }
925  }
928  DEBUG_PRINTF("Label %s not found", label);
930  }
931  return 0;
932  } else {
933  return 1;
934  }
935 }
static void jump_line ( int  linenum)
static

Definiert in Zeile 896 der Datei ubasic.c.

897 {
899  while(tokenizer_line_number() != linenum) {
900  tokenizer_next();
901  }
902  /* swallow the CR that would be read next */
904 
905 }
static void let_statement ( void  )
static

Definiert in Zeile 1370 der Datei ubasic.c.

1371 {
1372 
1373  int var;
1374 
1375  var = tokenizer_variable_num();
1376 
1379  ubasic_set_variable(var, expr());
1380  DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
1381  accept_cr();
1382 }
static void line_statement ( void  )
static

Definiert in Zeile 2680 der Datei ubasic.c.

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

Definiert in Zeile 2150 der Datei ubasic.c.

2151 {
2152  int columns;
2153  int rows;
2154  int pixel_measure_mode;
2155  int detection_timeout;
2156  int measure_interval;
2157  int threshold;
2158  int draw_grid=0;
2159  int clipping_region_mode=0;
2160  int clipping_region_row1=0;
2161  int clipping_region_column1=0;
2162  int clipping_region_row2=0;
2163  int clipping_region_column2=0;
2164  int parameters=0;
2165  int pixels_step=1;
2166  int msecs_before_trigger=0;
2167 
2169 
2170  columns=expr();tokenizer_next();
2171 
2172  rows=expr();tokenizer_next();
2173 
2174  pixel_measure_mode=expr();tokenizer_next();
2175 
2176  detection_timeout=expr();tokenizer_next();
2177 
2178  measure_interval=expr();tokenizer_next();
2179 
2180  threshold=expr();tokenizer_next();
2181 
2182  draw_grid=expr();tokenizer_next();
2183 
2185 
2187 
2189  // eat COMA
2190  // tokenizer_next();
2191  }
2192 
2194  tokenizer_next();
2195  clipping_region_mode = expr();
2196  }
2198  tokenizer_next();
2199  clipping_region_column1 = expr();
2200  }
2202  tokenizer_next();
2203  clipping_region_row1 = expr();
2204  }
2206  tokenizer_next();
2207  clipping_region_column2 = expr();
2208  }
2210  tokenizer_next();
2211  clipping_region_row2 = expr();
2212  }
2214  tokenizer_next();
2215  parameters = expr();
2216  }
2218  tokenizer_next();
2219  pixels_step = expr();
2220  }
2221 
2223  tokenizer_next();
2224  msecs_before_trigger = expr();
2225  }
2226 
2227  accept_cr();
2228 
2229 #ifdef UBASIC_TEST
2230  // TODO: add something here for ubasic_test
2231 #else
2233  columns, rows, pixel_measure_mode, detection_timeout,
2234  measure_interval, threshold, draw_grid,
2235  clipping_region_mode,
2236  clipping_region_column1, clipping_region_row1,
2237  clipping_region_column2, clipping_region_row2,
2238  parameters, pixels_step, msecs_before_trigger);
2239 #endif
2240 
2241  flag_yield=1;
2242 }
static void md_get_cell_diff_statement ( )
static

Definiert in Zeile 2110 der Datei ubasic.c.

2111 {
2112  int var, col, row;
2114 
2115  col=expr();tokenizer_next();
2116 
2117  row=expr();tokenizer_next();
2118 
2119  var = tokenizer_variable_num();
2121  accept_cr();
2122 
2123 #ifdef UBASIC_TEST
2124  // TODO: add something here for ubasic_test
2125 #else
2127 #endif
2128 }
static void md_get_cell_val_statement ( )
static

Definiert in Zeile 2130 der Datei ubasic.c.

2131 {
2132  int var, col, row;
2134 
2135  col=expr();tokenizer_next();
2136 
2137  row=expr();tokenizer_next();
2138 
2139  var = tokenizer_variable_num();
2141  accept_cr();
2142 
2143 #ifdef UBASIC_TEST
2144  // TODO: add something here for ubasic_test
2145 #else
2147 #endif
2148 }
static void next_statement ( void  )
static

Definiert in Zeile 1443 der Datei ubasic.c.

1444 {
1445  int var, value;
1446 
1448  var = tokenizer_variable_num();
1450  if(for_stack_ptr > 0 &&
1451  var == for_stack[for_stack_ptr - 1].for_variable) {
1452  value = ubasic_get_variable(var) + for_stack[for_stack_ptr - 1].step;
1453  ubasic_set_variable(var, value);
1454 
1455  if(((for_stack[for_stack_ptr - 1].step > 0) && (value <= for_stack[for_stack_ptr - 1].to)) ||
1456  ((for_stack[for_stack_ptr - 1].step < 0) && (value >= for_stack[for_stack_ptr - 1].to)))
1457  jump_line(for_stack[for_stack_ptr - 1].line_after_for);
1458  else {
1459  for_stack_ptr--;
1461  }
1462  } else {
1463  DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var);
1464  ended = 1;
1466  }
1467 
1468 }
static void on_off_statement ( int  token,
void(*)(void)  on,
void(*)(void)  off 
)
static

Definiert in Zeile 2058 der Datei ubasic.c.

2059 {
2060  accept(token);
2061  if (expr() > 0) on();
2062  else off();
2063  accept_cr();
2064 }
static void one_int_param_function ( int  token,
void(*)(int)  func 
)
static

Definiert in Zeile 1782 der Datei ubasic.c.

1783 {
1784  accept(token);
1785  func(expr());
1786  accept_cr();
1787 }
static void one_short_param_function ( int  token,
void(*)(short)  func 
)
static

Definiert in Zeile 1790 der Datei ubasic.c.

1791 {
1792  accept(token);
1793  func(expr());
1794  accept_cr();
1795 }
static void press_statement ( void  )
static

Definiert in Zeile 1620 der Datei ubasic.c.

1621 {
1622  int k;
1624  k = ubasic_get_key_arg();
1625  if (k > 0) {
1626  action_push_press(k);
1627  flag_yield=1;
1628  }
1629  DEBUG_PRINTF("End of press\n");
1630  accept_cr();
1631 }
static void print_statement ( void  )
static

Definiert in Zeile 953 der Datei ubasic.c.

954 {
955  static char buf[128];
956 
957  buf[0]=0;
959  do {
960  DEBUG_PRINTF("Print loop\n");
962  tokenizer_string(string, sizeof(string));
963  sprintf(buf+strlen(buf), "%s", string);
964  tokenizer_next();
965  } else if(tokenizer_token() == TOKENIZER_COMMA) {
966  strcat(buf, " ");
967  tokenizer_next();
968  } else if(tokenizer_token() == TOKENIZER_SEMICOLON) {
969  tokenizer_next();
970  } else {
971  sprintf(buf+strlen(buf), "%d", expr());
972  }
974  script_console_add_line((long)buf);
975  DEBUG_PRINTF("End of print\n");
976  accept_cr();
977 }
static void reboot_statement ( )
static

Definiert in Zeile 1924 der Datei ubasic.c.

1924  {
1927  tokenizer_string(string, sizeof(string));
1928  tokenizer_next();
1929  reboot(string);
1930  } else {
1931  reboot(NULL);
1932  }
1933 }
static int relation ( void  )
static

Definiert in Zeile 851 der Datei ubasic.c.

852 {
853  int r1, r2;
854  int op;
855 
856  r1 = expr();
857  op = tokenizer_token();
858  DEBUG_PRINTF("relation: token %d\n", op);
859  while(op == TOKENIZER_LAND) {
860  tokenizer_next();
861  r2 = expr();
862  DEBUG_PRINTF("relation: %d %d %d\n", r1, op, r2);
863  switch(op) {
864  case TOKENIZER_LAND:
865  r1 = r1 && r2;
866  break;
867  }
868  op = tokenizer_token();
869  }
870  return r1;
871 }
static void release_statement ( void  )
static

Definiert in Zeile 1634 der Datei ubasic.c.

1635 {
1636  int k;
1638  k = ubasic_get_key_arg();
1639  if (k > 0) {
1641  flag_yield=1;
1642  }
1643  DEBUG_PRINTF("End of release\n");
1644  accept_cr();
1645 }
static void rem_statement ( void  )
static

Definiert in Zeile 1385 der Datei ubasic.c.

1386 {
1388  DEBUG_PRINTF("rem_statement\n");
1390 }
static void return_statement ( void  )
static

Definiert in Zeile 1429 der Datei ubasic.c.

1430 {
1432  if(gosub_stack_ptr > 0) {
1433  gosub_stack_ptr--;
1435  } else {
1436  DEBUG_PRINTF("return_statement: non-matching return\n");
1437  ended = 1;
1439  }
1440 }
static void select_statement ( void  )
static

Definiert in Zeile 1338 der Datei ubasic.c.

1339 {
1340 
1341  int select_value;
1342 
1344  select_value = expr();
1346 //REM
1347  while (tokenizer_token() == TOKENIZER_REM) {statement();}
1348 //REM
1349 
1351  select_stack[select_stack_ptr].select_value = select_value;
1353  DEBUG_PRINTF("select_statement: new select, value %d\n",select_stack[select_stack_ptr].select_value);
1354  select_stack_ptr++;
1355  if (tokenizer_token() != TOKENIZER_CASE) {
1356  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case-statement\n");
1357  ended = 1;
1359  }
1360  else { case_statement(); }
1361  } else {
1362  DEBUG_PRINTF("select_statement: SELECT-stack depth exceeded\n");
1363  ended = 1;
1365  }
1366 }
static void set_autostart_statement ( )
static

Definiert in Zeile 1900 der Datei ubasic.c.

1901 {
1902  int to;
1904  to = expr();
1905 #ifndef UBASIC_TEST
1906  if (to >= 0 && to <= 3) conf.script_startup=to;
1907  conf_save();
1908 #endif
1909  accept_cr();
1910 }
static void set_capture_mode_canon_statement ( )
static

Definiert in Zeile 1912 der Datei ubasic.c.

1913 {
1914  int to;
1916  to = expr();
1917  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
1918  if( to < 0)
1919  to &= 0xFFFF;
1921  accept_cr();
1922 }
static void set_config_value_statement ( )
static

Definiert in Zeile 1935 der Datei ubasic.c.

1936 {
1937  int id, value;
1938  tConfigVal configVal = {0};
1939 
1941  id = expr();
1942  value = expr();
1943  if( conf_getValue(id, &configVal) == CONF_VALUE ) {
1944  configVal.numb = value;
1945  configVal.isNumb = 1;
1946  conf_setValue(id, configVal);
1947  }
1948  accept_cr();
1949 }
static void set_console_autoredraw ( void  )
static

Definiert in Zeile 1717 der Datei ubasic.c.

1718 {
1721  accept_cr();
1722 }
static void set_console_layout ( void  )
static

Definiert in Zeile 1705 der Datei ubasic.c.

1706 {
1707  int x1,y1,x2,y2;
1709  x1 = expr();
1710  y1 = expr();
1711  x2 = expr();
1712  y2 = expr();
1713  console_set_layout(x1,y1,x2,y2);
1714  accept_cr();
1715 }
static void set_ev_statement ( )
static

Definiert in Zeile 1816 der Datei ubasic.c.

1817  {
1818  int to;
1820  to = expr();
1823  accept_cr();
1824  }
static void set_exit_key_statement ( )
static

Definiert in Zeile 2014 der Datei ubasic.c.

2015 {
2016  int k;
2019  {
2020  tokenizer_string(string, sizeof(string));
2021  k = script_keyid_by_name(string);
2022  if (k <= 0)
2023  {
2025  ended = 1 ;
2026  }
2027  else
2028  {
2029  script_set_terminate_key(k,string);
2030  }
2031  }
2032  else
2033  {
2034  DEBUG_PRINTF("ubasic.c: set_exit_key no key specified\n");
2035  ended = 1;
2037  }
2038  accept_cr() ;
2039 }
static void set_focus_statement ( )
static

Definiert in Zeile 1850 der Datei ubasic.c.

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

Definiert in Zeile 1874 der Datei ubasic.c.

1875 {
1876  int to, to1, to2;
1878  to = expr();
1879  to1 = expr();
1880  to2 = 200;
1882  to2 = expr();
1883  }
1884  camera_set_led(to, to1, to2);
1885  accept_cr();
1886 }
static void set_mf_statement ( )
static

Definiert in Zeile 1842 der Datei ubasic.c.

1843 {
1845  if (expr() > 0) DoMFLock();
1846  else UnlockMF();
1847  accept_cr();
1848 }
static void set_movie_status_statement ( )
static

Definiert in Zeile 1826 der Datei ubasic.c.

1827 {
1830  accept_cr();
1831 }
static void set_prop_statement ( )
static

Definiert in Zeile 1888 der Datei ubasic.c.

1889 {
1890  int to, to1;
1892  to = expr();
1893  to1 = expr();
1894  shooting_set_prop(to, to1);
1895  accept_cr();
1896 }
static void set_propcase_statement ( int  token,
int  prop 
)
static

Definiert in Zeile 1834 der Datei ubasic.c.

1835 {
1836  accept(token);
1837  shooting_set_prop(prop, expr());
1838  accept_cr();
1839 }
static void set_yield_statement ( )
static

Definiert in Zeile 1731 der Datei ubasic.c.

1732 {
1734  int val = expr();
1736  val = expr();
1738  accept_cr();
1739 }
static void shoot_statement ( void  )
static

Definiert in Zeile 1689 der Datei ubasic.c.

1690 {
1692  ubasic_as_ret_var_num = -1;
1693  if (tokenizer_token() != TOKENIZER_CR)
1694  {
1697  }
1698  action_push_shoot(1);
1699  flag_yield=1;
1700  DEBUG_PRINTF("End of shoot\n");
1701  accept_cr();
1702 }
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 2067 der Datei ubasic.c.

2067  {
2070  accept_cr();
2071 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 1659 der Datei ubasic.c.

1660 {
1661  /* delay of -1 signals indefinite (actually 1 day) delay */
1662  if (delay == -1)
1663  delay = 86400000;
1664 
1665  if (delay > 0)
1666  return delay + get_tick_count();
1667 
1668  return 0;
1669 }
static void sleep_statement ( void  )
static

Definiert in Zeile 1672 der Datei ubasic.c.

1673 {
1675 
1676  int delay = sleep_delay(expr());
1677  if (delay > 0)
1678  {
1679  action_push(delay);
1681  }
1682 
1683  flag_yield=1;
1684  DEBUG_PRINTF("End of sleep\n");
1685  accept_cr();
1686 }
static void statement ( void  )
static

Definiert in Zeile 2257 der Datei ubasic.c.

2258 {
2260 
2261  token = tokenizer_token();
2262 
2263  switch(token) {
2264  // aelock
2265  case TOKENIZER_SET_AELOCK:
2267  break;
2268  // aflock
2269  case TOKENIZER_SET_AFLOCK:
2271  break;
2272 
2275  break;
2276  case TOKENIZER_PRINT:
2277  print_statement();
2278  break;
2279 
2280  case TOKENIZER_SLEEP:
2281  sleep_statement();
2282  break;
2283  case TOKENIZER_CLICK:
2284  click_statement();
2285  break;
2286  case TOKENIZER_PRESS:
2287  press_statement();
2288  break;
2289  case TOKENIZER_RELEASE:
2291  break;
2292  case TOKENIZER_SHOOT:
2293  shoot_statement();
2294  break;
2297  break;
2300  break;
2303  break;
2304 #ifdef INCLUDE_OLD_GET__SYNTAX
2305  case TOKENIZER_GET_TV96:
2307  break;
2310  break;
2313  break;
2314  case TOKENIZER_GET_AV96:
2316  break;
2319  break;
2322  break;
2323  case TOKENIZER_GET_ZOOM:
2325  break;
2326  case TOKENIZER_GET_FOCUS:
2328  break;
2331  break;
2334  break;
2335  case TOKENIZER_GET_DOF:
2337  break;
2340  break;
2343  break;
2346  break;
2347  case TOKENIZER_GET_BV96:
2349  break;
2350  case TOKENIZER_GET_SV96:
2352  break;
2355  break;
2356  case TOKENIZER_GET_VBATT:
2357  get_int_var_statement(token, (int (*)(void))stat_get_vbatt);
2358  break;
2360  get_int_var_statement(token, (int (*)(void))GetTotalCardSpaceKb);
2361  break;
2363  get_int_var_statement(token, (int (*)(void))GetFreeCardSpaceKb);
2364  break;
2366  get_int_var_statement(token, (int (*)(void))GetJpgCount);
2367  break;
2369  get_int_var_statement(token, (int (*)(void))GetRawCount);
2370  break;
2371  case TOKENIZER_GET_PROP:
2373  break;
2374 #endif
2377  break;
2378  case TOKENIZER_SET_TV96:
2380  break;
2381  case TOKENIZER_PLAY_SOUND:
2382  one_int_param_function(token, (void (*)(int))play_sound);
2383  break;
2386  break;
2389  break;
2392  break;
2395  break;
2396  case TOKENIZER_SET_AV96:
2398  break;
2399 
2402  break;
2405  break;
2408  break;
2409 
2412  break;
2413 
2414  case TOKENIZER_SET_ZOOM:
2416  break;
2419  break;
2422  break;
2423  case TOKENIZER_SET_FOCUS:
2425  break;
2426  case TOKENIZER_SET_MF:
2427  set_mf_statement();
2428  break;
2429 
2430 /*
2431  case TOKENIZER_SET_ISO_MARKET:
2432  one_int_param_function(token, shooting_set_iso_market);
2433  break;
2434  case TOKENIZER_SET_ISO_DL_F_B:
2435  one_int_param_function(token, shooting_set_iso_real_delta_from_base);
2436  break;
2437 */
2438  //ARM End
2439 
2442  break;
2443  case TOKENIZER_SET_SV96:
2445  break;
2446 
2449  break;
2450 
2451  case TOKENIZER_SET_PROP:
2453  break;
2454  case TOKENIZER_SET_LED:
2456  break;
2457 
2458  case TOKENIZER_SET_EV:
2459  set_ev_statement();
2460  break;
2461 
2464  break;
2467  break;
2468  case TOKENIZER_SET_QUALITY:
2470  break;
2471 
2472  case TOKENIZER_WAIT_CLICK:
2474  break;
2475  case TOKENIZER_IS_KEY:
2476  is_key_statement();
2477  break;
2480  break;
2481 
2482  case TOKENIZER_WHEEL_LEFT:
2483  accept(token);
2484  JogDial_CCW();
2485  accept_cr();
2486  break;
2487  case TOKENIZER_WHEEL_RIGHT:
2488  accept(token);
2489  JogDial_CW();
2490  accept_cr();
2491  break;
2492 
2493  case TOKENIZER_IF:
2494  if_statement();
2495  break;
2496  case TOKENIZER_ELSE:
2497  else_statement();
2498  break;
2499  case TOKENIZER_ENDIF:
2500  endif_statement();
2501  break;
2502  case TOKENIZER_SELECT:
2503  select_statement();
2504  break;
2505  case TOKENIZER_CASE:
2506  case_statement();
2507  break;
2508  case TOKENIZER_CASE_ELSE:
2510  break;
2511  case TOKENIZER_GOTO:
2512  goto_statement();
2513  break;
2514  case TOKENIZER_GOSUB:
2515  gosub_statement();
2516  break;
2517  case TOKENIZER_RETURN:
2518  return_statement();
2519  break;
2520  case TOKENIZER_FOR:
2521  for_statement();
2522  break;
2523  case TOKENIZER_NEXT:
2524  next_statement();
2525  break;
2526  case TOKENIZER_DO:
2527  do_statement();
2528  break;
2529  case TOKENIZER_UNTIL:
2530  until_statement();
2531  break;
2532  case TOKENIZER_WHILE:
2533  while_statement();
2534  break;
2535  case TOKENIZER_WEND:
2536  wend_statement();
2537  break;
2538  case TOKENIZER_END:
2539  end_statement();
2540  break;
2541  case TOKENIZER_LET:
2543  /* Fall through. */
2544  case TOKENIZER_VARIABLE:
2545  let_statement();
2546  break;
2547  case TOKENIZER_REM:
2548  rem_statement();
2549  break;
2550  case TOKENIZER_CLS:
2551  cls_statement();
2552  break;
2553  case TOKENIZER_SET_RAW:
2554  accept(token);
2555  conf.save_raw = expr();
2556  accept_cr();
2557  break;
2558  case TOKENIZER_SET_RAW_NR:
2559  accept(token);
2560  conf.raw_nr = expr();
2561  accept_cr();
2562  break;
2565  break;
2566  case TOKENIZER_EXIT_ALT:
2567  accept(token);
2568  exit_alt();
2569  accept_cr();
2570  break;
2571  case TOKENIZER_ENTER_ALT:
2572  accept(token);
2573  enter_alt(1);
2574  accept_cr();
2575  break;
2576  case TOKENIZER_SHUT_DOWN:
2580  break;
2583  break;
2585  accept(token);
2587  accept_cr();
2588  break;
2589 
2590  // >> mx3 . motion detector
2593  break;
2596  break;
2599  break;
2600  // << mx3 . motion_detector
2601 
2603  accept(token);
2606  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
2607  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
2608  // clear previous values
2610  camera_info.perf.af_led.min = 0xFFFFFFFF;
2611  } else {
2612  camera_info.perf.md_af_tuning = 0; // Disable MD testing
2613  }
2614  accept_cr();
2615  break;
2616 
2618  one_int_param_function(token, (void (*)(int))_shot_histogram_set);
2619  break;
2620 
2621  case TOKENIZER_SET_RECORD:
2623  break;
2624 
2626  one_int_param_function(token, (void (*)(int))shooting_set_mode_chdk);
2627  break;
2628 
2631  break;
2632 
2633  case TOKENIZER_REBOOT:
2634  reboot_statement();
2635  break;
2636 
2639  break;
2640 
2643  break;
2644  case TOKENIZER_SET_YIELD:
2646  break;
2647 
2650 #ifdef UBASIC_TEST
2651  // TODO: add something here for ubasic_test
2652 #else
2653  if (expr()) usb_sync_wait_flag = 1;
2654  else usb_sync_wait_flag = 0;
2655 #endif
2656  accept_cr();
2657  break;
2658 
2661 #ifdef UBASIC_TEST
2662  // TODO: add something here for ubasic_test
2663 #else
2664  int hpenable= expr();
2665  if ( hpenable > 0) start_usb_HPtimer(hpenable);
2666  else stop_usb_HPtimer();
2667 #endif
2668  accept_cr();
2669  break;
2670 
2671  default:
2672  DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
2673  ended = 1;
2675  }
2676 }
static int term ( void  )
static

Definiert in Zeile 750 der Datei ubasic.c.

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

Definiert in Zeile 2073 der Datei ubasic.c.

2073  {
2075  return ;
2076 }
static void uB_set_av96_direct ( int  param)
static

Definiert in Zeile 2078 der Datei ubasic.c.

2078  {
2080  return ;
2081 }
static void uB_set_iso_real ( int  param)
static

Definiert in Zeile 2103 der Datei ubasic.c.

2103  {
2105  return ;
2106 }
static void uB_set_nd_filter_state ( int  param)
static

Definiert in Zeile 2098 der Datei ubasic.c.

2098  {
2100  return ;
2101 }
static void uB_set_sv96 ( int  param)
static

Definiert in Zeile 2093 der Datei ubasic.c.

2093  {
2095  return ;
2096 }
static void uB_set_tv96 ( int  param)
static

Definiert in Zeile 2083 der Datei ubasic.c.

2083  {
2085  return ;
2086 }
static void uB_set_tv96_direct ( int  param)
static

Definiert in Zeile 2088 der Datei ubasic.c.

2088  {
2090  return ;
2091 }
void ubasic_end ( void  )

Definiert in Zeile 2787 der Datei ubasic.c.

2787  {
2788 }
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 2778 der Datei ubasic.c.

2779 {
2780  if(varnum >= 0 && varnum < MAX_VARNUM) {
2781  return variables[varnum];
2782  }
2783  return 0;
2784 }
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 2722 der Datei ubasic.c.

2723 {
2724  unsigned start_tick = get_tick_count();
2725  unsigned lines = 0;
2726  flag_yield = 0;
2727 
2728  do
2729  {
2730  if ( ended || tokenizer_finished() )
2731  {
2732  DEBUG_PRINTF("uBASIC program finished\n");
2733  if (ubasic_error)
2734  {
2735  // Generate error message
2736  char buf[100];
2737  const char *msg;
2739  {
2741  }
2742  else
2743  {
2745  }
2746  sprintf(buf, "uBASIC:%d %s ", ubasic_linenumber(), msg);
2747  // Show error message
2748  script_console_add_error((long)buf);
2750  return SCRIPT_RUN_ERROR;
2751  }
2752  // Show 'Finished' message
2754  return SCRIPT_RUN_ENDED;
2755  }
2756 
2757  line_statement();
2758 
2759  // Return control to CHDK only if external processing required
2760  if ( flag_yield )
2761  return SCRIPT_RUN_RUNNING;
2762 
2763  lines++;
2764  } while (lines < yield_max_lines && get_tick_count() - start_tick < yield_max_ms);
2765 
2766  return SCRIPT_RUN_RUNNING;
2767 }
void ubasic_set_as_ret ( int  md_ret)

Definiert in Zeile 2792 der Datei ubasic.c.

2793 {
2794  if (ubasic_as_ret_var_num >= 0)
2796 }
void ubasic_set_variable ( int  varum,
int  value 
)

Definiert in Zeile 2770 der Datei ubasic.c.

2771 {
2772  if(varnum >= 0 && varnum < MAX_VARNUM) {
2773  variables[varnum] = value;
2774  }
2775 }
static void until_statement ( void  )
static

Definiert in Zeile 1522 der Datei ubasic.c.

1523 {
1524  int r;
1525 
1527  r = relation();
1528  if(do_stack_ptr > 0) {
1529  if(!r) {
1531  } else {
1532  do_stack_ptr--;
1533  accept_cr();
1534  }
1535  } else {
1536  DEBUG_PRINTF("until_statement: unmatched until\n");
1537  ended = 1;
1539  }
1540 }
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 1972 der Datei ubasic.c.

1973 {
1975 
1976  int delay = -1;
1978  {
1979  delay = expr();
1980  if (delay == 0) delay = -1;
1981  }
1982  delay = sleep_delay(delay);
1983 
1984  accept_cr();
1985 
1986  // Reset 'clicked' key if it has not changed since last time
1988  {
1990  }
1991 
1992  // Set up for wait or click testing
1993  action_push(delay);
1995 
1996  // Check for short delay or key already pressed by calling action stack routine once now
1998  {
1999  flag_yield=1;
2000  }
2001 }
static void wend_statement ( void  )
static

Definiert in Zeile 1585 der Datei ubasic.c.

1586 {
1588  if(while_stack_ptr > 0) {
1590  } else {
1591  DEBUG_PRINTF("wend_statement: unmatched wend\n");
1592  ended = 1;
1594  }
1595 }
static void while_statement ( void  )
static

Definiert in Zeile 1543 der Datei ubasic.c.

1544 {
1545  int r, while_cntr;
1546 
1551  while_stack_ptr++;
1552  }
1553  } else {
1554  DEBUG_PRINTF("while_statement: while stack depth exceeded\n");
1555  ended = 1;
1557  return;
1558  }
1559 
1560  r = relation();
1561  if(while_stack_ptr > 0) {
1562  if(!r) {
1563  while_cntr=0;
1564  while((tokenizer_token() != TOKENIZER_WEND || while_cntr ) &&
1566  if (tokenizer_token() == TOKENIZER_WHILE) while_cntr+=1;
1567  if (tokenizer_token() == TOKENIZER_WEND) while_cntr-=1;
1568  tokenizer_next();
1569  }
1570  while_stack_ptr--;
1571 
1573  accept(TOKENIZER_CR);
1574  } else {
1575  accept_cr();
1576  }
1577  } else {
1578  DEBUG_PRINTF("while_statement: unmatched wend\n");
1579  ended = 1;
1581  }
1582 }

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.