how to count pulses/time USB input is high ? - Script Writing - CHDK Forum

how to count pulses/time USB input is high ?

  • 8 Replies
  • 5931 Views
how to count pulses/time USB input is high ?
« on: 25 / January / 2014, 12:46:18 »
Advertisements
I need to be able to make external controller select between photo/video, press shutter, and maybe other things, like zoom in/out.

How can I make a script that determine USB input:

pseudeo-code:
wait for USB high,
if USB=high for >10ms  goto function 1
if USB=high for >20ms  goto function 2
if USB=high for >30ms  goto function 3


or :

if USB = high, then low, wait for possible second pulse for 20ms, on pulse, increase "cntr".
When no more pulses, goto function(cntr)


Thank you in advance



Re: how to count pulses/time USB input is high ?
« Reply #1 on: 25 / January / 2014, 13:32:25 »
I need to be able to make external controller select between photo/video, press shutter, and maybe other things, like zoom in/out.
The built-in USB remote code supports both pulse counting and pulse width measurement so you can choose to do either. 

Documentaiton is here :  http://chdk.wikia.com/wiki/USB_Remote_V2#Scripting_Interface

If you need help with the actual scriptng, let me know.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: how to count pulses/time USB input is high ?
« Reply #2 on: 25 / January / 2014, 13:46:58 »
Thank you, CHDK proves yet again to be very, very useful. 

CHDK is allo the reason I'm on my 5th Canon camera in a row, I hope they realise how important CHDK is, and continue to make cameras that can run it.

Re: how to count pulses/time USB input is high ?
« Reply #3 on: 27 / November / 2016, 11:09:28 »
The built-in USB remote code supports both pulse counting and pulse width measurement so you can choose to do either. 

Documentaiton is here :  http://chdk.wikia.com/wiki/USB_Remote_V2#Scripting_Interface


I'd like a function, among others, to manage releasing the synch hook, for a multi-camera setup, in script, simplified e.g.
Code: [Select]
function cmds.usb_sync_wait()
   press('shoot_half')
   sleep(2000)
   usb_sync_wait(1)
   press('shoot_full')
   sleep(9000) --usb transistion from +5v -> 0V in this period
   release('shoot_full')
end
   
When this function has finished (as part of a long running script similar to multicam.lua but without choosing which function to run as a result of a received ptp message) i'd then like to choose another function (e.g. to set Canon AV/TV/ISO) utilising "get_usb_power(3)" (pulses from a ucontroller pulse generator) but note the wiki page states "USB remote must be enabled for this function to work"

Is there a scheme whereby, following the  +5v -> 0V transistion in my example "function cmds.usb_sync_wait()" the next usb transistion (0V->+5V) can be ignored in respect of activating a "Shoot Half" so the script can merely continue with it's monitoring of pulses (similarly to the way multicam.lua "function mc.run(opts)" monitors for ptp messages and chooses which function to execute)?

Further to above, noting msl's advice here https://chdk.setepontos.com/index.php?topic=12772.msg126824#msg126824,
is there any difference (in the proposed scenario) between using
Code: [Select]
usb_sync_wait(1)to set the usb_sync_wait_flag rather than
Code: [Select]
set_config_value(core.synch_enable, 1)in my simplified example functon above?
« Last Edit: 27 / November / 2016, 11:23:39 by andrew.stephens.754365 »

Re: how to count pulses/time USB input is high ?
« Reply #4 on: 27 / November / 2016, 12:10:38 »
I'd like a function, among others,
others?

Quote
to manage releasing the synch hook, for a multi-camera setup, in script, simplified e.g.
Code: [Select]
function cmds.usb_sync_wait()
   press('shoot_half')
   sleep(2000)
   usb_sync_wait(1)
   press('shoot_full')
   sleep(9000) --usb transistion from +5v -> 0V in this period
   release('shoot_full')
end
 
 
When this function has finished (as part of a long running script similar to multicam.lua but without choosing which function to run as a result of a received ptp message) i'd then like to choose another function (e.g. to set Canon AV/TV/ISO) utilising "get_usb_power(3)" (pulses from a ucontroller pulse generator) but note the wiki page states "USB remote must be enabled for this function to work"

Is there a scheme whereby, following the  +5v -> 0V transistion in my example "function cmds.usb_sync_wait()" the next usb transistion (0V->+5V) can be ignored in respect of activating a "Shoot Half" so the script can merely continue with it's monitoring of pulses (similarly to the way multicam.lua "function mc.run(opts)" monitors for ptp messages and chooses which function to execute)?
ummm .. wow.  Let me see if I can restate what I think you want to do.

First of all, it looks like you are not actually using chdkptp (multicam.lua) for anything here. You are trying to do all of this by toggling the USB +5V pin to either trigger a sync'd shot or to communicate (i.e. bit banging) some other information to the script. 

Correct so far?

You want to trigger a sync'd shooting process using your script rather than the built-in CHDK USB Remote code. But you also want the built-in code to do pulse counting for you so you don't want it disabled. So your concern is how to enable the built-in code without having it also trigger a shot when the USB 5V line changes state.

Am I still correct?

If so, the simple answer is to set the  Enable Remote [ * ] option in the CHDK Remote Parameters menu but to leave Switch Type [ None  ] and Control Mode [ None ]

If I've missed something here, or you are also trying to use chdkptp, then please elaborate here and I'll give it another try.

Incidentally,  if you use the Script Shooting Hooks you can eliminate the sleep(9000) statement and have your function return right after the actual shot takes place.

Quote
Further to above, noting msl's advice here https://chdk.setepontos.com/index.php?topic=12772.msg126824#msg126824,
is there any difference (in the proposed scenario) between using
Code: [Select]
usb_sync_wait(1)to set the usb_sync_wait_flag rather than
Code: [Select]
set_config_value(core.synch_enable, 1)in my simplified example functon above?
Yes - there is a big difference.   Using usb_sync_wait(1) works as you have describe.  However, using set_config_value(core.synch_enable, 1) will only cause the shot to sync if the shot is originated from the built-in USB remote code. Triggering the shot from a script will not cause a sync wait when the core.synch_enable parameter is set.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: how to count pulses/time USB input is high ?
« Reply #5 on: 27 / November / 2016, 12:52:32 »
Correct so far?
Yes.
Am I still correct?

Yes - this is belt & braces in case my extended "multicam.lua" proves too difficult a beast with "communication errors" or merely as a simplified solution if the complexity/flexibility of multicam.lua proves as overkill. Image download may not prove the big issue that concurrent usbremote/ptp has already solved and i'm just about to purchase an Arduino Leonardo as a multi-speedlite flash delay controller - it seems a good time to compare the two approaches.

If so, the simple answer is to set the  Enable Remote [ * ] option in the CHDK Remote Parameters menu but to leave Switch Type [ None  ] and Control Mode [ None ]
That was easy - many thanks!

Incidentally,  if you use the Script Shooting Hooks you can eliminate the sleep(9000) statement and have your function return right after the actual shot takes place.
Yes, that was an oversight - I shouldn't have copied from my multicam.lua...it was part of a test to check the 10 second timeout.
Yes - there is a big difference.
Understood.

In a similar fashion must I set the:
Enable Remote [ * ] option
but to leave Switch Type [ None  ]
and Control Mode [ None ]
in the CHDK Remote Parameters menu

rather than, in script, as:

core=require("gen/cnf_core")
set_config_value(core.remote_enable, 1)
set_config_value(core.remote_switch_type, 0)
set_config_value(core.remote_control_mode, 0)
« Last Edit: 27 / November / 2016, 12:57:19 by andrew.stephens.754365 »

Re: how to count pulses/time USB input is high ?
« Reply #6 on: 27 / November / 2016, 13:05:47 »
Image download may not prove the big issue that concurrent usbremote/ptp has already solved
hint :  usb_force_active(1)

Quote
In a similar fashion must I set the:
Enable Remote [ * ] option but to leave Switch Type [ None  ] and Control Mode [ None ]
in the CHDK Remote Parameters menu  rather than, in script, as:
core=require("gen/cnf_core")
set_config_value(core.remote_enable, 1)
set_config_value(core.remote_switch_type, 0)
set_config_value(core.remote_control_mode, 0)
Both methods work well - it's up to you.   In my more polished scripts,  I use set_config_value( ... ) a lot so that I don't have to remember to set things up manually in the CHDK menus.  I also try to disable the remote when the script exists - makes things like ptp communications during script development a lot easier that way.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: how to count pulses/time USB input is high ?
« Reply #7 on: 27 / November / 2016, 13:09:37 »

Re: how to count pulses/time USB input is high ?
« Reply #8 on: 27 / November / 2016, 14:04:53 »
hint :  usb_force_active(1)

Ah, i'd overlooked your comment - yes. that seems to work fine. I tested and reported here:
https://chdk.setepontos.com/index.php?topic=12827.msg128700#msg128700

 

Related Topics


SimplePortal © 2008-2014, SimplePortal