Background Script - General Discussion and Assistance - CHDK Forum  

Background Script

  • 7 Replies
  • 555 Views
Background Script
« on: 30 / December / 2019, 07:52:32 »
Advertisements
I'm playing around with an idea that requires my Lua script to always be active, ie running in the background.
One thought was to run the script in an 'infinite' loop. But this means only this script will run.
Does anyone know if there is another way of achieving my objective?


Re: Background Script
« Reply #1 on: 30 / December / 2019, 11:05:04 »
I'm playing around with an idea that requires my Lua script to always be active, ie running in the background.
One thought was to run the script in an 'infinite' loop. But this means only this script will run.
Does anyone know if there is another way of achieving my objective?
If your script calls exit_alt( ) then the following script code runs while the camera continues in "normal" Canon mode (i.e. the script continues execution in the background while the camera appears to operate normally).

This may work for what you have in mind but, as reyalp has repeatedly reminded me, much of the script's behaviour and other side effects on normal camera operation are indeterminate. Bad things could happen, up to and including bricking your camera or damaging the mechanical parts.

The less the script tries to control the camera, the better in this situation. If it's just watching and maybe collecting local data you might be okay.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Background Script
« Reply #2 on: 30 / December / 2019, 11:14:07 »
@waterwingz


Many thanks, I’ll look into that approach.


‘All’ I’m looking to do is to get focus feedback running on my M3; that is diffraction corrected depth of field, defocus blur at infinity, ie to inform infinity focusing, and the focus overlap with the last image taken.


Thus all I’m doing is taking the focus position and the aperture, doing my own calculations and reporting these, continuously.


Cheers


Garry

*

Offline reyalp

  • ******
  • 12690
Re: Background Script
« Reply #3 on: 30 / December / 2019, 12:47:00 »
Thus all I’m doing is taking the focus position and the aperture, doing my own calculations and reporting these, continuously.
This would likely be more straightforward and reliable in C code. Putting something in spytask that updates an OSD continuously is straightforward. The downside is maintaining your own patch, or convincing us to add it. If it's something of general value, adding it isn't necessarily a big deal.

I don't think the module system allows you to just drop in a custom module that adds an OSD. That could be a pretty handy feature though :-[

This may work for what you have in mind but, as reyalp has repeatedly reminded me, much of the script's behaviour and other side effects on normal camera operation are indeterminate. Bad things could happen, up to and including bricking your camera or damaging the mechanical parts.
I wouldn't be especially worried about damage or bricking compared to other scripts, it's mostly just that the behavior of "script running not in alt mode" in CHDK doesn't appear to have been specifically designed, or if it was, the intent was forgotten many revisions age.

Another script approach is the one I used in https://chdk.fandom.com/wiki/Lua/Scripts:_Continuous_Autoexposure - The script runs in the foreground, but it forwards most key presses to the canon firmware. This would be overkill for an OSD though.
Don't forget what the H stands for.


Re: Background Script
« Reply #4 on: 30 / December / 2019, 12:52:53 »
@reyalp


I think the biggest ‘problem’ is that the M3 ‘only’ gives access to the Canon upper and lower focus positions, whatever they mean.


I will need to (re)look at the calibration, ie should I use upper or lower or something in between.


Early days and I’m limited to Lua scripting, ie nor C or compiling  ;)


Cheers


Garry

*

Offline Caefix

  • ****
  • 253
  • Sorry, busy deleting test shots...
Re: Background Script
« Reply #5 on: 01 / January / 2020, 12:14:18 »
 :-[ core/script.c /line 192++
 Maybe here´s some space between the lines for something like an optional osd?
Code: [Select]
void gui_script_draw()
{
    extern void gui_chdk_draw();
    gui_chdk_draw();

    if (camera_info.state.mode_rec || camera_info.state.mode_play)
    {
        static int show_md_grid=0;
        if (camera_info.state.state_kbd_script_run) show_md_grid=5;
        if (show_md_grid)
        {
            --show_md_grid;
            libmotiondetect->md_draw_grid();
        }
    }
}

// GUI handler for Script mode
gui_handler scriptGuiHandler = { GUI_MODE_SCRIPT, gui_script_draw, gui_script_kbd_process, 0, 0, 0 };

static gui_handler *old_gui_handler = 0;

//-------------------------------------------------------------------
All lifetime is a loan from eternity.

Re: Background Script
« Reply #6 on: 01 / January / 2020, 21:20:47 »


:-[ core/script.c /line 192++
 Maybe here´s some space between the lines for something like an ...

For simplicity and the least side effects, my suggestion would be to add code to the main spy task loop.  Especially if it's a personal patch.

Been there, done that, still have the t-shirt.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline Caefix

  • ****
  • 253
  • Sorry, busy deleting test shots...
Re: Background Script
« Reply #7 on: 07 / January / 2020, 11:48:49 »
:2020  :o :blink: :o :-X the jokenumber has changed in firmware!
I remember the last, expect the next, calculating
how they are arranged, take care...
All lifetime is a loan from eternity.


 

Related Topics