Current
nightly builds can now run
PicoC scripts

General-purpose functions[spoiler]
void sleep(float seconds); // sleep X seconds
void beep(); // short beep sound
void beeps(int num); // short consecutive beeps
void console_show(); // show the script console
void console_hide(); // hide the script console
void cls(); // clear the script console
void screenshot(); // take a screenshot (BMP+422)
unsigned int rand(); // random numbers
[/spoiler]
Date/time[spoiler]
struct tm
{
int hour;
int minute;
int second;
int year;
int month;
int day;
}
struct tm * get_time(); // get current date/time
float get_uptime(); // get uptime, in seconds, 1ms resolution (from DIGIC clock)
[/spoiler]
Picture taking[spoiler]
void takepic(); // take a picture
void bulbpic(float seconds); // take a picture in bulb mode
void take_fast_pics(int number); // take N pictures in burst mode
void wait_pic(); // waits until you take a picture (e.g. for starting a custom bracket sequence)
[/spoiler]
Video recording[spoiler]
void movie_start(); // start recording
void movie_end(); // stop recording
[/spoiler]
Key press emulation[spoiler]
Available button codes:
LEFT, RIGHT, UP, DOWN, SET, MENU, PLAY, ERASE, LV, INFO, ZOOM_IN
SHOOT_FULL, SHOOT_HALF, AF_ON
Q, ZOOM_OUT (if present on your camera)
UNPRESS (for key input only)
void press(int button); // "press" a button
void unpress(int button); // "unpress" a button
void click(int button); // "press" and then "unpress" a button
[/spoiler]
Key input[spoiler]
Two methods:
- blocking: int key = wait_key(); // waits for key to be pressed, then returns the key code
- non-blocking: int key = last_key(); // returns the last key code without waiting (or -1)
Keys are trapped when you call one of those, and also 1 second after. This lets you write loops like:
while(1)
{
int key = wait_key();
// process the key
if (key == SET) { ... }
}
or
while(1)
{
int key = last_key();
// process the key
if (key == SET) { ... }
sleep(0.1);
}
int wait_key(); // waits until you press some key, then returns key code
int last_key(); // returns last key pressed, without waiting
[/spoiler]
Exposure settings[spoiler]
// APEX units
float get_tv();
float get_av();
float get_sv();
void set_tv(float tv);
void set_av(float av);
void set_sv(float sv);
// Conventional units ( ISO 100, 1.0/4000, 2.8 )
int get_iso();
float get_shutter();
float get_aperture();
void set_iso(int iso);
void set_shutter(float s);
void set_aperture(float s);
// Raw units (1/8 EV steps)
int get_rawiso();
int get_rawshutter();
int get_rawaperture();
void set_rawiso(int raw);
void set_rawshutter(int raw);
void set_rawaperture(int raw);
[/spoiler]
Exposure compensation (in EV)[spoiler]
float get_ae();
void set_ae(float ae);
[/spoiler]
Flash functions[spoiler]
int get_flash(); // 1=enabled, 0=disabled, 2=auto
int set_flash(int enabled);
int pop_flash(); // pop-up built-in flash
float get_flash_ae();
void set_flash_ae(float ae); // flash exposure compensation
[/spoiler]
White balance[spoiler]
int get_kelvin();
int get_green();
void set_kelvin(int k); // from 1500 to 15000
void set_green(int gm); // green-magenta shift, from -9 to 9
[/spoiler]
Focus[spoiler]
void focus(int steps); // move the focus ring by X steps
void focus_setup(int stepsize, int delay, int wait); // see Focus -> Focus Settings menu
int get_focus_confirm(); // return AF confirmation state (outside LiveView, with shutter halfway pressed)
void set_af(int af); // enable or disable AF for half-shutter press
void reset_af(int af); // restore the original setting from Canon menu (CFn) (auto-called when script finishes)
int get_afma(int mode); // get AF microadjust value
void set_afma(int value, int mode); // set AF microadjust value
struct dof
{
char* lens_name;
int focal_len;
int focus_dist;
int dof; int far;
int near;
int hyperfocal;
}
struct dof * get_dof();
[/spoiler]
Low-level I/O[spoiler]
void mic_out(int value); // digital output via microphone jack, by toggling mic power
void set_led(int led, int value); // set LED state; 1 = card LED, 2 = blue LED
[/spoiler]
Graphics[spoiler]
Graphics constants:
Colors:
COLOR_EMPTY, COLOR_BLACK, COLOR_WHITE, COLOR_BG,
COLOR_RED, COLOR_DARK_RED, COLOR_GREEN1, COLOR_GREEN2, COLOR_BLUE, COLOR_LIGHT_BLUE,
COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_ORANGE,
COLOR_ALMOST_BLACK, COLOR_ALMOST_WHITE,
COLOR_GRAY(percent)
Fonts:
FONT_LARGE, FONT_MED, FONT_SMALL
FONT(fnt, fg, bg)
SHADOW_FONT(fnt)
e.g. FONT(FONT_LARGE, COLOR_YELLOW, COLOR_BLACK) or SHADOW_FONT(FONT_MED)
void clrscr(); // clear screen
int get_pixel(int x, int y);
void put_pixel(int x, int y, int color);
void draw_line(int x1, int y1, int x2, int y2, int color);
void draw_line_polar(int x, int y, int radius, float angle, int color);
void draw_circle(int x, int y, int radius, int color);
void fill_circle(int x, int y, int radius, int color);
void draw_rect(int x, int y, int w, int h, int color);
void fill_rect(int x, int y, int w, int h, int color);
[/spoiler]
Text output[spoiler]
void bmp_printf(int fnt, int x, int y, char* fmt, ...);
void notify_box(float duration, char* fmt, ...);
[/spoiler]
Interaction with Canon GUI[spoiler]
void set_canon_gui(int enabled); // allow disabling Canon graphics
void set_gui_mode(int mode); // set Canon GUI mode (current dialog, 0=idle, 1=play, 2=menu, others camera-specific)
int get_gui_mode();
[/spoiler]
Interaction with ML menus[spoiler]
// Tip: to get a list with menus and possible values, go to Prefs -> Config File -> Export as PicoC script
// You can also use these functions to create custom presets.
void menu_open(); // open ML menu
void menu_close(); // close ML menu
void menu_select(char* tab, char* entry); // select a menu tab and entry (e.g. Overlay, Focus Peak)
int menu_get(char* tab, char* entry); // return the raw (integer) value from a menu entry
int menu_set(char* tab, char* entry, int value); // set a menu entry to some arbitrary value; 1 = success, 0 = failure
char* menu_get_str(char* tab, char* entry); // return the displayed (string) value from a menu entry
int menu_set_str(char* tab, char* entry, char* value); // set a menu entry to some arbitrary string value (cycles until it gets it); 1 = success, 0 = failure
[/spoiler]
Image analysis[spoiler]
Don't expect too much; it's quite slow to operate at pixel level due to interpreter overhead.
Consider using plain C for this task.
Functions that operate on larger data sets (e.g. spotmeter, histogram analysis) should be fast enough.
struct yuv
{
int Y; // 0...255
int U; // -128...127
int V; // -128...127
}
struct rgb
{
int R; // 0...255
int G; // 0...255
int B; // 0...255
}
// The following functions operate on normalized coordinates (720x480)
// This means they should work on external monitors without extra care, for example.
// Details: http://magiclantern.wikia.com/wiki/VRAM/Geometry
struct yuv * get_pixel_yuv(int x, int y); // get the YUV components of a pixel from LiveView buffer
struct rgb * get_pixel_rgb(int x, int y); // similar for RGB
struct yuv * get_spot_yuv(int x, int y, int size); // spotmeter: average pixels from a (small) box and return average YUV.
struct rgb * get_spot_rgb(int x, int y, int size); // similar for RGB
For low-level image processing
struct vram
{
void* buffer;
int width;
int pitch;
int height;
}
struct vram * get_lv_vram(); // get LiveView image buffer
struct vram * get_hd_vram(); // get LiveView recording buffer
[/spoiler]
Powersaving[spoiler]
void display_on();
void display_off();
int display_is_on();
void lv_pause(); // pause LiveView without dropping the mirror
void lv_resume();
[/spoiler]
Cache hacking[spoiler]
unsigned int cache_locked();
void cache_lock();
void cache_unlock();
void cache_fake(unsigned int address, unsigned int data, unsigned int type);
[/spoiler]
Camera info[spoiler]
char* get_model();
char* get_firmware();
[/spoiler]
Sample scriptshello.c - first steps
brack.c - custom bracketing sequence
keys.c - key press demo
test.c - API tests, and usage example for each function
sokoban.c - a simple game
To create a script, just place it in the ML/SCRIPTS directory, with the C extension, and they will be autodetected. Use short 8.3 names. You can place max 15 scripts there.
Startup scriptIf one of the scripts is named
AUTORUN.C, it will be executed at startup, automatically.
Looking forward to see what you can do with these scripts. You can use this forum section to share them.
TODO:
- Extend the API (and keep it clean). Here I'd like to see your suggestions. Feel free to implement the todo list (commented APIs) from
picoc/library_ml.c.
- [DONE] Edit script parameters (like CHDK).
- In-camera script editing (so you can change small things in the field).
-
Compile a desktop PicoC interpreter (so you can try the scripts offline). ML will run in QEMU
- etc