Lua Help!!!!

Started by garry23, February 07, 2016, 10:29:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

I'm bashing my head trying to get a Lua script to work.

It does, but I keep getting the console starting (when I'm not switch it on) and the repeated message...

"Lua semaphore time out (another task is running this script)" followed by a Save Configs,

Can anyone suggest what I'm doing wrong?

dmilligan


garry23

David

This is not the finished script, but I believe it works well, other than the console coming on and me getting the semaphore messages (which I don't understand).

This script is the manual version of the auto one that I will release, once Lua can control the lens in both directions.

I also note that when I press SET to run the script, a 0 comes up in the Run sub menu.

I hope you can find the time to cast your eyes over the script.

Cheers

Garry

--[[
Manual Landscape bracketing script
Version 0.3
Garry George Feb 2016
http://photography.grayheron.net/
Assumes lens is first focused at nearest bracket
in focus stack then moved towards infinity.
************************
* Must be in liveview! *
************************
--]]
require('keys')
function main()
-- Declare a few local variables for use only in this main function
local b2 = lens.dof_far
local fp = lens.focal_distance
local inf_reached = false
local inf = 1000000
local key
keys:start()
display.clear()
for i = keymenu.submenu["Delay"].value,0,-1
do
msleep(1000)
end
task.yield(100)
camera.shoot(64, 0)
repeat
task.yield(100)
key = keys:getkey()
if key == KEY.JOY_CENTER
then -- grab an image
task.yield(100)
b2 = lens.dof_far
fp = lens.focal_distance
if keymenu.submenu["Bracket to bracket overlap"].value == "1%"
then
b2 = b2 - (b2-fp*10)*0.01
end
if keymenu.submenu["Bracket to bracket overlap"].value == "5%"
then
b2 = b2 - (b2-fp*10)*0.05
end
-- Delay for requested seconds
for i = keymenu.submenu["Delay"].value,0,-1
do
msleep(1000)
end
task.yield(100)
camera.shoot(64, 0)
if lens.dof_far == inf then inf_reached = true end
end
-- provide feedback for next bracket position
if lens.dof_near > b2 then led_blink (3,50,500) end
if lens.dof_far == inf then beep(4, 100, 500) end
until key == KEY.RATE or inf_reached == true
-- quit script
beep(3, 100, 630)
keys:stop()
end

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run",
help = "Starts the script",
help2 = "Take first bracket and press SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(main) end,
},
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
},
{
name = "Bracket to bracket overlap",
help = "% to overlap each bracket",
help2 = "% of current fp-2-DoF",
choices = {"1%","5%", "None"},
}
}
}

dmilligan

You're probably seeing that error because your script is sleeping for long periods of time instead of yielding. This blocks your key event handler from running (the 'keys' lib is just a wrapper around event.keypress to make it easier to use a procedural rather than event-driven paradigm). msleep and task.yield are basically the same thing except yield allows other parts of your script to be run in the mean time (for example property or event handlers).

Since it appears you only are doing something in response to key events, the keys lib might actually be making your life harder. Some of the example scripts use 'keys' lib, but they do that because they "take over" the camera, and basically the only thing going on is them drawing and handling input (like a game).

To re-write your script using an event-driven design would look something like:

is_running = false
is_taking_picture = false

function do_take_picture()
--take the picture in another task so we don't block the key handler from returning
is_taking_picture = true
task.create(function()
msleep(1000 * keymenu.submenu["Delay"].value)
camera.shoot(64, 0)
is_taking_picture = false
end)
end

function main()
if is_running then return end
is_running = true
local b2 = lens.dof_far
local fp = lens.focal_distance
local inf_reached = false
local inf = 1000000
display.clear()
--take the first picture
msleep(1000 * keymenu.submenu["Delay"].value)
camera.shoot(64, 0)

