Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1701 → Rev 1702

/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/PSCapture.pde
0,0 → 1,106
/* Canon Powershot Capture Demo */
#include <inttypes.h>
#include <avr/pgmspace.h>
 
//#include <Spi.h>
#include <Max3421e.h>
#include <Max3421e_constants.h>
#include <Max_LCD.h>
#include <Usb.h>
 
#include <ptp.h>
#include <ptpdebug.h>
#include <canonps.h>
#include <simpletimer.h>
#include "pseventparser.h"
#include "ptpobjinfoparser.h"
 
#define DEV_ADDR 1
 
// Canon PowerShot S3 IS
#define DATA_IN_EP 1
#define DATA_OUT_EP 2
#define INTERRUPT_EP 3
#define CONFIG_NUM 1
 
void setup();
void loop();
 
class CamStateHandlers : public PSStateHandlers
{
bool stateConnected;
public:
CamStateHandlers() : stateConnected(false) {};
virtual void OnDeviceDisconnectedState(PTP *ptp);
virtual void OnDeviceInitializedState(PTP *ptp);
} CamStates;
 
CanonPS Ps(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);
SimpleTimer eventTimer, captureTimer;
 
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
{
if (stateConnected)
{
eventTimer.Disable();
captureTimer.Disable();
stateConnected = false;
Notify(PSTR("Camera disconnected\r\n"));
}
}
 
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
{
if (!stateConnected)
{
Notify(PSTR("stateConnected\r\n"));
stateConnected = true;
eventTimer.Enable();
captureTimer.Enable();
}
}
 
void setup()
{
Serial.begin( 115200 );
Serial.println("Start");
Ps.Setup();
eventTimer.Set(&OnEventTimer, 200);
captureTimer.Set(&OnCaptureTimer, 5000);
delay( 200 );
}
 
void loop()
{
eventTimer.Run();
captureTimer.Run();
Ps.Task();
}
 
void OnCaptureTimer()
{
Ps.SetDevicePropValue(PS_DPC_CaptureTransferMode, (uint16_t)0x0D);
uint16_t rc = Ps.Capture();
if (rc != PTP_RC_OK)
Message(PSTR("Error: "), rc);
}
 
void OnEventTimer()
{
PSEventParser prs;
Ps.EventCheck(&prs);
if (uint32_t handle = prs.GetObjHandle())
{
PTPObjInfoParser inf;
Ps.GetObjectInfo(handle, &inf);
}
}
 
 
/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/pseventparser.cpp
0,0 → 1,86
#include "pseventparser.h"
 
void PSEventParser::Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset)
{
uint16_t cntdn = (uint16_t)len;
uint8_t *p = (uint8_t*)pbuf;
 
switch (nStage)
{
case 0:
p += 12;
cntdn -= 12;
 
if (!cntdn)
return;
nStage ++;
 
case 1:
//Notify(PSTR("\r\nEvent Block Size:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 2:
if (!valueParser.Parse(&p, &cntdn))
return;
 
//PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 3:
//Notify(PSTR("\r\nNumber of Fields:\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 4:
if (!valueParser.Parse(&p, &cntdn))
return;
 
//PrintHex<uint16_t>(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 5:
//Notify(PSTR("\r\nEvent Code:\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 6:
if (!valueParser.Parse(&p, &cntdn))
return;
 
eventCode = *((uint16_t*)theBuffer.pValue);
//PrintHex<uint16_t>(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 7:
//Notify(PSTR("\r\nTransaction ID:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 8:
if (!valueParser.Parse(&p, &cntdn))
return;
 
//PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 9:
if (eventCode == PTP_EC_ObjectAdded)
Notify(PSTR("\r\nObject Added:\t\t"));
 
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 10:
if (eventCode == PTP_EC_ObjectAdded)
{
if (!valueParser.Parse(&p, &cntdn))
return;
 
objHandle = *((uint32_t*)theBuffer.pValue);
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
Notify(PSTR("\r\n"));
}
if (eventCode == PTP_EC_CaptureComplete)
Notify(PSTR("\r\nCapture complete.\r\n"));
nStage ++;
case 11:
nStage = 0;
}
}
/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/pseventparser.h
0,0 → 1,29
#ifndef __PSEVENTPARSER_H__
#define __PSEVENTPARSER_H__
 
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "ptpcallback.h"
#include "ptpdebug.h"
#include "canonps.h"
 
class PSEventParser : public PTPReadParser
{
MultiValueBuffer theBuffer;
uint32_t varBuffer;
uint8_t nStage;
uint16_t eventCode;
uint32_t objHandle;
 
MultiByteValueParser valueParser;
 
public:
PSEventParser() : nStage(0), varBuffer(0), objHandle(0)
{
theBuffer.pValue = &varBuffer;
};
uint32_t GetObjHandle() { return objHandle; };
virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset);
};
 
#endif // __PSEVENTPARSER_H__
/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/ptpobjinfoparser.cpp
0,0 → 1,298
#include "ptpobjinfoparser.h"
 
const char* PTPObjInfoParser::acNames[] PROGMEM =
{
msgUndefined,
msgAssociation,
msgScript,
msgExecutable,
msgText,
msgHTML,
msgDPOF,
msgAIFF,
msgWAV,
msgMP3,
msgAVI,
msgMPEG,
msgASF,
msgQT
};
 
const char* PTPObjInfoParser::imNames[] PROGMEM =
{
msgUndefined,
msgEXIF_JPEG,
msgTIFF_EP,
msgFlashPix,
msgBMP,
msgCIFF,
msgUndefined_0x3806,
msgGIF,
msgJFIF,
msgPCD,
msgPICT,
msgPNG,
msgUndefined_0x380C,
msgTIFF,
msgTIFF_IT,
msgJP2,
msgJPX,
};
 
void PTPObjInfoParser::PrintFormat(uint16_t op)
{
Serial.print(op, HEX);
Serial.print("\t");
//Notify(msgTab);
 
if ((((op >> 8) & 0xFF) == 0x30) && ((op & 0xFF) <= (PTP_OFC_QT & 0xFF)))
Notify((char*)pgm_read_word(&acNames[(op & 0xFF)]));
else
if ((((op >> 8) & 0xFF) == 0x38) && ((op & 0xFF) <= (PTP_OFC_JPX & 0xFF)))
Notify((char*)pgm_read_word(&imNames[(op & 0xFF)]));
else
{
switch (op)
{
case MTP_OFC_Undefined_Firmware:
Notify(msgUndefined_Firmware);
break;
case MTP_OFC_Windows_Image_Format:
Notify(msgWindows_Image_Format);
break;
case MTP_OFC_Undefined_Audio:
Notify(msgUndefined_Audio);
break;
case MTP_OFC_WMA:
Notify(msgWMA);
break;
case MTP_OFC_OGG:
Notify(msgOGG);
break;
case MTP_OFC_AAC:
Notify(msgAAC);
break;
case MTP_OFC_Audible:
Notify(msgAudible);
break;
case MTP_OFC_FLAC:
Notify(msgFLAC);
break;
case MTP_OFC_Undefined_Video:
Notify(msgUndefined_Video);
break;
case MTP_OFC_WMV:
Notify(msgWMV);
break;
case MTP_OFC_MP4_Container:
Notify(msgMP4_Container);
break;
case MTP_OFC_MP2:
Notify(msgMP2);
break;
case MTP_OFC_3GP_Container:
Notify(msg3GP_Container);
break;
default:
Notify(PSTR("Vendor defined"));
}
}
Notify(PSTR("\r\n"));
}
 
void PTPObjInfoParser::Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset)
{
uint16_t cntdn = (uint16_t)len;
uint8_t *p = (uint8_t*)pbuf;
 
switch (nStage)
{
case 0:
p += 12;
cntdn -= 12;
nStage ++;
case 1:
Notify(PSTR("Storage ID:\t\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 2:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 3:
Notify(PSTR("\r\nObject Format:\t\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 4:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintFormat(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 5:
Notify(PSTR("Protection Status:\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 6:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint16_t>(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 7:
Notify(PSTR("\r\nObject Compressed Size:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 8:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 9:
Notify(PSTR("\r\nThumb Format:\t\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 10:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintFormat(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 11:
Notify(PSTR("Thumb Compressed Size:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 12:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 13:
Notify(PSTR("\r\nThumb Pix Width:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 14:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 15:
Notify(PSTR("\r\nThumb Pix Height:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 16:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 17:
Notify(PSTR("\r\nImage Pix Width:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 18:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 19:
Notify(PSTR("\r\nImage Pix Height:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 20:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 21:
Notify(PSTR("\r\nImage Bit Depth:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 22:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 23:
Notify(PSTR("\r\nParent Object:\t\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 24:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 25:
Notify(PSTR("\r\nAssociation Type:\t"));
theBuffer.valueSize = 2;
valueParser.Initialize(&theBuffer);
nStage ++;
case 26:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint16_t>(*((uint16_t*)theBuffer.pValue));
nStage ++;
case 27:
Notify(PSTR("\r\nAssociation Desc:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 28:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 29:
Notify(PSTR("\r\nSequence Number:\t"));
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
nStage ++;
case 30:
if (!valueParser.Parse(&p, &cntdn))
return;
PrintHex<uint32_t>(*((uint32_t*)theBuffer.pValue));
nStage ++;
case 31:
Notify(PSTR("\r\nFile Name:\t\t"));
arrayParser.Initialize(1, 2, &theBuffer);
nStage ++;
case 32:
if (!arrayParser.Parse(&p, &cntdn, (PTP_ARRAY_EL_FUNC)&PrintChar))
return;
nStage ++;
case 33:
Notify(PSTR("\r\nCapture Date:\t\t"));
arrayParser.Initialize(1, 2, &theBuffer);
nStage ++;
case 34:
if (!arrayParser.Parse(&p, &cntdn, (PTP_ARRAY_EL_FUNC)&PrintChar))
return;
nStage ++;
case 35:
Notify(PSTR("\r\nModification Date:\t"));
arrayParser.Initialize(1, 2, &theBuffer);
nStage ++;
case 36:
if (!arrayParser.Parse(&p, &cntdn, (PTP_ARRAY_EL_FUNC)&PrintChar))
return;
nStage ++;
case 37:
Notify(PSTR("\r\nKeywords:\t"));
arrayParser.Initialize(1, 2, &theBuffer);
nStage ++;
case 38:
if (!arrayParser.Parse(&p, &cntdn, (PTP_ARRAY_EL_FUNC)&PrintChar))
return;
Notify(PSTR("\r\n"));
nStage = 0;
}
}
/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/ptpobjinfoparser.h
0,0 → 1,83
#ifndef __PTPOBJINFOPARSER_H__
#define __PTPOBJINFOPARSER_H__
 
#include <ptp.h>
#include <mtpconst.h>
#include <ptpcallback.h>
 
const char msgUndefined [] PROGMEM = "Undefined";
 
// Ancillary formats
const char msgAssociation [] PROGMEM = "Association";
const char msgScript [] PROGMEM = "Script";
const char msgExecutable [] PROGMEM = "Executable";
const char msgText [] PROGMEM = "Text";
const char msgHTML [] PROGMEM = "HTML";
const char msgDPOF [] PROGMEM = "DPOF";
const char msgAIFF [] PROGMEM = "AIFF";
const char msgWAV [] PROGMEM = "WAV";
const char msgMP3 [] PROGMEM = "MP3";
const char msgAVI [] PROGMEM = "AVI";
const char msgMPEG [] PROGMEM = "MPEG";
const char msgASF [] PROGMEM = "ASF";
const char msgQT [] PROGMEM = "QT";
 
// Image formats
const char msgEXIF_JPEG [] PROGMEM = "EXIF_JPEG";
const char msgTIFF_EP [] PROGMEM = "TIFF_EP";
const char msgFlashPix [] PROGMEM = "FlashPix";
const char msgBMP [] PROGMEM = "BMP";
const char msgCIFF [] PROGMEM = "CIFF";
const char msgUndefined_0x3806 [] PROGMEM = "Undefined_0x3806";
const char msgGIF [] PROGMEM = "GIF";
const char msgJFIF [] PROGMEM = "JFIF";
const char msgPCD [] PROGMEM = "PCD";
const char msgPICT [] PROGMEM = "PICT";
const char msgPNG [] PROGMEM = "PNG";
const char msgUndefined_0x380C [] PROGMEM = "Undefined_0x380C";
const char msgTIFF [] PROGMEM = "TIFF";
const char msgTIFF_IT [] PROGMEM = "TIFF_IT";
const char msgJP2 [] PROGMEM = "JP2";
const char msgJPX [] PROGMEM = "JPX";
 
// MTP Object Formats
const char msgUndefined_Firmware [] PROGMEM = "Undefined_Firmware";
const char msgWindows_Image_Format [] PROGMEM = "Windows_Image_Format";
const char msgUndefined_Audio [] PROGMEM = "Undefined_Audio";
const char msgWMA [] PROGMEM = "WMA";
const char msgOGG [] PROGMEM = "OGG";
const char msgAAC [] PROGMEM = "AAC";
const char msgAudible [] PROGMEM = "Audible";
const char msgFLAC [] PROGMEM = "FLAC";
const char msgUndefined_Video [] PROGMEM = "Undefined_Video";
const char msgWMV [] PROGMEM = "WMV";
const char msgMP4_Container [] PROGMEM = "MP4_Container";
const char msgMP2 [] PROGMEM = "MP2";
const char msg3GP_Container [] PROGMEM = "3GP_Container";
 
 
class PTPObjInfoParser : public PTPReadParser
{
static const char* acNames[];
static const char* imNames[];
 
MultiValueBuffer theBuffer;
uint32_t varBuffer;
uint8_t nStage;
 
MultiByteValueParser valueParser;
PTPListParser arrayParser;
 
static void PrintChar(MultiValueBuffer *p)
{
if (((unsigned char*)p->pValue)[0])
Serial.print(((unsigned char*)p->pValue)[0]);
};
void PrintFormat(uint16_t op);
 
public:
PTPObjInfoParser() : nStage(0) { theBuffer.pValue = (uint8_t*)&varBuffer; };
virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset);
};
 
#endif // __PTPOBJINFOPARSER_H__
/C-OSD/arducam-osd/libraries/PTPCamera/examples/PSCapture/sample_output.txt
0,0 → 1,96
Session opened
stateConnected
 
Object Added: 00000005
Storage ID: 00010001
Object Format: 3801 EXIF_JPEG
Protection Status: 0000
Object Compressed Size: 00315A1A
Thumb Format: 3808 JFIF
Thumb Compressed Size: 0000107A
Thumb Pix Width: 000000A0
Thumb Pix Height: 00000078
Image Pix Width: 00000E40
Image Pix Height: 00000AB0
Image Bit Depth: 00000000
Parent Object: 00000004
Association Type: 0000
Association Desc: 00000001
Sequence Number: 00000000
File Name: IMG_0991.JPG
Capture Date: 20110115T010141.0
Modification Date:
Keywords:
 
Capture complete.
 
Object Added: 00000006
Storage ID: 00010001
Object Format: 3801 EXIF_JPEG
Protection Status: 0000
Object Compressed Size: 002F6B25
Thumb Format: 3808 JFIF
Thumb Compressed Size: 0000106B
Thumb Pix Width: 000000A0
Thumb Pix Height: 00000078
Image Pix Width: 00000E40
Image Pix Height: 00000AB0
Image Bit Depth: 00000000
Parent Object: 00000004
Association Type: 0000
Association Desc: 00000001
Sequence Number: 00000000
File Name: IMG_0992.JPG
Capture Date: 20110115T010146.0
Modification Date:
Keywords:
 
Capture complete.
 
Object Added: 00000007
Storage ID: 00010001
Object Format: 3801 EXIF_JPEG
Protection Status: 0000
Object Compressed Size: 002FE0BF
Thumb Format: 3808 JFIF
Thumb Compressed Size: 00001085
Thumb Pix Width: 000000A0
Thumb Pix Height: 00000078
Image Pix Width: 00000E40
Image Pix Height: 00000AB0
Image Bit Depth: 00000000
Parent Object: 00000004
Association Type: 0000
Association Desc: 00000001
Sequence Number: 00000000
File Name: IMG_0993.JPG
Capture Date: 20110115T010151.0
Modification Date:
Keywords:
 
Capture complete.
 
Object Added: 00000008
Storage ID: 00010001
Object Format: 3801 EXIF_JPEG
Protection Status: 0000
Object Compressed Size: 002EDF53
Thumb Format: 3808 JFIF
Thumb Compressed Size: 00001082
Thumb Pix Width: 000000A0
Thumb Pix Height: 00000078
Image Pix Width: 00000E40
Image Pix Height: 00000AB0
Image Bit Depth: 00000000
Parent Object: 00000004
Association Type: 0000
Association Desc: 00000001
Sequence Number: 00000000
File Name: IMG_0994.JPG
Capture Date: 20110115T010157.0
Modification Date:
Keywords:
 
Capture complete.
Camera disconnected