retract the lens before power cut

  • 1 Replies
  • 579 Views
*

Offline axman

  • ***
  • 142
retract the lens before power cut
« on: 19 / November / 2015, 01:19:46 »
Advertisements
Hello,

ixus160-elph160, CHDK build 1.4.0 rev 4286, chdkptp rev 676.  Basic rig is a tiny PC, plus an Aruino driving various cameras.  Doing intervalometry and weather data acquisition/processing.

Ixus160 is modified: power on-off switch shorted together, external power by way of 12v 55AH AGM battery (from a wheelchair/electric scooter) - all hardware mods Working fine.  Thanks to this post 

Here's post in another thread that might be of interest :  Auto on-off management

Note the little gold pin sockets - shorting those fires the shutter.
and the referred post re: Auto on-off management
were quite helpful to me, thanks waterwingz.

I was looking now to gracefully retract the lens before cutting power to camera when chdkptp tasks are complete.  Started here;  http://chdk.setepontos.com/index.php?topic=2751.msg25770#msg25770
Discovered function named "shut_down" - but it's an old post..  Casual grep thru scripts provided with 1.4.0 rev 4286 did not reveal a function named shut_down,

But in looking at source code from Ultimate, http://chdk.wikia.com/wiki/Ultimate_Intervalometer , I found reference where we reboot() and post_levent_to_ui('PressPowerButton')  :) 

I run un-ashamedly stolen* lua snips from within a chdkptp session to the cam.  This code works perfectly. 
Code: [Select]
con> =status,msg=post_levent_to_ui('PressPowerButton') sleep(10000) if msg then print(msg) end
Lens retracts.  Cam power remains on, LCD remains on (because I have not yet cut power.)  I cut power.  It goes off.  All fine.  My chdkptp session dutifully reports           ERROR:  I/O error

My lua understanding improves.  I/O Error is due to cam "turning off" (thinking it is turning off) before the lua I started in chdkptp can gracefully complete.. 

The '=' means run at cam, the '.' means despool lua action to cam and return immediately, I think.

Code: [Select]
con3> .status,msg=post_levent_to_ui('PressPowerButton') sleep(10000) if msg then print(msg) end
con4>

No error!   :-D

Will report on power consumption if interesting to anyone.  Thanks to reyalp, waterwingz, and all who develop CHDK and related tools.

*<ahem - "borrowed & adapted" - from stuff reyalp and waterwingz wrote>

*

Offline reyalp

  • ******
  • 11084
Re: retract the lens before power cut
« Reply #1 on: 19 / November / 2015, 02:17:00 »
Discovered function named "shut_down" - but it's an old post..  Casual grep thru scripts provided with 1.4.0 rev 4286 did not reveal a function named shut_down,
shut_down exists, but I tend recommend the post_levent method, since it should make the canon firmware respond exactly as if you had pressed the power button, while shut_down was something developed before we knew how to use levents.

If you haven't already, you may want to bookmark http://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page

Quote
I run un-ashamedly stolen* lua snips from within a chdkptp session to the cam.  This code works perfectly. 
Code: [Select]
con> =status,msg=post_levent_to_ui('PressPowerButton') sleep(10000) if msg then print(msg) end
FWIW,  post_levent_to_ui doesn't actually return anything, so you don't need the status,msg= or if ...

If you wanted to check that the camera actually shut down, you'd have to do it in chdkptp side code, for example by checking con:is_connected()

Quote
The '=' means run at cam, the '.' means despool lua action to cam and return immediately, I think.
Correct.
= sends the code, waits for it to finish, and then prints any return values or error messages.
. sends the code, and returns immediately after the camera Lua engine compiles it. It will only report compile time errors, not run time errors or return values. You can check for error or return values from . using the getm command.
Don't forget what the H stands for.

 

Related Topics