--set the key handler
--main actually exits immediately after this b/c all it does is set the key handler
--but main's local variables stick around because the key handler "closes" on them (this is called a "closure")
event.keypress = function(key)
if is_taking_picture then
return false
elseif key == KEY.JOY_CENTER then
b2 = lens.dof_far
fp = lens.focal_distance
if keymenu.submenu["Bracket to bracket overlap"].value == "1%" then
b2 = b2 - (b2-fp*10)*0.01
end
if keymenu.submenu["Bracket to bracket overlap"].value == "5%" then
b2 = b2 - (b2-fp*10)*0.05
end
do_take_picture()
if lens.dof_far == inf then
--stop: unregister keypress handler so we stop recieving events
event.keypress = nil
is_running = false
beep(4, 100, 500)
end
    return true
elseif key == KEY.JOY_CENTER then
--stop: unregister keypress handler so we stop recieving events
event.keypress = nil
is_running = false
beep(4, 100, 500)
return true
end
return false
end
end

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run",
help = "Starts the script",
help2 = "Take first bracket and press SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(main) end,
},
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
},
{
name = "Bracket to bracket overlap",
help = "% to overlap each bracket",
help2 = "% of current fp-2-DoF",
choices = {"1%","5%", "None"},
}
}
}

garry23

David

Many thanks for taking the time to respond, educate me and rewrite my code.

I'll look tonight.

Cheers

Garry

garry23

David

I studied your 'version' of my code and other pieces of code on the Lua github pages, and hope you can explain something.

If I going to use events to track changes the basic framework would seem to me like this, ie I need a main loop (note not coded, just text)):

-- Set up things here

function do_something
-- for example
task.create(function()
msleep(1000 * keymenu.submenu["Delay"].value)
camera.shoot(64, 0)
is_taking_picture = false
end)
end

function do_something_else
-- other stuff
           task.create(function()
-- other stuff that needs 'isolating'
   end)
end

function main()
  repeat
  -- provide feedback on lens position

  -- look for keypress
  event.keypress = function(key)
    if is_taking_picture then
return false
elseif key == KEY.JOY_CENTER then
    do_something
    elseif key == KEY.RATE then
    do_something_else
    end
  end
  until end condition meet
end -- function main()

-- menu set up stuff


My confusion in looking at your example of my code is that I can't see the 'infinite' loop, ie repeat-until.

Or is the event.keypress the loop? That is if event.keypress returns false it simply keeps looking.

That is event.keypress becomes the 'main loop' waiting for the end key to be pressed, ie RATE for me.

Or have I miss interpreted event handling.

Cheers

Garry

BTW what does CBRs means?

dmilligan

The point of event driven programming, is that there is no "main loop". You simply declare some functions that will be executed in response to certain events (these are sometimes called "handlers" or CBRs: "call back routines"), and then tell the underlying framework about them. The underlying framework is then responsible for calling those functions when the events occur.

When you set event.keypress like this:

event.keypress = function(key)
    print(key)
    return false
end

You are basically telling the Lua backend that you want the function you declared to be executed each time there is a keypress. It won't get executed until there is a keypress and the backend passes the key that was pressed to the handler (the handler then prints it). It will keep executing your event handler each time another key is pressed until you tell the backend you don't want it to anymore like this:

event.keypress = nil


The return value of the handler is a way of sending information back to the backend. In the case of event.keypress it indicates whether or not the backend should consider that the keypress was "handled". There might be other things listening for keypresses (like other scripts, ML code, or Canon code). If you return true from the handler, it blocks all those other things from receiving the keypress. In the example above we always return false, so we're not "stealing" any keypress, we are just intercepting them and printing out the key, before they continue on their way and get processed by other things.

garry23

David

Truly I thank you for your time. I get it now.

The 'only' thing I'm struggling with is how to continuously get the DoF info and provide user feedback, eg dof_far >  inf, say, but continue looking for events.

The script I'm writing continuously provides the user feedback and only needs two key presses, to take a picture or stop the script.

The user manually adjusts the lens until the lens is positioned correctly according to user feedback.

I hope this makes sense:-)

dmilligan

