Continued from
@rivlb's post
https://chdk.setepontos.com/index.php?topic=650.msg150290#msg150290 to avoid cluttering the patch thread with discussion:
While experimenting with my SX150, I noticed that I could not get jog dial clicks in Lua script in a simple way like using is_key() or is_pressed() for example. So I tried to fix this problem. Now it is possible to get jog dial rotation event by using script function is_key() (tested in Lua script on SX150):
is_key("jog_left" ) - true if jog dial performed left click
is_key("jog_right") - true if jog dial performed left click
If you find this useful, it might be helpful to update the table here. Patch in attachment.
This has been a requested feature in the past (for example
waterwingz post here and
outslider here) but I'm not sure if making it a key click for script is the right way to go, or whether there would be undesirable side effects.
Some general thoughts and observations from poking around the related code:
If we treat jogdial as click, the behavior of existing scripts that use wait_click will be affected somewhat (for example, a script with "press any key to exit" logic would now exit on dial event), but I don't feel like this should be a problem for most scripts.
It's a bit odd to have a "key" for which is_pressed would always be false, but it doesn't seem like it should cause any real problem.
Currently, when a script is running, dial events are still seen by the Canon OS (on most ports, at least). This is in contrast to non-script "alt" mode, where correctly implemented ports block the jogdial (see jogdial_control, some ports probably don't implement it). rivlb's patch doesn't change this, and there are at least some scripts which expect this behavior, but IMO scripts that want to handle dial events would probably want to block them from OS in most cases.
The CHDK C UI code kind of treats the dials like a key click in that it treats the *DIAL_* constants as keyboard constants, but get_jogdial_direction is called at the point of use, if there are no key clicks (see gui_menu.c gui_menu_kbd_process for a typical example), so it isn't currently included in the "clicked" logic.
get_jogdial_direction is implemented per-platform and returns the direction of cumulative movement since the previous call. This means it should really only be called from kbd_task and at most once per kbd_task iteration.
Waterwingz post linked above suggested exposing the dial count to script, which would be annoying to do directly given the counters are only available in each platforms kbd.c. In practice though, it should be very rare for the dial to move more than once per ~10ms kbd_task iteration, so one could make a count based on get_jogdial_direction outside if desired.
A script might check keyboard state less frequently than kbd_task, in which case using is_key would only see one "click" per check, but this is consistent with how real keys are handled.
However we support jogdial in script, it would be good to include the secondary control dial for cameras that have them in a similar way. Currently, cameras that support a secondary dial report it from get_jogdial_direction, if the main dial has not moved. This seems a bit sketchy but I suppose it's a fairly safe assumption they won't both change in the same 10ms interval, or the user won't notice a missing step if they do.