CHDK menus - General Help and Assistance on using CHDK stable releases - CHDK Forum supplierdeeply

CHDK menus

  • 17 Replies
  • 5764 Views
CHDK menus
« on: 12 / February / 2019, 14:45:39 »
Advertisements
i hope one of the CHDK gurus can help with a couple of questions I have.



In Magic Lantern Lua there is a means to dynamically change the script and ML menu states. Now I appreciate CHDK is a different environment, so I’m not looking for the same functionality, however, I wonder if there is a way to get the script to dynamically change menu entries, eg in response to other menu choices.


One way I thought was to do a text substitution in the .lua file.


The other question relates to running a script in the background, ie in non alt mode. Is there a way?


I don’t think there is, as this would mean two scripts running at the same time. But I could be wrong.


Cheers


Garry
« Last Edit: 12 / February / 2019, 15:36:32 by pigeonhill »

Re: CHDK menus
« Reply #1 on: 12 / February / 2019, 15:52:39 »
I wonder if there is a way to get the script to dynamically change menu entries, eg in response to other menu choices.
Not really - the menu structure is essentially hard coded at compile time.  However, it might be possible to tweak the User Menu -  I'd have to take a look at that.  But it won't really do what you want as AFAIK the CHDK Menu handling code only runs when the script interpreter is not running.

Quote
The other question relates to running a script in the background, ie in non alt mode. Is there a way?
Take a look at the exit_alt( ) function. That causes CHDK to leave <ALT> mode while the script is still running. What you can do then is somewhat limited and things like keyboard I/O get weird.  Or as @reyalp like to say - script behavior becomes indeterminate. 
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK menus
« Reply #2 on: 12 / February / 2019, 16:02:03 »
@waterwingz

Thanks for the quick response...as always ;-)

I must say, being able to change the user menu, dynamically, as the user interacted with the script would be great.

As an example, in the following menu I would like the script to always reset to 0 after the user selects yes. At the moment the user has to remember/know to reset the next time the script runs.

@param e New Log File?
    @default e 0
    @values  e No Yes

Cheers

Garry

Re: CHDK menus
« Reply #3 on: 12 / February / 2019, 19:14:39 »
As an example, in the following menu I would like the script to always reset to 0 after the user selects yes. At the moment the user has to remember/know to reset the next time the script runs.
@param e New Log File?
    @default e 0
    @values  e No Yes
Hmmm .. now I see what you are after.

You are looking for the ability to change the user parameters associated with a script - the stuff in the script's header.  That's a little different than generically changing the CHDK Menus.   CHDK saves those in seperate files on the SD card and allows 10 sets of different parameters per script. 

While I don't think there is currently any easy way to edit those config files, you could do it the hard way with file i/o code in Lua. Alternatively, it might be a nice new bit of functionality to add to the CHDK implementation of Lua.  Assuming I'm not missing something obvious that allows us to already do this...
Ported :   A1200    SD940   G10    Powershot N    G16


*

Online reyalp

  • ******
  • 14121
Re: CHDK menus
« Reply #4 on: 13 / February / 2019, 00:25:56 »
While I don't think there is currently any easy way to edit those config files, you could do it the hard way with file i/o code in Lua. Alternatively, it might be a nice new bit of functionality to add to the CHDK implementation of Lua.  Assuming I'm not missing something obvious that allows us to already do this...
I don't think you are missing anything.

To do it from Lua, you'd need to open CHDK/DATA/scriptname.CFG read the current config index and then load CHDK/DATA/scriptname.n, parse it, update and write back out.

The script doesn't actually know what it was named, so you'd have to either hard code and assume it wasn't renamed, or get the current script with get_config_value

Would be ugly, but probably not too terrible.
Don't forget what the H stands for.

Re: CHDK menus
« Reply #5 on: 13 / February / 2019, 01:26:11 »
The functionality I had in mind are the get and set menu API calls in ML, 

https://builds.magiclantern.fm/lua_api/modules/menu.html#set

But as I said, I recognize this is a different environment.

Re: CHDK menus
« Reply #6 on: 13 / February / 2019, 02:27:52 »
BTW had a look at the CHDK/DATA/scriptname.CFG associated with the script and all it contains is 0null.

Re: CHDK menus
« Reply #7 on: 13 / February / 2019, 04:43:22 »
@reyalp

Your suggestion seems to work well, ie resetting the menu state, ie

Code: [Select]
@param e New Log File?
    @default e 0
    @values  e No Yes

I did it like this. I would welcome any feedback as to how 'ugly' I've been  :)

Code: [Select]
if e == 1 then
    os.remove("A/CHDK/LOGS/LOG_2306.TXT")
    local fp = io.open ("A/CHDK/DATA/LBS.0","r")
    if fp == nil then
        return
    else
        local str = fp:read("*all")
        fp:close()
        str = string.gsub(str,"#e=1","#e=0")
        fp = io.open ("A/CHDK/DATA/LBS.0","w")
        fp:write(str)
        fp:close()
        print("Log deleted")
        return -- exit script
    end
end


*

Online reyalp

  • ******
  • 14121
Re: CHDK menus
« Reply #8 on: 13 / February / 2019, 23:44:32 »
BTW had a look at the CHDK/DATA/scriptname.CFG associated with the script and all it contains is 0null.
Right, if you select parameter set 1 in in the script menu, then it should be 1, and the setting would be in the .1 file. Without digging into the code, I'm not sure why the null is there, but it's expected.

If you hardcode 0, then only set 0 will ever be modified. That could be totally fine for your personal use, but perhaps less good for something you want to distribute to other users.
Don't forget what the H stands for.

Re: CHDK menus
« Reply #9 on: 14 / February / 2019, 02:52:56 »
@reyalp

Got it. Thanks.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal