Clean script exit? - Script Writing - CHDK Forum
supplierdeeply

Clean script exit?

  • 11 Replies
  • 8133 Views
Clean script exit?
« on: 20 / June / 2009, 05:58:42 »
Advertisements
Hi there, just noticed that interrupting a script that uses AF lock will leave my a590 in a state where it cannot focus without a power cycle. 

So I added a trap for the 'shoot_half' key to clean exit the script by clearing the AF lock and turning display on.

Was wondering if there's either a) a way to trap the 'shoot' key in ubasic for clean exit, or b) a consensus on which key to use for clean script exit.

The 'shoot_half' seems okay for this, I now use 'set' to wakeup the cam from idle state.

Thoughts?

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Clean script exit?
« Reply #1 on: 21 / June / 2009, 14:56:59 »
Using shoot_half for this is probably the best you can do, but monitoring a keypress is of course not very convenient for all scripts (impossible during md_detect_motion, inconvenient in scripts that mostly spend their time shooting). AFAIK you can't trap shoot, which is a good thing because it's the way to interrupt an unwanted/buggy/malfunctioning/erraneously started/whatever script that always works the same way. Of course the problem with half shoot is that it requires a delicate touch and you may full press by accident.

But I remember an old feature request (well, at least this has been discussed before) that -- for example -- the script interpreter should not immediately interrupt with the shoot key but instead jump to a shutdown function/subroutine/whatever if one has been defined in the script. A second shutter press could then interrupt a malfunctioning/slow shutdown routine.

Feel free to search the bugtracker for this request and add it there if not found... and naturally you're warmly invited to implement this (preferably for both lua and ubasic) if you're up to it...

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Clean script exit?
« Reply #2 on: 21 / June / 2009, 15:08:44 »
But I remember an old feature request (well, at least this has been discussed before) that -- for example -- the script interpreter should not immediately interrupt with the shoot key but instead jump to a shutdown function/subroutine/whatever if one has been defined in the script. A second shutter press could then interrupt a malfunctioning/slow shutdown routine.

It was also implemented both in uBASIC and Lua.
IIRC,
uBASIC tries to jump to label :restore
Lua tries to call function restore()

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Clean script exit?
« Reply #3 on: 21 / June / 2009, 15:18:26 »
It was also implemented both in uBASIC and Lua.
IIRC,
uBASIC tries to jump to label :restore
Lua tries to call function restore()

Wow, I had forgotten that :)

You're right, implemented in changeset 417 for ubasic from http://chdk.setepontos.com/index.php/topic,1687.0.html and 474 for Lua.


Re: Clean script exit?
« Reply #4 on: 21 / June / 2009, 16:02:08 »
Okay, I check for 'shoot_half' for clean exit, 'set' for wakeup LCD, during the script interval delays.  I used 'set' 'cos it's easy to find by feel on a590 in the dark -- it's on a tripod staring out the kitchen window at the sky with dark screen and green LED on during the night, waiting for predawn timelapse start.

I meant trap for what you've got with :restore / restore(), will try that out too.  Thanks :)

Re: Clean script exit?
« Reply #5 on: 22 / June / 2009, 06:56:08 »
uBASIC tries to jump to label :restore

Works as advertised on a590 101b -778 :)  Thanks!

*

Offline Mac

  • *
  • 40
Re: Clean script exit?
« Reply #6 on: 22 / June / 2009, 09:32:40 »
Question: What does restore() buy you?
Tried the following:
function restore()
   print("Restore activated")
   for i =1,5 do print("fun")
   n=0
   end
n=1
while n==1 do
   sleep(1000)
   print("Sleeping!")
   end
print("Script successfully terminated")
When the shutter was pressed, the message "Restore activated" was printed followed by "Script Terminated!".
Nothing else was done.
How is this any better than just dumping out of the script?

*

Offline reyalp

  • ******
  • 14111
Re: Clean script exit?
« Reply #7 on: 22 / June / 2009, 18:24:19 »
Mac if you want to restore settings you changed earlier in the script, or save files or anything like that.
Don't forget what the H stands for.


*

Offline Mac

  • *
  • 40
Re: Clean script exit?
« Reply #8 on: 23 / June / 2009, 07:41:21 »
Missed my point or am I missing something?
Restore() only executed the first line of code and not the rest of the test script.
Would be hard to reset camera defaults with only one line of code.
Maybe my cameras are different (S2is &S5is)?

Re: Clean script exit?
« Reply #9 on: 23 / June / 2009, 08:05:38 »
Missed my point or am I missing something?
Restore() only executed the first line of code and not the rest of the test script.
Would be hard to reset camera defaults with only one line of code.
Maybe my cameras are different (S2is &S5is)?

Here's an example, this is tail end of daylapse:
Code: [Select]
...
wend

:restore
rem ubasic traps 'shoot_full', clear shutdown
o = 0

:done
set_aflock 0
sleep 100
click "shoot_half"
sleep A
if o & 4 then goto "shutdown"

print "'half shoot' to exit..."
wait_click 20000
is_key k "shoot_half"
if k > 0 then end
goto "shutdown"

:lobatt
print v; "mV, LoBatt exit"
sleep 2000

:shutdown
shut_down
sleep 3000
end

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal