source: trunk/core/luascript.c @ 679

Revision 679, 20.7 KB checked in by phyrephox, 4 years ago (diff)

+ added two small functions... TurnOnBackLight? & TurnOffBackLight?, which turn on and off the LCD Backlight (or EVF backlight) - useful for energy saving or camouflage missions :D
also added ubasic and lua commands: set_backlight(x), whereas 0 disables Backlight and 1 enables it. mind you, after a shot the display is turned on again (probably loop set_backlight_statement(0) in script!?).
an example script can be found here: http://chdk.setepontos.com/index.php/topic,2744.msg27703.html#msg27703
todo: PERHAPS make it that you can disable (automatically after a given time?) LCD directly in CHDK, also on todo list: Dimming the light

thx to fudgey, ewavr & Dataghost, who made that happen \o/ (see https://chdk.kernreaktor.org/mantis/view.php?id=65 for links)

  • Property svn:eol-style set to native
Line 
1#include "luascript.h"
2#include "../lib/ubasic/camera_functions.h"
3#include "kbd.h"
4#include "platform.h"
5#include "script.h"
6#include "lua.h"
7#include "lualib.h"
8#include "lauxlib.h"
9#include "../include/conf.h"
10#include "shot_histogram.h"
11#include "ubasic.h"
12#include "stdlib.h"
13#include "raw.h"
14#include "raw_merge.h"
15
16static int luaCB_shoot( lua_State* L )
17{
18  kbd_sched_shoot();
19  return lua_yield( L, 0 );
20}
21
22static int luaCB_sleep( lua_State* L )
23{
24  kbd_sched_delay( luaL_checknumber( L, 1 ) );
25  return lua_yield( L, 0 );
26}
27
28// for press,release and click
29static int luaCB_keyfunc( lua_State* L )
30{
31  long k = keyid_by_name( luaL_checkstring( L, 1 ) );
32  if (k > 0 ) {
33    void* func = lua_touserdata( L, lua_upvalueindex(1) );
34    ((void(*)(long))func)( k );
35  }
36  else
37    luaL_error( L, "unknown key" );
38  return lua_yield( L, 0 );
39}
40
41static int luaCB_cls( lua_State* L )
42{
43  script_console_clear();
44  return 0;
45}
46
47static int luaCB_get_av96( lua_State* L )
48{
49  lua_pushnumber( L, shooting_get_av96() );
50  return 1;
51}
52
53static int luaCB_get_bv96( lua_State* L )
54{
55  lua_pushnumber( L, shooting_get_bv96() );
56  return 1;
57}
58
59static int luaCB_get_day_seconds( lua_State* L )
60{
61  lua_pushnumber( L, shooting_get_day_seconds() );
62  return 1;
63}
64
65static int luaCB_get_disk_size( lua_State* L )
66{
67  lua_pushnumber( L, GetTotalCardSpaceKb() );
68  return 1;
69}
70
71static int luaCB_get_dof( lua_State* L )
72{
73  lua_pushnumber( L, shooting_get_depth_of_field() );
74  return 1;
75}
76
77static int luaCB_get_far_limit( lua_State* L )
78{
79  lua_pushnumber( L, shooting_get_far_limit_of_acceptable_sharpness() );
80  return 1;
81}
82
83static int luaCB_get_free_disk_space( lua_State* L )
84{
85  lua_pushnumber( L, GetFreeCardSpaceKb() );
86  return 1;
87}
88
89static int luaCB_get_focus( lua_State* L )
90{
91  lua_pushnumber( L, shooting_get_subject_distance() );
92  return 1;
93}
94
95static int luaCB_get_hyp_dist( lua_State* L )
96{
97  lua_pushnumber( L, shooting_get_hyperfocal_distance() );
98  return 1;
99}
100
101static int luaCB_get_iso_market( lua_State* L )
102{
103  lua_pushnumber( L, shooting_get_iso_market() );
104  return 1;
105}
106
107static int luaCB_get_iso_mode( lua_State* L )
108{
109  lua_pushnumber( L, shooting_get_iso_mode() );
110  return 1;
111}
112
113static int luaCB_get_iso_real( lua_State* L )
114{
115  lua_pushnumber( L, shooting_get_iso_real() );
116  return 1;
117}
118
119static int luaCB_get_jpg_count( lua_State* L )
120{
121  lua_pushnumber( L, GetJpgCount() );
122  return 1;
123}
124
125static int luaCB_get_near_limit( lua_State* L )
126{
127  lua_pushnumber( L, shooting_get_near_limit_of_acceptable_sharpness() );
128  return 1;
129}
130
131static int luaCB_get_prop( lua_State* L )
132{
133  lua_pushnumber( L, shooting_get_prop( luaL_checknumber( L, 1 ) ) );
134  return 1;
135}
136
137static int luaCB_get_raw_count( lua_State* L )
138{
139  lua_pushnumber( L, GetRawCount() );
140  return 1;
141}
142
143static int luaCB_get_sv96( lua_State* L )
144{
145  lua_pushnumber( L, shooting_get_sv96() );
146  return 1;
147}
148
149static int luaCB_get_tick_count( lua_State* L )
150{
151  lua_pushnumber( L, shooting_get_tick_count() );
152  return 1;
153}
154
155static int luaCB_get_exp_count( lua_State* L )
156{
157  lua_pushnumber( L, get_exposure_counter() );
158  return 1;
159}
160
161static int luaCB_get_tv96( lua_State* L )
162{
163  lua_pushnumber( L, shooting_get_tv96() );
164  return 1;
165}
166
167static int luaCB_get_user_av_id( lua_State* L )
168{
169  lua_pushnumber( L, shooting_get_user_av_id() );
170  return 1;
171}
172
173static int luaCB_get_user_av96( lua_State* L )
174{
175  lua_pushnumber( L, shooting_get_user_av96() );
176  return 1;
177}
178
179static int luaCB_get_user_tv_id( lua_State* L )
180{
181  lua_pushnumber( L, shooting_get_user_tv_id() );
182  return 1;
183}
184
185static int luaCB_get_user_tv96( lua_State* L )
186{
187  lua_pushnumber( L, shooting_get_user_tv_id() );
188  return 1;
189}
190
191static int luaCB_get_vbatt( lua_State* L )
192{
193  lua_pushnumber( L, stat_get_vbatt() );
194  return 1;
195}
196
197static int luaCB_get_zoom( lua_State* L )
198{
199  lua_pushnumber( L, shooting_get_zoom() );
200  return 1;
201}
202
203static int luaCB_get_parameter_data( lua_State* L )
204{
205  extern long* FlashParamsTable[];
206
207  unsigned size;
208  unsigned id = luaL_checknumber( L, 1 );
209  unsigned val;
210
211  if (id >= get_flash_params_count()) {
212    // return nil
213    return 0;
214  }
215
216  size = FlashParamsTable[id][1]>>16;
217  if (size == 0) {
218    // return nil
219    return 0;
220  }
221  if (size >= 1 && size <= 4) {
222    val = 0;
223    get_parameter_data( id, &val, size );
224    lua_pushlstring( L, (char *)&val, size );
225    // for convenience, params that fit in a number are returned in one as a second result
226    lua_pushnumber( L, val );
227    return 2;
228  }
229  else {
230    char *buf = malloc(size);
231    if(!buf) {
232      luaL_error( L, "malloc failed in luaCB_get_parameter_data" );
233    }
234    get_parameter_data( id, buf, size );
235    lua_pushlstring( L, buf, size );
236    free(buf);
237    return 1;
238  }
239}
240
241static int luaCB_get_flash_params_count( lua_State* L )
242{
243  lua_pushnumber( L, get_flash_params_count() );
244  return 1;
245}
246
247static int luaCB_set_av96_direct( lua_State* L )
248{
249  shooting_set_av96_direct( luaL_checknumber( L, 1 ), SET_LATER );
250  return 0;
251}
252
253static int luaCB_set_av96( lua_State* L )
254{
255  shooting_set_av96( luaL_checknumber( L, 1 ), SET_LATER );
256  return 0;
257}
258
259static int luaCB_set_focus( lua_State* L )
260{
261    int to = luaL_checknumber( L, 1 );
262    int m=mode_get()&MODE_SHOOTING_MASK;
263    int mode_video=MODE_IS_VIDEO(m);
264
265#if CAM_HAS_MANUAL_FOCUS
266    if (shooting_get_focus_mode() || (mode_video)) shooting_set_focus(to, SET_NOW);
267    else shooting_set_focus(to, SET_LATER);
268#else
269    if (mode_video) shooting_set_focus(to, SET_NOW);
270    else shooting_set_focus(to, SET_LATER);   
271#endif   
272  return 0;
273}
274
275static int luaCB_set_iso_mode( lua_State* L )
276{
277  shooting_set_iso_mode( luaL_checknumber( L, 1 ) );
278  return 0;
279}
280
281static int luaCB_set_iso_real( lua_State* L )
282{
283  shooting_set_iso_real( luaL_checknumber( L, 1 ), SET_LATER);
284  return 0;
285}
286
287static int luaCB_set_led( lua_State* L )
288{
289  int to, to1, to2;
290  to = luaL_checknumber( L, 1 );
291  to1 = luaL_checknumber( L, 2 );
292  to2 = 200;
293  if( lua_isnumber( L, 3 ) )
294    to = lua_tonumber( L, 3 );
295  ubasic_set_led(to, to1, to2);
296  return 0;
297}
298
299static int luaCB_set_nd_filter( lua_State* L )
300{
301  shooting_set_nd_filter_state( luaL_checknumber( L, 1 ), SET_LATER);
302  return 0;
303}
304
305static int luaCB_set_prop( lua_State* L )
306{
307  int to, to1;
308  to = luaL_checknumber( L, 1 );
309  to1 = luaL_checknumber( L, 2 );
310  shooting_set_prop(to, to1);
311  return 0;
312}
313
314static int luaCB_set_raw_nr( lua_State* L )
315{
316  ubasic_camera_set_nr(luaL_checknumber( L, 1 ));
317  return 0;
318}
319
320static int luaCB_get_raw_nr( lua_State* L )
321{
322  lua_pushnumber( L, ubasic_camera_get_nr() );
323  return 1;
324}
325
326static int luaCB_set_raw( lua_State* L )
327{
328  ubasic_camera_set_raw(luaL_checknumber( L, 1 ));
329  return 0;
330}
331
332static int luaCB_get_raw( lua_State* L )
333{
334  lua_pushnumber( L, conf.save_raw );
335  return 1;
336}
337
338static int luaCB_set_sv96( lua_State* L )
339{
340  shooting_set_sv96(luaL_checknumber( L, 1 ), SET_LATER);
341  return 0;
342}
343
344static int luaCB_set_tv96_direct( lua_State* L )
345{
346  shooting_set_tv96_direct(luaL_checknumber( L, 1 ), SET_LATER);
347  return 0;
348}
349
350static int luaCB_set_tv96( lua_State* L )
351{
352  shooting_set_tv96(luaL_checknumber( L, 1 ), SET_LATER);
353  return 0;
354}
355
356static int luaCB_set_user_av_by_id_rel( lua_State* L )
357{
358  shooting_set_user_av_by_id_rel(luaL_checknumber( L, 1 ));
359  return 0;
360}
361
362static int luaCB_set_user_av_by_id( lua_State* L )
363{
364  shooting_set_user_av_by_id(luaL_checknumber( L, 1 ));
365  return 0;
366}
367
368static int luaCB_set_user_av96( lua_State* L )
369{
370  shooting_set_user_av96(luaL_checknumber( L, 1 ));
371  return 0;
372}
373
374static int luaCB_set_user_tv_by_id_rel( lua_State* L )
375{
376  shooting_set_user_tv_by_id_rel(luaL_checknumber( L, 1 ));
377  return 0;
378}
379
380static int luaCB_set_user_tv_by_id( lua_State* L )
381{
382  shooting_set_user_tv_by_id(luaL_checknumber( L, 1 ));
383  return 0;
384}
385
386static int luaCB_set_user_tv96( lua_State* L )
387{
388  shooting_set_user_tv96(luaL_checknumber( L, 1 ));
389  return 0;
390}
391
392static int luaCB_set_zoom_speed( lua_State* L )
393{
394  shooting_set_zoom_speed(luaL_checknumber( L, 1 ));
395  return 0;
396}
397
398static int luaCB_set_zoom_rel( lua_State* L )
399{
400  shooting_set_zoom_rel(luaL_checknumber( L, 1 ));
401  return 0;
402}
403
404static int luaCB_set_zoom( lua_State* L )
405{
406  shooting_set_zoom(luaL_checknumber( L, 1 ));
407  return 0;
408}
409
410static int luaCB_wait_click( lua_State* L )
411{
412  int timeout = luaL_optnumber( L, 1, 0 );
413  ubasic_camera_wait_click(timeout);
414  return lua_yield( L, 0 );
415}
416
417static int luaCB_is_pressed( lua_State* L )
418{
419  lua_pushboolean( L, ubasic_camera_is_pressed(luaL_checkstring( L, 1 )));
420  return 1;
421}
422
423static int luaCB_is_key( lua_State* L )
424{
425  lua_pushboolean( L, ubasic_camera_is_clicked(luaL_checkstring( L, 1 )));
426  return 1;
427}
428
429#if CAM_HAS_JOGDIAL
430static int luaCB_wheel_right( lua_State* L )
431{
432  JogDial_CW();
433  return 0;
434}
435
436static int luaCB_wheel_left( lua_State* L )
437{
438  JogDial_CCW();
439  return 0;
440}
441#endif
442
443static int luaCB_md_get_cell_diff( lua_State* L )
444{
445  lua_pushnumber( L, md_get_cell_diff(luaL_checknumber(L,1),
446                                      luaL_checknumber(L,2)));
447  return 1;
448}
449
450static int luaCB_md_detect_motion( lua_State* L )
451{
452  int columns = (luaL_optnumber(L,1,6));
453  int rows = (luaL_optnumber(L,2,4));
454  int pixel_measure_mode = (luaL_optnumber(L,3,1));
455  int detection_timeout = (luaL_optnumber(L,4,10000));
456  int measure_interval = (luaL_optnumber(L,5,7));
457  int threshold = (luaL_optnumber(L,6,10));
458  int draw_grid = (luaL_optnumber(L,7,1));
459   // arg 8 is the return value in ubasic. We
460   // ignore it here. - AUJ
461  int clipping_region_mode = (luaL_optnumber(L,9,0));
462  int clipping_region_column1 = (luaL_optnumber(L,10,0));
463  int clipping_region_row1 = (luaL_optnumber(L,11,0));
464  int clipping_region_column2 = (luaL_optnumber(L,12,0));
465  int clipping_region_row2 = (luaL_optnumber(L,13,0));
466  int parameters = (luaL_optnumber(L,14,1));
467  int pixels_step = (luaL_optnumber(L,15,6));
468  int msecs_before_trigger = (luaL_optnumber(L,16,0));
469  ubasic_set_variable(0, 0);
470  md_init_motion_detector(
471    columns, rows, pixel_measure_mode, detection_timeout,
472    measure_interval, threshold, draw_grid, 0,
473    clipping_region_mode,
474    clipping_region_column1, clipping_region_row1,
475    clipping_region_column2, clipping_region_row2,
476    parameters, pixels_step, msecs_before_trigger
477  );
478
479  return lua_yield(L, 0);
480}
481
482static int luaCB_autostarted( lua_State* L )
483{
484  lua_pushboolean( L, ubasic_camera_script_autostart() );
485  return 1;
486}
487
488static int luaCB_get_autostart( lua_State* L )
489{
490  lua_pushnumber( L, conf.script_startup );
491  return 1;
492}
493
494static int luaCB_set_autostart( lua_State* L )
495{
496  int to;
497  to = luaL_checknumber( L, 1 );
498  if ( to >= 0 && to <= 2 ) conf.script_startup = to;
499  conf_save();
500  return 0;
501}
502
503static int luaCB_get_usb_power( lua_State* L )
504{
505  if (luaL_optnumber( L, 1, 0 )) lua_pushnumber( L, get_usb_power(1) );
506  else lua_pushnumber( L, get_usb_power(0) );
507  return 1;
508}
509
510static int luaCB_exit_alt( lua_State* L )
511{
512  exit_alt();
513  return 0;
514}
515
516static int luaCB_shut_down( lua_State* L )
517{
518  camera_shutdown_in_a_second();
519  return 0;
520}
521
522static int luaCB_print_screen( lua_State* L )
523{
524 
525  if (lua_isboolean( L, 1 ))
526    script_print_screen_statement( lua_toboolean( L, 1 ) );
527  else
528    script_print_screen_statement( luaL_checknumber( L, 1 )+10000 );
529  return 0;
530}
531
532static int luaCB_get_movie_status( lua_State* L )
533{
534  lua_pushnumber( L, movie_status );
535  return 1;
536}
537
538static int luaCB_set_movie_status( lua_State* L )
539{
540  int to;
541  switch(luaL_checknumber( L, 1 )) {
542    case 1:
543      if (movie_status == 4) {
544        movie_status = 1;
545      }
546    break;
547    case 2:
548      if (movie_status == 1) {
549        movie_status = 4;
550      }
551    break;
552    case 3:
553      if (movie_status == 1 || movie_status == 4) {
554        movie_status = 5;
555      }
556    break;
557  }
558  return 0;
559}
560
561static int luaCB_get_drive_mode( lua_State* L )
562{
563  lua_pushnumber( L, shooting_get_prop(PROPCASE_DRIVE_MODE) );
564  return 1;
565}
566
567static int luaCB_get_focus_mode( lua_State* L )
568{
569  lua_pushnumber( L, shooting_get_prop(PROPCASE_FOCUS_MODE) );
570  return 1;
571}
572
573static int luaCB_get_flash_mode( lua_State* L )
574{
575  lua_pushnumber( L, shooting_get_prop(PROPCASE_FLASH_MODE) );
576  return 1;
577}
578
579static int luaCB_get_shooting( lua_State* L )
580{
581  lua_pushboolean( L, shooting_get_prop(PROPCASE_SHOOTING) );
582  return 1;
583}
584
585static int luaCB_get_flash_ready( lua_State* L )
586{
587  lua_pushboolean( L, shooting_get_prop(PROPCASE_IS_FLASH_READY) );
588  return 1;
589}
590
591static int luaCB_get_IS_mode( lua_State* L )
592{
593  lua_pushnumber( L, shooting_get_prop(PROPCASE_IS_MODE) );
594  return 1;
595}
596
597static int luaCB_get_orientation_sensor( lua_State* L )
598{
599  lua_pushnumber( L, shooting_get_prop(PROPCASE_ORIENTATION_SENSOR) );
600  return 1;
601}
602
603static int luaCB_get_zoom_steps( lua_State* L )
604{
605  lua_pushnumber( L, zoom_points );
606  return 1;
607}
608
609static int luaCB_get_nd_present( lua_State* L )
610{
611  int to;
612  #if !CAM_HAS_ND_FILTER
613  to = 0;
614  #endif
615  #if CAM_HAS_ND_FILTER && !CAM_HAS_IRIS_DIAPHRAGM
616  to = 1;
617  #endif
618  #if CAM_HAS_ND_FILTER && CAM_HAS_IRIS_DIAPHRAGM
619  to = 2;
620  #endif
621  lua_pushnumber( L, to );
622  return 1;
623}
624
625static int luaCB_get_propset( lua_State* L )
626{
627  lua_pushnumber( L, CAM_PROPSET );
628  return 1;
629}
630
631static int luaCB_get_ev( lua_State* L )
632{
633  lua_pushnumber( L, shooting_get_prop(PROPCASE_EV_CORRECTION_1) );
634  return 1;
635}
636
637static int luaCB_set_ev( lua_State* L )
638{
639  int to;
640  to = luaL_checknumber( L, 1 );
641  shooting_set_prop(PROPCASE_EV_CORRECTION_1, to);
642  shooting_set_prop(PROPCASE_EV_CORRECTION_2, to);
643  return 0;
644}
645
646static int luaCB_get_histo_range( lua_State* L )
647{
648  int from = (luaL_checknumber(L,1));
649  int to = (luaL_checknumber(L,2));
650  if (shot_histogram_enabled) lua_pushnumber( L, (unsigned short)shot_histogram_get_range(from, to) );
651  else lua_pushnumber( L, -1 );
652  return 1;
653}
654
655static int luaCB_shot_histo_enable( lua_State* L )
656{
657  shot_histogram_enabled = luaL_checknumber( L, 1 );
658  return 0;
659}
660
661static int luaCB_play_sound( lua_State* L )
662{
663  play_sound(luaL_checknumber( L, 1 ));
664  return 0;
665}
666
667static int luaCB_get_temperature( lua_State* L )
668{
669  int which = (luaL_checknumber( L, 1 ));
670  int temp = -100; // do something insane if users passes bad value
671  switch (which)
672  {
673    case 0:
674      temp = get_optical_temp();
675      break;
676    case 1:
677      temp = get_ccd_temp();
678      break;
679    case 2:
680      temp = get_battery_temp();
681      break;
682  }
683  lua_pushnumber( L, temp );
684  return 1;
685}
686
687static int luaCB_get_time( lua_State* L )
688{
689  int r = -1;
690  unsigned long t2 = time(NULL);
691  static struct tm *ttm;
692  ttm = localtime(&t2);
693  const char *t = luaL_checkstring( L, 1 );
694  if (strncmp("s", t, 1)==0) r = ( L, ttm->tm_sec );
695  else if (strncmp("m", t, 1)==0) r = ( L, ttm->tm_min );
696  else if (strncmp("h", t, 1)==0) r = ( L, ttm->tm_hour );
697  else if (strncmp("D", t, 1)==0) r = ( L, ttm->tm_mday );
698  else if (strncmp("M", t, 1)==0) r = ( L, ttm->tm_mon+1 );
699  else if (strncmp("Y", t, 1)==0) r = ( L, 1900+ttm->tm_year );
700  lua_pushnumber( L, r );
701  return 1;
702}
703
704static int luaCB_peek( lua_State* L )
705{
706  int addr = (luaL_checknumber(L,1));
707  // must be alligned
708  if (addr & 0x3) {
709        lua_pushnil(L);
710  }
711  else {
712    lua_pushnumber( L, *(unsigned *)(addr) );
713  }
714  return 1;
715}
716
717static int luaCB_poke( lua_State* L )
718{
719  int addr = (luaL_checknumber(L,1));
720  int val = (luaL_checknumber(L,2));
721  if (addr & 0x3) {
722        lua_pushnil(L);
723  }
724  else {
725    *(unsigned *)(addr) = val;
726    lua_pushboolean(L,1);
727  }
728  return 1;
729}
730
731static int luaCB_bitand( lua_State* L )
732{
733  int v1 = (luaL_checknumber(L,1));
734  int v2 = (luaL_checknumber(L,2));
735  lua_pushnumber( L, v1 & v2 );
736  return 1;
737}
738
739static int luaCB_bitor( lua_State* L )
740{
741  int v1 = (luaL_checknumber(L,1));
742  int v2 = (luaL_checknumber(L,2));
743  lua_pushnumber( L, v1 | v2 );
744  return 1;
745}
746
747static int luaCB_bitxor( lua_State* L )
748{
749  int v1 = (luaL_checknumber(L,1));
750  int v2 = (luaL_checknumber(L,2));
751  lua_pushnumber( L, v1 ^ v2 );
752  return 1;
753}
754
755static int luaCB_bitshl( lua_State* L )
756{
757  int val = (luaL_checknumber(L,1));
758  unsigned shift = (luaL_checknumber(L,2));
759  lua_pushnumber( L, val << shift );
760  return 1;
761}
762
763static int luaCB_bitshri( lua_State* L )
764{
765  int val = (luaL_checknumber(L,1));
766  unsigned shift = (luaL_checknumber(L,2));
767  lua_pushnumber( L, val >> shift );
768  return 1;
769}
770
771static int luaCB_bitshru( lua_State* L )
772{
773  unsigned val = (luaL_checknumber(L,1));
774  unsigned shift = (luaL_checknumber(L,2));
775  lua_pushnumber( L, val >> shift );
776  return 1;
777}
778
779static int luaCB_bitnot( lua_State* L )
780{
781  unsigned val = (luaL_checknumber(L,1));
782  lua_pushnumber( L, ~val );
783  return 1;
784}
785
786static void set_string_field(lua_State* L, const char *key, const char *val)
787{
788  lua_pushstring(L, val);
789  lua_setfield(L, -2, key);
790}
791
792static int luaCB_get_buildinfo( lua_State* L )
793{
794  lua_createtable(L, 0, 8);
795  set_string_field( L,"platform", PLATFORM );
796  set_string_field( L,"platsub", PLATFORMSUB );
797  set_string_field( L,"version", HDK_VERSION );
798  set_string_field( L,"build_number", BUILD_NUMBER );
799  set_string_field( L,"build_date", __DATE__ );
800  set_string_field( L,"build_time", __TIME__ );
801#ifndef CAM_DRYOS
802  set_string_field( L,"os", "vxworks" );
803#else
804  set_string_field( L,"os", "dryos" );
805#endif
806  lua_pushnumber( L, PLATFORMID );
807  lua_setfield(L, -2, "platformid");
808  return 1;
809}
810
811static int luaCB_get_mode( lua_State* L )
812{
813  int m = mode_get();
814  lua_pushboolean( L, (m&MODE_MASK) != MODE_PLAY );
815  lua_pushboolean( L, MODE_IS_VIDEO(m) );
816  lua_pushnumber( L, m );
817  return 3;
818}
819
820// TODO sanity check file ?
821static int luaCB_set_raw_develop( lua_State* L )
822{
823  raw_prepare_develop(luaL_optstring( L, 1, NULL ));
824  return 0;
825}
826
827static int luaCB_raw_merge_start( lua_State* L )
828{
829  int op = luaL_checknumber(L,1);
830  if (op == RAW_OPERATION_SUM || op == RAW_OPERATION_AVERAGE) {
831    raw_merge_start(op);
832  }
833  else {
834    return luaL_argerror(L,1,"invalid raw merge op");
835  }
836  return 0;
837}
838
839// TODO sanity check file ?
840static int luaCB_raw_merge_add_file( lua_State* L )
841{
842  raw_merge_add_file(luaL_checkstring( L, 1 ));
843  return 0;
844}
845
846static int luaCB_raw_merge_end( lua_State* L )
847{
848  raw_merge_end();
849  return 0;
850}
851
852// Enable/disable LCD back light (input argument 1/0)
853static int luaCB_set_backlight( lua_State* L )
854{
855  int val = (luaL_checknumber(L,1));
856
857  if (val > 0) TurnOnBackLight();
858  else TurnOffBackLight();
859  return 0;
860}
861
862void register_lua_funcs( lua_State* L )
863{
864#define FUNC( X )                       \
865  lua_pushcfunction( L, luaCB_##X );    \
866  lua_setglobal( L, #X )
867
868  FUNC(shoot);
869  FUNC(sleep);
870  FUNC(cls);
871
872  lua_pushlightuserdata( L, kbd_sched_click );
873  lua_pushcclosure( L, luaCB_keyfunc, 1 );
874  lua_setglobal( L, "click" );
875
876  lua_pushlightuserdata( L, kbd_sched_press );
877  lua_pushcclosure( L, luaCB_keyfunc, 1 );
878  lua_setglobal( L, "press" );
879
880  lua_pushlightuserdata( L, kbd_sched_release );
881  lua_pushcclosure( L, luaCB_keyfunc, 1 );
882  lua_setglobal( L, "release" );
883
884  FUNC(get_av96);
885  FUNC(get_av96);
886  FUNC(get_bv96);
887  FUNC(get_day_seconds);
888  FUNC(get_disk_size);
889  FUNC(get_dof);
890  FUNC(get_far_limit);
891  FUNC(get_free_disk_space);
892  FUNC(get_focus);
893  FUNC(get_hyp_dist);
894  FUNC(get_iso_market);
895  FUNC(get_iso_mode);
896  FUNC(get_iso_real);
897  FUNC(get_jpg_count);
898  FUNC(get_near_limit);
899  FUNC(get_prop);
900  FUNC(get_raw_count);
901  FUNC(get_raw_nr);
902  FUNC(get_raw);
903  FUNC(get_sv96);
904  FUNC(get_tick_count);
905  FUNC(get_tv96);
906  FUNC(get_user_av_id);
907  FUNC(get_user_av96);
908  FUNC(get_user_tv_id);
909  FUNC(get_user_tv96);
910  FUNC(get_vbatt);
911  FUNC(get_zoom);
912  FUNC(get_exp_count);
913  FUNC(get_flash_params_count);
914  FUNC(get_parameter_data);
915
916  FUNC(set_av96_direct);
917  FUNC(set_av96);
918  FUNC(set_focus);
919  FUNC(set_iso_mode);
920  FUNC(set_iso_real);
921  FUNC(set_led);
922  FUNC(set_nd_filter);
923  FUNC(set_prop);
924  FUNC(set_raw_nr);
925  FUNC(set_raw);
926  FUNC(set_sv96);
927  FUNC(set_tv96_direct);
928  FUNC(set_tv96);
929  FUNC(set_user_av_by_id_rel);
930  FUNC(set_user_av_by_id);
931  FUNC(set_user_av96);
932  FUNC(set_user_tv_by_id_rel);
933  FUNC(set_user_tv_by_id);
934  FUNC(set_user_tv96);
935  FUNC(set_zoom_speed);
936  FUNC(set_zoom_rel);
937  FUNC(set_zoom);
938
939  FUNC(wait_click);
940  FUNC(is_pressed);
941  FUNC(is_key);
942#ifdef CAM_HAS_JOGDIAL
943  FUNC(wheel_right);
944  FUNC(wheel_left);
945#endif
946  FUNC(md_get_cell_diff);
947  FUNC(md_detect_motion);
948  FUNC(autostarted);
949  FUNC(get_autostart);
950  FUNC(set_autostart);
951  FUNC(get_usb_power);
952  FUNC(exit_alt);
953  FUNC(shut_down);
954  FUNC(print_screen);
955
956  FUNC(get_focus_mode);
957  FUNC(get_propset);
958  FUNC(get_zoom_steps);
959  FUNC(get_drive_mode);
960  FUNC(get_flash_mode);
961  FUNC(get_shooting);
962  FUNC(get_flash_ready);
963  FUNC(get_IS_mode);
964  FUNC(set_ev);
965  FUNC(get_ev);
966  FUNC(get_orientation_sensor);
967  FUNC(get_nd_present);
968  FUNC(get_movie_status);
969  FUNC(set_movie_status);
970 
971  FUNC(get_histo_range);
972  FUNC(shot_histo_enable);
973  FUNC(play_sound);
974  FUNC(get_temperature);
975  FUNC(peek);
976  FUNC(poke);
977  FUNC(bitand);
978  FUNC(bitor);
979  FUNC(bitxor);
980  FUNC(bitshl);
981  FUNC(bitshri);
982  FUNC(bitshru);
983  FUNC(bitnot);
984
985  FUNC(get_time);
986
987  FUNC(get_buildinfo);
988  FUNC(get_mode);
989 
990  FUNC(set_raw_develop);
991  // NOTE these functions normally run in the spytask.
992  // called from lua they will run from kbd task instead
993  FUNC(raw_merge_start);
994  FUNC(raw_merge_add_file);
995  FUNC(raw_merge_end);
996  FUNC(set_backlight);
997}
Note: See TracBrowser for help on using the repository browser.