Allowing scripts to trap full & half press shutter button activations - General Discussion and Assistance - CHDK Forum

Allowing scripts to trap full & half press shutter button activations

  • 57 Replies
  • 26308 Views
Advertisements
Currently,  CHDK uses the shutter button to indicate that a script should be started or stopped.  This makes it impossible to write scripts that use the shutter button as an input.  Something like a shooting script that lets the user press the shutter button to actually initiate the shot -  or a full manual exposure control widget like I described here :
http://chdk.setepontos.com/index.php?topic=10506

Lapser asked about a similiar function today :
http://chdk.setepontos.com/index.php?topic=10579.msg104387#msg104387

So if we wanted to add this to scripting,  its seems pretty easy to make sure the full and half shutter buttons become something that the standard script is_key() & is_pressed()  can read.  But those buttons need  to be masked out like the other buttons - easy enough.  The question is the best way to enable that masking ?

Options might be :
1) A menu option in the Script menu that enables the shutter button for reading from a script.
2) A function call that a script makes to enable the button for script use at run time.
3) A new special class of scripts that enable the shutter button for script use when they are run.

Might be some other ideas ??


Update :  while I think of it,  it might be nice to also have an "on direct" mode like the user menu where the current script runs as soon as you press the <ALT> key
« Last Edit: 23 / August / 2013, 21:27:21 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: Allowing scripts to trap full & half press shutter button activations
« Reply #1 on: 23 / August / 2013, 22:16:43 »
2) A function call that a script makes to enable the button for script use at run time.
This would be my choice.

My goal would be for the function to have options to give the script complete control of the camera, with only the script writing on the display, in addition to handling all the key input including <shoot_full> and <alt>.

It still would be desirable to have a way for the user to interrupt the script. Maybe holding the <menu> button down for 1 or 2 seconds?
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: Allowing scripts to trap full & half press shutter button activations
« Reply #2 on: 24 / August / 2013, 14:31:58 »
Okay,  here's a patch file for the 1.3.0 trunk that implements this.  Turned out to be pretty easy - feedback welcome.

I chose to add a menu item to the script menu to enable or disable script abort via fullpress.  You can also use :
 
Code: [Select]
set_config_value(232, 1)to activate / deactivate in a script.

I'm not totally happy with the menu string but its the best I could come up with after a 10 minutes of thought. 

Test script for this :

Code: [Select]
--[[
 @title ShootFull
 --]]

  set_console_layout(1, 0, 45, 12)

  key_table = {"up" , "down", "left", "right", "set", "shoot_half", "shoot_full", "shoot_full_only","zoom_in", "zoom_out",
             "menu", "display", "print", "erase", "iso", "flash", "mf", "macro", "video",
             "timer", "expo_corr", "fe","zoom_assist","ae_lock","metering_mode","no_key"}

  repeat 
    wait_click()
    kstring="key press : "
    nf_flag=true
    for key_nr=1, table.getn(key_table) do
        if (is_key(key_table[key_nr])) then
            print(kstring..key_table[key_nr])
            nf_flag = false
        end
    end
    if ( nf_flag ) then print("no key name found") end
  until is_key "menu"
  print("menu key = exit")
I'm not sure I quite understand the behavior of the playback key - it seems to not get trapped the same way as the others.  Its the <ALT> key -  I'll look at that interaction.
« Last Edit: 24 / August / 2013, 14:38:57 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Allowing scripts to trap full & half press shutter button activations
« Reply #3 on: 24 / August / 2013, 14:38:32 »
My goal would be for the function to have options to give the script complete control of the camera, with only the script writing on the display, in addition to handling all the key input including <shoot_full> and <alt>.
I think it will be hard to get the Canon OSD to shutdown?   But removing the CHDK OSD,  <ALT> icon and script name should be possible.

Quote
It still would be desirable to have a way for the user to interrupt the script. Maybe holding the <menu> button down for 1 or 2 seconds?
Locking out the shutter button is sort of a "power script programmer" thing.  I would expect such script to handle exiting the script themselves.   Or,  as you said, there is always the On/Off button.
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline reyalp

  • ******
  • 14121
Re: Allowing scripts to trap full & half press shutter button activations
« Reply #4 on: 24 / August / 2013, 14:42:14 »
I'm not sure I quite understand the behavior of the playback key - it seems to not get trapped the same way as the others.
That depends on the cameras kbd.c implementation: whether KEY_PLAYBACK is in the keyboard map, and whether the corresponding bit is in the key mask. Since the playback key is a relatively recent addition to CHDK code, the implementations are probably inconsistent.
Don't forget what the H stands for.

