LUA: Block a "for" loop

Started by PizziDellaMaremma, May 09, 2022, 10:59:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PizziDellaMaremma

Hi!
I'm new to photography, new to astrophotography and new to ML! What a wonderful piece of code :D

I was hoping to find a long exposure intervalometer integrated in ML but there's not. So I'm writing it by myself.

The biggest problem with the following code is when the for loop is working, nothing can stop the loop.

I need to find a way to catch the exception like another button press, but I'm not too skilled on Lua. (be kind with the following code, it's wrote bad, I know)


lexi = menu.new
{
    parent = "Shoot",
    name = "LExI",
    help = "Long Exposure Intervalometer (w/reps)",
    submenu =
    {
{
            name = "Enable",
            help = "Enable LEXI",
choices = {"Off","On"}
        },
{
            name = "Initial delay",
            help = "Initial delay after shutter start.",
min = 5,
max = 20,
value = 10,
unit = UNIT.TIME
        },
{
name = "Exposure length",
help = "Length of the exposure.",
min = 0,
max = 900,
value = 20,
unit = UNIT.TIME
},
{
name = "Delay",
help = "Delay between shoots.",
min = 5,
max = 30,
value = 8,
unit = UNIT.TIME
},
{
name = "Repetitions",
help = "Number of repetitions.",
min = 1,
max = 999,
value = 1,
unit = UNIT.INT
},
    }
}

-- return false if something wrong, else true
function checks()
-- check bulb
if camera.mode ~= MODE.BULB then
display.notify_box("LEXI chk - Not in Bulb!")
return false
end
-- check af
if camera.af == true then
display.notify_box("LEXI chk - Disable AF and stab!")
return false
end
return true
end

function repeated_shots(init_delay, exp_length, dly, reps)

display.notify_box("Starting LEXI...")
sleep(init_delay)

-- repeated shots
local n = 1
for i = reps, 1, -1 do
display.notify_box(string.format("Running cycle %s", n))
camera.bulb(exp_length)

if n == reps then
break
else
sleep(dly)
n = n + 1
end
end
end

-- trigger
function event.keypress(key)
-- check halfshutter and enable
if key == KEY.HALFSHUTTER and lexi.submenu["Enable"].value == "On" then

-- check bulb mode
if checks() == true then

-- set variables
local init_delay = lexi.submenu["Initial delay"].value
local exp_length = lexi.submenu["Exposure length"].value
local dly = lexi.submenu["Delay"].value
local reps = lexi.submenu["Repetitions"].value

--
repeated_shots(init_delay,exp_length,dly,reps)

-- ERROR: BLOCK NEW CYCLE
lexi.submenu["Enable"].value = "Off"

end
end
end


Any suggestion? [AF check isn't working, but it's not a problem at the moment]

Cheers!
D.

Walter Schulz

At the moment forum's scripting corner is quite abandoned. User garry23 is active on CHDK with EOS M3 and may be able to help you.
Dev talk on ML has switched to Discord and none of the new devs is involved in LUA.
Some years ago another astro photographer wrote a major script for catching critical phases of a solar eclipse. If Garry can't support you it might be a last straw to go there.
https://www.cloudynights.com/topic/581411-new-canonmagic-lantern-script-eclipse-magic-generate-and-execute-a-full-sequence-of-varied-exposures-spanning-all-eclipse-phases/


PizziDellaMaremma

Ok, thank you for your reply. Should be quite simple, maybe I can try to copy some stuffs from that script.