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.
Thanks! That would be much better.
I think I have an easier solution though. I can reset the shot_ready flag to false whenever get_shot_ready() returns true. That is, it will only return true once per shot.
volatile static int shot_ready=0;
int get_shot_ready()
{
int iret=shot_ready;
shot_ready=0;
return iret;
}
I had tried this before, but it would never return true sometimes. I think the reason was that shot_ready was set to 1 in a different thread. I think what was happening was this:
iret=shot_ready; //iret=0 in thread 1
shot_ready=1; //in thread 2
shot_ready=0;//thread 1
return iret; //return 0 thread 1 (Missed it!!)
Making shot_ready volatile may have helped, but I'm still not sure it's totally thread safe. Do you think it would be? Is there a way to block other threads from running to prevent this (synchronized blocks)?
I can try having thread 2 increment a shot counter and have thread 1 return the value of the counter to Lua. This sounds a lot like get_exp_count(), but my counter would increment in raw.c right after build_shot_histogram. get_exp_count() increments in yet another thread, sometimes before build_shot_histogram, and sometimes after. There's a test in capt_seq.c to wait for get_exp_count() if raw file saving is enabled, to get the right raw file name. The comments note that doing this all the time would slow up burst mode.
So the new function would be: get_shot_count().
nshot=get_shot_count()
press("shoot_full_only")
repeat sleep(50)until nshot~=get_shot_count()
This is the same code I was using with get_exp_count() that didn't work when get_exposure_cnt() changed before the histogram was ready. It requires storing get_shot_count() before pressing _shoot_full_only, which even has the advantage of telling you if more than 1 shot went by for some reason.
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.
I think I'm a little confused about the meaning of "static" in C. All of the variables in shot_histogram.c that are outside of a function are declared without the qualifier, "static". Variables and functions that need to be referenced in other source files are contained in shot_histogram.h.
Some people seem to put "extern" in front of everything in the ".h" files, and some don't. Isn't "extern" the default if a variable is defined outside a function? And variables names that aren't included in a ".h" file won't be visible to other source files, will they?
I guess I don't see the difference between a static variable and a variable that's not included in an h file. Can you help? Thanks.