Masato YAMANISHI / Mbed 2 deprecated USBHostC210_example

Dependencies:   TextLCD USBHost mbed

Fork of USBHostC270_example by Norimasa Okamoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostC270.h Source File

USBHostC270.h

00001 #include "USBHostConf.h"
00002 #include "USBHost.h"
00003 #include "BaseUvc.h"
00004 #include "decodeMJPEG.h"
00005 
00006 // Logitech C270
00007 #define C270_VID 0x046d
00008 // #define C270_PID 0x0825 
00009 #define C270_PID 0x0819 // for C210
00010 #define C270_160x120 2
00011 #define C270_176x144 3
00012 #define C270_320x176 4
00013 #define C270_320x240 5
00014 #define C270_352x288 6
00015 #define C270_432x240 7
00016 #define C270_640x480 1
00017 #define C270_544x288 8
00018 #define C270_640x360 9
00019 #define C270_752x416 10
00020 #define C270_800x448 11
00021 #define C270_800x600 12
00022 
00023 #define C270_MJPEG 2
00024 #define C270_YUV2  1
00025 
00026 #define C270_EN  0x81
00027 #define C270_MPS  192
00028 #define C270_IF_ALT 1
00029 
00030 #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
00031 
00032 class IsochronousEp;
00033 class BaseUvc;
00034 /** 
00035  * A class to communicate a C270
00036  */
00037 class USBHostC270 : public IUSBEnumerator, public BaseUvc, public decodeMJPEG {
00038 public:
00039     /**
00040     * Constructor
00041     *
00042     */
00043     USBHostC270(int formatIndex = C270_MJPEG, int frameIndex = C270_160x120, uint32_t interval = _5FPS);
00044 
00045     /**
00046     * Check if a C270 device is connected
00047     *
00048     * @return true if a MSD device is connected
00049     */
00050     bool connected();
00051 
00052     /**
00053      * Try to connect to a C270 device
00054      *
00055      * @return true if connection was successful
00056      */
00057     bool connect();
00058 
00059     /**
00060      * read jpeg image
00061      *
00062      * @param buf read buffer 
00063      * @param size buffer size 
00064      * @param timeout_ms timeout default 15sec
00065      * @return jpeg size if read success else -1
00066      */
00067     int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000);
00068 
00069 protected:
00070     //From IUSBEnumerator
00071     virtual void setVidPid(uint16_t vid, uint16_t pid);
00072     virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
00073     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00074 
00075 private:
00076     bool dev_connected;
00077 
00078     int c270_intf;
00079     bool c270_device_found;
00080     bool c270_vid_pid_found;
00081     int _formatIndex;
00082     int _frameIndex;
00083     uint32_t _interval;
00084     uint8_t _seq;
00085     uint8_t* _buf;
00086     int _pos;
00087     int _size;
00088 
00089     virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG
00090     void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len);
00091     void init();
00092     void onDisconnect();
00093 };