How to set camera time with scripts "lua or uBasic"? - page 3 - Script Writing - CHDK Forum

How to set camera time with scripts "lua or uBasic"?

  • 22 Replies
  • 13370 Views
Re: How to set camera time with scripts "lua or uBasic"?
« Reply #20 on: 20 / February / 2013, 20:51:29 »
Advertisements
If I switch to another language (and back to English, doesn't matter afterwards), "Enable Lua Native Calls" becomes "Exposure Control (No Flash)". This looks like a bug.
edit: The language files of CHDK 1.1 and 1.2 are not compatible (why?).
Looks like somebody decided to reuse a string ID #  ( 259 ) in the LANG files. That ID was used for something in 1.1 that was subsequently deleted in 1.2.   Later,  somebody decide to reuse it rather than take the next free string number.


Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14082
Re: How to set camera time with scripts "lua or uBasic"?
« Reply #21 on: 20 / February / 2013, 23:13:49 »
Its a pain to have to edit the minutes so I can set them.  I would like to just be able to set the year, month, day, hour, minutes and second automatically when I connect the camera to the USB port. 
There isn't really a convenient way to do this. You could use the PTP extension http://chdk.wikia.com/wiki/PTP_Extension to run the same script functions using time values from your PC, but it wouldn't be automatic without additional work on your part. Also, installing the libusb driver will disable normal windows PTP functionality, so you may not want to do that if you normally use it to transfer files.

Using chdkptp, you could do something like this to set the camera time to your current pc time:
Code: [Select]
con 1> =return call_event_proc('FA.Create')
2:return:0
con 2> =return call_event_proc('InitializeAdjustmentFunction')
3:return:0
con 3> !return con:execwait(string.format("return call_event_proc('SetHour',%d),call_event_proc('SetMinute',%d),call_event_proc('SetSecond',%d),os.date()",os.date('%H'),os.date('%M'),os.date('%S')))
=true,1361390643,1361390643,1361390644,"Wed Feb 20 20:04:04 2013"
The various returns let you know if the functions worked. If either of the 1st two are -1, the registration names are different on your camera.
The final one should return the new camera time as the final result. The preceding values might be -1 if the functions weren't registered correctly.

You could of course put the whole thing in a file instead of typing it every time.
Quote
This will take some playing around.  I've already found the date and time statements/commands in the lua syntax page at <   http://www.lua.org/pil/22.1.html   >.  This would be a nice "standard" feature for CHDK. 
CHDK lua does support os.date and os.time, with some minor exceptions relating to timezones and formats not supported by the underlying OS. However, these functions only get or format time values, they do not allow you to set the system clock.
Don't forget what the H stands for.

Re: How to set camera time with scripts "lua or uBasic"?
« Reply #22 on: 20 / February / 2013, 23:50:06 »
I found a cute emulator that in the case of the first suggested script produced the same results as the camera.

http://www.lua.org/cgi-bin/demo

I will be busy with other things for a few days and then I may be able to get back to this.

Thanks everyone.

 

Related Topics