Author Topic: Webcam operation  (Read 4254 times)

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Webcam operation
« on: 01 / December / 2008, 03:39:35 »
As I noted on another thread http://chdk.setepontos.com/index.php/topic,2686.0.html, limited webcam operation is now possible.

I did a quick hack with patched Lua and gphoto2 on Ubuntu on my a570is. As is, the setup shoots an image approximately every 10 seconds and moves it out of the camera to the PC via USB (PTP).

The scripts (lua and bash) and a help text are attached. Read the help file, Ubuntu needs some configuring to make it ignore the camera so that gphoto2 can use it directly.

The way I did it Lua needs access to four new Canon firmware functions. It's pretty easy to crash the camera using them, so this all needs a lot of polishing before we can think of adding it to the trunk. That's one reason I haven't spend time prepared a patch for this.

Additions required for a570is 1.00e are:

platform/a570/sub/100e/stubs_entry_2.S:
NHSTUB(PB2Rec, 0xffc119b8)
NHSTUB(Rec2PB, 0xffc119f8)
NHSTUB(ForceQuitPTPMode, 0xffd8e158)
NHSTUB(RefreshUSBMode, 0xffd8df5c)

include/lolevel.h:
extern void _PB2Rec(void);
extern void _Rec2PB(void);
extern void _ForceQuitPTPMode(void);
extern void _RefreshUSBMode(void);

platform/generic/wrappers.c:
void PB2Rec(void)
{
  _PB2Rec();
}
 
void Rec2PB(void)
{
  _Rec2PB();
}
 
void ForceQuitPTPMode(void)
{
  _ForceQuitPTPMode();
}

void RefreshUSBMode(void)
{
  _RefreshUSBMode();
}

include/platform.h:
void PB2Rec(void);
void Rec2PB(void);
void ForceQuitPTPMode(void);
void RefreshUSBMode(void);

core/luascript.c:
static int luaCB_PB2Rec( lua_State* L )
{
  PB2Rec();
  return 0; 
}
 
static int luaCB_Rec2PB( lua_State* L )
{
  Rec2PB();
  return 0; 
}
 
static int luaCB_ForceQuitPTPMode( lua_State* L )
{
  ForceQuitPTPMode();
  return 0; 
}

static int luaCB_RefreshUSBMode( lua_State* L )
{
  RefreshUSBMode();
  return 0;
}

core/luascript.c function register_lua_funcs()
  FUNC(PB2Rec);
  FUNC(Rec2PB);
  FUNC(ForceQuitPTPMode);
  FUNC(RefreshUSBMode);


(after those modifications CHDK will of course not build for any other firmware due to missing stubs/dummy wrappers).

I wanted to signal things from the PC by uploading a file after the PC script is done transferring, but sadly upload didn't work at all. Has anyone ever managed to upload files via USB to an a570is on any OS?

Offline fe50

  • Guru Member
  • ******
  • Posts: 2602
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
Re: Webcam operation
« Reply #1 on: 01 / December / 2008, 03:56:37 »
...I wanted to signal things from the PC by uploading a file after the PC script is done transferring, but sadly upload didn't work at all. Has anyone ever managed to upload files via USB to an a570is on any OS?


Hi fudgey,
not on A570, but on a SD870 & SD400: for Windows there's Digicanon's firmware uploader: digicanon.narod.ru, you can upload files to the card's root via USB; it should work on all Canon P&S cams...
It's described in the wikia FAQ, see also How to copy the CHDK firmware onto Canon Powershot S2 IS ? here in the forum.

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Re: Webcam operation
« Reply #2 on: 03 / December / 2008, 04:50:02 »
Some progress... turned out simpler than I thought it would:

1) power up in play mode
2) connect USB cable to PC
3) call PB2Rec()

We are now in REC mode (a bit fuzzled up one but it's a REC mode), shooting works etc. But what's cool is that PTP transfers such as gphoto2 --list-files and gphoto2 --get-all-files work. None of that usb_magic RAM manipulation necessary as long as we start out this way from play mode.

And what's even greater is that these file transfers seem to work even during (long) exposures and burst shooting!

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Webcam operation
« Reply #3 on: 03 / December / 2008, 04:51:49 »
great news :)

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Re: Webcam operation
« Reply #4 on: 03 / December / 2008, 05:01:46 »
Oh and some more.. the above requires a PC that doesn't auto detect and mount the camera instantly when plugged in. For my Ubuntu that means my previous hald disable workaround.

But turns out that's not necessary with what I just said if we add a call to DisableNotificationPTP() to the procedure:


1) power up in play mode
2) call DisableNotificationPTP()
3) connect USB cable to PC (camera appears on desktop)
4) call PB2Rec()

Camera is now usable by normal interactive shooting and scripts (some confusion to be expected, CHDK doesn't quite know we're in REC mode and possibly neither some parts of the camera; for example there's no CHDK osd until I switch the rec/play lever to rec mode too but then USB disconnects) and the camera is available on the PC's PTP explorer thingies, whatever your OS is using (I believe my Ubuntu is using libgphoto2 for mounting and viewing the camera's contents in nautilus, in Windows that would be something else but should work just the same).

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Re: Webcam operation
« Reply #5 on: 03 / December / 2008, 05:15:01 »
I'm really starting to wish that PTP upload would work...

If I'm not mistaken, it would then be possible to do things like use PTP and Lua to install scripts without removing the SD card... just run a Lua script (play mode should suffice for this) that monitors for uploads in some folder PTP is able to upload to and moves them to where they belong to, possibly according to a control file (which could be written in form of a Lua script as I believe Lua can run newly uploaded scripts if they're written in a way that can be require()'d?).

Maybe even update CHDK binaries via USB?

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Webcam operation
« Reply #6 on: 03 / December / 2008, 05:46:33 »
using gphoto i was able to move binary and other files onto the camera (DCIM folder though). but should be no problem moving them via lua to other directories... the binary can even be overwritten while chdk is booted (not tested though).
this worked on s3is and imo on a620 as well.
gphoto can send the files to the camera, but NOT display them (very confusing :D)

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Re: Webcam operation
« Reply #7 on: 04 / December / 2008, 00:22:34 »
I've now tried uploading files on Windows Vista (which recognized the camera without 3rd party drivers and showed it as a removable device of a sort, much like Ubuntu), but it fails too.

And yes, I tried uploading to DCIM and the Canon created directories under DCIM, I even only tried copying JPG files previously shot with the same camera. And I tried without card write protect, and I tried without CHDK. I'm really starting to think a570is doesn't support PTP upload one bit...  >:(

Offline silas

  • Rookie
  • *
  • Posts: 19
Re: Webcam operation
« Reply #8 on: 24 / February / 2009, 00:36:21 »
On my camera (a550) it works to upload whit the program camerawindow (from canon).

CHDK Forum

Re: Webcam operation
« Reply #8 on: 24 / February / 2009, 00:36:21 »

Offline delco

  • Newbie
  • *
  • Posts: 1
SUCCESS
« Reply #9 on: 22 / January / 2010, 07:53:00 »
« Last Edit: 22 / January / 2010, 07:56:22 by delco »

Offline maxim

  • Newbie
  • *
  • Posts: 1
Re: Webcam operation
« Reply #10 on: 15 / February / 2010, 05:21:32 »
Good job, but i have lost something,
both A550 and A570is are listed as not able to capture from remote in the gphoto2 ( http://www.gphoto.org/doc/remote/ ) and in the psRemote websites
How did you manage to make it work???

« Last Edit: 15 / February / 2010, 05:41:48 by maxim »

Offline fudgey

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 1690
  • a570is
Re: Webcam operation
« Reply #11 on: 16 / February / 2010, 02:22:14 »
First, the recent posts about eye-fi have nothing much to do with camera capabilities as the memory card is doing it all (i.e. CHDK isn't needed for an eye-fi cards to work, but you may want to run a CHDK script to keep your camera shooting the way you want).

Other things mentioned in this thread are rather old (but they do work and are a lot easier to experiment with now that we have the eventproc script interface). My old demonstration somewhere above basically worked by setting the camera to run a script to shoot a lot, hacking the camera to make PTP USB transfer from camera to PC work in REC mode (instead of just PLAY mode) and having the PC constantly poll the camera for new files via USB.

My problem was that I wasn't able to upload anything (even simple commands) to the camera in order to control the script in any way. This has recently been cunningly resolved by having CHDK add some custom functionality to the camera's PTP interface in order to enable commands to be sent and data to be transferred, see http://chdk.setepontos.com/index.php/topic,4338.0.html.

Offline crashtest

  • Newbie
  • *
  • Posts: 3
Re: Webcam operation
« Reply #12 on: 23 / October / 2010, 04:06:25 »
Hi,

I also purchased the EyeFi card for my project. I am running it in a Canon A550 with a DC power supply attached and a very simple script that takes a picture every 10 min between 6am and 6pm. The camera script should run indefinitely until I stop the script or switch the camera off.

Unfortunately after about 2 days the camera switches off by itself, sometimes sooner. I can not find the common denominator in all this. I want the camera to run automated as long as possible with out me touching it.

Any one having similar problems? Any suggestions will be much appreciated.

If you want to see my project got to: sydney.candco.ca

Offline reyalp

  • Guru Member
  • ******
  • Posts: 4468
Re: Webcam operation
« Reply #13 on: 23 / October / 2010, 08:08:24 »
A romlog http://chdk.wikia.com/wiki/LUA/Scripts:Standard/Test/Romlog may provide some clues. You'll have to build your own CHDK to do this.

CHDK also now includes the capability to reboot the camera, so you could try rebooting daily.

Is the script ubasic or lua ? If it's very simple, you can try the other language. Note that it is possible for lua to exhaust all available memory without running garbage collection, or allocate so much that some other camera process fails. You can check lua memory usage and force garbage collection with http://www.lua.org/manual/5.1/manual.html#pdf-collectgarbage

I'm not sure this why this is in the "webcam operation" thread, it probably deserves it's own thread.

Don't forget what the H stands for.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal