Code: (C) [Select]// for press,release and clickstatic int luaCB_keyfunc( lua_State* L ){ raw_set_shot_wait(); //clears shot ready flag to 0 - polled by get_shot_ready() void* func = lua_touserdata( L, lua_upvalueindex(1) ); ((void(*)(long))func)( lua_get_key_arg( L, 1 ) ); return lua_yield( L, 0 );}//below is in raw.cvoid raw_set_shot_wait() //called when shoot_full or shoot_full_only is clicked or pressed{ shot_ready=0;}Just adding one call in luascript.c solved the timing problem without adding another lua function. I realized I don't even have to know anything about the key, or if it was pressed, released, or clicked. As long as pressing shoot_full_only clears the shot_ready flag, it will work.I could put the shoot_full_only flag itself in raw.h and save the space and time overhead of defining and calling a function in raw.c. The function call would become: shot_ready=0 Would this be acceptable, and preferable?I have the new test time lapse video, and a discussion of the new metering method in the other topic here:http://chdk.setepontos.com/index.php?topic=8997.new#new
// for press,release and clickstatic int luaCB_keyfunc( lua_State* L ){ raw_set_shot_wait(); //clears shot ready flag to 0 - polled by get_shot_ready() void* func = lua_touserdata( L, lua_upvalueindex(1) ); ((void(*)(long))func)( lua_get_key_arg( L, 1 ) ); return lua_yield( L, 0 );}//below is in raw.cvoid raw_set_shot_wait() //called when shoot_full or shoot_full_only is clicked or pressed{ shot_ready=0;}
Set the variable in both the action_push_click and action_push_press routines (action_stack.c) not in the lua function. Test the 'key' value is either KEY_SHOOT_FULL or KEY_SHOOT_FULL_ONLY and only set the variable if it is one of these.
volatile static int shot_ready=0;int get_shot_ready(){ int iret=shot_ready; shot_ready=0; return iret;}
iret=shot_ready; //iret=0 in thread 1shot_ready=1; //in thread 2shot_ready=0;//thread 1return iret; //return 0 thread 1 (Missed it!!)
nshot=get_shot_count()press("shoot_full_only")repeat sleep(50)until nshot~=get_shot_count()
Put the variable in raw.c as a static and use functions to set/clear/test it. There's already too may global variables so I prefer to use an interface (even a simple one) rather than create more.
Quote from: lapser on 07 / December / 2012, 01:17:50Actually, I just want to set a flag when Lua calls for a press or click of shoot_full_only. I've tracked it down to luascript.c here:Why on earth would you want to do that???
Actually, I just want to set a flag when Lua calls for a press or click of shoot_full_only. I've tracked it down to luascript.c here:
edit:If you can give a general description of what you are trying to accomplish and how you would use this flag to do it, we may be able to suggest better approaches.
//in raw.cstatic int shot_count=0; //doesn't need to be volatileint raw_get_shot_count() // called from Lua{ return shot_count;} //in raw_save_file() if (state_kbd_script_run && shot_histogram_isenabled()) build_shot_histogram(); //unchanged shot_count++; //updated only in this thread, so should be safe.========================--in Lua script nshot=get_shot_count() press("shoot_full_only") repeat sleeper(10) until get_shot_count()~=nshot -- waits for build_histogram release("shoot_full_only")
I know I've said this before, but I think I've got it now.Code: [Select]//in raw.cstatic int shot_count=0; //doesn't need to be volatileint raw_get_shot_count() // called from Lua{ return shot_count;} //in raw_save_file() if (state_kbd_script_run && shot_histogram_isenabled()) build_shot_histogram(); //unchanged shot_count++; //updated only in this thread, so should be safe.========================--in Lua script nshot=get_shot_count() press("shoot_full_only") repeat sleeper(10) until get_shot_count()~=nshot -- waits for build_histogram release("shoot_full_only")This method never requires a reset, and is thread safe because the common variable is only changed in one thread. The script (keyboard?) thread (or task) only reads the variable.I timed it at 0.9 seconds per picture (1/25th second exposure time) with this method and no extra delay between shots (1/25 sec shutter).
Translation: "Your'e an idiot."
I think I'm a little confused about the meaning of "static" in C.
Looks ok. My only concern is that the 'get_shot_count' name might confuse people in future, that it is somehow related to the total number of images taken by the camera, not just the number since last startup.
Started by Hyst Feature Requests
Started by zumbido General Discussion and Assistance
Started by VALKYRIE Script Writing
Started by walterjwhite General Help and Assistance on using CHDK stable releases
Started by Indizacam LUA Scripting