Lens info in Lua - General Discussion and Assistance - CHDK Forum  

Lens info in Lua

  • 16 Replies
  • 3986 Views
Lens info in Lua
« on: 30 / July / 2019, 12:58:36 »
Advertisements
@reyalp  or @anyone ;)

I can get camera info from get_buildinfo, but how do I get what lens is attached?

Or can't I?

Cheers

Garry

*

Offline reyalp

  • ******
  • 14080
Re: Lens info in Lua
« Reply #1 on: 30 / July / 2019, 13:23:07 »
I can get camera info from get_buildinfo, but how do I get what lens is attached?
There isn't any CHDK functions for this, since CHDK mostly doesn't support ILC cameras. I would expect some event proc or function returns that information for Canon lenses, at least.

Based on name alone, some candidates for further investigation:
EFLensCom.GetID
EFLensCom.GetLensType
EFLensCom.PrintCameraInfo
EFLensCom.PrintStatus
EFLensCom.PrintUnitSpec
ShowEFLensInfo
Don't forget what the H stands for.

Re: Lens info in Lua
« Reply #2 on: 30 / July / 2019, 13:51:30 »
@reyalp

Thanks for the pointers.

Doing a simple call eg

Code: [Select]
w = call_event_proc("EFLensCom.GetID")
Doesn't return anything of interest, eg 0 or -1.

My problem is I don't know if the above calls are enabled or need addition parameters.

*

Offline reyalp

  • ******
  • 14080
Re: Lens info in Lua
« Reply #3 on: 30 / July / 2019, 16:45:07 »
My problem is I don't know if the above calls are enabled or need addition parameters.
Yep, reverse engineering is required.
Code: [Select]
$ ./discam2.sh m3 120f -s=ShowEFLensInfo_FW -c=100                                                                     

; ShowEFLensInfo_FW 0xfc43e9af
    push    {r1, r2, r3, lr}
    adr     r0, #0xa0
    bl      sub_fc38010c
    adr     r0, #0x364 ;  *"[LENS INFO] =============================================\n"
    bl      sub_fc38010c
    bl      sub_fc2cc5ea
    mov     r1, r0
    adr     r0, #0x394 ;  *"LensID           = 0x%04X\n"
    bl      sub_fc38010c
    add     r1, sp, #4
    add     r0, sp, #8
    bl      sub_fc2f3fd4
    ldrb.w  r2, [sp, #4]
    adr     r0, #0x39c ;  *"LENS NAME: %s (Size: %ld Byte)\n"
    ldr     r1, [sp, #8]
    bl      sub_fc38010c
    bl      sub_fc2cc5de
    mov     r1, r0
    adr     r0, #0x3b0 ;  *"Wide FocalLength = %ld mm\n"
    bl      sub_fc38010c
    bl      sub_fc2cc5e4
    mov     r1, r0
    adr     r0, #0x3c0 ;  *"Tele FocalLength = %ld mm\n"
So fc2cc5ea returns the "lens ID" in r0. The eventproc GetLensIDValue ends up there too, after a few veneers.

fc38010c is something like f(char **name, int *namelen)
Don't forget what the H stands for.


Re: Lens info in Lua
« Reply #4 on: 30 / July / 2019, 17:00:37 »
@reyalp

First, once again thanks for the insight and education.

If only I knew where to go from here.

I'm afraid I will have to give up on this line of enquiry, as such low level stuff is beyond me.

I'm just a simple Lua scripter.

But, as I say, thanks for the response.

*

Offline reyalp

  • ******
  • 14080
Re: Lens info in Lua
« Reply #5 on: 30 / July / 2019, 17:11:23 »
First, once again thanks for the insight and education.
You can try call_event_proc("GetLensIDValue")
I think that should return a number that identifies the lens model. If it returns -1, you need to find the registration function, or call the function directly, like call_func_ptr(0xfc2cc5eb) for firmware 120f.

Getting the name is more complicated, but I can come up with some code if you want to try it.
Don't forget what the H stands for.

Re: Lens info in Lua
« Reply #6 on: 31 / July / 2019, 00:54:57 »
@reyalp

Many thanks for the support. I'm sure you have a lot of other things to focus on.

I would be grateful for any lua code you can throw my way that allows me to access the lens name or a lens unique Id, as I need to adjust my script according to the lens that is connected.

I did get -1, but didn't know where to go next. I'm afraid peeking around is something I have not done before, other than copying what someone else has done, i.e. the upper and lower focus distances.

BTW I am running on 120f.

Cheers

Garry

*

Offline reyalp

  • ******
  • 14080
Re: Lens info in Lua
« Reply #7 on: 31 / July / 2019, 02:10:55 »
I would be grateful for any lua code you can throw my way that allows me to access the lens name or a lens unique Id, as I need to adjust my script according to the lens that is connected.
Attached is a script that attempts to use the name function, for 120F. Note I don't have any M cameras, so that part is untested. I did test the rest of the logic on elph180 with dummy values.

It just tries to print the name, but if it works you should be able to adapt it.

Quote
I did get -1, but didn't know where to go next.
Did you try call_func_ptr(0xfc2cc5eb) ? If that gets a useful value, we can figure out what the registration call is.
Don't forget what the H stands for.


Re: Lens info in Lua
« Reply #8 on: 31 / July / 2019, 02:18:40 »
I got 4147

Re: Lens info in Lua
« Reply #9 on: 31 / July / 2019, 02:23:21 »
@reyalp

Have run your script  :)

status 27 pname 0x2449ad
leb 27
found nul at 26
name EF-M11-22mm f/4-5.6
IS STM

 :) :) :)

Thank you!!!

 

Related Topics