source: trunk/core/luascript.c @ 687

Revision 687, 20.9 KB checked in by reyalp, 4 years ago (diff)

make shot_histogram memory dynamic. Allocated on shot_histo_enable(1), deallocated on disable or script end.

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