Thanks for your help and suggestions!
I removed the set_aflock(1) and set_prop(props.AF_LOCK,1) calls and only left in set_mf(1). I also moved press("shoot_half") right to the top, after switch_recmode(1).
set_aelock(1) -- disable auto exposure
CHDK overrides are applied after Canon AE, so you should need AE lock if you are overriding all exposure parameters. Using this may be the cause of your unexpected behavior, since overrides in auto exposure mode expect to be applied at a certain point in the AE process.
OK, so this is correct as is - right?
set_aelock(1)
enables the lock, i.e.
disables auto exposure. After that I set the exposure manually in the code.
By doing all of the above, exposure now works much better in general, but the camera still behaves strangely.
Flash behaves opposite of what the manual says: set_prop(props.FLASH_MODE, 1) switches if off (
should be on), set_prop(props.FLASH_MODE, 2) switches it on (
should be off).
Sometimes exposure times are reported as 1/10th or 1/8th of a second by the OSD (neither are in the list of exposure times I set).
The camera also sporadically goes into "continuous fire" mode, i.e. after triggering it
once via USB, it continues to take pictures (about one frame every 2 seconds) until I power it off. This is not reproducible, happens sporadically.
If this was C and not LUA, I'd say it's uninitalized memory or buffer overflows or race conditions (missing thread locking), and fire up gdb. But what can be the reason here?