source: trunk/core/luascript.c @ 709

Revision 709, 21.1 KB checked in by phyrephox, 4 years ago (diff)

cleaning the bugtracker a bit...
s2is - remote should work as advertised now (fatal, #223)
makefiles - fixed the slashes on topdir (whim, #225)
finnish.lng - update (mikko70, #227)
lua - new command to switch custom curve state (msl, #226)
bugtracker url: https://chdk.kernreaktor.org
happy valentines day XOXO (lol)

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