source: trunk/core/luascript.c @ 731

Revision 731, 21.2 KB checked in by reyalp, 4 years ago (diff)

fix bug in lua set_led

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