Using chdkptp to set the resolution and quality - Script Writing - CHDK Forum

Using chdkptp to set the resolution and quality

  • 6 Replies
  • 5718 Views
Using chdkptp to set the resolution and quality
« on: 13 / July / 2015, 08:08:16 »
Advertisements
Hello, I am using chdkptp to connect to my camera that runs CHDK 1.3.

I wanted to lower the resolution of the picture that I get with "remoteshoot" and I have found this piece of code works:

Code: [Select]
print('Setting resolution')
cli:execute('set_prop(require("propcase").RESOLUTION, 2)')

However, I am not sure this is how it is supposed to be used. Thanks for any help.

bye!

*

Offline reyalp

  • ******
  • 14125
Re: Using chdkptp to set the resolution and quality
« Reply #1 on: 13 / July / 2015, 16:47:04 »
Not quite.

cli:execute executes a cli command, as you would type at the con> prompt, something like 'help' or 'remoteshoot' or '='. set_prop is a camera side lua function.

If you want to execute on the camera, you either need to use a cli command that sends code the camera like
Code: [Select]
cli:execute('luar set_prop(require("propcase").RESOLUTION, 2)')
('luar' aka '=' sends lua to the camera and waits for it to complete)

or use the connection object exec* methods to send the code directly like
Code: [Select]
con:execwait('set_prop(require("propcase").RESOLUTION, 2)')

In either case, it's a good idea to check or report the status of call like this, so you can see if there is an error. For cli:execute, you can use
Code: [Select]
cli:print_status(cli:execute('luar set_prop(require("propcase").RESOLUTION, 2)'))
If you had done this with your original code, you should have seen output like
Code: [Select]
ERROR: unknown command 'set_prop'

con:execwait will throw a Lua error if something fails. Normally this will terminate the running lua script and print some error information, but depending how it was invoked the error might be caught and printed instead (for example, if you executed it through the exec/! command)

If you want to catch errors instead, con:execwait_pcall or the Lua pcall/xpcall functions (see http://www.lua.org/manual/5.1/manual.html#pdf-pcall)
Don't forget what the H stands for.

Re: Using chdkptp to set the resolution and quality
« Reply #2 on: 15 / July / 2015, 09:57:32 »
Hello reyalp - you are absolutely right. I forgot the '=' (and the error check in this example). However, I wanted to focus on what is written internally in the command:

set_prop(require("propcase").RESOLUTION, 2)

why does the above work?

*

Offline reyalp

  • ******
  • 14125
Re: Using chdkptp to set the resolution and quality
« Reply #3 on: 15 / July / 2015, 21:58:40 »
set_prop(require("propcase").RESOLUTION, 2)

why does the above work?
Um, because that's the propcase that controls the resolution setting? In any case, that's the correct way to do it.
Don't forget what the H stands for.

Re: Using chdkptp to set the resolution and quality
« Reply #4 on: 16 / July / 2015, 01:54:57 »
Well in theory, I would need to inquiry the camera about which levels of resolution it supports, to be able to specify that '2' from a list of values that are known to work; in my tests, I think the number '1' crashed the camera.

Also, I was able to express that in a single line using 'require("propcase").RESOLUTION' but the original piece of code I read to perform this action used variables and two or three lines of code. Is it possible to send a bigger unit of execution to the camera instead of a single expression?

Code: [Select]
props=require("propcase")
value = 1
status=set_prop(props.RESOLUTION, value)

*

Offline reyalp

  • ******
  • 14125
Re: Using chdkptp to set the resolution and quality
« Reply #5 on: 16 / July / 2015, 02:45:34 »
Well in theory, I would need to inquiry the camera about which levels of resolution it supports, to be able to specify that '2' from a list of values that are known to work; in my tests, I think the number '1' crashed the camera.
I wouldn't expect 1 to crash. The values vary some between models, but see http://chdk.wikia.com/wiki/PropertyCase

In general 0, 1, 2 and 4 should work on all cameras, with 0 being native res, 1 and 2 being some camera dependent smaller sizes and 4 being 640x480.

To find out what the camera supports, you can set the resolution in the canon UI and check the propcase value with get_prop.

Quote
Also, I was able to express that in a single line using 'require("propcase").RESOLUTION' but the original piece of code I read to perform this action used variables and two or three lines of code. Is it possible to send a bigger unit of execution to the camera instead of a single expression?
Code: [Select]
props=require("propcase")
value = 1
status=set_prop(props.RESOLUTION, value)
chdkptp CLI (including cli:execute) only accept single lines.

edit: My mistake, cli:execute will actually accept multi-line strings, so you could do something like
Code: [Select]
cli:execute([[luar
props=require("propcase")
value = 1
set_prop(props.RESOLUTION, value)
]])

In Lua, new lines are just a white space, so you could put the second version in one line if you wanted.




If you use con:execwait, you can use mutli-line strings like
Code: [Select]
con:execwait([[
props=require("propcase")
value = 1
set_prop(props.RESOLUTION, value)
]])
but as I mentioned in the other post, this will have different error handling.
« Last Edit: 16 / July / 2015, 02:54:50 by reyalp »
Don't forget what the H stands for.

Re: Using chdkptp to set the resolution and quality
« Reply #6 on: 16 / July / 2015, 16:29:57 »
I wouldn't expect 1 to crash. The values vary some between models, but see http://chdk.wikia.com/wiki/PropertyCase

In general 0, 1, 2 and 4 should work on all cameras, with 0 being native res, 1 and 2 being some camera dependent smaller sizes and 4 being 640x480.

My mistake - it was "3" that crashed things:

Code: [Select]
con 6> =set_prop(require("propcase").RESOLUTION, 3)
con 7> remoteshoot image
WARNING: capture_get_data error I/O error
WARNING: error waiting for shot script nil
ERROR: /root/chdkptp/lua/cli.lua:2274: attempt to concatenate local 'err' (a table value)
stack traceback:
        [C]: in function 'xpcall'
        /root/chdkptp/lua/cli.lua:244: in function 'execute'
        /root/chdkptp/lua/cli.lua:351: in function </root/chdkptp/lua/cli.lua:342>
        (...tail calls...)
        /root/chdkptp/lua/main.lua:281: in main chunk
        [C]: in function 'require'
        [string "require('main')"]:1: in main chunk
___>


Good to know for the multi-line part, that answers my question perfectly.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal