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