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

  • 22 Replies
  • 3040 Views
  • Publish
    How to set camera time with scripts "lua or uBasic"?
    « on: 15 / December / 2011, 15:06:54 »
    Advertisements
    Is there away to set camera time using Lua or uBasic script?

  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #1 on: 15 / December / 2011, 15:10:18 »
    A kind of exotic;D

    AFAIK there is no script function that does this directly...
    if (2*b || !2*b) {
        cout<<question
    }

    Compile error: poor Yorick

    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #2 on: 16 / December / 2011, 00:32:33 »
    Is there away to set camera time using Lua or uBasic script?
    You might find an eventproc http://chdk.wikia.com/wiki/Event_Procedure which allows you to do this.

    What would you want this for ?
    Don't forget what the H stands for.

  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #3 on: 16 / December / 2011, 09:28:29 »
    I am using CHDK on a project with lots of cameras and would like to time synch them.

    Thanks,


    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #4 on: 17 / December / 2011, 00:00:45 »
    I am using CHDK on a project with lots of cameras and would like to time synch them.

    Thanks,
    How would you get the correct time ? Would you be doing this from a PC with PTP ?

    One alternative in a situation like this would just be to record the offset to a known time and fix it up in some post-process.

    FWIW, from http://chdk.wikia.com/wiki/User:ReyalP/EventProcNotes#SetDate there are some likely looking event procs known. From the a540 dump, it looks like SetDate expects an array of 6 ints.
    Don't forget what the H stands for.

  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #5 on: 17 / December / 2011, 14:06:40 »
    Hi;

    Yes I use PTP.
    I am having a hard time to just use the SetDate function correctly.  I look in the tstcallf.lua for example but did not get it.  Can you please give me an example how to call it?

    Thanks,

    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #6 on: 17 / December / 2011, 16:12:08 »
    I am having a hard time to just use the SetDate function correctly.  I look in the tstcallf.lua for example but did not get it. 
    Did you not understand it, or did it not work ? If you want help, you will get much better results if you give us a few more details.

    To call event procs, you need to be using a build of CHDK that supports "native calls". This is off by default in the CHDK autobuilds. You can build your own (using whims chdkshell for example http://chdk.setepontos.com/index.php?topic=845.0 ), or use chdkde, which has it enabled by default.

    See also http://chdk.wikia.com/wiki/Lua/Lua_Reference/Native_Function_Calls

    Quote
    Can you please give me an example how to call it?
    Again, it's not clear what you are asking. testcalf.lua shows you how to call event procs. The exact parameters required by SetDate need to be found by disassembling the firmware or experiment. It looks like it expects an array of 6 ints, which would correspond to year, month, day, hour, minute, second although not necessarily in that order.

    Eventprocs are just C functions. From lua, you can can only pass a string or number, so to pass a C array, you need to create it using AllocateMemory and poke, and pass the pointer as a lua number. Don't forget to free it when you are done. tstcallf has an example of this, although the wrappers to record test results make it a bit convoluted.

    To call SetDate as an event proc, you need to figure out what sequence of eventprocs is needed to register it. Generally, a return value of -1 from an eventproc means it wasn't registered, although of course there is no way to tell this from a registered function that happens to return -1.

    On a540  (and later cameras by the looks of it) InitializeAdjustmentFunction registers this function. Alternatively, if you are only using one or two camera/firmware versions, you can just figure out the address of the functions from the dump and call directly with call_func_ptr.

    edit:
    I wasn't able to get SetDate to work, but
    Code: [Select]
    call_event_proc('InitializeAdjustmentFunction')
    call_event_proc('SetHour',19)
    call_event_proc('SetMinute',01)
    worked as expected.

    edit:
    These functions call SetDate under the hood, so I must have done something wrong with the parameters.
    « Last Edit: 17 / December / 2011, 22:12:52 by reyalp »
    Don't forget what the H stands for.

  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #7 on: 19 / December / 2011, 22:44:32 »
    Hi Reyalp:
    Thank you so much for your help. 
    I was not able to get it working yet but you gave me lots of info to go on.

    I built CHDK and turn on all compile option relate to LUA including OPT_LUA_CALL_NATIVE. 
    I tried this on the SX30IS but it did not work.
    all_event_proc('InitializeAdjustmentFunction')
    call_event_proc('SetHour',19)
    call_event_proc('SetMinute',01)

    I looked into the strings.txt file from the firmware dump it is a little different then the A540, on the SX30IS the setDate, setHour, setMin etc..  they are spreading out.

    SetHour from SX30 strings.txt file:
    00000047F67D   00000047F67D      0   SetHour   
    if I use "call_func_ptr" how can I call the setHour?

    Again, thank you so much for your help.


    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #8 on: 19 / December / 2011, 23:57:46 »
    I tried this on the SX30IS but it did not work.
    all_event_proc('InitializeAdjustmentFunction')
    I guess the missing c here in your forum post ? It would be easier to help if you were more specific about than "did not work". Was there some error message ? What did the call_event_proc calls return ?

    Generally, call_event_proc returns  -1 if the eventproc wasn't registered.  Registration functions like "InitializeAdjustmentFunction" usually return 0. On a540, the date function return the new date as something like unix timestamp.

    you can use code like this to see what they are returning
    Code: [Select]
    function cep(name,...)
    print(name..':',call_event_proc(name,...))
    end

    cep('InitializeAdjustmentFunction')
    cep('SetHour',19)
    cep('SetMinute',01)


    Checking the status of each event proc call can give you some hints about what is going wrong.

    You cannot find the function address eventproc from the strings file, you need to use a disassembled firmware dump. You are probably better off figuring out why the eventproc doesn't work. I can see in the sx30 dump that both "InitializeAdjustmentFunction" and "SetHour" etc exist and look similar to whats on a540.

    Which canon firmware version does your sx30 have ?
    Don't forget what the H stands for.

  • Publish
    Re: How to set camera time with scripts "lua or uBasic"?
    « Reply #9 on: 20 / December / 2011, 10:49:17 »
    Hi Reyalp
    Quote
    function cep(name,...)
    print(name..':',call_event_proc(name,...))
    end
    cep('InitializeAdjustmentFunction')
    cep('SetHour',19)
    cep('SetMinute',01)

    I tried the above as you suggested all return "-1" on the following camera:
    SX30IS firmware version p
    G12      firmware version e
    SX20IS firmware version d

    When I built CHDK I turn on the following:
    ubasic, lua_stringlib, lua_oslib, exmem_malloc, exmem_testing, ptp, lua, lua_iolib, lua_call_Native, CHDK_in Exmem, GEN_SIGS, GEN_STUBB. 
    I also try to build CHDK with only the following turn on:
    ubasic, lua_stringlib, lua_oslib, ptp, lua, lua_iolib, lua_call_Native

    so, if the eventproc wasn't registered what should I do?


    Again, thank you so much for your help

     

    Related Topics