Author Topic: PicoC scripting API  (Read 88758 times)

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #25 on: February 24, 2013, 12:19:24 AM »
Just added some more APIs:
- key interaction (get_key)
- menu interaction (select a menu item, get/set value)
- DOF and focus info (get_dof: hyperfocal, focus distance, DOF far/near etc)
- set_led
- mic_out (digital output via mic jack)
- focus, focus_setup (in LiveView, like follow focus)
- get/set AFMA

There are some more commented out in picoc/library_ml.c; feel free to implement them.

scrax

  • Contributor
  • Hero Member
  • *****
  • Posts: 1543
  • Code monkey
Re: PicoC scripting API
« Reply #26 on: February 24, 2013, 12:54:54 PM »
Is already possible to add a label to @param?
For example I want to make set param in the script that make the scrip load or save some settings, so t should show Loan and Save instead of On Off, also another idea on something form complex labels with also the value shown.
Code: [Select]
/*
@title PicoC script's title

@param a First variable name
@range a 0 1
@labels a Load Save

@param b Second variable name
@range b 0 5
@labels b Off 'C-Mode:%d, @range'
*/
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #27 on: February 24, 2013, 01:01:19 PM »
CHDK has @values for this, but it's not implemented yet.

http://chdk.wikia.com/wiki/CHDK_scripting#The_Script_Header

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #28 on: February 24, 2013, 07:59:28 PM »
Graphics functions (draw_line, draw_circle, bmp_printf etc) are working.

Anyone would like to write a nice demo script?

photo360

  • New to the forum
  • *
  • Posts: 5
Re: PicoC scripting API
« Reply #29 on: February 25, 2013, 11:53:41 AM »
Is it possible with PicoC scripting API to do a special bracketing sequence with/without flash?
I need to take some pictures with flash at some shutter speed and to take the same pictures without flash...
this should work on 5DII with canon speedlite 580EX.

Thanks for your help

Exemple of script:

set_aperture(11);
set_iso(100);
set_shutter(1./160);
"flash off"
takepic();

"flash on"
takepic();

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #30 on: February 25, 2013, 12:11:19 PM »
I've just added set_flash(1) / set_flash(0), but I have no idea if it works on external flashes.

Also pop_flash() should work for built-in flash.

photo360

  • New to the forum
  • *
  • Posts: 5
Re: PicoC scripting API
« Reply #31 on: February 26, 2013, 02:55:36 PM »
Thanks !

Some tests:

set_flash(0)/set_flash(1) works great on canon 50D with external flash (canon speedlite 580 EX) or with built-in flash.
pop_flash() does not work on my 50D. The flash shoud be pop up manually.

set_flash(0)/set_flash(1)  does not work en 5DMKII with canon speedlite 580 EX. the flash fire each time.
It seems that this function works only for canon with build-in flash.

Is there another solution for 5DMKII ?

gerk.raisen

  • Member
  • ***
  • Posts: 161
Re: PicoC scripting API
« Reply #32 on: February 27, 2013, 11:57:59 AM »
Hello,

please add an API to read the sound dB level so that we can trigger when sound level go up (or also go down) a threshold.

Thank you.

SDX

  • Guest
Re: PicoC scripting API
« Reply #33 on: February 27, 2013, 01:08:27 PM »
Audio Remote Shoot does exactly that - it's in the shoot menu.

gerk.raisen

  • Member
  • ***
  • Posts: 161
Re: PicoC scripting API
« Reply #34 on: February 27, 2013, 02:48:28 PM »
Yes, I know that, but the idea is to have an API to use it within a script.

wolf

  • Senior
  • ****
  • Posts: 263
Re: PicoC scripting API
« Reply #35 on: February 27, 2013, 07:13:17 PM »
You could switch the audio trigger on and off with picoc:

Code: [Select]
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


Kent

  • New to the forum
  • *
  • Posts: 15
Re: PicoC scripting API
« Reply #36 on: March 02, 2013, 08:34:53 PM »
Is it possible to add functionality to export AF mode and the settings for AF Case 1 , Case 2 etc.
as a PicoC script ?
5D3 , EF 100 2.8L Macro, EF 24-105 4L, EF 70-200 2.8L IS, EF 400 5.6L, 580 EX II's, RRS BH-55, Gitzo GT5532LS, Pixel King's, ZOOM H4N

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #37 on: March 02, 2013, 08:54:47 PM »
Ouch, that looks painful...

Kent

  • New to the forum
  • *
  • Posts: 15
Re: PicoC scripting API
« Reply #38 on: March 02, 2013, 08:56:31 PM »
Sorry Alex ! LOL
5D3 , EF 100 2.8L Macro, EF 24-105 4L, EF 70-200 2.8L IS, EF 400 5.6L, 580 EX II's, RRS BH-55, Gitzo GT5532LS, Pixel King's, ZOOM H4N

Alia5

  • Freshman
  • **
  • Posts: 99
  • 600D
Re: PicoC scripting API
« Reply #39 on: March 07, 2013, 02:39:55 PM »
Would anyone mind extending beep() to beep(int msecs, int frequency)? ;)

scrax

  • Contributor
  • Hero Member
  • *****
  • Posts: 1543
  • Code monkey
Re: PicoC scripting API
« Reply #40 on: March 17, 2013, 10:43:21 PM »
I can't find a way to change image quality with scripts, seems not yet implemented. To explain better my idea this is the script I'm working on:
Code: [Select]
/*
@title Custom Burst Shot
@param r Number of raw burst
@range r 0 9
@default r 3
@param l Number of L Jpg burst
@range l 0 9
@defaull r 6
@param m Number of M Jpg burst
@range m 1 29
@default m 16
*/
console_hide();
int quality = get_quality();
int key = wait_key();
while(key != SET){
    if (key == SHOOT_FULL){
        if(r != 0){
            set_quality(RAW);
            take_fast_pics(r);
            sleep(0.1);
        }
        if(l != 0){
            set_quality(JPGLF);
            take_fast_pics(l);
            sleep(0.1);
        }
    }
    set_quality(JPGMF);
    take_fast_pics(m);
    sleep(0.1);
    set_quality_to(quality);
}
if (key == SET){
    break;
}
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #41 on: March 17, 2013, 10:51:03 PM »
Yes, it's not implemented. And since some of these constants are camera-specific, and wrong values cause persistent ERR70 (even if you boot without ML), I'm a bit hesitant to add it.

A common subset (e.g. plain RAW and a few JPEG presets) should be OK though.

scrax

  • Contributor
  • Hero Member
  • *****
  • Posts: 1543
  • Code monkey
Re: PicoC scripting API
« Reply #42 on: March 17, 2013, 11:37:00 PM »
Yes, it's not implemented. And since some of these constants are camera-specific, and wrong values cause persistent ERR70 (even if you boot without ML), I'm a bit hesitant to add it.

A common subset (e.g. plain RAW and a few JPEG presets) should be OK though.
Totally agree, adding just a safe subset can be enough.

I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

engardeknave

  • Senior
  • ****
  • Posts: 339
Re: PicoC scripting API
« Reply #43 on: March 25, 2013, 09:23:11 AM »
How about listing/renaming files or even triggering a directory creation/change ala the canon menu? I plan to do one of these things after a bracket set to organize the sets.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #44 on: March 25, 2013, 09:50:57 AM »
That's difficult, since Canon code also expects a catalog of files (not just what's on the filesystem). If you rename the files from the camera, you'll get ERR70.

engardeknave

  • Senior
  • ****
  • Posts: 339
Re: PicoC scripting API
« Reply #45 on: March 25, 2013, 05:29:54 PM »
What about changing folders exactly as if it were manually done from the menu?

engardeknave

  • Senior
  • ****
  • Posts: 339
Re: PicoC scripting API
« Reply #46 on: March 26, 2013, 05:28:47 AM »
A couple more things.

1. Right now when I have a script continuously running, it says "script running" when I view photos. Then the console pops up when I try to delete a photo by pressing the set button. There's got to be a way to keep a script completely in the background during normal use. Well that's mostly fixed now.

2. Still really, really want to be able to perform a select folder/create folder programmatically exactly the way it is in the Canon menus.

3. It would be great to be able to get the current camera mode.

4. An easy way to execute scripts from a script.

edit: 5. Location of the focus box in liveview. And maybe even the value of the spotmeter.

This new ability to script is extremely exciting.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: PicoC scripting API
« Reply #47 on: March 26, 2013, 02:55:34 PM »
2. This needs reverse engineering, we don't know how to do that.

3. should be easy, I'll add it.

4. sounds interesting, but I'm not sure where it would be useful; can you describe some use case for this?

5. should be easy. You can already use custom spotmeters, see img.c.

Also, we are considering to upgrade the engine to TCC (it's much faster, roughly 1000x, since TCC is a compiler, not an interpreter). Technical discussion: http://www.magiclantern.fm/forum/index.php?topic=4877 . The existing GUI is already working with TCC (just compile with CONFIG_TCC=y instead of CONFIG_PICOC if you want to try it).

The main issues that need to be solved:
- memory usage is a bit higher now (so 60D won't boot with it), but TCC only needs to be loaded when compiling the scripts, and then unloaded.
- compatibility with existing scripts (TCC is more strict, it requires a main function)
- how to stop the scripts? (we could just kill the task, but it's ugly)

The existing API should be easy to port, I don't foresee any difficulties here.

engardeknave

  • Senior
  • ****
  • Posts: 339
Re: PicoC scripting API
« Reply #48 on: March 26, 2013, 05:04:49 PM »
My purpose in running scripts from a script would be to execute scripts at startup from autorun.c, possibly contingent on some conditions, such as camera mode.

The things I want to do so far will actually work in PicoC, but TCC sounds fantastic.

scrax

  • Contributor
  • Hero Member
  • *****
  • Posts: 1543
  • Code monkey
Re: PicoC scripting API
« Reply #49 on: March 27, 2013, 11:28:36 PM »
totally agree for 3 and 4.
I fell the need to call other script too from a main script.
Best of this will be to call a script saved in any folder on the card, so to not fill the 11 limit in the main script folder.
That way we can also build a sort of script library that is used by one of the 11 launcher scripts we can run from ML.
For example Marsu42 request of a beep after bracketing could be a script in /EOS_DIGITAL/ML/script/library/ called from a braketing "launcher" script when finished, maybe triggered by a script option.
Same beep script will then be called also from another "launcher" script.

This is really a simple example that could already be done without this implementation but I think that once added it will be used a lot for more interesting things.

TCC is really fascinating, but will put my questions about it in the other topic.
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-