| 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 "levent.h" |
|---|
| 16 | |
|---|
| 17 | #ifdef OPT_CURVES |
|---|
| 18 | #include "curves.h" |
|---|
| 19 | |
|---|
| 20 | static int luaCB_set_curve_state( lua_State* L ) |
|---|
| 21 | { |
|---|
| 22 | int value; |
|---|
| 23 | value=luaL_checknumber( L, 1 ); |
|---|
| 24 | curve_set_mode(value); |
|---|
| 25 | return 0; |
|---|
| 26 | } |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | static int luaCB_set_aflock(lua_State* L) |
|---|
| 30 | { |
|---|
| 31 | int val = luaL_checknumber(L, 1); |
|---|
| 32 | if (val>0) DoAFLock(); // 1: enable AFLock |
|---|
| 33 | else UnlockAF(); // 0: disable unlock AF |
|---|
| 34 | return 0; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | static int luaCB_shoot( lua_State* L ) |
|---|
| 39 | { |
|---|
| 40 | kbd_sched_shoot(); |
|---|
| 41 | return lua_yield( L, 0 ); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | static int luaCB_sleep( lua_State* L ) |
|---|
| 45 | { |
|---|
| 46 | kbd_sched_delay( luaL_checknumber( L, 1 ) ); |
|---|
| 47 | return lua_yield( L, 0 ); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | // for press,release and click |
|---|
| 51 | static int luaCB_keyfunc( lua_State* L ) |
|---|
| 52 | { |
|---|
| 53 | long k = keyid_by_name( luaL_checkstring( L, 1 ) ); |
|---|
| 54 | if (k > 0 ) { |
|---|
| 55 | void* func = lua_touserdata( L, lua_upvalueindex(1) ); |
|---|
| 56 | ((void(*)(long))func)( k ); |
|---|
| 57 | } |
|---|
| 58 | else |
|---|
| 59 | luaL_error( L, "unknown key" ); |
|---|
| 60 | return lua_yield( L, 0 ); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | static int luaCB_cls( lua_State* L ) |
|---|
| 64 | { |
|---|
| 65 | script_console_clear(); |
|---|
| 66 | return 0; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | static int luaCB_get_av96( lua_State* L ) |
|---|
| 70 | { |
|---|
| 71 | lua_pushnumber( L, shooting_get_av96() ); |
|---|
| 72 | return 1; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | static int luaCB_get_bv96( lua_State* L ) |
|---|
| 76 | { |
|---|
| 77 | lua_pushnumber( L, shooting_get_bv96() ); |
|---|
| 78 | return 1; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static int luaCB_get_day_seconds( lua_State* L ) |
|---|
| 82 | { |
|---|
| 83 | lua_pushnumber( L, shooting_get_day_seconds() ); |
|---|
| 84 | return 1; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | static int luaCB_get_disk_size( lua_State* L ) |
|---|
| 88 | { |
|---|
| 89 | lua_pushnumber( L, GetTotalCardSpaceKb() ); |
|---|
| 90 | return 1; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | static int luaCB_get_dof( lua_State* L ) |
|---|
| 94 | { |
|---|
| 95 | lua_pushnumber( L, shooting_get_depth_of_field() ); |
|---|
| 96 | return 1; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | static int luaCB_get_far_limit( lua_State* L ) |
|---|
| 100 | { |
|---|
| 101 | lua_pushnumber( L, shooting_get_far_limit_of_acceptable_sharpness() ); |
|---|
| 102 | return 1; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | static int luaCB_get_free_disk_space( lua_State* L ) |
|---|
| 106 | { |
|---|
| 107 | lua_pushnumber( L, GetFreeCardSpaceKb() ); |
|---|
| 108 | return 1; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | static int luaCB_get_focus( lua_State* L ) |
|---|
| 112 | { |
|---|
| 113 | lua_pushnumber( L, shooting_get_subject_distance() ); |
|---|
| 114 | return 1; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | static int luaCB_get_hyp_dist( lua_State* L ) |
|---|
| 118 | { |
|---|
| 119 | lua_pushnumber( L, shooting_get_hyperfocal_distance() ); |
|---|
| 120 | return 1; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | static int luaCB_get_iso_market( lua_State* L ) |
|---|
| 124 | { |
|---|
| 125 | lua_pushnumber( L, shooting_get_iso_market() ); |
|---|
| 126 | return 1; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | static int luaCB_get_iso_mode( lua_State* L ) |
|---|
| 130 | { |
|---|
| 131 | lua_pushnumber( L, shooting_get_iso_mode() ); |
|---|
| 132 | return 1; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | static int luaCB_get_iso_real( lua_State* L ) |
|---|
| 136 | { |
|---|
| 137 | lua_pushnumber( L, shooting_get_iso_real() ); |
|---|
| 138 | return 1; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | static int luaCB_get_jpg_count( lua_State* L ) |
|---|
| 142 | { |
|---|
| 143 | lua_pushnumber( L, GetJpgCount() ); |
|---|
| 144 | return 1; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | static int luaCB_get_near_limit( lua_State* L ) |
|---|
| 148 | { |
|---|
| 149 | lua_pushnumber( L, shooting_get_near_limit_of_acceptable_sharpness() ); |
|---|
| 150 | return 1; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | static int luaCB_get_prop( lua_State* L ) |
|---|
| 154 | { |
|---|
| 155 | lua_pushnumber( L, shooting_get_prop( luaL_checknumber( L, 1 ) ) ); |
|---|
| 156 | return 1; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | static int luaCB_get_raw_count( lua_State* L ) |
|---|
| 160 | { |
|---|
| 161 | lua_pushnumber( L, GetRawCount() ); |
|---|
| 162 | return 1; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | static int luaCB_get_sv96( lua_State* L ) |
|---|
| 166 | { |
|---|
| 167 | lua_pushnumber( L, shooting_get_sv96() ); |
|---|
| 168 | return 1; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | static int luaCB_get_tick_count( lua_State* L ) |
|---|
| 172 | { |
|---|
| 173 | lua_pushnumber( L, shooting_get_tick_count() ); |
|---|
| 174 | return 1; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | static int luaCB_get_exp_count( lua_State* L ) |
|---|
| 178 | { |
|---|
| 179 | lua_pushnumber( L, get_exposure_counter() ); |
|---|
| 180 | return 1; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | static int luaCB_get_tv96( lua_State* L ) |
|---|
| 184 | { |
|---|
| 185 | lua_pushnumber( L, shooting_get_tv96() ); |
|---|
| 186 | return 1; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | static int luaCB_get_user_av_id( lua_State* L ) |
|---|
| 190 | { |
|---|
| 191 | lua_pushnumber( L, shooting_get_user_av_id() ); |
|---|
| 192 | return 1; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | static int luaCB_get_user_av96( lua_State* L ) |
|---|
| 196 | { |
|---|
| 197 | lua_pushnumber( L, shooting_get_user_av96() ); |
|---|
| 198 | return 1; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | static int luaCB_get_user_tv_id( lua_State* L ) |
|---|
| 202 | { |
|---|
| 203 | lua_pushnumber( L, shooting_get_user_tv_id() ); |
|---|
| 204 | return 1; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | static int luaCB_get_user_tv96( lua_State* L ) |
|---|
| 208 | { |
|---|
| 209 | lua_pushnumber( L, shooting_get_user_tv_id() ); |
|---|
| 210 | return 1; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | static int luaCB_get_vbatt( lua_State* L ) |
|---|
| 214 | { |
|---|
| 215 | lua_pushnumber( L, stat_get_vbatt() ); |
|---|
| 216 | return 1; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | static int luaCB_get_zoom( lua_State* L ) |
|---|
| 220 | { |
|---|
| 221 | lua_pushnumber( L, shooting_get_zoom() ); |
|---|
| 222 | return 1; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | static int luaCB_get_parameter_data( lua_State* L ) |
|---|
| 226 | { |
|---|
| 227 | extern long* FlashParamsTable[]; |
|---|
| 228 | |
|---|
| 229 | unsigned size; |
|---|
| 230 | unsigned id = luaL_checknumber( L, 1 ); |
|---|
| 231 | unsigned val; |
|---|
| 232 | |
|---|
| 233 | if (id >= get_flash_params_count()) { |
|---|
| 234 | // return nil |
|---|
| 235 | return 0; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | size = FlashParamsTable[id][1]>>16; |
|---|
| 239 | if (size == 0) { |
|---|
| 240 | // return nil |
|---|
| 241 | return 0; |
|---|
| 242 | } |
|---|
| 243 | if (size >= 1 && size <= 4) { |
|---|
| 244 | val = 0; |
|---|
| 245 | get_parameter_data( id, &val, size ); |
|---|
| 246 | lua_pushlstring( L, (char *)&val, size ); |
|---|
| 247 | // for convenience, params that fit in a number are returned in one as a second result |
|---|
| 248 | lua_pushnumber( L, val ); |
|---|
| 249 | return 2; |
|---|
| 250 | } |
|---|
| 251 | else { |
|---|
| 252 | char *buf = malloc(size); |
|---|
| 253 | if(!buf) { |
|---|
| 254 | luaL_error( L, "malloc failed in luaCB_get_parameter_data" ); |
|---|
| 255 | } |
|---|
| 256 | get_parameter_data( id, buf, size ); |
|---|
| 257 | lua_pushlstring( L, buf, size ); |
|---|
| 258 | free(buf); |
|---|
| 259 | return 1; |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | static int luaCB_get_flash_params_count( lua_State* L ) |
|---|
| 264 | { |
|---|
| 265 | lua_pushnumber( L, get_flash_params_count() ); |
|---|
| 266 | return 1; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | static int luaCB_set_av96_direct( lua_State* L ) |
|---|
| 270 | { |
|---|
| 271 | shooting_set_av96_direct( luaL_checknumber( L, 1 ), SET_LATER ); |
|---|
| 272 | return 0; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | static int luaCB_set_av96( lua_State* L ) |
|---|
| 276 | { |
|---|
| 277 | shooting_set_av96( luaL_checknumber( L, 1 ), SET_LATER ); |
|---|
| 278 | return 0; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | static int luaCB_set_focus( lua_State* L ) |
|---|
| 282 | { |
|---|
| 283 | int to = luaL_checknumber( L, 1 ); |
|---|
| 284 | int m=mode_get()&MODE_SHOOTING_MASK; |
|---|
| 285 | int mode_video=MODE_IS_VIDEO(m); |
|---|
| 286 | |
|---|
| 287 | #if CAM_HAS_MANUAL_FOCUS |
|---|
| 288 | if (shooting_get_focus_mode() || (mode_video)) shooting_set_focus(to, SET_NOW); |
|---|
| 289 | else shooting_set_focus(to, SET_LATER); |
|---|
| 290 | #else |
|---|
| 291 | if (mode_video) shooting_set_focus(to, SET_NOW); |
|---|
| 292 | else shooting_set_focus(to, SET_LATER); |
|---|
| 293 | #endif |
|---|
| 294 | return 0; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | static int luaCB_set_iso_mode( lua_State* L ) |
|---|
| 298 | { |
|---|
| 299 | shooting_set_iso_mode( luaL_checknumber( L, 1 ) ); |
|---|
| 300 | return 0; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | static int luaCB_set_iso_real( lua_State* L ) |
|---|
| 304 | { |
|---|
| 305 | shooting_set_iso_real( luaL_checknumber( L, 1 ), SET_LATER); |
|---|
| 306 | return 0; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | static int luaCB_set_led( lua_State* L ) |
|---|
| 310 | { |
|---|
| 311 | int to, to1, to2; |
|---|
| 312 | to = luaL_checknumber( L, 1 ); |
|---|
| 313 | to1 = luaL_checknumber( L, 2 ); |
|---|
| 314 | to2 = 200; |
|---|
| 315 | if( lua_isnumber( L, 3 ) ) |
|---|
| 316 | to2 = lua_tonumber( L, 3 ); |
|---|
| 317 | ubasic_set_led(to, to1, to2); |
|---|
| 318 | return 0; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | static int luaCB_set_nd_filter( lua_State* L ) |
|---|
| 322 | { |
|---|
| 323 | shooting_set_nd_filter_state( luaL_checknumber( L, 1 ), SET_LATER); |
|---|
| 324 | return 0; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | static int luaCB_set_prop( lua_State* L ) |
|---|
| 328 | { |
|---|
| 329 | int to, to1; |
|---|
| 330 | to = luaL_checknumber( L, 1 ); |
|---|
| 331 | to1 = luaL_checknumber( L, 2 ); |
|---|
| 332 | shooting_set_prop(to, to1); |
|---|
| 333 | return 0; |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | static int luaCB_set_raw_nr( lua_State* L ) |
|---|
| 337 | { |
|---|
| 338 | ubasic_camera_set_nr(luaL_checknumber( L, 1 )); |
|---|
| 339 | return 0; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | static int luaCB_get_raw_nr( lua_State* L ) |
|---|
| 343 | { |
|---|
| 344 | lua_pushnumber( L, ubasic_camera_get_nr() ); |
|---|
| 345 | return 1; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | static int luaCB_set_raw( lua_State* L ) |
|---|
| 349 | { |
|---|
| 350 | ubasic_camera_set_raw(luaL_checknumber( L, 1 )); |
|---|
| 351 | return 0; |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | static int luaCB_get_raw( lua_State* L ) |
|---|
| 355 | { |
|---|
| 356 | lua_pushnumber( L, conf.save_raw ); |
|---|
| 357 | return 1; |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | static int luaCB_set_sv96( lua_State* L ) |
|---|
| 361 | { |
|---|
| 362 | shooting_set_sv96(luaL_checknumber( L, 1 ), SET_LATER); |
|---|
| 363 | return 0; |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | static int luaCB_set_tv96_direct( lua_State* L ) |
|---|
| 367 | { |
|---|
| 368 | shooting_set_tv96_direct(luaL_checknumber( L, 1 ), SET_LATER); |
|---|
| 369 | return 0; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | static int luaCB_set_tv96( lua_State* L ) |
|---|
| 373 | { |
|---|
| 374 | shooting_set_tv96(luaL_checknumber( L, 1 ), SET_LATER); |
|---|
| 375 | return 0; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | static int luaCB_set_user_av_by_id_rel( lua_State* L ) |
|---|
| 379 | { |
|---|
| 380 | shooting_set_user_av_by_id_rel(luaL_checknumber( L, 1 )); |
|---|
| 381 | return 0; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | static int luaCB_set_user_av_by_id( lua_State* L ) |
|---|
| 385 | { |
|---|
| 386 | shooting_set_user_av_by_id(luaL_checknumber( L, 1 )); |
|---|
| 387 | return 0; |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | static int luaCB_set_user_av96( lua_State* L ) |
|---|
| 391 | { |
|---|
| 392 | shooting_set_user_av96(luaL_checknumber( L, 1 )); |
|---|
| 393 | return 0; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | static int luaCB_set_user_tv_by_id_rel( lua_State* L ) |
|---|
| 397 | { |
|---|
| 398 | shooting_set_user_tv_by_id_rel(luaL_checknumber( L, 1 )); |
|---|
| 399 | return 0; |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | static int luaCB_set_user_tv_by_id( lua_State* L ) |
|---|
| 403 | { |
|---|
| 404 | shooting_set_user_tv_by_id(luaL_checknumber( L, 1 )); |
|---|
| 405 | return 0; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | static int luaCB_set_user_tv96( lua_State* L ) |
|---|
| 409 | { |
|---|
| 410 | shooting_set_user_tv96(luaL_checknumber( L, 1 )); |
|---|
| 411 | return 0; |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | static int luaCB_set_zoom_speed( lua_State* L ) |
|---|
| 415 | { |
|---|
| 416 | shooting_set_zoom_speed(luaL_checknumber( L, 1 )); |
|---|
| 417 | return 0; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | static int luaCB_set_zoom_rel( lua_State* L ) |
|---|
| 421 | { |
|---|
| 422 | shooting_set_zoom_rel(luaL_checknumber( L, 1 )); |
|---|
| 423 | return 0; |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | static int luaCB_set_zoom( lua_State* L ) |
|---|
| 427 | { |
|---|
| 428 | shooting_set_zoom(luaL_checknumber( L, 1 )); |
|---|
| 429 | return 0; |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | static int luaCB_wait_click( lua_State* L ) |
|---|
| 433 | { |
|---|
| 434 | int timeout = luaL_optnumber( L, 1, 0 ); |
|---|
| 435 | ubasic_camera_wait_click(timeout); |
|---|
| 436 | return lua_yield( L, 0 ); |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | static int luaCB_is_pressed( lua_State* L ) |
|---|
| 440 | { |
|---|
| 441 | lua_pushboolean( L, ubasic_camera_is_pressed(luaL_checkstring( L, 1 ))); |
|---|
| 442 | return 1; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | static int luaCB_is_key( lua_State* L ) |
|---|
| 446 | { |
|---|
| 447 | lua_pushboolean( L, ubasic_camera_is_clicked(luaL_checkstring( L, 1 ))); |
|---|
| 448 | return 1; |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | #if CAM_HAS_JOGDIAL |
|---|
| 452 | static int luaCB_wheel_right( lua_State* L ) |
|---|
| 453 | { |
|---|
| 454 | JogDial_CW(); |
|---|
| 455 | return 0; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | static int luaCB_wheel_left( lua_State* L ) |
|---|
| 459 | { |
|---|
| 460 | JogDial_CCW(); |
|---|
| 461 | return 0; |
|---|
| 462 | } |
|---|
| 463 | #endif |
|---|
| 464 | |
|---|
| 465 | static int luaCB_md_get_cell_diff( lua_State* L ) |
|---|
| 466 | { |
|---|
| 467 | lua_pushnumber( L, md_get_cell_diff(luaL_checknumber(L,1), |
|---|
| 468 | luaL_checknumber(L,2))); |
|---|
| 469 | return 1; |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | static int luaCB_md_detect_motion( lua_State* L ) |
|---|
| 473 | { |
|---|
| 474 | int columns = (luaL_optnumber(L,1,6)); |
|---|
| 475 | int rows = (luaL_optnumber(L,2,4)); |
|---|
| 476 | int pixel_measure_mode = (luaL_optnumber(L,3,1)); |
|---|
| 477 | int detection_timeout = (luaL_optnumber(L,4,10000)); |
|---|
| 478 | int measure_interval = (luaL_optnumber(L,5,7)); |
|---|
| 479 | int threshold = (luaL_optnumber(L,6,10)); |
|---|
| 480 | int draw_grid = (luaL_optnumber(L,7,1)); |
|---|
| 481 | // arg 8 is the return value in ubasic. We |
|---|
| 482 | // ignore it here. - AUJ |
|---|
| 483 | int clipping_region_mode = (luaL_optnumber(L,9,0)); |
|---|
| 484 | int clipping_region_column1 = (luaL_optnumber(L,10,0)); |
|---|
| 485 | int clipping_region_row1 = (luaL_optnumber(L,11,0)); |
|---|
| 486 | int clipping_region_column2 = (luaL_optnumber(L,12,0)); |
|---|
| 487 | int clipping_region_row2 = (luaL_optnumber(L,13,0)); |
|---|
| 488 | int parameters = (luaL_optnumber(L,14,1)); |
|---|
| 489 | int pixels_step = (luaL_optnumber(L,15,6)); |
|---|
| 490 | int msecs_before_trigger = (luaL_optnumber(L,16,0)); |
|---|
| 491 | ubasic_set_variable(0, 0); |
|---|
| 492 | if(md_init_motion_detector( |
|---|
| 493 | columns, rows, pixel_measure_mode, detection_timeout, |
|---|
| 494 | measure_interval, threshold, draw_grid, 0, |
|---|
| 495 | clipping_region_mode, |
|---|
| 496 | clipping_region_column1, clipping_region_row1, |
|---|
| 497 | clipping_region_column2, clipping_region_row2, |
|---|
| 498 | parameters, pixels_step, msecs_before_trigger |
|---|
| 499 | )) |
|---|
| 500 | return lua_yield(L, 0); |
|---|
| 501 | else |
|---|
| 502 | return luaL_error( L, "md_init_motion_detector failed" ); |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | static int luaCB_autostarted( lua_State* L ) |
|---|
| 506 | { |
|---|
| 507 | lua_pushboolean( L, ubasic_camera_script_autostart() ); |
|---|
| 508 | return 1; |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | static int luaCB_get_autostart( lua_State* L ) |
|---|
| 512 | { |
|---|
| 513 | lua_pushnumber( L, conf.script_startup ); |
|---|
| 514 | return 1; |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | static int luaCB_set_autostart( lua_State* L ) |
|---|
| 518 | { |
|---|
| 519 | int to; |
|---|
| 520 | to = luaL_checknumber( L, 1 ); |
|---|
| 521 | if ( to >= 0 && to <= 2 ) conf.script_startup = to; |
|---|
| 522 | conf_save(); |
|---|
| 523 | return 0; |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | static int luaCB_get_usb_power( lua_State* L ) |
|---|
| 527 | { |
|---|
| 528 | if (luaL_optnumber( L, 1, 0 )) lua_pushnumber( L, get_usb_power(1) ); |
|---|
| 529 | else lua_pushnumber( L, get_usb_power(0) ); |
|---|
| 530 | return 1; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | static int luaCB_exit_alt( lua_State* L ) |
|---|
| 534 | { |
|---|
| 535 | exit_alt(); |
|---|
| 536 | return 0; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | static int luaCB_shut_down( lua_State* L ) |
|---|
| 540 | { |
|---|
| 541 | camera_shutdown_in_a_second(); |
|---|
| 542 | return 0; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | static int luaCB_print_screen( lua_State* L ) |
|---|
| 546 | { |
|---|
| 547 | |
|---|
| 548 | if (lua_isboolean( L, 1 )) |
|---|
| 549 | script_print_screen_statement( lua_toboolean( L, 1 ) ); |
|---|
| 550 | else |
|---|
| 551 | script_print_screen_statement( luaL_checknumber( L, 1 )+10000 ); |
|---|
| 552 | return 0; |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | static int luaCB_get_movie_status( lua_State* L ) |
|---|
| 556 | { |
|---|
| 557 | lua_pushnumber( L, movie_status ); |
|---|
| 558 | return 1; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | static int luaCB_set_movie_status( lua_State* L ) |
|---|
| 562 | { |
|---|
| 563 | int to; |
|---|
| 564 | switch(luaL_checknumber( L, 1 )) { |
|---|
| 565 | case 1: |
|---|
| 566 | if (movie_status == 4) { |
|---|
| 567 | movie_status = 1; |
|---|
| 568 | } |
|---|
| 569 | break; |
|---|
| 570 | case 2: |
|---|
| 571 | if (movie_status == 1) { |
|---|
| 572 | movie_status = 4; |
|---|
| 573 | } |
|---|
| 574 | break; |
|---|
| 575 | case 3: |
|---|
| 576 | if (movie_status == 1 || movie_status == 4) { |
|---|
| 577 | movie_status = 5; |
|---|
| 578 | } |
|---|
| 579 | break; |
|---|
| 580 | } |
|---|
| 581 | return 0; |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | static int luaCB_get_drive_mode( lua_State* L ) |
|---|
| 585 | { |
|---|
| 586 | lua_pushnumber( L, shooting_get_drive_mode() ); |
|---|
| 587 | return 1; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | static int luaCB_get_focus_mode( lua_State* L ) |
|---|
| 591 | { |
|---|
| 592 | lua_pushnumber( L, shooting_get_prop(PROPCASE_FOCUS_MODE) ); |
|---|
| 593 | return 1; |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | static int luaCB_get_flash_mode( lua_State* L ) |
|---|
| 597 | { |
|---|
| 598 | lua_pushnumber( L, shooting_get_prop(PROPCASE_FLASH_MODE) ); |
|---|
| 599 | return 1; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | static int luaCB_get_shooting( lua_State* L ) |
|---|
| 603 | { |
|---|
| 604 | lua_pushboolean( L, shooting_get_prop(PROPCASE_SHOOTING) ); |
|---|
| 605 | return 1; |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | static int luaCB_get_flash_ready( lua_State* L ) |
|---|
| 609 | { |
|---|
| 610 | lua_pushboolean( L, shooting_get_prop(PROPCASE_IS_FLASH_READY) ); |
|---|
| 611 | return 1; |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | static int luaCB_get_IS_mode( lua_State* L ) |
|---|
| 615 | { |
|---|
| 616 | lua_pushnumber( L, shooting_get_prop(PROPCASE_IS_MODE) ); |
|---|
| 617 | return 1; |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | static int luaCB_get_orientation_sensor( lua_State* L ) |
|---|
| 621 | { |
|---|
| 622 | lua_pushnumber( L, shooting_get_prop(PROPCASE_ORIENTATION_SENSOR) ); |
|---|
| 623 | return 1; |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | static int luaCB_get_zoom_steps( lua_State* L ) |
|---|
| 627 | { |
|---|
| 628 | lua_pushnumber( L, zoom_points ); |
|---|
| 629 | return 1; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | static int luaCB_get_nd_present( lua_State* L ) |
|---|
| 633 | { |
|---|
| 634 | int to; |
|---|
| 635 | #if !CAM_HAS_ND_FILTER |
|---|
| 636 | to = 0; |
|---|
| 637 | #endif |
|---|
| 638 | #if CAM_HAS_ND_FILTER && !CAM_HAS_IRIS_DIAPHRAGM |
|---|
| 639 | to = 1; |
|---|
| 640 | #endif |
|---|
| 641 | #if CAM_HAS_ND_FILTER && CAM_HAS_IRIS_DIAPHRAGM |
|---|
| 642 | to = 2; |
|---|
| 643 | #endif |
|---|
| 644 | lua_pushnumber( L, to ); |
|---|
| 645 | return 1; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | static int luaCB_get_propset( lua_State* L ) |
|---|
| 649 | { |
|---|
| 650 | lua_pushnumber( L, CAM_PROPSET ); |
|---|
| 651 | return 1; |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | static int luaCB_get_ev( lua_State* L ) |
|---|
| 655 | { |
|---|
| 656 | lua_pushnumber( L, shooting_get_prop(PROPCASE_EV_CORRECTION_1) ); |
|---|
| 657 | return 1; |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | static int luaCB_set_ev( lua_State* L ) |
|---|
| 661 | { |
|---|
| 662 | int to; |
|---|
| 663 | to = luaL_checknumber( L, 1 ); |
|---|
| 664 | shooting_set_prop(PROPCASE_EV_CORRECTION_1, to); |
|---|
| 665 | shooting_set_prop(PROPCASE_EV_CORRECTION_2, to); |
|---|
| 666 | return 0; |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | static int luaCB_get_histo_range( lua_State* L ) |
|---|
| 670 | { |
|---|
| 671 | int from = (luaL_checknumber(L,1)); |
|---|
| 672 | int to = (luaL_checknumber(L,2)); |
|---|
| 673 | if (shot_histogram_isenabled()) lua_pushnumber( L, shot_histogram_get_range(from, to) ); |
|---|
| 674 | else lua_pushnumber( L, -1 ); // TODO should probably return nil |
|---|
| 675 | return 1; |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | static int luaCB_shot_histo_enable( lua_State* L ) |
|---|
| 679 | { |
|---|
| 680 | shot_histogram_set(luaL_checknumber( L, 1 )); |
|---|
| 681 | return 0; |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | static int luaCB_play_sound( lua_State* L ) |
|---|
| 685 | { |
|---|
| 686 | play_sound(luaL_checknumber( L, 1 )); |
|---|
| 687 | return 0; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | static int luaCB_get_temperature( lua_State* L ) |
|---|
| 691 | { |
|---|
| 692 | int which = (luaL_checknumber( L, 1 )); |
|---|
| 693 | int temp = -100; // do something insane if users passes bad value |
|---|
| 694 | switch (which) |
|---|
| 695 | { |
|---|
| 696 | case 0: |
|---|
| 697 | temp = get_optical_temp(); |
|---|
| 698 | break; |
|---|
| 699 | case 1: |
|---|
| 700 | temp = get_ccd_temp(); |
|---|
| 701 | break; |
|---|
| 702 | case 2: |
|---|
| 703 | temp = get_battery_temp(); |
|---|
| 704 | break; |
|---|
| 705 | } |
|---|
| 706 | lua_pushnumber( L, temp ); |
|---|
| 707 | return 1; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | static int luaCB_get_time( lua_State* L ) |
|---|
| 711 | { |
|---|
| 712 | int r = -1; |
|---|
| 713 | unsigned long t2 = time(NULL); |
|---|
| 714 | static struct tm *ttm; |
|---|
| 715 | ttm = localtime(&t2); |
|---|
| 716 | const char *t = luaL_checkstring( L, 1 ); |
|---|
| 717 | if (strncmp("s", t, 1)==0) r = ( L, ttm->tm_sec ); |
|---|
| 718 | else if (strncmp("m", t, 1)==0) r = ( L, ttm->tm_min ); |
|---|
| 719 | else if (strncmp("h", t, 1)==0) r = ( L, ttm->tm_hour ); |
|---|
| 720 | else if (strncmp("D", t, 1)==0) r = ( L, ttm->tm_mday ); |
|---|
| 721 | else if (strncmp("M", t, 1)==0) r = ( L, ttm->tm_mon+1 ); |
|---|
| 722 | else if (strncmp("Y", t, 1)==0) r = ( L, 1900+ttm->tm_year ); |
|---|
| 723 | lua_pushnumber( L, r ); |
|---|
| 724 | return 1; |
|---|
| 725 | } |
|---|
| 726 | |
|---|
| 727 | static int luaCB_peek( lua_State* L ) |
|---|
| 728 | { |
|---|
| 729 | int addr = (luaL_checknumber(L,1)); |
|---|
| 730 | // must be alligned |
|---|
| 731 | if (addr & 0x3) { |
|---|
| 732 | lua_pushnil(L); |
|---|
| 733 | } |
|---|
| 734 | else { |
|---|
| 735 | lua_pushnumber( L, *(unsigned *)(addr) ); |
|---|
| 736 | } |
|---|
| 737 | return 1; |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | static int luaCB_poke( lua_State* L ) |
|---|
| 741 | { |
|---|
| 742 | int addr = (luaL_checknumber(L,1)); |
|---|
| 743 | int val = (luaL_checknumber(L,2)); |
|---|
| 744 | if (addr & 0x3) { |
|---|
| 745 | lua_pushnil(L); |
|---|
| 746 | } |
|---|
| 747 | else { |
|---|
| 748 | *(unsigned *)(addr) = val; |
|---|
| 749 | lua_pushboolean(L,1); |
|---|
| 750 | } |
|---|
| 751 | return 1; |
|---|
| 752 | } |
|---|
| 753 | |
|---|
| 754 | static int luaCB_bitand( lua_State* L ) |
|---|
| 755 | { |
|---|
| 756 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 757 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 758 | lua_pushnumber( L, v1 & v2 ); |
|---|
| 759 | return 1; |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | static int luaCB_bitor( lua_State* L ) |
|---|
| 763 | { |
|---|
| 764 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 765 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 766 | lua_pushnumber( L, v1 | v2 ); |
|---|
| 767 | return 1; |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | static int luaCB_bitxor( lua_State* L ) |
|---|
| 771 | { |
|---|
| 772 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 773 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 774 | lua_pushnumber( L, v1 ^ v2 ); |
|---|
| 775 | return 1; |
|---|
| 776 | } |
|---|
| 777 | |
|---|
| 778 | static int luaCB_bitshl( lua_State* L ) |
|---|
| 779 | { |
|---|
| 780 | int val = (luaL_checknumber(L,1)); |
|---|
| 781 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 782 | lua_pushnumber( L, val << shift ); |
|---|
| 783 | return 1; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | static int luaCB_bitshri( lua_State* L ) |
|---|
| 787 | { |
|---|
| 788 | int val = (luaL_checknumber(L,1)); |
|---|
| 789 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 790 | lua_pushnumber( L, val >> shift ); |
|---|
| 791 | return 1; |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | static int luaCB_bitshru( lua_State* L ) |
|---|
| 795 | { |
|---|
| 796 | unsigned val = (luaL_checknumber(L,1)); |
|---|
| 797 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 798 | lua_pushnumber( L, val >> shift ); |
|---|
| 799 | return 1; |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | static int luaCB_bitnot( lua_State* L ) |
|---|
| 803 | { |
|---|
| 804 | unsigned val = (luaL_checknumber(L,1)); |
|---|
| 805 | lua_pushnumber( L, ~val ); |
|---|
| 806 | return 1; |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | static void set_string_field(lua_State* L, const char *key, const char *val) |
|---|
| 810 | { |
|---|
| 811 | lua_pushstring(L, val); |
|---|
| 812 | lua_setfield(L, -2, key); |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | static int luaCB_get_buildinfo( lua_State* L ) |
|---|
| 816 | { |
|---|
| 817 | lua_createtable(L, 0, 8); |
|---|
| 818 | set_string_field( L,"platform", PLATFORM ); |
|---|
| 819 | set_string_field( L,"platsub", PLATFORMSUB ); |
|---|
| 820 | set_string_field( L,"version", HDK_VERSION ); |
|---|
| 821 | set_string_field( L,"build_number", BUILD_NUMBER ); |
|---|
| 822 | set_string_field( L,"build_date", __DATE__ ); |
|---|
| 823 | set_string_field( L,"build_time", __TIME__ ); |
|---|
| 824 | #ifndef CAM_DRYOS |
|---|
| 825 | set_string_field( L,"os", "vxworks" ); |
|---|
| 826 | #else |
|---|
| 827 | set_string_field( L,"os", "dryos" ); |
|---|
| 828 | #endif |
|---|
| 829 | lua_pushnumber( L, PLATFORMID ); |
|---|
| 830 | lua_setfield(L, -2, "platformid"); |
|---|
| 831 | return 1; |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | static int luaCB_get_mode( lua_State* L ) |
|---|
| 835 | { |
|---|
| 836 | int m = mode_get(); |
|---|
| 837 | lua_pushboolean( L, (m&MODE_MASK) != MODE_PLAY ); |
|---|
| 838 | lua_pushboolean( L, MODE_IS_VIDEO(m) ); |
|---|
| 839 | lua_pushnumber( L, m ); |
|---|
| 840 | return 3; |
|---|
| 841 | } |
|---|
| 842 | |
|---|
| 843 | // TODO sanity check file ? |
|---|
| 844 | static int luaCB_set_raw_develop( lua_State* L ) |
|---|
| 845 | { |
|---|
| 846 | raw_prepare_develop(luaL_optstring( L, 1, NULL )); |
|---|
| 847 | return 0; |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | static int luaCB_raw_merge_start( lua_State* L ) |
|---|
| 851 | { |
|---|
| 852 | int op = luaL_checknumber(L,1); |
|---|
| 853 | if (op == RAW_OPERATION_SUM || op == RAW_OPERATION_AVERAGE) { |
|---|
| 854 | raw_merge_start(op); |
|---|
| 855 | } |
|---|
| 856 | else { |
|---|
| 857 | return luaL_argerror(L,1,"invalid raw merge op"); |
|---|
| 858 | } |
|---|
| 859 | return 0; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | // TODO sanity check file ? |
|---|
| 863 | static int luaCB_raw_merge_add_file( lua_State* L ) |
|---|
| 864 | { |
|---|
| 865 | raw_merge_add_file(luaL_checkstring( L, 1 )); |
|---|
| 866 | return 0; |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | static int luaCB_raw_merge_end( lua_State* L ) |
|---|
| 870 | { |
|---|
| 871 | raw_merge_end(); |
|---|
| 872 | return 0; |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | // Enable/disable LCD back light (input argument 1/0) |
|---|
| 876 | static int luaCB_set_backlight( lua_State* L ) |
|---|
| 877 | { |
|---|
| 878 | int val = (luaL_checknumber(L,1)); |
|---|
| 879 | |
|---|
| 880 | if (val > 0) TurnOnBackLight(); |
|---|
| 881 | else TurnOffBackLight(); |
|---|
| 882 | return 0; |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | // get the string or number passed in index and return it as an event id |
|---|
| 886 | static unsigned levent_id_from_lua_arg( lua_State* L, int index) |
|---|
| 887 | { |
|---|
| 888 | unsigned event_id; |
|---|
| 889 | if (lua_type(L, index) == LUA_TSTRING) { |
|---|
| 890 | const char *ev_name = lua_tostring(L, index); |
|---|
| 891 | event_id = levent_id_for_name(ev_name); |
|---|
| 892 | if (event_id == 0) { |
|---|
| 893 | return luaL_error( L, "bad event name '%s'", ev_name ); |
|---|
| 894 | } |
|---|
| 895 | } |
|---|
| 896 | // could check here if it is in the table, but even valid ones can crash |
|---|
| 897 | // so we avoid searching the table if given a number |
|---|
| 898 | else if (lua_type(L,index) == LUA_TNUMBER){ |
|---|
| 899 | event_id = lua_tonumber(L,index); |
|---|
| 900 | } |
|---|
| 901 | else { |
|---|
| 902 | return luaL_error( L, "expected event name or id" ); |
|---|
| 903 | } |
|---|
| 904 | return event_id; |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | /* |
|---|
| 908 | get a value where boolean or 0/!0 are accepted for on/off. |
|---|
| 909 | normal lua toboolean will convert 0 to true, but ubasic and c users |
|---|
| 910 | will expect 0 to be off |
|---|
| 911 | intentional HACK: numbers greater than 1 are returned as is |
|---|
| 912 | */ |
|---|
| 913 | static unsigned on_off_value_from_lua_arg( lua_State* L, int index) |
|---|
| 914 | { |
|---|
| 915 | if( lua_isboolean(L,index) ) { |
|---|
| 916 | return lua_toboolean(L,index); |
|---|
| 917 | } |
|---|
| 918 | else { |
|---|
| 919 | return luaL_checknumber(L,index); |
|---|
| 920 | } |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | /* |
|---|
| 924 | return the index of an event, given it's name or event id |
|---|
| 925 | */ |
|---|
| 926 | static unsigned levent_index_from_id_lua_arg( lua_State* L, int index ) |
|---|
| 927 | { |
|---|
| 928 | if (lua_type(L, index) == LUA_TSTRING) { |
|---|
| 929 | return levent_index_for_name(lua_tostring(L, index)); |
|---|
| 930 | } |
|---|
| 931 | else if (lua_type(L,index) == LUA_TNUMBER){ |
|---|
| 932 | return levent_index_for_id(lua_tonumber(L,index)); |
|---|
| 933 | } |
|---|
| 934 | else { |
|---|
| 935 | return luaL_error( L, "expected string or number" ); |
|---|
| 936 | } |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | /* |
|---|
| 940 | name,id,param = get_levent_def(event) |
|---|
| 941 | event is an event id (number) or name (string) |
|---|
| 942 | returns nil if event is not found |
|---|
| 943 | */ |
|---|
| 944 | static int luaCB_get_levent_def( lua_State* L ) |
|---|
| 945 | { |
|---|
| 946 | unsigned event_index = levent_index_from_id_lua_arg(L,1); |
|---|
| 947 | if (event_index == LEVENT_INVALID_INDEX) { |
|---|
| 948 | lua_pushnil(L); |
|---|
| 949 | return 1; |
|---|
| 950 | } |
|---|
| 951 | lua_pushstring(L, levent_table[event_index].name); |
|---|
| 952 | lua_pushnumber(L, levent_table[event_index].id); |
|---|
| 953 | lua_pushnumber(L, levent_table[event_index].param); |
|---|
| 954 | return 3; |
|---|
| 955 | } |
|---|
| 956 | |
|---|
| 957 | /* |
|---|
| 958 | index=get_levent_index(event) |
|---|
| 959 | event is an event id (number) or name (string) |
|---|
| 960 | returns index or nil if not found |
|---|
| 961 | */ |
|---|
| 962 | static int luaCB_get_levent_index( lua_State* L ) |
|---|
| 963 | { |
|---|
| 964 | unsigned event_index = levent_index_from_id_lua_arg(L,1); |
|---|
| 965 | if (event_index == LEVENT_INVALID_INDEX) { |
|---|
| 966 | lua_pushnil(L); |
|---|
| 967 | } |
|---|
| 968 | else { |
|---|
| 969 | lua_pushnumber(L, event_index); |
|---|
| 970 | } |
|---|
| 971 | return 1; |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | /* |
|---|
| 975 | name,id,param = get_levent_def_by_index(event_index) |
|---|
| 976 | event_index is number index into the event table |
|---|
| 977 | returns nil if event is not found |
|---|
| 978 | */ |
|---|
| 979 | static int luaCB_get_levent_def_by_index( lua_State* L ) |
|---|
| 980 | { |
|---|
| 981 | unsigned i = luaL_checknumber(L,1); |
|---|
| 982 | if(i >= levent_count()) { |
|---|
| 983 | lua_pushnil(L); |
|---|
| 984 | return 1; |
|---|
| 985 | } |
|---|
| 986 | lua_pushstring(L, levent_table[i].name); |
|---|
| 987 | lua_pushnumber(L, levent_table[i].id); |
|---|
| 988 | lua_pushnumber(L, levent_table[i].param); |
|---|
| 989 | return 3; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | /* |
|---|
| 993 | post_levent_*(event[,unk]) |
|---|
| 994 | post the event with PostLogicalEventToUI or PostLogicaEventForNotPowerType |
|---|
| 995 | This sends the event. The difference between functions isn't clear. |
|---|
| 996 | event is an event id (number) or name (string). |
|---|
| 997 | unk is an optional number whose meaning is unknown, defaults to zero. |
|---|
| 998 | Based on code, other values would probably be a pointer. |
|---|
| 999 | This is NOT the 3rd item in the event table. |
|---|
| 1000 | */ |
|---|
| 1001 | static int luaCB_post_levent_to_ui( lua_State* L ) |
|---|
| 1002 | { |
|---|
| 1003 | unsigned event_id,arg; |
|---|
| 1004 | |
|---|
| 1005 | event_id = levent_id_from_lua_arg(L,1); |
|---|
| 1006 | arg = luaL_optnumber(L, 2, 0); |
|---|
| 1007 | PostLogicalEventToUI(event_id,arg); |
|---|
| 1008 | return 0; |
|---|
| 1009 | } |
|---|
| 1010 | |
|---|
| 1011 | static int luaCB_post_levent_for_npt( lua_State* L ) |
|---|
| 1012 | { |
|---|
| 1013 | unsigned event_id,arg; |
|---|
| 1014 | |
|---|
| 1015 | event_id = levent_id_from_lua_arg(L,1); |
|---|
| 1016 | arg = luaL_optnumber(L, 2, 0); |
|---|
| 1017 | PostLogicalEventForNotPowerType(event_id,arg); |
|---|
| 1018 | return 0; |
|---|
| 1019 | } |
|---|
| 1020 | |
|---|
| 1021 | /* |
|---|
| 1022 | set_levent_active(event,state) |
|---|
| 1023 | event is an event id (number) or name (string) |
|---|
| 1024 | state is a numeric or boolean state. true or non zero numbers turn on zero, false or nil turn off |
|---|
| 1025 | exact meaning is unknown, but it has something to do with the delivery of the specified event. |
|---|
| 1026 | */ |
|---|
| 1027 | static int luaCB_set_levent_active( lua_State* L ) |
|---|
| 1028 | { |
|---|
| 1029 | unsigned event_id; |
|---|
| 1030 | unsigned state; |
|---|
| 1031 | |
|---|
| 1032 | event_id = levent_id_from_lua_arg(L,1); |
|---|
| 1033 | state = on_off_value_from_lua_arg(L,2); |
|---|
| 1034 | SetLogicalEventActive(event_id,state); |
|---|
| 1035 | return 0; |
|---|
| 1036 | } |
|---|
| 1037 | |
|---|
| 1038 | /* |
|---|
| 1039 | set_levent_script_mode(state) |
|---|
| 1040 | state is numeric or boolean state. true or non zero numbers turn on zero, false or nil turn off |
|---|
| 1041 | exact meaning is unknown, but it has something to do with the behavior of events and/or SetLogicalEventActive. |
|---|
| 1042 | */ |
|---|
| 1043 | static int luaCB_set_levent_script_mode( lua_State* L ) |
|---|
| 1044 | { |
|---|
| 1045 | SetScriptMode(on_off_value_from_lua_arg(L,1)); |
|---|
| 1046 | return 0; |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | /* |
|---|
| 1050 | result=set_capture_mode_canon(value) |
|---|
| 1051 | where value is a valid PROPCASE_SHOOTING_MODE value for the current camera |
|---|
| 1052 | result is true if the camera is in rec mode |
|---|
| 1053 | */ |
|---|
| 1054 | static int luaCB_set_capture_mode_canon( lua_State* L ) |
|---|
| 1055 | { |
|---|
| 1056 | int modenum = luaL_checknumber(L,1); |
|---|
| 1057 | // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value |
|---|
| 1058 | if(modenum < 0) |
|---|
| 1059 | modenum &= 0xFFFF; |
|---|
| 1060 | lua_pushboolean( L, shooting_set_mode_canon(modenum) ); |
|---|
| 1061 | return 1; |
|---|
| 1062 | } |
|---|
| 1063 | |
|---|
| 1064 | /* |
|---|
| 1065 | result=set_capture_mode(modenum) |
|---|
| 1066 | where modenum is a valid CHDK modemap value |
|---|
| 1067 | result is true if modenum is a valid modemap value, otherwise false |
|---|
| 1068 | */ |
|---|
| 1069 | static int luaCB_set_capture_mode( lua_State* L ) |
|---|
| 1070 | { |
|---|
| 1071 | int modenum = luaL_checknumber(L,1); |
|---|
| 1072 | lua_pushboolean( L, shooting_set_mode_chdk(modenum) ); |
|---|
| 1073 | return 1; |
|---|
| 1074 | } |
|---|
| 1075 | |
|---|
| 1076 | /* |
|---|
| 1077 | result=is_capture_mode_valid(modenum) |
|---|
| 1078 | where modenum is a valid CHDK modemap value |
|---|
| 1079 | result is true if modenum is a valid modemap value, otherwise false |
|---|
| 1080 | */ |
|---|
| 1081 | static int luaCB_is_capture_mode_valid( lua_State* L ) |
|---|
| 1082 | { |
|---|
| 1083 | int modenum = luaL_checknumber(L,1); |
|---|
| 1084 | lua_pushboolean( L, shooting_mode_chdk2canon(modenum) != -1 ); |
|---|
| 1085 | return 1; |
|---|
| 1086 | } |
|---|
| 1087 | |
|---|
| 1088 | /* |
|---|
| 1089 | set_record(state) |
|---|
| 1090 | if state is 0 (or false) the camera is set to play mode. If 1 or true, the camera is set to record mode. |
|---|
| 1091 | NOTE: this only begins the mode change. Script should wait until get_mode() reflects the change, |
|---|
| 1092 | before doing anything that requires the new mode. e.g. |
|---|
| 1093 | set_record(true) |
|---|
| 1094 | while not get_mode() do |
|---|
| 1095 | sleep(10) |
|---|
| 1096 | end |
|---|
| 1097 | */ |
|---|
| 1098 | static int luaCB_set_record( lua_State* L ) |
|---|
| 1099 | { |
|---|
| 1100 | if(on_off_value_from_lua_arg(L,1)) { |
|---|
| 1101 | levent_set_record(); |
|---|
| 1102 | } |
|---|
| 1103 | else { |
|---|
| 1104 | levent_set_play(); |
|---|
| 1105 | } |
|---|
| 1106 | return 0; |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | void register_lua_funcs( lua_State* L ) |
|---|
| 1110 | { |
|---|
| 1111 | #define FUNC( X ) \ |
|---|
| 1112 | lua_pushcfunction( L, luaCB_##X ); \ |
|---|
| 1113 | lua_setglobal( L, #X ) |
|---|
| 1114 | |
|---|
| 1115 | FUNC(shoot); |
|---|
| 1116 | FUNC(sleep); |
|---|
| 1117 | FUNC(cls); |
|---|
| 1118 | |
|---|
| 1119 | lua_pushlightuserdata( L, kbd_sched_click ); |
|---|
| 1120 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 1121 | lua_setglobal( L, "click" ); |
|---|
| 1122 | |
|---|
| 1123 | lua_pushlightuserdata( L, kbd_sched_press ); |
|---|
| 1124 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 1125 | lua_setglobal( L, "press" ); |
|---|
| 1126 | |
|---|
| 1127 | lua_pushlightuserdata( L, kbd_sched_release ); |
|---|
| 1128 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 1129 | lua_setglobal( L, "release" ); |
|---|
| 1130 | |
|---|
| 1131 | FUNC(get_av96); |
|---|
| 1132 | FUNC(get_av96); |
|---|
| 1133 | FUNC(get_bv96); |
|---|
| 1134 | FUNC(get_day_seconds); |
|---|
| 1135 | FUNC(get_disk_size); |
|---|
| 1136 | FUNC(get_dof); |
|---|
| 1137 | FUNC(get_far_limit); |
|---|
| 1138 | FUNC(get_free_disk_space); |
|---|
| 1139 | FUNC(get_focus); |
|---|
| 1140 | FUNC(get_hyp_dist); |
|---|
| 1141 | FUNC(get_iso_market); |
|---|
| 1142 | FUNC(get_iso_mode); |
|---|
| 1143 | FUNC(get_iso_real); |
|---|
| 1144 | FUNC(get_jpg_count); |
|---|
| 1145 | FUNC(get_near_limit); |
|---|
| 1146 | FUNC(get_prop); |
|---|
| 1147 | FUNC(get_raw_count); |
|---|
| 1148 | FUNC(get_raw_nr); |
|---|
| 1149 | FUNC(get_raw); |
|---|
| 1150 | FUNC(get_sv96); |
|---|
| 1151 | FUNC(get_tick_count); |
|---|
| 1152 | FUNC(get_tv96); |
|---|
| 1153 | FUNC(get_user_av_id); |
|---|
| 1154 | FUNC(get_user_av96); |
|---|
| 1155 | FUNC(get_user_tv_id); |
|---|
| 1156 | FUNC(get_user_tv96); |
|---|
| 1157 | FUNC(get_vbatt); |
|---|
| 1158 | FUNC(get_zoom); |
|---|
| 1159 | FUNC(get_exp_count); |
|---|
| 1160 | FUNC(get_flash_params_count); |
|---|
| 1161 | FUNC(get_parameter_data); |
|---|
| 1162 | |
|---|
| 1163 | FUNC(set_av96_direct); |
|---|
| 1164 | FUNC(set_av96); |
|---|
| 1165 | FUNC(set_focus); |
|---|
| 1166 | FUNC(set_iso_mode); |
|---|
| 1167 | FUNC(set_iso_real); |
|---|
| 1168 | FUNC(set_led); |
|---|
| 1169 | FUNC(set_nd_filter); |
|---|
| 1170 | FUNC(set_prop); |
|---|
| 1171 | FUNC(set_raw_nr); |
|---|
| 1172 | FUNC(set_raw); |
|---|
| 1173 | FUNC(set_sv96); |
|---|
| 1174 | FUNC(set_tv96_direct); |
|---|
| 1175 | FUNC(set_tv96); |
|---|
| 1176 | FUNC(set_user_av_by_id_rel); |
|---|
| 1177 | FUNC(set_user_av_by_id); |
|---|
| 1178 | FUNC(set_user_av96); |
|---|
| 1179 | FUNC(set_user_tv_by_id_rel); |
|---|
| 1180 | FUNC(set_user_tv_by_id); |
|---|
| 1181 | FUNC(set_user_tv96); |
|---|
| 1182 | FUNC(set_zoom_speed); |
|---|
| 1183 | FUNC(set_zoom_rel); |
|---|
| 1184 | FUNC(set_zoom); |
|---|
| 1185 | |
|---|
| 1186 | FUNC(wait_click); |
|---|
| 1187 | FUNC(is_pressed); |
|---|
| 1188 | FUNC(is_key); |
|---|
| 1189 | #ifdef CAM_HAS_JOGDIAL |
|---|
| 1190 | FUNC(wheel_right); |
|---|
| 1191 | FUNC(wheel_left); |
|---|
| 1192 | #endif |
|---|
| 1193 | FUNC(md_get_cell_diff); |
|---|
| 1194 | FUNC(md_detect_motion); |
|---|
| 1195 | FUNC(autostarted); |
|---|
| 1196 | FUNC(get_autostart); |
|---|
| 1197 | FUNC(set_autostart); |
|---|
| 1198 | FUNC(get_usb_power); |
|---|
| 1199 | FUNC(exit_alt); |
|---|
| 1200 | FUNC(shut_down); |
|---|
| 1201 | FUNC(print_screen); |
|---|
| 1202 | |
|---|
| 1203 | FUNC(get_focus_mode); |
|---|
| 1204 | FUNC(get_propset); |
|---|
| 1205 | FUNC(get_zoom_steps); |
|---|
| 1206 | FUNC(get_drive_mode); |
|---|
| 1207 | FUNC(get_flash_mode); |
|---|
| 1208 | FUNC(get_shooting); |
|---|
| 1209 | FUNC(get_flash_ready); |
|---|
| 1210 | FUNC(get_IS_mode); |
|---|
| 1211 | FUNC(set_ev); |
|---|
| 1212 | FUNC(get_ev); |
|---|
| 1213 | FUNC(get_orientation_sensor); |
|---|
| 1214 | FUNC(get_nd_present); |
|---|
| 1215 | FUNC(get_movie_status); |
|---|
| 1216 | FUNC(set_movie_status); |
|---|
| 1217 | |
|---|
| 1218 | FUNC(get_histo_range); |
|---|
| 1219 | FUNC(shot_histo_enable); |
|---|
| 1220 | FUNC(play_sound); |
|---|
| 1221 | FUNC(get_temperature); |
|---|
| 1222 | FUNC(peek); |
|---|
| 1223 | FUNC(poke); |
|---|
| 1224 | FUNC(bitand); |
|---|
| 1225 | FUNC(bitor); |
|---|
| 1226 | FUNC(bitxor); |
|---|
| 1227 | FUNC(bitshl); |
|---|
| 1228 | FUNC(bitshri); |
|---|
| 1229 | FUNC(bitshru); |
|---|
| 1230 | FUNC(bitnot); |
|---|
| 1231 | |
|---|
| 1232 | FUNC(get_time); |
|---|
| 1233 | |
|---|
| 1234 | FUNC(get_buildinfo); |
|---|
| 1235 | FUNC(get_mode); |
|---|
| 1236 | |
|---|
| 1237 | FUNC(set_raw_develop); |
|---|
| 1238 | // NOTE these functions normally run in the spytask. |
|---|
| 1239 | // called from lua they will run from kbd task instead |
|---|
| 1240 | FUNC(raw_merge_start); |
|---|
| 1241 | FUNC(raw_merge_add_file); |
|---|
| 1242 | FUNC(raw_merge_end); |
|---|
| 1243 | FUNC(set_backlight); |
|---|
| 1244 | FUNC(set_aflock); |
|---|
| 1245 | #ifdef OPT_CURVES |
|---|
| 1246 | FUNC(set_curve_state); |
|---|
| 1247 | #endif |
|---|
| 1248 | // get levent definition by name or id, nil if not found |
|---|
| 1249 | FUNC(get_levent_def); |
|---|
| 1250 | // get levent definition by index, nil if out of range |
|---|
| 1251 | FUNC(get_levent_def_by_index); |
|---|
| 1252 | // get levent index from name or ID |
|---|
| 1253 | FUNC(get_levent_index); |
|---|
| 1254 | FUNC(post_levent_to_ui); |
|---|
| 1255 | FUNC(post_levent_for_npt); |
|---|
| 1256 | FUNC(set_levent_active); |
|---|
| 1257 | FUNC(set_levent_script_mode); |
|---|
| 1258 | |
|---|
| 1259 | FUNC(set_capture_mode); |
|---|
| 1260 | FUNC(set_capture_mode_canon); |
|---|
| 1261 | FUNC(is_capture_mode_valid); |
|---|
| 1262 | |
|---|
| 1263 | FUNC(set_record); |
|---|
| 1264 | } |
|---|