Author Topic: [Solved] Stop a running picoc script (thanks a1ex)  (Read 3225 times)

wolf

  • Senior
  • ****
  • Posts: 263
[Solved] Stop a running picoc script (thanks a1ex)
« on: February 13, 2013, 06:19:44 PM »
I tried to detect a key while a script is running...
Code: [Select]
if (script_state != SCRIPT_IDLE)
    {
        if (event->param == BGMT_PRESS_UP)
        {
         ??????
         ??????
        }
    }

 but could not find the comand or function to stop a script. Whatever I tried results in no effect or in hanging.

Is there a way to stop a task. Sorry if this question is stupid.
Code: [Select]
task_create("run_script", 0x1c, 0x4000, run_script, 0);

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: Stop a running picoc script
« Reply #1 on: February 13, 2013, 06:42:30 PM »
That's not very easy. I think you can find picoc's main loop (probably around parse.c:838, not sure) and add something like this: if (stop_requested) ProgramFail(blahblah). In the GUI event handler, you make stop_requested = true and the script should stop at next instruction.

wolf

  • Senior
  • ****
  • Posts: 263
Re: Stop a running picoc script
« Reply #2 on: February 13, 2013, 09:47:27 PM »
I can't figure out where to define the variable stop_requeseted

if I define it in picoc.h:

Code: [Select]
int stop_requested;
and add to parse.c
 
Code: [Select]
do {
        Ok = ParseStatement(&Parser, TRUE);
        if (stop_requested)
        ProgramFail(&Parser, "please stop");

    } while (Ok == ParseResultOk);

and in src/picoc.c
Code: [Select]
if (event->param == BGMT_PRESS_UP)
        {
            stop_requested=1;
            return 0;
        }


nothing happes.
but when I for test reasons add
Code: [Select]
stop_requested=1; to parse.c it will stop or not start.

So I guess with my little C understanding the variable stop_requested isn't right defined.


a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: Stop a running picoc script
« Reply #3 on: February 13, 2013, 10:28:04 PM »
Added to repo; that loop wasn't quite the right place for stopping the script.

I've tested it with the image processing example from http://www.magiclantern.fm/forum/index.php?topic=4571 .

wolf

  • Senior
  • ****
  • Posts: 263
Re: Stop a running picoc script
« Reply #4 on: February 14, 2013, 12:00:39 AM »
Thanks again.