Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBHostC270_example by
USBHostCam.h
00001 // USBHostCam.h 00002 #include "USBHostConf.h" 00003 #include "USBHost.h" 00004 #include "USBIsochronous.h" 00005 #include "BaseUvc.h" 00006 #include "decodeMJPEG.h" 00007 #pragma once 00008 00009 #define _160x120 2 00010 #define _176x144 3 00011 #define _320x176 4 00012 #define _320x240 5 00013 #define _352x288 6 00014 #define _432x240 7 00015 #define _640x480 1 00016 #define _544x288 8 00017 #define _640x360 9 00018 #define _752x416 10 00019 #define _800x448 11 00020 #define _800x600 12 00021 00022 #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; 00023 00024 struct CamInfo { 00025 uint16_t vid; 00026 uint16_t pid; 00027 uint8_t size; 00028 uint8_t option; 00029 // 00030 const char* name; 00031 uint8_t formatIndex; 00032 uint8_t frameIndex; 00033 uint32_t interval; 00034 uint8_t en; 00035 uint8_t mps; 00036 uint8_t if_alt; 00037 uint8_t frameCount; // ITD frame count 1-8 00038 uint8_t queueLimit; // ITD queue limit 1-3 00039 }; 00040 00041 /** 00042 * A class to communicate a Cam 00043 */ 00044 class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { 00045 public: 00046 /** 00047 * Constructor 00048 * 00049 */ 00050 USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); 00051 00052 /** 00053 * Check if a Cam device is connected 00054 * 00055 * @return true if a Cam device is connected 00056 */ 00057 bool connected(); 00058 00059 /** 00060 * Try to connect to a Cam device 00061 * 00062 * @return true if connection was successful 00063 */ 00064 bool connect(); 00065 00066 /** 00067 * read jpeg image 00068 * 00069 * @param buf read buffer 00070 * @param size buffer size 00071 * @param timeout_ms timeout default 15sec 00072 * @return jpeg size if read success else -1 00073 */ 00074 int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); 00075 00076 protected: 00077 //From IUSBEnumerator 00078 virtual void setVidPid(uint16_t vid, uint16_t pid); 00079 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 00080 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00081 00082 private: 00083 bool dev_connected; 00084 00085 int cam_intf; 00086 bool device_found; 00087 bool caminfo_found; 00088 uint8_t _seq; 00089 uint8_t* _buf; 00090 int _pos; 00091 int _size; 00092 CamInfo* CamInfoList; 00093 CamInfo* caminfo; 00094 uint8_t _caminfo_size; 00095 uint8_t _caminfo_option; 00096 00097 virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG 00098 void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); 00099 void init(); 00100 void onDisconnect(); 00101 };
Generated on Mon Jul 18 2022 19:52:39 by
1.7.2
