
Simple USBHost WebCam test program
Dependencies: F401RE-USBHost mbed
Fork of KL46Z-USBHostC270_example by
WebカメラからJPEG画像を読み取るテストプログラムです。
使い方はKL46Z-USBHostC270_exampleと同じです。
動作確認カメラ: Logitech C270, Logitech C210, Logitech Q200R(Qcam Orbit AF), LifeCam VX-500
Diff: KL46Z_USBHostC270/USBHostCam.h
- Revision:
- 1:22304b8f8395
- Child:
- 2:2a40888db9fc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KL46Z_USBHostC270/USBHostCam.h Tue Jan 28 06:54:16 2014 +0000 @@ -0,0 +1,72 @@ +// USBHostCam.h +#include "USBHostConf.h" +#include "USBHost.h" +#include "BaseUvc.h" +#include "decodeMJPEG.h" +#pragma once + +#define _160x120 2 +#define _176x144 3 +#define _320x176 4 +#define _320x240 5 +#define _352x288 6 +#define _432x240 7 +#define _640x480 1 +#define _544x288 8 +#define _640x360 9 +#define _752x416 10 +#define _800x448 11 +#define _800x600 12 + +#define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; + +struct CamInfo { + uint16_t vid; + uint16_t pid; + uint8_t size; + uint8_t option; +// + const char* name; + uint8_t formatIndex; + uint8_t frameIndex; + uint32_t interval; + uint8_t en; + uint8_t mps; + uint8_t if_alt; +}; + +/** + * A class to communicate a Cam + */ +class USBHostCam : public BaseUvc, public decodeMJPEG { +public: + /** + * Constructor + * + */ + USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); + + /** + * read jpeg image + * + * @param buf read buffer + * @param size buffer size + * @param timeout_ms timeout default 15sec + * @return jpeg size if read success else -1 + */ + int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); + +private: + uint8_t _seq; + uint8_t* _buf; + int _pos; + int _size; + CamInfo* CamInfoList; + CamInfo* caminfo; + uint8_t _caminfo_size; + uint8_t _caminfo_option; + + void setup(); + virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG + void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); +};