help with custom bracketing script

Started by gpedder, November 08, 2024, 02:33:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gpedder

I have limited experience of ML and Lua. I need a script that does a set of preset exposures. It should repeat each time the shutter is pressed until the user exits. I'm not sure what i'm doing wrong but i am not having any success. Any ideas?

--[[
Magic Lantern exposure sequence script
Takes a series of exposures with varying shutter speeds and apertures
]]

-- Global variable to control script execution
running = true

-- Error handling function
local function set_camera_property(property, value, property_name)
    if property.value == value then
        return true
    end
   
    property.value = value
    if property.value ~= value then
        print(string.format("Failed to set %s to %s", property_name, tostring(value)))
        return false
    end
    return true
end

-- Main sequence function
local function run_exposure_sequence()
    -- Initial setup
    if not (set_camera_property(camera.iso, 100, "ISO") and
            set_camera_property(camera.aperture, 8.0, "aperture") and
            set_camera_property(camera.shutter, 1.0, "shutter")) then
        print("Failed to set initial camera properties")
        return false
    end

    -- Alert user sequence is starting
    beep(2)
    msleep(3000)  -- 3 second delay before starting

    -- Exposure sequence
    local exposures = {
        {aperture = 8.0,  shutter = 1.0},
        {aperture = 8.0,  shutter = 1/4},
        {aperture = 8.0,  shutter = 1/32},
        {aperture = 16.0, shutter = 1/16},
        {aperture = 16.0, shutter = 1/125},
        {aperture = 16.0, shutter = 1/1000},
        {aperture = 22.0, shutter = 1/8000}
    }

    for i, exposure in ipairs(exposures) do
        if not running then
            return false
        end

        -- Set aperture if it changed
        if i == 1 or exposure.aperture ~= exposures[i-1].aperture then
            if not set_camera_property(camera.aperture, exposure.aperture, "aperture") then
                return false
            end
        end
       
        -- Set shutter speed
        if not set_camera_property(camera.shutter, exposure.shutter, "shutter") then
            return false
        end
       
        -- Take the shot
        camera.shoot()
       
        -- Small delay between shots
        msleep(1000)
    end

    -- Signal completion
    beep(3)
    return true
end

-- Menu button handler
function menu_handler()
    running = false
    print("Menu button pressed - exiting script")
    return true -- Prevents other handlers from processing the event
end

-- Shutter button handler
function shutter_handler()
    if running then
        print("Starting new sequence")
        run_exposure_sequence()
    end
    return true
end

-- Main function
function main()
    print("Starting exposure sequence script")
    print("Press shutter to start sequence")
    print("Press menu button to exit")
   
    -- Register event handlers
    menu.handler = menu_handler
    camera.shutter.handler = shutter_handler
   
    -- Keep script running until menu is pressed
    while running do
        msleep(1000)
    end
   
    -- Clean up
    menu.handler = nil
    camera.shutter.handler = nil
end

main()