Quote from: garry23 on February 09, 2016, 08:12:48 PM
The user manually adjusts the lens until the lens is positioned correctly according to user feedback.
Ah, missed that part.
Since this is LV, you can use the lv.info API to provider user feedback. See recdelay for an example.

garry23

David

More testing of things plus deeper reading of your demo recdelay demo script.

Also I tried running your recdelay script on my 5D3, but, although I'm in movie mode and have entered times for the delay etc, pressing SET fails to trigger the script, ie when Run highlighted.

Is there a nuance I'm not picking up?

Cheers

Garry

garry23

David :-)

I hope you still have time to help nudge me in the right direction.

I'm starting simple, to create a working framework, into which I'll add other functionality.

Here is the code:

--[[
Manual Landscape bracketing script
Version 0.3
Garry George Feb 2016
http://photography.grayheron.net/
Assumes lens is first focused at nearest bracket
in focus stack then moved towards infinity.
************************
* Must be in liveview! *
************************
--]]
is_taking_picture = false
b2 = lens.dof_far
fp = lens.focal_distance
inf_reached = false
inf = 1000000

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
},
{
name = "Bracket to bracket overlap",
help = "% to overlap each bracket",
help2 = "% of current fp-2-DoF",
choices = {"1%","5%", "None"},
}
}
}

event.post_shoot = function()
      beep(4, 100, 500)
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
           this.background = COLOR.RED
           this.foreground = COLOR.WHITE
this.value = string.format("DoF %dcm",lens.dof_near)
    end
}


The problem is, because it doesn't beed, I don't think the post shoot event is being picked up.

The LV is working and I see the DoF displayed in the bar at the top right of the ML menu. BTW how do I reposition this, or is it fixed in that location?

Cheers

Garry

garry23

David

I'm close to giving up, but don't want to!

This script keeps generating semaphore errors and I can't work out how to keep the ML LV display on, ie to get the visual feedback.

Can you kindly put me out of my misery: where am I going wrong.

All the script does is set up the key handler, provide LV feedback in the ML top bar, look for the joy stick (to take a picture and continue) or look for the INFO button to stop.

--[[
Manual Landscape bracketing script
Version 0.3.1
Garry George Feb 2016
http://photography.grayheron.net/
Assumes lens is first focused at nearest bracket
in focus stack then moved towards infinity.
************************
* Must be in liveview! *
************************
--]]
is_taking_picture = false
is_running = false
b2 = lens.dof_far
fp = lens.focal_distance
inf_reached = false
inf = 1000000

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run",
help = "Starts the script",
help2 = "Press SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(main) end,
},
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
},
{
name = "Bracket to bracket overlap",
help = "% to overlap each bracket",
help2 = "% of current fp-2-DoF",
choices = {"1%","5%", "None"},
}
}
}

function do_take_picture()
--take the picture in another task so we don't block the key handler from returning
is_taking_picture = true
task.create(function()
msleep(1000 * keymenu.submenu["Delay"].value)
beep(4, 100, 500)
camera.shoot(64, 0)
is_taking_picture = false
end)
end

function main()
if is_running then
return end
is_running = true
local b2 = lens.dof_far
local fp = lens.focal_distance
local inf_reached = false
local inf = 1000000
--set the key handler
--main actually exits immediately after this b/c all it does is set the key handler
--but main's local variables stick around because the key handler "closes" on them (this is called a "closure")
event.keypress = function(key)
if is_taking_picture then return false
elseif key == KEY.JOY_CENTER then
do_take_picture()
is_running = false
    return true
elseif key == KEY.INFO then
--stop: unregister keypress handler so we stop recieving events
event.keypress = nil
is_running = false
return true
end
return false
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
           this.background = COLOR.RED
           this.foreground = COLOR.WHITE
this.value = string.format("DoF %dcm",lens.dof_near)
    end
}

dmilligan

Changing msleep to task.yield should probably fix the problem

garry23

David

I had tried that before: but no luck.

Does anything else jump out at you:

