| 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 | // must be alligned |
|---|
| 663 | if (addr & 0x3) { |
|---|
| 664 | lua_pushnil(L); |
|---|
| 665 | } |
|---|
| 666 | else { |
|---|
| 667 | lua_pushnumber( L, *(unsigned *)(addr) ); |
|---|
| 668 | } |
|---|
| 669 | return 1; |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | static int luaCB_poke( lua_State* L ) |
|---|
| 673 | { |
|---|
| 674 | int addr = (luaL_checknumber(L,1)); |
|---|
| 675 | int val = (luaL_checknumber(L,2)); |
|---|
| 676 | if (addr & 0x3) { |
|---|
| 677 | lua_pushnil(L); |
|---|
| 678 | } |
|---|
| 679 | else { |
|---|
| 680 | *(unsigned *)(addr) = val; |
|---|
| 681 | lua_pushboolean(L,1); |
|---|
| 682 | } |
|---|
| 683 | return 1; |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | static int luaCB_bitand( lua_State* L ) |
|---|
| 687 | { |
|---|
| 688 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 689 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 690 | lua_pushnumber( L, v1 & v2 ); |
|---|
| 691 | return 1; |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | static int luaCB_bitor( lua_State* L ) |
|---|
| 695 | { |
|---|
| 696 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 697 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 698 | lua_pushnumber( L, v1 | v2 ); |
|---|
| 699 | return 1; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | static int luaCB_bitxor( lua_State* L ) |
|---|
| 703 | { |
|---|
| 704 | int v1 = (luaL_checknumber(L,1)); |
|---|
| 705 | int v2 = (luaL_checknumber(L,2)); |
|---|
| 706 | lua_pushnumber( L, v1 ^ v2 ); |
|---|
| 707 | return 1; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | static int luaCB_bitshl( lua_State* L ) |
|---|
| 711 | { |
|---|
| 712 | int val = (luaL_checknumber(L,1)); |
|---|
| 713 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 714 | lua_pushnumber( L, val << shift ); |
|---|
| 715 | return 1; |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | static int luaCB_bitshri( lua_State* L ) |
|---|
| 719 | { |
|---|
| 720 | int val = (luaL_checknumber(L,1)); |
|---|
| 721 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 722 | lua_pushnumber( L, val >> shift ); |
|---|
| 723 | return 1; |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | static int luaCB_bitshru( lua_State* L ) |
|---|
| 727 | { |
|---|
| 728 | unsigned val = (luaL_checknumber(L,1)); |
|---|
| 729 | unsigned shift = (luaL_checknumber(L,2)); |
|---|
| 730 | lua_pushnumber( L, val >> shift ); |
|---|
| 731 | return 1; |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | static int luaCB_bitnot( lua_State* L ) |
|---|
| 735 | { |
|---|
| 736 | unsigned val = (luaL_checknumber(L,1)); |
|---|
| 737 | lua_pushnumber( L, ~val ); |
|---|
| 738 | return 1; |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | static void set_string_field(lua_State* L, const char *key, const char *val) |
|---|
| 742 | { |
|---|
| 743 | lua_pushstring(L, val); |
|---|
| 744 | lua_setfield(L, -2, key); |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | static int luaCB_get_buildinfo( lua_State* L ) |
|---|
| 748 | { |
|---|
| 749 | lua_createtable(L, 0, 6); /* 9 = number of fields */ |
|---|
| 750 | set_string_field( L,"platform", PLATFORM ); |
|---|
| 751 | set_string_field( L,"platsub", PLATFORMSUB ); |
|---|
| 752 | set_string_field( L,"version", HDK_VERSION ); |
|---|
| 753 | set_string_field( L,"build_number", BUILD_NUMBER ); |
|---|
| 754 | set_string_field( L,"build_date", __DATE__ ); |
|---|
| 755 | set_string_field( L,"build_time", __TIME__ ); |
|---|
| 756 | return 1; |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | void register_lua_funcs( lua_State* L ) |
|---|
| 760 | { |
|---|
| 761 | #define FUNC( X ) \ |
|---|
| 762 | lua_pushcfunction( L, luaCB_##X ); \ |
|---|
| 763 | lua_setglobal( L, #X ) |
|---|
| 764 | |
|---|
| 765 | FUNC(shoot); |
|---|
| 766 | FUNC(sleep); |
|---|
| 767 | FUNC(cls); |
|---|
| 768 | |
|---|
| 769 | lua_pushlightuserdata( L, kbd_sched_click ); |
|---|
| 770 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 771 | lua_setglobal( L, "click" ); |
|---|
| 772 | |
|---|
| 773 | lua_pushlightuserdata( L, kbd_sched_press ); |
|---|
| 774 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 775 | lua_setglobal( L, "press" ); |
|---|
| 776 | |
|---|
| 777 | lua_pushlightuserdata( L, kbd_sched_release ); |
|---|
| 778 | lua_pushcclosure( L, luaCB_keyfunc, 1 ); |
|---|
| 779 | lua_setglobal( L, "release" ); |
|---|
| 780 | |
|---|
| 781 | FUNC(get_av96); |
|---|
| 782 | FUNC(get_av96); |
|---|
| 783 | FUNC(get_bv96); |
|---|
| 784 | FUNC(get_day_seconds); |
|---|
| 785 | FUNC(get_disk_size); |
|---|
| 786 | FUNC(get_dof); |
|---|
| 787 | FUNC(get_far_limit); |
|---|
| 788 | FUNC(get_free_disk_space); |
|---|
| 789 | FUNC(get_focus); |
|---|
| 790 | FUNC(get_hyp_dist); |
|---|
| 791 | FUNC(get_iso_market); |
|---|
| 792 | FUNC(get_iso_mode); |
|---|
| 793 | FUNC(get_iso_real); |
|---|
| 794 | FUNC(get_jpg_count); |
|---|
| 795 | FUNC(get_near_limit); |
|---|
| 796 | FUNC(get_prop); |
|---|
| 797 | FUNC(get_raw_count); |
|---|
| 798 | FUNC(get_raw_nr); |
|---|
| 799 | FUNC(get_raw); |
|---|
| 800 | FUNC(get_sv96); |
|---|
| 801 | FUNC(get_tick_count); |
|---|
| 802 | FUNC(get_tv96); |
|---|
| 803 | FUNC(get_user_av_id); |
|---|
| 804 | FUNC(get_user_av96); |
|---|
| 805 | FUNC(get_user_tv_id); |
|---|
| 806 | FUNC(get_user_tv96); |
|---|
| 807 | FUNC(get_vbatt); |
|---|
| 808 | FUNC(get_zoom); |
|---|
| 809 | FUNC(get_exp_count); |
|---|
| 810 | |
|---|
| 811 | FUNC(set_av96_direct); |
|---|
| 812 | FUNC(set_av96); |
|---|
| 813 | FUNC(set_focus); |
|---|
| 814 | FUNC(set_iso_mode); |
|---|
| 815 | FUNC(set_iso_real); |
|---|
| 816 | FUNC(set_led); |
|---|
| 817 | FUNC(set_nd_filter); |
|---|
| 818 | FUNC(set_prop); |
|---|
| 819 | FUNC(set_raw_nr); |
|---|
| 820 | FUNC(set_raw); |
|---|
| 821 | FUNC(set_sv96); |
|---|
| 822 | FUNC(set_tv96_direct); |
|---|
| 823 | FUNC(set_tv96); |
|---|
| 824 | FUNC(set_user_av_by_id_rel); |
|---|
| 825 | FUNC(set_user_av_by_id); |
|---|
| 826 | FUNC(set_user_av96); |
|---|
| 827 | FUNC(set_user_tv_by_id_rel); |
|---|
| 828 | FUNC(set_user_tv_by_id); |
|---|
| 829 | FUNC(set_user_tv96); |
|---|
| 830 | FUNC(set_zoom_speed); |
|---|
| 831 | FUNC(set_zoom_rel); |
|---|
| 832 | FUNC(set_zoom); |
|---|
| 833 | |
|---|
| 834 | FUNC(wait_click); |
|---|
| 835 | FUNC(is_pressed); |
|---|
| 836 | FUNC(is_key); |
|---|
| 837 | #if defined (CAMERA_g7) || defined (CAMERA_sx100is) |
|---|
| 838 | FUNC(wheel_right); |
|---|
| 839 | FUNC(wheel_left); |
|---|
| 840 | #endif |
|---|
| 841 | FUNC(md_get_cell_diff); |
|---|
| 842 | FUNC(md_detect_motion); |
|---|
| 843 | FUNC(autostarted); |
|---|
| 844 | FUNC(get_autostart); |
|---|
| 845 | FUNC(set_autostart); |
|---|
| 846 | FUNC(get_usb_power); |
|---|
| 847 | FUNC(exit_alt); |
|---|
| 848 | FUNC(shut_down); |
|---|
| 849 | FUNC(print_screen); |
|---|
| 850 | |
|---|
| 851 | FUNC(get_focus_mode); |
|---|
| 852 | FUNC(get_propset); |
|---|
| 853 | FUNC(get_zoom_steps); |
|---|
| 854 | FUNC(get_drive_mode); |
|---|
| 855 | FUNC(get_flash_mode); |
|---|
| 856 | FUNC(get_shooting); |
|---|
| 857 | FUNC(get_flash_ready); |
|---|
| 858 | FUNC(get_IS_mode); |
|---|
| 859 | FUNC(set_ev); |
|---|
| 860 | FUNC(get_ev); |
|---|
| 861 | FUNC(get_orientation_sensor); |
|---|
| 862 | FUNC(get_nd_present); |
|---|
| 863 | FUNC(get_movie_status); |
|---|
| 864 | FUNC(set_movie_status); |
|---|
| 865 | |
|---|
| 866 | FUNC(get_histo_range); |
|---|
| 867 | FUNC(shot_histo_enable); |
|---|
| 868 | FUNC(play_sound); |
|---|
| 869 | FUNC(get_temperature); |
|---|
| 870 | FUNC(peek); |
|---|
| 871 | FUNC(poke); |
|---|
| 872 | FUNC(bitand); |
|---|
| 873 | FUNC(bitor); |
|---|
| 874 | FUNC(bitxor); |
|---|
| 875 | FUNC(bitshl); |
|---|
| 876 | FUNC(bitshri); |
|---|
| 877 | FUNC(bitshru); |
|---|
| 878 | FUNC(bitnot); |
|---|
| 879 | |
|---|
| 880 | FUNC(get_time); |
|---|
| 881 | |
|---|
| 882 | FUNC(get_buildinfo); |
|---|
| 883 | } |
|---|