What would be the correct sequence of commands through ptp to do the initial setup (focus preset to infinity if that's possible), let the camera do the preshoot process in advance, shoot, and ultimately retrieve the name of the picture then go back to ready state?
This is going to depend on your camera and specific requirements, but my general approach would be to use a message script like rsint and multicam.
You can see msg_shell in rlibs.lua for a more basic example. You can extend this on the fly by sending lua code.
Essentially, at startup you would send a script to the camera using chdkptp, like
!con:exec('msg_shell:run()',{rlibs={'msg_shell','serialize_msgs'}})
This starts the msg_shell script and doesn't wait for it to quit. msg_shell sits in a loop waiting for commands sent as messages. The serialize_msgs library allows you to send lua values directly from the camera to Lua scripts running in chdkptp.
Now you can switch to record mode set your focus and exposure settings by sending the exec command, which treats the rest of the message as lua code to execute:
> putm exec switch_mode_usb(1)
> putm exec set_mf(1)
> putm exec set_focus(-1)
...
To shoot repeatedly with the same settings, you can just let the script hold shoot_half, and send click'shoot_full_only' for each shot (shoot_full_only is needed because for historical reasons shoot_full implicitly releases shoot_half)
> putm exec press'shoot_half'
> putm exec click'shoot_full_only'
> putm exec click'shoot_full_only'
...
> putm exec release'shoot_half'
To retrieve the name of the image, you need to do something a bit more complicated than click 'shoot_full_only': You will need to wait for the shot to be completed by using the raw shoot hook or checking the file counter, and you will need to have your code send back a message like
write_usb_msg(string.format('%s/IMG_%04d.JPG',get_image_dir(),get_exp_count()))
You can retrieve the message with the getm cli command, like
> getm
4:user:'A/DCIM/103CANON/IMG_3115.JPG'
To combine this with a shot, I'd use something like this (formatted for clarity, if sent it chdkptp putm exec it would be all one line)
local prev=get_exp_count()
click'shoot_full'
repeat sleep(10) until get_exp_count() ~= last
write_usb_msg(string.format('%s/IMG_%04d.JPG',get_image_dir(),get_exp_count()))
Rather than using getm, you probably want to use chdkptp side code to wait the message to arrive, and have your controller wait for it to appear on stdout before issuing the next shoot_full_only.
> !printf('file:%s\n',con:wait_msg({unserialize=true,mtype='user'}).value)
file:A/DCIM/103CANON/IMG_3119.JPG
In a real application, you'd probably want to create a lua module that has most of this code already in and just have a few functions to call. The multicam module may be a useful example. The rlib part at the bottom defines the camera side code.
Overriding focus is a somewhat complicated and camera dependent subject by itself, and IIRC elph110 may have unresolved issues, so I'm going to leave that for another post.