--[[
Manual Landscape bracketing script
Version 0.3.1
Garry George Feb 2016
http://photography.grayheron.net/
Assumes lens is first focused at nearest bracket
in focus stack then moved towards infinity.
************************
* Must be in liveview! *
************************
--]]
is_taking_picture = false
is_running = false
b2 = lens.dof_far
fp = lens.focal_distance
inf_reached = false
inf = 1000000

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run",
help = "Starts the script",
help2 = "Press SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(main) end,
},
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
},
{
name = "Bracket to bracket overlap",
help = "% to overlap each bracket",
help2 = "% of current fp-2-DoF",
choices = {"1%","5%", "None"},
}
}
}

function do_take_picture()
--take the picture in another task so we don't block the key handler from returning
is_taking_picture = true
task.create(function()
task.yield(1000 * keymenu.submenu["Delay"].value)
beep(4, 100, 500)
camera.shoot(64, 0)
is_taking_picture = false
end)
end

function main()
if is_running then
return end
is_running = true
local b2 = lens.dof_far
local fp = lens.focal_distance
local inf_reached = false
local inf = 1000000
--set the key handler
--main actually exits immediately after this b/c all it does is set the key handler
--but main's local variables stick around because the key handler "closes" on them (this is called a "closure")
event.keypress = function(key)
if is_taking_picture then return false
elseif key == KEY.JOY_CENTER then
do_take_picture()
is_running = true
    return true
elseif key == KEY.INFO then
--stop: unregister keypress handler so we stop recieving events
event.keypress = nil
is_running = true
return true
end
return false
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
           this.background = COLOR.RED
           this.foreground = COLOR.WHITE
this.value = string.format("DoF %dcm",lens.dof_near)
    end
}

garry23

David

I hope you are still watching my 'progress' and sorry for all the posts. This post is the one to read  ;)

Here is the script that I think should run.

--[[
Manual Landscape bracketing script
Version 0.3.1
Garry George Feb 2016
http://photography.grayheron.net/
Assumes lens is first focused at nearest bracket
in focus stack then moved towards infinity.
************************
* Must be in liveview! *
************************
--]]
is_taking_picture = false
is_running = false

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacker",
help = "Focus at nearest point in bracket set",
help2 = "AF must be on and in LV!",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run",
help = "Starts the script",
help2 = "Press SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(main) end,
},
{
name = "Delay",
help = "Seconds to delay start (0-10s)",
value = 5,
min = 0,
max = 10,
}
}
}

function do_take_picture()
--take the picture in another task so we don't block the key handler from returning
is_taking_picture = true
task.create(function()
task.yield(1000 * keymenu.submenu["Delay"].value)
camera.shoot(64, 0)
end)
is_taking_picture = false
end

function main()
if is_running then return end
is_running = true
local b2 = lens.dof_far
local fp = lens.focal_distance
local inf_reached = false
local inf = 1000000
--press half shutter to toggle menu off (but this doesn't work!!!)
-- key.press(HALFSHUTTER)
-- task.yield(50)
-- key.press(UNPRESS_HALFSHUTTER)
--set up the key handler
--main exits immediately after this b/c all it does is set the key handler
event.keypress = function(key)
if is_taking_picture then
is_running = true
return false
elseif key == KEY.JOY_CENTER then
-- take a picture and keep looking for JOY_CENTER key press
do_take_picture()
is_running = true
return false
elseif key == KEY.RATE then
-- stop: unregister keypress handler so we stop receiving events and end script
event.keypress = nil
is_running = false
return true
end
return true
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
           this.background = COLOR.RED
           this.foreground = COLOR.WHITE
this.value = string.format("DoF %dcm",lens.dof_near)
    end
}


I still get semaphore messages in the console and the script exits after a press the JOY_CENTER button, and I don't think it should.

Also, after I press RUN in the menu, the menu stays on the screen. I can get rid of it, by manually pressing a half_shutter. So I tried to emulate that in the script, but that failed (so I commented it out).

All I want this script to do is remove the run menu, leave the ML bars on the LV, so I can provide feedback on DoF, and allow me to keep grabbing images via pressing the JOY_CENTER.

I just can't see what I'm doing wrong!

Hope you can put me out of my misery.

Cheers

Garry

garry23

David (hope you are scanning  :))

In a previous post http://www.magiclantern.fm/forum/index.php?topic=16614.msg162054#msg162054 you indicated that to 'steal' a keypress from the Lua event you should "...return true from the handler, it blocks all those other things from receiving the keypress. In the example above we always return false, so we're not "stealing" any keypress, we are just intercepting them and printing out the key, before they continue on their way and get processed by other things."

However, having spent hours testing various scripts the following will steal a key press. To not steal a key press, ie do my stuff and let the 'backend' carry on using the key press I would return true.

event.keypress = function(key)
    -- do my stuff
    return false
end


Bottom line: if I wish to 'steal' a keypress inside the event.keypress handler I would return false, if I wanted the key to be used 'as normal', ie not steal it, I would return true, ie letting ML access/use the keypress.

Or am I off base?

dmilligan

Got it backwards, sorry. In ML it actually is this way, but I switched it on purpose in Lua for consistency with the way the other CBRs work. The documentation is correct: http://davidmilligan.github.io/ml-lua/modules/event.html#keypress
Quote
whether or not to continue executing CBRs for this event

garry23


garry23

David

A Sunday, so more Lua testing/experimenting  :)

Your insight into semaphores has helped me appreciate the issues, but not how to resolve the problems.

Of course, maybe there are no work arounds to the like of script I have created, eg this one:

--[[
Manual Landscape bracketing helper script
Version 0.3.4
Garry George Feb 2016
http://photography.grayheron.net/
Workflow helper script for focus and exposure bracketing.
Try using ML follow focus to control the lens, as opposed to rotating lens by hand.
Yellow means move more towards the infinity end, Red means move more towards macro end,
Green means at the sweet spot. If Green not seen, move to just being in the Yellow from being in the Red.
************************
* Must be in liveview! *
************************
--]]
a1 = lens.dof_near
b1 = lens.dof_far
c1 = 0
fp = lens.focal_distance
inf = 1000000
started = false
bookend = true
current_tv = camera.shutter.apex
current_av = camera.aperture.apex

function do_bookend()
task.create(function()
if bookend then
current_tv = camera.shutter.apex
current_av = camera.aperture.apex
camera.shutter.apex = 100
task.yield(50)
camera.aperture.apex = 90
task.yield(50)
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",0) end
bookend = false
else
camera.aperture.apex = current_av
task.yield(50)
camera.shutter.apex = current_tv
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",1) end
task.yield(50)
bookend = true
end
end)
end

