Sure thing... It isn't great (so I'd appreciate any refinements, etc), but it is finally working!
--[[\
@title BalloonTimer - by Nathan White
@param k InitDelay --initial delay length
@default k 300
@param x InitVid -- launch video length (liftoff)
@default x 300
@param a LoopDelay -- Delay before moving into the loop
@default a 600
@param b Pduration --Duration of stills cycle
@default b 300
@param c Pinterval -- Time between stills
@default c 5
@param d Vduration -- Duration of video
@default d 120
@param e backlight: 0=Off 1=On
default e 0
@param p printf --toggle print to screen
@default p 0
@param l logf --toggle print to log file
@default l 1
@param n Pmode: 1=Auto 2=Program 8=Landscape
@default n 2
--]]
--This is a script designed for a near-space balloon launch using our SD940 IS
--It alternatives between video and stills, and turns the backlight off to conserver battery
--Would like to set it to infinity focus mode, but havent found a way yet
--Hopefully "landscape" mode will favour long focal distances.
capmode=require("capmode")
props = require("propcase")
logname = "A/BalloonTimer.log"
log = io.open(logname,"wb")
if not log then
error("Failed to Open Log\n")
end
function printf(...)
if (p == 1) then --if we're writing to the screen
print(string.format(...))
end
if (l == 1) then --if we're writing to the log
log:write(string.format(...))
log:close()
log = io.open(logname,"ab")
end
end
function log_rec_change(rec) --switch between shoot and playback mode
local status_str, sleep_count
if rec then
printf("Leaving Playback Mode\n")
else
printf("Entering Playback Mode\n")
end
set_record(rec)
sleep_count = 0
while sleep_count < 100 do -- wait up to 10 seconds for function change
if (rec and get_mode()) or not (rec or get_mode()) then
break
end
sleep(100)
sleep_count = sleep_count + 1
end
if (rec and get_mode()) or not (rec or get_mode()) then
printf("Left Playback Mode, Success!\n")
elseif not (rec or get_mode()) then
printf("Entered Playback Mode, Success!\n")
else
printf("Display Mode Not Set!\n")
end
end
function change_mode(mCode) --change shooting mode (auto/program/video/etc)
local status, sleep_count, id
if mCode == "Picture" then --translate mCode into id value
id = n --photo mode
else
id = 9 --video
end
if not get_mode() then
log_rec_change(true)
end
printf("Changing to " .. mCode .. " mode\n")
status = capmode.set(id)
if status then
sleep_count = 0
while sleep_count < 100 do --wait up to 10 seconds for mode to change
if (capmode.get() == id) then
printf("Changed to " .. mCode .. " mode\n")
break
end
sleep(100)
sleep_count = sleep_count + 1
end
if capmode.get() ~= id then
printf("Could not change to " .. mCode .. " mode\n")
end
else
printf("Error setting " .. mCode .. " mode\n")
end
end
function delay_cycle(duration) --delay
printf("Delaying for " .. duration .. " seconds\n")
if e == 0 then --if we're turning the backlight off
set_backlight(0)
end
sleep(duration*1000)
end
function pic_cycle(duration, interval) --take photos for a specified duration with a specified interval between each
local numShots = duration/interval
local i = 0
change_mode("Picture")
sleep(1000)
printf("Will now shoot " .. numShots .. " shots\n")
while i < numShots do
printf("Shot " .. i+1 .. " of " .. numShots .. " \n")
shoot()
i = i + 1
if e == 0 then --if we're turning the backlight off (after shoot, it automatically turns back on)
set_backlight(0)
end
sleep(interval*1000)
end
end
function vid_cycle(duration) --take video for a specified duration
local sleep_count, status
change_mode("Video")
printf("Will now shoot " .. duration .. " seconds of video\n")
if e == 0 then --if we're turning the backlight off
set_backlight(0)
end
press("shoot_full")
sleep(300)
release("shoot_full")
sleep(duration*1000)
press("shoot_full")
sleep(300)
release("shoot_full")
while (get_movie_status == 4) do --needed this because sometimes it wouldnt stop recording without pressing the button a few times (weird)
printf("Video Termination Required")
sleep(1000)
if (get_movie_status == 4) then
press("shoot_full")
sleep(300)
release("shoot_full")
end
end
printf("Video Done\n")
end
--program runs as follows:
-- delay initially (once we press the shutter button because we need a few more minutes to setup the launch)
-- take a video of the launch (lift-off!)
-- transition into a cycle of video and photos until the battery runs out.
printf("***\n")
printf("** BEGIN **\n")
log_rec_change(true)
printf("***\n")
printf("** INITIAL DELAY **\n")
delay_cycle(k)
printf("***\n")
printf("** INITIAL LAUNCH VIDEO **\n")
vid_cycle(x)
printf("***\n")
printf("** VID/STILL CYCLE **\n")
local t = 1
while 0 < 1 do --loop forever
printf("Cycle " .. t .. " and counting\n")
delay_cycle(a)
pic_cycle(b, c)
sleep(5000)
vid_cycle(d)
t = t + 1
printf(" \n")
end