CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/CHDK-Scripts/Cannon S100/3DR_EAI_S100.lua
Views: 1799
1
2
--[[
3
4
KAP UAV Exposure Control Script v3.2
5
-- Released under GPL by waterwingz and wayback/peabody
6
http://chdk.wikia.com/wiki/KAP_%26_UAV_Exposure_Control_Script
7
8
3DR EAI 1.0 is a fork of KAP 3.1 with settings specific to Canon cameras triggered off the Pixhawk autopilot.
9
Changelog:
10
-Modified Tv, Av, and ISO settings for the Canon SX260
11
-Added an option to turn the GPS on and off
12
-Added control of GPS settings in Main Loop
13
-Changed USB OneShot mode to listen for 100ms command pulse from Pixhawk
14
-Adapted for S100 settings
15
16
@title 3DR EAI 1.0 - Lets Map!
17
@param i Shot Interval (sec)
18
@default i 2
19
@range i 2 120
20
@param s Total Shots (0=infinite)
21
@default s 0
22
@range s 0 10000
23
@param j Power off when done?
24
@default j 0
25
@range j 0 1
26
@param e Exposure Comp (stops)
27
@default e 6
28
@values e -2.0 -1.66 -1.33 -1.0 -0.66 -0.33 0.0 0.33 0.66 1.00 1.33 1.66 2.00
29
@param d Start Delay Time (sec)
30
@default d 0
31
@range d 0 10000
32
@param y Tv Min (sec)
33
@default y 5
34
@values y None 1/60 1/100 1/200 1/400 1/640
35
@param t Target Tv (sec)
36
@default t 7
37
@values t 1/100 1/200 1/400 1/640 1/800 1/1000 1/1250 1/1600 1/2000
38
@param x Tv Max (sec)
39
@default x 4
40
@values x 1/1000 1/1250 1/1600 1/2000 1/3200 1/5000 1/10000
41
@param f Av Low(f-stop)
42
@default f 1
43
@values f 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
44
@param a Av Target (f-stop)
45
@default a 2
46
@values a 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
47
@param m Av Max (f-stop)
48
@default m 13
49
@values m 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
50
@param p ISO Min
51
@default p 0
52
@values p 80 100 200 400 800 1250 1600
53
@param q ISO Max1
54
@default q 1
55
@values q 100 200 400 800 1250 1600
56
@param r ISO Max2
57
@default r 3
58
@values r 100 200 400 800 1250 1600
59
@param n Allow use of ND filter?
60
@default n 0
61
@values n No Yes
62
@param z Zoom position
63
@default z 0
64
@values z Off 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
65
@param c Focus @ Infinity Mode
66
@default c 3
67
@values c None @Shot AFL MF
68
@param v Video Interleave (shots)
69
@default v 0
70
@values v Off 1 5 10 25 50 100
71
@param w Video Duration (sec)
72
@default w 10
73
@range w 5 300
74
@param u Trigger Type
75
@default u 2
76
@values u Interval Cont. USB PWM
77
@param g GPS On
78
@default g 1
79
@range g 0 1
80
@param b Backlight Off?
81
@default b 1
82
@range b 0 1
83
@param l Logging
84
@default l 3
85
@values l Off Screen SDCard Both
86
--]]
87
88
props=require("propcase")
89
capmode=require("capmode")
90
91
-- convert user parameter to usable variable names and values
92
tv_table = { -320, 576, 640, 736, 832, 896, 928, 960, 992, 1024, 1056, 1113, 1180, 1276}
93
tv96target = tv_table[t+3]
94
tv96max = tv_table[x+8]
95
tv96min = tv_table[y+1]
96
sv_table = { 381, 411, 507, 603, 699, 761, 795 }
97
sv96min = sv_table[p+1]
98
sv96max1 = sv_table[q+2]
99
sv96max2 = sv_table[r+2]
100
av_table = { 171, 192, 218, 265, 285, 322, 347, 384, 417, 446, 477, 510, 543, 576 }
101
av96target = av_table[a+1]
102
av96minimum = av_table[f+1]
103
av96max = av_table[m+1]
104
ec96adjust = (e - 6)*32
105
video_table = { 0, 1, 5, 10, 25, 50, 100 }
106
video_mode = video_table[v+1]
107
video_duration = w
108
interval = i*1000
109
max_shots = s
110
poff_if_done = j
111
start_delay = d
112
backlight = b
113
log_mode= l
114
focus_mode = c
115
usb_mode = u
116
gps = g
117
if ( z==0 ) then zoom_setpoint = nil else zoom_setpoint = (z-1)*10 end
118
119
-- initial configuration values
120
nd96offset=3*96 -- ND filter's number of equivalent f-stops (f * 96)
121
infx = 50000 -- focus lock distance in mm (approximately 55 yards)
122
shot_count = 0 -- shot counter
123
blite_timer = 300 -- backlight off delay in 100mSec increments
124
old_console_timeout = get_config_value( 297 )
125
shot_request = false -- pwm mode flag to request a shot be taken
126
127
-- check camera Av configuration ( variable aperture and/or ND filter )
128
if n==0 then -- use of nd filter allowed?
129
if get_nd_present()==1 then -- check for ND filter only
130
Av_mode = 0 -- 0 = ND disabled and no iris available
131
else
132
Av_mode = 1 -- 1 = ND disabled and iris available
133
end
134
else
135
Av_mode = get_nd_present()+1 -- 1 = iris only , 2=ND filter only, 3= both ND & iris
136
end
137
138
function printf(...)
139
if ( log_mode == 0) then return end
140
local str=string.format(...)
141
if (( log_mode == 1) or (log_mode == 3)) then print(str) end
142
if ( log_mode > 1 ) then
143
local logname="A/3DR_EAI_log.log"
144
log=io.open(logname,"a")
145
log:write(os.date("%Y%b%d %X ")..string.format(...),"\n")
146
log:close()
147
end
148
end
149
150
tv_ref = { -- note : tv_ref values set 1/2 way between shutter speed values
151
-608, -560, -528, -496, -464, -432, -400, -368, -336, -304,
152
-272, -240, -208, -176, -144, -112, -80, -48, -16, 16,
153
48, 80, 112, 144, 176, 208, 240, 272, 304, 336,
154
368, 400, 432, 464, 496, 528, 560, 592, 624, 656,
155
688, 720, 752, 784, 816, 848, 880, 912, 944, 976,
156
1008, 1040, 1072, 1096, 1129, 1169, 1192, 1225, 1265, 1376 }
157
158
tv_str = {
159
">64",
160
"64", "50", "40", "32", "25", "20", "16", "12", "10", "8.0",
161
"6.0", "5.0", "4.0", "3.2", "2.5", "2.0", "1.6", "1.3", "1.0", "0.8",
162
"0.6", "0.5", "0.4", "0.3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13",
163
"1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125",
164
"1/160", "1/200", "1/250", "1/320", "1/400", "1/500", "1/640", "1/800", "1/1000","1/1250",
165
"1/1600","1/2000","1/2500","1/3200","1/4000","1/5000","1/6400","1/8000","1/10000","hi" }
166
167
function print_tv(val)
168
if ( val == nil ) then return("-") end
169
local i = 1
170
while (i <= #tv_ref) and (val > tv_ref[i]) do i=i+1 end
171
return tv_str[i]
172
end
173
174
av_ref = { 160, 176, 208, 243, 275, 304, 336, 368, 400, 432, 464, 480, 496, 512, 544, 592, 624, 656, 688, 720, 752, 784 }
175
av_str = {"n/a","1.8", "2.0","2.2","2.6","2.8","3.2","3.5","4.0","4.5","5.0","5.6","5.9","6.3","7.1","8.0","9.0","10.0","11.0","13.0","14.0","16.0","hi"}
176
177
function print_av(val)
178
if ( val == nil ) then return("-") end
179
local i = 1
180
while (i <= #av_ref) and (val > av_ref[i]) do i=i+1 end
181
return av_str[i]
182
end
183
184
sv_ref = { 370, 397, 424, 456, 492, 523, 555, 588, 619, 651, 684, 731, 779, 843, 907 }
185
sv_str = {"n/a","80","100","120","160","200","250","320","400","500","640","800","1250","1600","3200","hi"}
186
187
function print_sv(val)
188
if ( val == nil ) then return("-") end
189
local i = 1
190
while (i <= #sv_ref) and (val > sv_ref[i]) do i=i+1 end
191
return sv_str[i]
192
end
193
194
function pline(message, line) -- print line function
195
fg = 258 bg=259
196
197
end
198
199
-- switch between shooting and playback modes
200
function switch_mode( m )
201
if ( m == 1 ) then
202
if ( get_mode() == false ) then
203
set_record(1) -- switch to shooting mode
204
while ( get_mode() == false ) do
205
sleep(100)
206
end
207
sleep(1000)
208
end
209
else
210
if ( get_mode() == true ) then
211
set_record(0) -- switch to playback mode
212
while ( get_mode() == true ) do
213
sleep(100)
214
end
215
sleep(1000)
216
end
217
end
218
end
219
220
-- focus lock and unlock
221
function lock_focus()
222
if (focus_mode > 1) then -- focus mode requested ?
223
if ( focus_mode == 2 ) then -- method 1 : set_aflock() command enables MF
224
if (chdk_version==120) then
225
set_aflock(1)
226
set_prop(props.AF_LOCK,1)
227
else
228
set_aflock(1)
229
end
230
if (get_prop(props.AF_LOCK) == 1) then printf(" AFL enabled") else printf(" AFL failed ***") end
231
else -- mf mode requested
232
if (chdk_version==120) then -- CHDK 1.2.0 : call event proc or levents to try and enable MF mode
233
if call_event_proc("SS.Create") ~= -1 then
234
if call_event_proc("SS.MFOn") == -1 then
235
call_event_proc("PT_MFOn")
236
end
237
elseif call_event_proc("RegisterShootSeqEvent") ~= -1 then
238
if call_event_proc("PT_MFOn") == -1 then
239
call_event_proc("MFOn")
240
end
241
end
242
if (get_prop(props.FOCUS_MODE) == 0 ) then -- MF not set - try levent PressSw1AndMF
243
post_levent_for_npt("PressSw1AndMF")
244
sleep(500)
245
end
246
elseif (chdk_version >= 130) then -- CHDK 1.3.0 : set_mf()
247
if ( set_mf(1) == 0 ) then set_aflock(1) end -- as a fall back, try setting AFL is set_mf fails
248
end
249
if (get_prop(props.FOCUS_MODE) == 1) then printf(" MF enabled") else printf(" MF enable failed ***") end
250
end
251
sleep(1000)
252
set_focus(infx)
253
sleep(1000)
254
end
255
end
256
257
function unlock_focus()
258
if (focus_mode > 1) then -- focus mode requested ?
259
if (focus_mode == 2 ) then -- method 1 : AFL
260
if (chdk_version==120) then
261
set_aflock(0)
262
set_prop(props.AF_LOCK,0)
263
else
264
set_aflock(0)
265
end
266
if (get_prop(props.AF_LOCK) == 0) then printf(" AFL unlocked") else printf(" AFL unlock failed") end
267
else -- mf mode requested
268
if (chdk_version==120) then -- CHDK 1.2.0 : call event proc or levents to try and enable MF mode
269
if call_event_proc("SS.Create") ~= -1 then
270
if call_event_proc("SS.MFOff") == -1 then
271
call_event_proc("PT_MFOff")
272
end
273
elseif call_event_proc("RegisterShootSeqEvent") ~= -1 then
274
if call_event_proc("PT_MFOff") == -1 then
275
call_event_proc("MFOff")
276
end
277
end
278
if (get_prop(props.FOCUS_MODE) == 1 ) then -- MF not reset - try levent PressSw1AndMF
279
post_levent_for_npt("PressSw1AndMF")
280
sleep(500)
281
end
282
elseif (chdk_version >= 130) then -- CHDK 1.3.0 : set_mf()
283
if ( set_mf(0) == 0 ) then set_aflock(0) end -- fall back so reset AFL is set_mf fails
284
end
285
if (get_prop(props.FOCUS_MODE) == 0) then printf(" MF disabled") else printf(" MF disable failed") end
286
end
287
sleep(100)
288
end
289
end
290
291
-- zoom position
292
function update_zoom(zpos)
293
local count = 0
294
if(zpos ~= nil) then
295
zstep=((get_zoom_steps()-1)*zpos)/100
296
printf("setting zoom to "..zpos.." percent step="..zstep)
297
sleep(200)
298
set_zoom(zstep)
299
sleep(2000)
300
press("shoot_half")
301
repeat
302
sleep(100)
303
count = count + 1
304
until (get_shooting() == true ) or (count > 40 )
305
release("shoot_half")
306
end
307
end
308
309
-- restore camera settings on shutdown
310
function restore()
311
set_config_value(121,0) -- USB remote disable
312
set_config_value(297,old_console_timeout) -- restore console timeout value
313
if (backlight==1) then set_lcd_display(1) end -- display on
314
unlock_focus()
315
if( zoom_setpoint ~= nil ) then update_zoom(0) end
316
if( shot_count >= max_shots) and ( max_shots > 1) then
317
if ( poff_if_done == 1 ) then -- did script ending because # of shots done ?
318
printf("power off - shot count at limit") -- complete power down
319
sleep(2000)
320
post_levent_to_ui('PressPowerButton')
321
else
322
set_record(0) end -- just retract lens
323
end
324
end
325
326
-- Video mode
327
function check_video(shot)
328
local capture_mode
329
if ((video_mode>0) and(shot>0) and (shot%video_mode == 0)) then
330
unlock_focus()
331
printf("Video mode started. Button:"..tostring(video_button))
332
if( video_button ) then
333
click "video"
334
else
335
capture_mode=capmode.get()
336
capmode.set('VIDEO_STD')
337
press("shoot_full")
338
sleep(300)
339
release("shoot_full")
340
end
341
local end_second = get_day_seconds() + video_duration
342
repeat
343
wait_click(500)
344
until (is_key("menu")) or (get_day_seconds() > end_second)
345
if( video_button ) then
346
click "video"
347
else
348
press("shoot_full")
349
sleep(300)
350
release("shoot_full")
351
capmode.set(capture_mode)
352
end
353
printf("Video mode finished.")
354
sleep(1000)
355
lock_focus()
356
return(true)
357
else
358
return(false)
359
end
360
end
361
362
-- PWM USB pulse functions
363
364
function ch1up()
365
printf(" * usb pulse = ch1up")
366
shot_request = true
367
end
368
369
function ch1mid()
370
printf(" * usb pulse = ch1mid")
371
if ( get_mode() == false ) then
372
switch_mode(1)
373
lock_focus()
374
end
375
end
376
377
function ch1down()
378
printf(" * usb pulse = ch1down")
379
switch_mode(0)
380
end
381
382
function ch2up()
383
printf(" * usb pulse = ch2up")
384
update_zoom(100)
385
end
386
387
function ch2mid()
388
printf(" * usb pulse = ch2mid")
389
if ( zoom_setpoint ~= nil ) then update_zoom(zoom_setpoint) else update_zoom(50) end
390
end
391
392
function ch2down()
393
printf(" * usb pulse = ch2down")
394
update_zoom(0)
395
end
396
397
function pwm_mode(pulse_width)
398
if pulse_width > 0 then
399
if pulse_width < 5 then ch1up()
400
elseif pulse_width < 8 then ch1mid()
401
elseif pulse_width < 11 then ch1down()
402
elseif pulse_width < 14 then ch2up()
403
elseif pulse_width < 17 then ch2mid()
404
elseif pulse_width < 20 then ch2down()
405
else printf(" * usb pulse width error") end
406
end
407
end
408
409
-- Basic exposure calculation using shutter speed and ISO only
410
-- called for Tv-only and ND-only cameras (cameras without an iris)
411
function basic_tv_calc()
412
tv96setpoint = tv96target
413
av96setpoint = nil
414
local min_av = get_prop(props.MIN_AV)
415
-- calculate required ISO setting
416
sv96setpoint = tv96setpoint + min_av - bv96meter
417
-- low ambient light ?
418
if (sv96setpoint > sv96max2 ) then -- check if required ISO setting is too high
419
sv96setpoint = sv96max2 -- clamp at max2 ISO if so
420
tv96setpoint = math.max(bv96meter+sv96setpoint-min_av,tv96min) -- recalculate required shutter speed down to Tv min
421
-- high ambient light ?
422
elseif (sv96setpoint < sv96min ) then -- check if required ISO setting is too low
423
sv96setpoint = sv96min -- clamp at minimum ISO setting if so
424
tv96setpoint = bv96meter + sv96setpoint - min_av -- recalculate required shutter speed and hope for the best
425
end
426
end
427
428
429
-- Basic exposure calculation using shutter speed, iris and ISO
430
-- called for iris-only and "both" cameras (cameras with an iris & ND filter)
431
function basic_iris_calc()
432
tv96setpoint = tv96target
433
av96setpoint = av96target
434
-- calculate required ISO setting
435
sv96setpoint = tv96setpoint + av96setpoint - bv96meter
436
-- low ambient light ?
437
if (sv96setpoint > sv96max1 ) then -- check if required ISO setting is too high
438
sv96setpoint = sv96max1 -- clamp at first ISO limit
439
av96setpoint = bv96meter + sv96setpoint - tv96setpoint -- calculate new aperture setting
440
if ( av96setpoint < av96min ) then -- check if new setting is goes below lowest f-stop
441
av96setpoint = av96min -- clamp at lowest f-stop
442
sv96setpoint = tv96setpoint + av96setpoint - bv96meter -- recalculate ISO setting
443
if (sv96setpoint > sv96max2 ) then -- check if the result is above max2 ISO
444
sv96setpoint = sv96max2 -- clamp at highest ISO setting if so
445
tv96setpoint = math.max(bv96meter+sv96setpoint-av96setpoint,tv96min) -- recalculate required shutter speed down to tv minimum
446
end
447
end
448
-- high ambient light ?
449
elseif (sv96setpoint < sv96min ) then -- check if required ISO setting is too low
450
sv96setpoint = sv96min -- clamp at minimum ISO setting if so
451
tv96setpoint = bv96meter + sv96setpoint - av96setpoint -- recalculate required shutter speed
452
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
453
tv96setpoint = tv96max -- clamp at maximum shutter speed if so
454
av96setpoint = bv96meter + sv96setpoint - tv96setpoint -- calculate new aperture setting
455
if ( av96setpoint > av96max ) then -- check if new setting is goes above highest f-stop
456
av96setpoint = av96max -- clamp at highest f-stop
457
tv96setpoint = bv96meter + sv96setpoint - av96setpoint -- recalculate shutter speed needed and hope for the best
458
end
459
end
460
end
461
end
462
463
-- calculate exposure for cams without adjustable iris or ND filter
464
function exposure_Tv_only()
465
insert_ND_filter = nil
466
basic_tv_calc()
467
end
468
469
-- calculate exposure for cams with ND filter only
470
function exposure_NDfilter()
471
insert_ND_filter = false
472
basic_tv_calc()
473
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
474
insert_ND_filter = true -- flag the ND filter to be inserted
475
bv96meter = bv96meter - nd96offset -- adjust meter for ND offset
476
basic_tv_calc() -- start over, but with new meter value
477
bv96meter = bv96meter + nd96offset -- restore meter for later logging
478
end
479
end
480
481
-- calculate exposure for cams with adjustable iris only
482
function exposure_iris()
483
insert_ND_filter = nil
484
basic_iris_calc()
485
end
486
487
-- calculate exposure for cams with both adjustable iris and ND filter
488
function exposure_both()
489
insert_ND_filter = false -- NOTE : assume ND filter never used automatically by Canon firmware
490
basic_iris_calc()
491
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
492
insert_ND_filter = true -- flag the ND filter to be inserted
493
bv96meter = bv96meter - nd96offset -- adjust meter for ND offset
494
basic_iris_calc() -- start over, but with new meter value
495
bv96meter = bv96meter + nd96offset -- restore meter for later logging
496
end
497
end
498
499
-- ========================== Main Program =================================
500
501
set_console_layout(1 ,1, 45, 14 )
502
503
--printf("KAP 3.1 started - press MENU to exit")
504
printf("3DR EAI 1.0 Canon SX260 - Lets Map!")
505
printf("Based On KAP 3.1")
506
printf("Press the shutter button to pause")
507
bi=get_buildinfo()
508
printf("%s %s-%s %s %s %s", bi.version, bi.build_number, bi.build_revision, bi.platform, bi.platsub, bi.build_date)
509
chdk_version= tonumber(string.sub(bi.build_number,1,1))*100 + tonumber(string.sub(bi.build_number,3,3))*10 + tonumber(string.sub(bi.build_number,5,5))
510
if ( tonumber(bi.build_revision) > 0 ) then
511
build = tonumber(bi.build_revision)
512
else
513
build = tonumber(string.match(bi.build_number,'-(%d+)$'))
514
end
515
516
if ((chdk_version<120) or ((chdk_version==120)and(build<3276)) or ((chdk_version==130)and(build<3383))) then
517
printf("CHDK 1.2.0 build 3276 or higher required")
518
else
519
if( props.CONTINUOUS_AF == nil ) then caf=-999 else caf = get_prop(props.CONTINUOUS_AF) end
520
if( props.SERVO_AF == nil ) then saf=-999 else saf = get_prop(props.SERVO_AF) end
521
cmode = capmode.get_name()
522
printf("Mode:%s,Continuous_AF:%d,Servo_AF:%d", cmode,caf,saf)
523
printf(" Tv:"..print_tv(tv96target).." max:"..print_tv(tv96max).." min:"..print_tv(tv96min).." ecomp:"..(ec96adjust/96).."."..(math.abs(ec96adjust*10/96)%10) )
524
printf(" Av:"..print_av(av96target).." minAv:"..print_av(av96minimum).." maxAv:"..print_av(av96max) )
525
printf(" ISOmin:"..print_sv(sv96min).." ISO1:"..print_sv(sv96max1).." ISO2:"..print_sv(sv96max2) )
526
printf(" MF mode:"..focus_mode.." Video:"..video_mode.." USB:"..usb_mode)
527
printf(" AvM:"..Av_mode.." int:"..(interval/1000).." Shts:"..max_shots.." Dly:"..start_delay.." B/L:"..backlight)
528
sleep(500)
529
530
if (start_delay > 0 ) then
531
printf("entering start delay of ".. start_delay.." seconds")
532
sleep( start_delay*1000 )
533
end
534
535
-- CAMERA CONFIGURATION -
536
-- FIND config table here http://subversion.assembla.com/svn/chdk/trunk/core/conf.c
537
set_config_value(2,0) --Save raw: off
538
if (gps==1) then
539
set_config_value(282,1) --turn GPS on
540
--set_config_value(278,1) --show GPS symbol
541
set_config_value(261,1) --wait for signal time
542
set_config_value(266,5) --battery shutdown percentage
543
end
544
545
-- enable USB remote in USB remote moded
546
if (usb_mode > 0 ) then
547
set_config_value(121,1) -- make sure USB remote is enabled
548
if (get_usb_power(1) == 0) then -- can we start ?
549
printf("waiting on USB signal")
550
repeat wait_click(20) until ((get_usb_power(1) == 1) or ( is_key("menu")))
551
--changed sleep from 1000 to 500
552
else sleep(500) end
553
printf("USB signal received")
554
end
555
556
-- switch to shooting mode
557
switch_mode(1)
558
559
-- set zoom position
560
update_zoom(zoom_setpoint)
561
-- lock focus at infinity
562
lock_focus()
563
-- disable flash and AF assist lamp
564
set_prop(props.FLASH_MODE, 2) -- flash off
565
set_prop(props.AF_ASSIST_BEAM,0) -- AF assist off if supported for this camera
566
set_config_value( 297, 60) -- set console timeout to 60 seconds
567
568
if (usb_mode > 2 ) then repeat until (get_usb_power(2) == 0 ) end -- flush pulse buffer
569
next_shot_time = get_tick_count()
570
script_exit = false
571
if( get_video_button() == 1) then video_button = true else video_button = false end
572
set_console_layout(2 ,0, 45, 4 )
573
repeat
574
--BB: Set get_usb_power(2) > 7 for a 70/100s pulse
575
--BB: Could consider a max threshold to prevent erroneous trigger events
576
--eg. get_usb_power(2) > 7 && get_usb_power(2) < 13
577
if( ( (usb_mode < 2 ) and ( next_shot_time <= get_tick_count() ) )
578
or ( (usb_mode == 2 ) and (get_usb_power(2) > 7 ) )
579
or ( (usb_mode == 3 ) and (shot_request == true ) ) ) then
580
581
-- time to insert a video sequence ?
582
if( check_video(shot_count) == true) then next_shot_time = get_tick_count() end
583
584
-- intervalometer timing
585
next_shot_time = next_shot_time + interval
586
587
-- set focus at infinity ? (maybe redundant for AFL & MF mode but makes sure it's set right)
588
if (focus_mode > 0) then
589
set_focus(infx)
590
sleep(100)
591
end
592
593
-- check exposure
594
local count = 0
595
local timeout = false
596
press("shoot_half")
597
repeat
598
sleep(50)
599
count = count + 1
600
if (count > 40 ) then timeout = true end
601
until (get_shooting() == true ) or (timeout == true)
602
603
-- shoot in auto mode if meter reading invalid, else calculate new desired exposure
604
if ( timeout == true ) then
605
release("shoot_half")
606
repeat sleep(50) until get_shooting() == false
607
shoot() -- shoot in Canon auto mode if we don't have a valid meter reading
608
shot_count = shot_count + 1
609
printf(string.format('IMG_%04d.JPG',get_exp_count()).." : shot in auto mode, meter reading invalid")
610
else
611
-- get meter reading values (and add in exposure compensation)
612
bv96raw=get_bv96()
613
bv96meter=bv96raw-ec96adjust
614
tv96meter=get_tv96()
615
av96meter=get_av96()
616
sv96meter=get_sv96()
617
618
-- set minimum Av to larger of user input or current min for zoom setting
619
av96min= math.max(av96minimum,get_prop(props.MIN_AV))
620
if (av96target < av96min) then av96target = av96min end
621
622
-- calculate required setting for current ambient light conditions
623
if (Av_mode == 1) then exposure_iris()
624
elseif (Av_mode == 2) then exposure_NDfilter()
625
elseif (Av_mode == 3) then exposure_both()
626
else exposure_Tv_only()
627
end
628
629
-- set up all exposure overrides
630
set_tv96_direct(tv96setpoint)
631
set_sv96(sv96setpoint)
632
if( av96setpoint ~= nil) then set_av96_direct(av96setpoint) end
633
634
if(Av_mode > 1) and (insert_ND_filter == true) then -- ND filter available and needed?
635
set_nd_filter(1) -- activate the ND filter
636
nd_string="NDin"
637
else
638
set_nd_filter(2) -- make sure the ND filter does not activate
639
nd_string="NDout"
640
end
641
642
-- and finally shoot the image
643
press("shoot_full_only")
644
sleep(100)
645
release("shoot_full")
646
repeat sleep(50) until get_shooting() == false
647
shot_count = shot_count + 1
648
649
-- update shooting statistic and log as required
650
shot_focus=get_focus()
651
if(shot_focus ~= -1) and (shot_focus < 20000) then
652
focus_string=" foc:"..(shot_focus/1000).."."..(((shot_focus%1000)+50)/100).."m"
653
if(focus_mode>0) then
654
error_string=" **WARNING : focus not at infinity**"
655
end
656
else
657
focus_string=" foc:infinity"
658
error_string=nil
659
end
660
printf(string.format('%d) IMG_%04d.JPG',shot_count,get_exp_count()))
661
printf(" meter : Tv:".. print_tv(tv96meter) .." Av:".. print_av(av96meter) .." Sv:"..print_sv(sv96meter).." "..bv96raw ..":"..bv96meter)
662
printf(" actual: Tv:".. print_tv(tv96setpoint).." Av:".. print_av(av96setpoint).." Sv:"..print_sv(sv96setpoint))
663
printf(" AvMin:".. print_av(av96min).." NDF:"..nd_string..focus_string )
664
665
if ((max_shots>0) and (shot_count >= max_shots)) then script_exit = true end
666
667
shot_request = false -- reset shot request flag
668
669
end
670
collectgarbage()
671
end
672
673
-- check if USB remote enabled in intervalometer mode and USB power is off -> pause if so
674
if ((usb_mode == 1 ) and (get_usb_power(1) == 0)) then
675
printf("waiting on USB signal")
676
unlock_focus()
677
switch_mode(0)
678
repeat wait_click(20) until ((get_usb_power(1) == 1) or ( is_key("menu")))
679
switch_mode(1)
680
lock_focus()
681
if ( is_key("menu")) then script_exit = true end
682
printf("USB wait finished")
683
sleep(100)
684
end
685
686
if (usb_mode == 3 ) then pwm_mode(get_usb_power(2)) end
687
688
if (blite_timer > 0) then
689
blite_timer = blite_timer-1
690
if ((blite_timer==0) and (backlight==1)) then set_lcd_display(0) end
691
end
692
693
if( error_string ~= nil) then
694
draw_string( 16, 144, string.sub(error_string.." ",0,42), 258, 259)
695
end
696
697
wait_click(100)
698
699
if( not( is_key("no_key"))) then
700
if ((blite_timer==0) and (backlight==1)) then set_lcd_display(1) end
701
blite_timer=300
702
if ( is_key("menu") ) then script_exit = true end
703
end
704
705
until (script_exit==true)
706
printf("script halt requested")
707
restore()
708
end
709
710
--[[ end of file ]]--
711
712
713
714