event.keypress = function(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
return true
else
if key == KEY.RATE then
if keymenu.submenu["Bookends"].value == "yes"
then
do_bookend()
return false
else
return true
end
end
if keymenu.submenu["Turn On/Off"].value == "Off" then started = false end
if fp ~= 0 then
if key == KEY.FULLSHUTTER
then
b1 = lens.dof_far -- in mm
fp = lens.focal_distance -- in cm
if keymenu.submenu["Bracket to bracket overlap"].value == "20%" then
factor = .2
elseif keymenu.submenu["Bracket to bracket overlap"].value == "10%" then
factor = .1
else
factor = .05
end
c1 = b1 - (b1 - fp*10)*factor
started = true
return true
end
end
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
    this.value = ""
if fp == 0 then
this.value = ""
else
    if keymenu.submenu["Turn On/Off"].value == "On"
    then
    if started then
a2 = lens.dof_near
this.value = ""
if a2 > b1 then
this.background = COLOR.RED
elseif a2 < c1 then
this.background = COLOR.YELLOW
this.foreground = COLOR.BLACK
else
this.background = COLOR.GREEN1
end
if lens.dof_far >= inf then
this.value = "Inf"
else
this.value = "   "
end
end
else
this.value = ""
end
end
end
}

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacking Helper",
help = "First focus at nearest point in bracket set",
help2 = "and take first picture",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Turn On/Off",
help = "Switches the script on/off",
help2 = "Simply enables addition button functionality",
depends_on = DEPENDS_ON.LIVEVIEW,
choices = {"Off","On"},
},
{
name = "Bracket to bracket overlap",
help = "Amount to overlap each bracket",
help2 = "% of FP-2-DoF(far) distance",
choices = {"20%","10%", "5%"},
},
{
name = "Bookends",
help = "Toggles a dark frame",
choices = {"no","yes"},
},
{
name = "Exposure bracketing",
help = "Set options in the ML bracketing menu",
choices = {"None","From here", "From ETTR"},
update = function(this)
if keymenu.submenu["Exposure bracketing"].value == "None" then
i = menu.set("Shoot","Advanced Bracket",0)
else
i = menu.set("Shoot","Advanced Bracket",1)
if keymenu.submenu["Exposure bracketing"].value == "From ETTR" then i = menu.set("Advanced Bracket","Sequence",2) end
if keymenu.submenu["Exposure bracketing"].value == "From here" then i = menu.set("Advanced Bracket","Sequence",1) end
end
end
}
}
}


It seems to me, and rather simplistically, it would be 'nice' if, when a script is running, it could take control or suspend 'semaphore' handling etc.

As I say, I'm most probably ignorant and I have to accept I can't do what I want. BTW the above code words fine sometimes, then every now an then it open the console and gives those damn semaphore errors  :(

dmilligan

I agree they probably shouldn't popup the console. I actually don't think I was the one who made it work like that ;)

garry23

David (I hope you find time to read this  ;) )

I'm seeing some strangeness with, what I believe are global variables.

This is part of my script, that I think sets up a few global variables and set up an event handler.

--[[
Manual Landscape bracketing helper script
Version 0.3.5
Garry George Feb 2016
http://photography.grayheron.net/
Workflow helper script for focus and exposure bracketing.
Try using ML follow focus to control the lens, as opposed to rotating lens by hand.
Yellow means move more towards the infinity end, Red means move more towards macro end,
Green means at the sweet spot. If Green not seen, move to just being in the Yellow from being in the Red.
************************
* Must be in liveview! *
************************
--]]

b1 = lens.dof_far
a1 = lens.dof_near
fp = lens.focal_distance
factor = .2
c1 = b1 - (b1 - fp*10)*factor
a2 = lens.dof_near
inf = 1000000
started = false
bookended = true
current_tv = camera.shutter.apex


event.keypress = function(key)
if key == KEY.RATE and keymenu.submenu["Turn On/Off"].value == "On" then
started = true
if started then display.notify_box (a1.."+"..b1.."+"..a2.."+"..factor) end
if keymenu.submenu["Bookends"].value == "yes"
then
if bookended then
current_tv = camera.shutter.apex
camera.shutter.apex = 100
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",0) end
bookended = false
else
camera.shutter.apex = current_tv
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",1) end
bookended = true
end
return false
else
return true
end
else
return true
end
end


variable factor (that is set in a menu) changes and I see that when I print the notify_box,

Variables a1, 2 and b1 all are zero, but I set them to non-zero when the script runs, eg a1 = lens.dof_near

What am I missing?

Cheers

Garry

dmilligan

How do you know that lens.dof_far, etc. are not returning zero when the globals are being set? If you are not in LV at the time the script loads, that makes sense.

garry23

David

I am in LV  :)

Also all the lens.dof_x calls reports OK when I call them again inside my code.

It seems to just be zero at the beginning, ie when set as a global, ie a1 = lens.dof_near

Strange.

garry23

David

Sorry!!!!!!!!!!!

Of course, it just dawned on me, that the script is loaded at camera start up BEFORE LV gets enabled.

I understand the zero now  :) :) :) :) :)

Cheers

Garry