a new function to allow Lua to determine if CHDK is currently in <ALT> mode

  • 4 Replies
  • 1485 Views
Advertisements
Attached for consideration is small patch that adds a new Lua function that return the current <ALT> state so that a script can tell if the user has exited <ALT> while the script is running. 

This is useful for scripts with a UI of some sort as it allows the script to take some specific actions when the user exits <ALT> Actions could be things like ignoring button pushes or stopping updates of onscreen information.  It could also be used to force the camera back into <ALT> mode via enter_alt() on the assumption the user really did not mean to exit <ALT>.  The later case is, of course, not a recommended use of the function  ;)

The function is called get_alt_mode() and returns true if CHDK is in <ALT> mode and false otherwise.  As usual, suggestions for a better name are anticipated.

Based on this post :  http://chdk.setepontos.com/index.php?topic=11284.msg117360#msg117360

Test script also attached.

Note : I chose not to add a uBASIC function as uBASIC does not currently support the enter_alt() function for some reason.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3070
    • Photos
Not sure if 'kbd_is_blocked()' is a reliable indicator of ALT mode.

The kbd_process() code seems to set the 'kbd_blocked' flag on and off when using a USB remote - even when not in ALT mode.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

Not sure if 'kbd_is_blocked()' is a reliable indicator of ALT mode.
At the time I was doing the "N" ports, I looked for a way to detect if CHDK was in ALT mode. I was somewhat surprised to find there was no flag or state variable indicating that.  But  quick look at the enter_alt() and exit_alt() functions showed the kbd_blocked flag seeming to say the same thing so that's what I used (in part because I had a million bigger problems with that port).  Seems to have worked pretty well so far but that's not to say it's had a ton of diverse user testing or that there are not side effects.

Quote
The kbd_process() code seems to set the 'kbd_blocked' flag on and off when using a USB remote - even when not in ALT mode.
Unfortunately,  that part of the code is mostly mine from back when I did the USB Remote 2.0 code.  I can clearly remember struggling with why things were certain ways in the existing kbd_process() code (scan the 1.0.0 version of kbd.c if you are curious) and that little bit of code you noticed is what the mess of funny states eventually reduced to.   I'll spend a little time trying to figure out why I left it that way (the part that says "Deal with the rest") as I recall hoping at the time that someone else would point ouf if that part was botched.

@philmoz  :  Irrespective of the above,  I guess it would also be cleaner to add an alt_state flag that gets set & cleared by enter_alt() and exit_alt() ? (the CHDK C functions - not the script ones).  Then change the patch (and the Powershot N code) to use that?  Is it worth wrapping that in a get_alt_mode() function rather than making the variable global?
« Last Edit: 09 / October / 2014, 08:54:46 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3070
    • Photos
@philmoz  :  Irrespective of the above,  I guess it would also be cleaner to add an alt_state flag that gets set & cleared by enter_alt() and exit_alt() ? (the CHDK C functions - not the script ones).  Then change the patch (and the Powershot N code) to use that?  Is it worth wrapping that in a get_alt_mode() function rather than making the variable global?

A state variable specific to ALT mode would be easier to understand (and less likely to have unexpected side effects).
If you add it to the camera_info structure then it is accessible in script code without exporting a new function in module_exportlist.c.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)


A state variable specific to ALT mode would be easier to understand (and less likely to have unexpected side effects).
If you add it to the camera_info structure then it is accessible in script code without exporting a new function in module_exportlist.c.

Code: [Select]
if ( camera_info.state.gui_mode == 0  )   /* not in ALT */  else /* in ALT */

Hmmm ... doh.   Updated patch file attached.
« Last Edit: 09 / October / 2014, 19:56:09 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics