Wikia

CHDK Wiki

Watchlist Recent changes

Lua/PTP Scripting

< Lua

Contents

General information about lua execution with PTPEdit

  • To execute a Lua script already loaded on your camera (e.g. testprgm.lua) from chdkptp interactive mode, use
              con 1 >  = loadfile('A/CHDK/SCRIPTS/testprgm.lua')()
  • Executing a script while another script is already running can cause crashes and memory leaks.
    • To check whether your script has terminated, you can use the script status command (script-status in ptpcam.)
  • The function switch_mode_usb() should be used instead of set_record to switch between record and play mode when PTP is connected.
  • Lua return values and errors messages are sent using the message interface.
    • Simple tables are returned in a limited human readable string format by default, see [1] for a description. This can be changed by providing your own usb_msg_table_to_string. A replacement that properly serializes lua tables can be found in chdkptp.
  • Lua script execution currently leaves CHDK alt mode in a confused state. You may need to press the alt button a couple times to get the alt menu and buttons to respond as expected.
  • While scripts in files already on the camera may be used, functions that yield (e.g. sleep(), wait_click() etc.) cannot be used inside require (or other pcall).

PTP FunctionsEdit

switch_mode_usbEdit

switch_mode_usb(mode)

Set the camera to play or record mode.

mode is 1 for record or 0 for play.

read_usb_msgEdit

msg = read_usb_msg([timeout])

Read a message from the CHDK ptp interface.

Returns the next available message as a string, or nil if no messages are available

If timeout is given and not zero, wait until a message is available or timeout expires

write_usb_msgEdit

status = write_usb_msg(msg,[timeout])

Writes a message to the CHDK ptp interface.

msg may be nil, boolean, number, string or table. Tables will be converted to a string by usb_msg_table_to_string

returns true if the message was queued successfully, otherwise false

If timeout is set and not zero, wait until message is written or timeout expires.

NOTE strings will not include a terminating NULL.

usb_msg_table_to_stringEdit

s=usb_msg_table_to_string(table)

This function is called when a table is returned from a lua script, or sent as a message. Lua code may override this function to provide different serialization formats. The return value should be a string on success. On failure, a lua error should be thrown.

Pages on CHDK Wiki

Add a Page
496pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
746photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki