Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Scripting Q&A => Topic started by: benpascoe on March 05, 2013, 11:04:24 PM

Title: Auto Focus with Live View Button
Post by: benpascoe on March 05, 2013, 11:04:24 PM
I originally posted about this in the General Help Q&A section but yesterday I got around to making a PicoC script and could do with some help to make it work a little better.

My Issue: I shoot surf photo's in the water with a fisheye (Tokina 10-17mm), the housing I have for my Canon 60D gives me access to the following controls: top scroll wheel, shutter button (manually and via a cable release on a pistol grip) and the live view button.

To focus above water I just set it to infinity and disable half press for auto focus, for below water I need to auto focus temporarily to get the virtual image from the dome port in focus, so shooting above and below in one session is not possible with my housing as it is.

The script uses the Live View button to auto focus for a certain period (I think 1 second will be enough but I haven't tried it out in the sea yet):


Here is my code, it does what I want it to but I don't really understand the important bits, I've just copied and pasted from the examples and tested it in the camera until it worked the way I wanted.

I'm actually amazed I got it to work, all down to the excellent examples in this forum, so a huge thanks for taking the time to write them and make them available.



/*
@title Focus With LV Button
@param n Focus duration in seconds
@range n 1 5
@default n 1
*/

while(1)
{
    int key = wait_key();

    if (key == LV) // when Live View button is pressed
{
console_hide(); // hide the script console

set_af(1); // enable AF for half-shutter press

press(SHOOT_HALF); // emulate half shutter being pressed
sleep(n); // hold button for n seconds
unpress(SHOOT_HALF); // emulate releasing half shutter

set_af(0); // disable AF for half-shutter press
}

    sleep(0.1);

}


The problem is, now the script runs until I switch the camera off, this isn't really an issue for me as I intend to leave it running until I finish shooting and take the camera out of the housing, but I assume there's a simple way to make it end the script

I've also written another script that allows me to use the Live view button to give me access to change the Aperture and ISO as well as the shutter speed which is something that I never thought I'd be able to do with my basic water housing, but I have the same problem as this script: not being able to exit.

I tried a couple of things to make it quit when I pressed a different button but I couldn't get it to work without an error message, is there some easy way to exit the script when I press the SET button?
Title: Re: Auto Focus with Live View Button
Post by: Kent on March 05, 2013, 11:31:03 PM
I have not tested it but maybe this can be used,, while (wait_key() != SET);
Title: Re: Auto Focus with Live View Button
Post by: benpascoe on March 06, 2013, 12:37:11 AM
Thanks for the suggestion, I have just tried it, I didn't know where to put it in the script so I tried it at the very end and inside the last set of brackets but both times it caused the script to work weird and still didn't allow me to exit the script when pressing the SET button.

I am going to stick with this bit which I put inside the last set of brackets:

    if (key == SET)
{
return(1);
}


That at least lets me end the script, even if it is with an error message, and allows the rest of it to work fine until I press SET.
Title: Re: Auto Focus with Live View Button
Post by: Kent on March 06, 2013, 05:44:09 PM
Try to replace    while(1)    with    while (wait_key() != SET);
tried it and it seems to work.
Title: Re: Auto Focus with Live View Button
Post by: benpascoe on March 06, 2013, 07:53:27 PM
Thanks, just tried it, it ends the script when I press the SET key with no error, but I have to press it twice, and it doesn't focus when I press the LV button any more.

I will try it in a different script later to see if I can get it working.

EDIT: I have now fixed it so it exits the script when the SET button is pressed with no error, and the LV button works as it should too, here's the finished code in case anyone's interested:


// Select duration of auto focus when live view button is pressed, default is 1 second

/*
@title Focus With LV Button
@param n Focus duration in seconds
@range n 1 5
@default n 1
*/

while(1)
{
    int key = wait_key();

    if (key == LV) // when Live View button is pressed
{
console_hide(); // hide the script console

set_af(1); // disable AF for half-shutter press

press(SHOOT_HALF); // emulate half shutter being pressed
sleep(n); // hold button for n seconds
unpress(SHOOT_HALF); // emulate releasing half shutter

set_af(0); // enable AF for half-shutter press
}

    sleep(0.1);

    if (key == SET)
{
break;
}
}