Re: Allowing scripts to trap full & half press shutter button activations
« Reply #5 on: 24 / August / 2013, 14:47:08 »
That depends on the cameras kbd.c implementation: whether KEY_PLAYBACK is in the keyboard map, and whether the corresponding bit is in the key mask. Since the playback key is a relatively recent addition to CHDK code, the implementations are probably inconsistent.
Did some more testing.  Changed the <ALT> key to the FACE key and now the KEY_PLAYBACK is trapped properly (althoug the script just displays "no key name found" as there is no "playback" string in the script).

More important,  the FACE key now toggles the camera in & out of <ALT> mode while the script is running.  I think I need to track that down and disable it too.

(Also,  there is no string for the playback key in keynames[] in script_key_funcs.c )
« Last Edit: 24 / August / 2013, 14:50:16 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Allowing scripts to trap full & half press shutter button activations
« Reply #6 on: 24 / August / 2013, 15:04:08 »
Modified shoot_full disable patch that also prevents leaving <ALT> mode while a script is running.

It might be worth submitting that as a seperate patch - do we really want to allow pressing the <ALT> key to let us leave <ALT> mode while a script is running?


Update :  I suppose we could make the "Script Terminate" button a user selectable option - like the choice if <ALT> key is for most cameras.   A lot of work though to do on a per camera basis.  Maybe not worth it?

« Last Edit: 24 / August / 2013, 15:25:22 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14121
Re: Allowing scripts to trap full & half press shutter button activations
« Reply #7 on: 24 / August / 2013, 15:54:05 »
I'm wary of having scripts that don't allow you to terminate them via the keyboard, at least without some notification to the user.

I definitely understand the use case, but the potential for frustration of users who download the script is high. Especially if they enable autostart, which seems to happen occasionally.

Not sure what the best way to handle this is. I don't really want a bunch of "This script does blah blah" warnings to pop up ;)
Quote
Update :  I suppose we could make the "Script Terminate" button a user selectable option - like the choice if <ALT> key is for most cameras.   A lot of work though to do on a per camera basis.  Maybe not worth it?
That would seem to fall under my generic keyboard re-write wishlist in
http://chdk.setepontos.com/index.php?topic=10506.msg103679#msg103679 (hmm, I should add that to the dev planning thread)
Don't forget what the H stands for.


*

Offline lapser

  • *****
  • 1093
Re: Allowing scripts to trap full & half press shutter button activations
« Reply #8 on: 24 / August / 2013, 15:57:47 »
Modified shoot_full disable patch that also prevents leaving <ALT> mode while a script is running.

It might be worth submitting that as a seperate patch - do we really want to allow pressing the <ALT> key to let us leave <ALT> mode while a script is running?


Update :  I suppose we could make the "Script Terminate" button a user selectable option - like the choice if <ALT> key is for most cameras.   A lot of work though to do on a per camera basis.  Maybe not worth it?
Thanks for working on this. I just looked at the patch file, and it looks like you're adding a menu item option. That's a good idea, and should be very useful. But it might be more useful to do it as a script function, after we get it working. The script has to be aware that it needs to exit by itself. A lot of my test scripts seem to include this:
repeat ...something... until false

Personally, I NEVER want to exit <alt> mode while a script is running. I only do it by accident, followed by some choice expletives every time, since it messes up the script.

It looks like CHDK will just ignore the <alt> key and not pass the key press to the script? That's better, but I would like to see the <alt> key be visible in the script. For example, there's no <display> key on the D20, so I modified the script to look for <display> or <video>. But the menu allows <video> to be set as the <alt> key, so the script will never be able to see it, as it stands.

Also, will is_key("shoot_full") work in a script now? It looks like it will to me. I'll check out your patch soon.

[edit]
I'm wary of having scripts that don't allow you to terminate them via the keyboard, at least without some notification to the user.
Yes, I agree. That's why I think it would work better as a Lua function, and turn off automatically when the script terminates. The script would have to tell you how to exit. My script says "Press <menu> to exit". I use the shoot_half key as a reset button when I'm setting my metering areas, but I frequently press shoot_full by mistake and have to start over. There aren't a lot of buttons that are on all cameras, so having the shoot_full button available would be very useful.
« Last Edit: 24 / August / 2013, 16:07:14 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: Allowing scripts to trap full & half press shutter button activations
« Reply #9 on: 24 / August / 2013, 16:45:39 »
But it might be more useful to do it as a script function, after we get it working.
Not sure I agree as you can always test /  set / reset / restore any menu selected value from your script.

I'm wary of having scripts that don't allow you to terminate them via the keyboard, at least without some notification to the user.
How about "long press" on shutter aborts,  short press is configurable to abort or not abort.
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal