i'm now trying to figure out what code i should add to my script, so i can connect the usb (maybe leave it connected) and keep it connected while the cam goes back and/or stays in record mode and resumes shooting.
if it stays connected i need some flag after each shot, so the pc can detect when it's safe to start downloading.
You could use the usb message interface for this. You'd probably want a handshake, like the PC sends something indicating "ready to start downloading" and waits for a reply indicating "ok to start now", which the camera sends after the shot is complete. The PC could also send a message indicating the download is done.
Note that messages from the camera are queued until a PTP client fetches them, so if you blindly use write_usb_msg when chdkptp isn't actively checking for messages, the queue would fill up (it has 15 slots) and then when chdkptp check for messages, it would get everything in the queue. Similarly, messages from the PC are queued in the PTP task until the script uses read_usb_msg()
If you are allowing the camera to auto-switch to play due to sensing USB, that would need additional time.
if at all possible, i'd like to prevent it switching to play as much as possible.
that is the code i am looking for.
Again, what I'm suggesting is avoiding the
Canon firmware triggered auto-switch. If you want to have the camera essentially always in rec, you should use force_usb_present at startup, before switching to rec (edit: with switch_mode_usb). If your camera boots into rec, that's a bug in the port, but in that case, you'd want to wait for it to be fully booted to rec, switch to play, force_usb_present, and then switch back to rec. This only needs to be done once per boot.
I see this as a fair chance the cam will fail quickly if it switches to play a 100 times a day.
Yes, it seems preferable to avoid that.
my first thought is that i should create a window of a few hours a day in the cam script that will enable connection and download.
outside those hours this connection can be blocked. possibly making (re)connection of usb safe outside the download hours.
I not clear how you intend to combine blocking USB and using force_usb_active. I see these as mutually exclusive approaches:
1) The camera script blocks USB until it's ready to accept downloads, then switches to play, unblocks USB, waits for download to complete. The PC detects this because it sees the camera device show up.
2) The script makes the camera think USB is always present, allowing it to stay in rec mode when USB shows up for real.