choosing focuspoints with lua script: need help

Started by alext, July 31, 2017, 01:50:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

alext

I'm working on a projekt, where I try to get the orientation of a plane by reading the focus motor position with different focuspoints on my 50d with the magiclanter-lua_fix.2017Jul06.50D109 build.
I already managed to automaticly focus and get the correct motor position with lens.focus_pos but I always have to change the focuspoint manually.
I got the Idea to use the key.press() funktion to automaticly change the focuspoints, but KEY.ZOOMIN (same hardware key as for choosing focuspoints) only works to zoom in on pictures.
I tried to use the keys:getkey() funtion to see, if i used the wrong key code for choosing focuspoints, but I always get an error in ML/Scripts/lib/keys.lua. With the following code I get an error in line 48: bad argument #1 to 'remove' ...


require('keys')
console.clear()
console.show()
console.write('press Key')
task.yield(500)
console.write(keys:getkey())


By using keys:keys() befor calling keys:getkey() I get the error: attempt to call a nil value (method 'keys)

Is there any point I'm missing or does anyone have a better idea for solving this problem?

Thanks in advance

Alexander

dmilligan

There appears to be a typo in the lua API docs. It's keys:start() not keys:keys(). These functions are designed to be used in a main loop. If you just want to detect a single key press, key.last or key.wait() will be easier.

a1ex

To change zoom in LiveView, try lv.zoom(5). That's what I've tested (see api_test.lua), although I'd expect the key event to work as well (will check).

ML has an API to change the focus box position; it's just not exposed to Lua.

alext

thanks for your quick reply
@dmilligan it worked with keys:start() but like I suspected, there is no key code for this event.
@a1ex I found your tutorial on writing modules and I'll try to solve it this way. I set everything up for compiling modules and allready found a few things in the source code but I didn't find anything on how to use autofocus. could you give me a few hints on how to solve this?

a1ex

For autofocus, look at lens_take_picture arguments (should_af can be AF_ENABLE, AF_DISABLE or AF_DONT_CHANGE - keep current setting from Canon menu). The same argument is also used in Lua camera.shoot(), but only with the first two choices.