While I was trying to find a solution to SticK's ISO problem, I started to notice magic constants in the 0x80xx range. They always seemed to appear in UI related functions. I started tracing them, and found out that there are event procedures which work with these 0x80xx IDs.
I was a bit surprised to see that these event procedures were never discussed before.
PTM stands for "Property Table Manager" as indicated by debug strings. Two of these functions are already in use by CHDK:
PTM_BackupUIProperty: SetParameterData (CHDK name)
PTM_RestoreUIProperty: conditionally calls GetParameterData (CHDK name)
The above two functions work with IDs in the 0x40xx range, and manage the "flash params" - settings which are stored in flash.
A different subset of the PTM functions works with 0x80xx IDs. They are camera dependent, and I don't know what most of them do.
In cases I have seen, the IDs are connected to certain UI elements (Canon calls these "controllers").
For example, on the a3200 (DryOS r47):
0x8021: focus mode (0 = normal, 1 = macro, 3 = "infinity")
0x800a: ISO setting (0 = auto, 1 = 80, 2 = 100, 5 = 200, ..., 14 = 1600)
On the a410 (yes, many of these event procedures are available even on the first DIGIC II models):
0x8005: ISO setting (0 = auto, 1 = 50, 2 = 100, 3 = 200)
sx100 (DryOS r23):
0x8005: ISO setting (0 = auto, 1 = hi ISO, 2 = 80, 3 = 100, 4 = 200, ..., 7 = 1600)
The current value of these UI properties can always be read (PTM_GetCurrentItem). Setting them is also possible (PTM_SetCurrentItem), but one must take care when doing so.
- values not supported in the current mode are either rejected (bit0 of the return value is set), or can even cause assert
- reading and writing unsupported IDs results in an assert
- although they seem to be well protected, it's unknown whether it's possible to enter invalid values which end up in a flash setting
- all UI properties are short integers (16bit)
- writing to these properties has an immediate effect on the UI and the underlying setting
Usually almost every setting found in the Canon shooting menu can be connected to some ID. Other settings (which are not in the shooting menu, but are available on keypress) are also have an ID - usually. A certain user interface element (like the ISO control) is always tied to the same ID.
Not all settings are part of the UI properties. The a3200 has a long shutter mode, in which one can specify the exposure time. This setting appears in a UI element that is found in the regular Canon menu, and I haven't been able to find it among the UI properties. The regular Canon menu (the one you enter with the Menu button) is not connected to this property system.
The UI flash setting appears to influence at least 3 UI properties.
The most important event procedures:PTM_GetCurrentItem(<ID>)
: returns the current value of the specified UI propertyPTM_SetCurrentItem(<ID>, <value>)
: sets the specified UI property, returns 0 when the setting is accepted
I haven't tried the following functions, but their name is descriptive:
There are even more related event procedures, but I haven't done much research on them.
The PTM functions are registered with
UI_RegistDebugEventProc on old VxWorks cameras
UI.CreatePublic on newer models
Some details on usage can be found here: http://chdk.setepontos.com/index.php?topic=8801.msg104253#msg104253
and the followup posts.tl;dr:
Keypress-based manipulation of the UI can be replaced
by this method in some cases.
Attached patch adds another "debug data display" page to CHDK, called UIProp. It can be used to discover the IDs of UI elements. The patch is not suitable for inclusion into the official source in this - incomplete - form.
To use the patch:
- you need PRIMARY.BIN for your camera to allow the sigfinder to find the functions
- put get_uiprop_count() found in stubs_entry.S into platform/<camera>/lib.c
- on VxWorks, you need to locate PTM_GetCurrentItem, and the number of UI properties inside the PTM_SetCurrentItem firmware function (it's possible to locate them automatically of course)
Observations and corrections are welcome.