CHDK PTP interface - page 37 - General Discussion and Assistance - CHDK Forum

CHDK PTP interface

  • 1244 Replies
  • 518103 Views
*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #360 on: 16 / January / 2011, 13:56:17 »
Advertisements
Related to a problem discussed over in chdkde:
http://forum.chdk-treff.de/viewtopic.php?f=3&t=2220

I don't like luar, the code on the camera is too complicated. If we remove it, maybe the problem goes away.

I think luar should work like this

on PC:
exec_lua("... return some value")
while(script_status() == LUA_IS_RUNNING)
  sleep()
get_lua_result()

On camera
when script ends, luascript code stores the value somewhere when script ends, instead of PTP task sleeping and playing with lua states
Could be a function or global instead of using lua return, example
ptp_result = "hello world"

Then code can set anywhere and not worry about having return in the right place. With a global, C code doesn't need to worry storing/freeing the value until the very end.

Need to clear the value if another script is started before result is fetched. Would also be good to clear if PTP is disconnected.

My script message experiment was similar, but I think for "run some code and return a result" should be simpler. Message queue may be useful later.

This will break compatibility with previous protocol, but might be a better use of time than debugging this.
Don't forget what the H stands for.

Re: CHDK PTP interface
« Reply #361 on: 16 / January / 2011, 14:12:31 »
Ixus 1000 HS

*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #362 on: 16 / January / 2011, 14:19:21 »
I don't think this is related to your problem on the ixus1000, I think it only affects luar
Don't forget what the H stands for.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: CHDK PTP interface
« Reply #363 on: 16 / January / 2011, 14:48:26 »
This will break compatibility with previous protocol, but might be a better use of time than debugging this.

I don't see a reason to maintain compatibility -- ptp has been announced as experimental and subject to change for the better, and the particular flavour now in trunk probably doesn't even have many users yet (at least not the kind that gets confused by change) given the state and age of the PC side tools.


*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #364 on: 16 / January / 2011, 17:35:31 »
This will break compatibility with previous protocol, but might be a better use of time than debugging this.

I don't see a reason to maintain compatibility -- ptp has been announced as experimental and subject to change for the better, and the particular flavour now in trunk probably doesn't even have many users yet (at least not the kind that gets confused by change) given the state and age of the PC side tools.
Agreed. I'm working on this now (instead of my new ptp tool  :-[ )
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #365 on: 16 / January / 2011, 22:16:27 »
Work in progress patch. There are still some issues, lots of mess and unfinished bits. Enclosed ptpcam will only work with this code.

Basic idea
set_usb_result() in lua sets the value to be returned. Accepts string, number boolean or nil. nil is the same as not setting a result. There is currently no way to tell the difference.  Setting more than once is fine, it just replaces the previous value. Tables are not allowed, but a lua function to serialize simple tables can be made standard somewhere. I already planned this for my lua based client.

Result is only available to ptp once the script has finished.

Result is saved for every script run, whether you use lua or luar. Old result is thrown away next time a script is run. This means a big result could be stored and never freed if you don't run any more scripts. I plan to add script execution status and error message to the result, so it will make sense even if script doesn't set result.

If you want the result from the previous lua (not luar) command, you can use getr [timeout]

Currently, if there is an error, the 'press a key to close' appears, and the result isn't available until this is done. I think we don't need this for ptp scripts, especially if they return flag and error message.

If you start another script while a script is running, the old scripts is killed and any result is thrown away. But I'm not sure this cleans up properly in other areas, needs to be looked into.

Currently getr and luar just polls script-status every 250ms. I may add additional bits for error or result available, but I'm not sure they are needed yet.

If there is no result (already received or not set) GetResult returns TYPE_NOTHING. This is a change of meaning, might indicate it in a different way later.


If anyone has feedback on how it should work, now is your time to speak.
Don't forget what the H stands for.

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: CHDK PTP interface
« Reply #366 on: 17 / January / 2011, 05:57:57 »
@reyalp
Thank you for your tireless work.

I think the last patch missing ptp_script.h / ptp_script.c. The compiler generates an error message.

I'm not a programmer, I am a CHDK user. ;)
If I understand this patch correctly, it is the right way. We need a good solution, with which  we can send e.g. mod maps or directories from the camera to the computer. In addition, there should be only one command for script functions, lua and not another luar.

Then we have all the options to build a GUI. A GUI is the most important condition to explain to a CHDK users, why should he use a different USB driver. Most people can not do much with a console.

msl
CHDK-DE:  CHDK-DE links

*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #367 on: 17 / January / 2011, 12:06:06 »
@reyalp
Thank you for your tireless work.

I think the last patch missing ptp_script.h / ptp_script.c. The compiler generates an error message.
You are right, missing ptp_script.h. It's only prototypes for some functions which are in ptp.c. Attached.

Unfortunately, I won't have much time to work on this until the next weekend.
Quote
If I understand this patch correctly, it is the right way. We need a good solution, with which  we can send e.g. mod maps or directories from the camera to the computer. In addition, there should be only one command for script functions, lua and not another luar.
Agreed.  New client I'm working on is mostly lua, so you can send lua table from camera as string, make back into table and use very easily.

Quote
Then we have all the options to build a GUI.
Lua client is nice. Real example:
Code: [Select]
button_shoot=iup.button{
title="shoot",
action=function(self)
chdk.execlua('shoot()')
end,
}
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 14110
Re: CHDK PTP interface
« Reply #368 on: 17 / January / 2011, 15:54:01 »
It looks like rudi has found the cause of the immediate problem with luar http://forum.chdk-treff.de/viewtopic.php?f=3&t=2220&start=15#p20567
Don't forget what the H stands for.

Re: CHDK PTP interface
« Reply #369 on: 18 / January / 2011, 04:06:44 »
>It looks like rudi has found the cause of the immediate problem with luar http://forum.chdk-treff.de>/viewtopic.php?f=3&t=2220&start=15#p20567

i test it and the ptpluartest work now ok on Ixus 1000 HS.
But it help not on the switch to record mode crash.

I dont know, whats diffrent, but it work, when i start a script in play mode, Camera switch to record mode, as soon a shoot command come and shoot a image.

but there seem no pb2rec use for this.

very strange wy pb2rec not work on my camera and on other it work.

I see the function  core_get_free_memory do not disable other tasks to work.I think its better when do a task lock so other tasks can not try to alloc memory during the memeaten and maybe fail due too few memory or memory get more fragment




int core_get_free_memory() {
    int size, l_size, d;
    char* ptr;

    size = 16;
    while (1) {
        ptr= malloc(size);
        if (ptr) {
            free(ptr);
            size <<= 1;
        } else
            break;
    }

    l_size = size;
    size >>= 1;
    d=1024;
    while (d) {
        ptr = malloc(size);
        if (ptr) {
            free(ptr);
            d = l_size-size;
            if (d<0) d=-d;
            l_size = size;
            size += d>>1;
        } else {
            d = size-l_size;
            if (d<0) d=-d;
            l_size = size;
            size -= d>>1;
        }
        
    }
    return size-1;
}
« Last Edit: 18 / January / 2011, 04:10:53 by Bernd R »
Ixus 1000 HS

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal