Starting a page to document these. this is an early, incomplete draft please update with your observations. This forum thread contains related discussion and test code http://chdk.setepontos.com/index.php/topic,3228.0.html
Logical events (correct terminology is unclear) are a component of the Canon firmware used to communicate events such as button presses, switch position changes etc to the rest of the firmware.
Known useful functions
The following functions are at least partially understood and known to be useful
- PostLogicalEventToUI(int id,int unk)
- PostEventShootSeqToUI(int id, int unk)
- PostLogicalEventForNotPowerType(int id, int unk)
All 3 of these functions "post" an event, causing the camera to act as the actual button press had taken place. The meaning of the second parameter is unknown, but is normally zero. Based on strings, it appears that it would be a pointer. The difference between the functions is unclear. On some cameras, the first two are identical.
- SetLogicalEventActive(int id, int state)
- SetScriptMode(int state)
Other functions of interest
There may be (probably are) functions that allow you to listen for events. This could be very useful! A function to determine if a given event was valid, without causing a crash or assert would also be useful.
Each camera contains a table in the format
const char *name, int event_number, int value
Some events have an empty name. This is a pointer to a zero length string, not a null pointer.
The event_number values are not entirely consistent between cameras
Not every event in a cameras table is valid for that camera. E.g. ModeDialToSport on a camera without a sport position on the dial.
The first event number in the table appears to always be 0x800, and the last two appear to be 0 and 0xFFFFFFFF respectively.
CHDK uses for logical events
Events can be use to do almost anything that can be done with the camera buttons and switches: shut down the camera cleanly, change between play and record mode, change recording settings, simulate button presses etc. They can also be used to simulate events such as plugging in the external video cable.
There is now a Lua API to access the event functions and table.
Finding Event Names
Shown below is a small Lua script that will dump the valid event names from a camera.
--[[ @title levents @chdk_version 1.3 @param a Start @default a 0 @range a 0 100000 @param b End @default b 500 @range b 1 100000 --]] bi=get_buildinfo() set_console_layout(1 ,1, 45, 14 ) filename = 'A/levents.txt' log,err=io.open(filename,"a") if not log then error('failed to open '..tostring(filename)..': ' .. tostring(err)) end log:write(string.format("%s %s-%s %s %s\n", bi.version, bi.build_number, bi.build_revision, bi.platform, bi.platsub)) repeat name,id,param=get_levent_def_by_index(a) if name==nil or name=="" then name="<nil>" end result = string.format("%d %s %d %d\n", a, name, id, param) print(result) log:write(result) a=a+1 until a==b