Skip to content

Instantly share code, notes, and snippets.

@adongy
Created May 6, 2014 13:41
Show Gist options
  • Save adongy/5985b6b4611edf5858bc to your computer and use it in GitHub Desktop.
Save adongy/5985b6b4611edf5858bc to your computer and use it in GitHub Desktop.
require('chdkptp')
require('lfs')
require('lbuf')
require('rawimg')
require('io')
require('os')
util=require('util')
util:import()
ustime=require('ustime')
fsutil=require('fsutil')
prefs=require('prefs')
chdku=require('chdku')
cli=require('cli')
exp=require('exposure')
dng=require('dng')
dngcli=require('dngcli')
--[[connect devices]]
--[[commands]]
--if you have a variable named con it's the connection accessed by default
con1=chdku.connection()
con2=chdku.connection()
dngcli.init_cli()
--then check https://www.assembla.com/code/chdkptp/subversion/nodes/564/trunk/lua/cli.lua#ln342
devs=chdk.list_usb_devices()
return devs
con1:connect(devs[1])
con=con1
con2:connect(devs[2])
con=con2
-- now you can do con1:exec(...) to execute remote code (execwait works too)
--2 choices: use the cli.lua frontend or do it manually
--[[example: in the chdkptp you want to do remoteshoot -tv=1/25 -sv=52 "/tmp/output"
what you actually do in a lua shell is
cli:print_status(cli:execute('remoteshoot -tv=1/25 -sv=52 "/tmp/output"'))
warning: you must have a connection already established, and it must be named con
or use it directly by looking at the func part
, resolve where it goes, and modify so that you can customize the ocnnection
rsint: isolate relevant sections (we don't need cli support)
]]
rsint=require('rsint')
rsint.register_rlib()
--https://www.assembla.com/code/chdkptp/subversion/nodes/564/trunk/lua/rsint.lua#ln71
--args=rsint from cli.lua args
local args,msg = cli.names[cmd].args:parse(args)
local opts,err = cli:get_shoot_common_opts(args)
if not opts then
return false,err
end
util.extend_table(opts,{
fformat=0,
lstart=0,
lcount=0,
})
-- fformat required for init
if args.jpg then
opts.fformat = opts.fformat + 1
end
if args.dng then
opts.fformat = opts.fformat + 6
else
if args.raw then
opts.fformat = opts.fformat + 2
end
if args.dnghdr then
opts.fformat = opts.fformat + 4
end
end
-- default to jpeg TODO won't be supported on cams without raw hook
if opts.fformat == 0 then
opts.fformat = 1
args.jpg = true
end
if args.badpix and not args.dng then
util.warnf('badpix without dng ignored\n')
end
if args.s or args.c then
if args.dng or args.raw then
if args.s then
opts.lstart = tonumber(args.s)
end
if args.c then
opts.lcount = tonumber(args.c)
end
else
util.warnf('subimage without raw ignored\n')
end
end
local rcopts
rcopts,err = init_handlers(args,opts)
if not rcopts then
return false, err
end
-- wait time for remotecap
opts.cap_timeout=30000
-- wait time for shoot hook
opts.shoot_hook_timeout=args.cmdwait * 1000
local opts_s = serialize(opts)
cli.dbgmsg('rs_init\n')
local status,rstatus,rerr = con:execwait('return rsint_init('..opts_s..')',{libs={'rsint'}})
if not status then
return false,rstatus
end
if not rstatus then
return false,rerr
end
local status,err = con:exec('return rsint_run('..opts_s..')',{libs={'rsint'}})
-- rs_shoot should not initialize remotecap if there's an error, so no need to uninit
if not status then
return false,err
end
--[[you can use con:write_msg(cmd) to send messages to exec on the camera
if cmd is s it shoots, if it's l it shoots then quits
remember to download the image if you shoot!
do con:capture_get_data(opts) with opts the rs opts
TODO: extract relevant parts from chdku.lua
]]
status, err = con:write_msg(cmd)
if not status then
done=true
warnf('write_msg failed %s\n',tostring(err))
-- TODO might have remotecap data, but probably won't be able to read it if msg failed
break
end
if cmd == 's' or cmd == 'l' then
status,err = con:capture_get_data(rcopts)
if not status then
warnf('capture_get_data error %s\n',tostring(err))
end
if cmd == 'l' then
done=true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment