![](/media/cache/profiles/f095cedd23b99f1696fc8caecbcf257e.jpg.50x50_q85.jpg)
see: http://mbed.org/users/okini3939/notebook/wifi_webcam/
Dependencies: GSwifiInterface_ap_webcam USBHost mbed
USBHostCam/USBHostCam.h@0:8558bdecb0fa, 2014-06-06 (annotated)
- Committer:
- okini3939
- Date:
- Fri Jun 06 00:44:06 2014 +0000
- Revision:
- 0:8558bdecb0fa
1st build
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:8558bdecb0fa | 1 | // USBHostCam.h |
okini3939 | 0:8558bdecb0fa | 2 | #include "USBHostConf.h" |
okini3939 | 0:8558bdecb0fa | 3 | #include "USBHost.h" |
okini3939 | 0:8558bdecb0fa | 4 | #include "USBIsochronous.h" |
okini3939 | 0:8558bdecb0fa | 5 | #include "BaseUvc.h" |
okini3939 | 0:8558bdecb0fa | 6 | #include "decodeMJPEG.h" |
okini3939 | 0:8558bdecb0fa | 7 | #pragma once |
okini3939 | 0:8558bdecb0fa | 8 | |
okini3939 | 0:8558bdecb0fa | 9 | #define _160x120 2 |
okini3939 | 0:8558bdecb0fa | 10 | #define _176x144 3 |
okini3939 | 0:8558bdecb0fa | 11 | #define _320x176 4 |
okini3939 | 0:8558bdecb0fa | 12 | #define _320x240 5 |
okini3939 | 0:8558bdecb0fa | 13 | #define _352x288 6 |
okini3939 | 0:8558bdecb0fa | 14 | #define _432x240 7 |
okini3939 | 0:8558bdecb0fa | 15 | #define _640x480 1 |
okini3939 | 0:8558bdecb0fa | 16 | #define _544x288 8 |
okini3939 | 0:8558bdecb0fa | 17 | #define _640x360 9 |
okini3939 | 0:8558bdecb0fa | 18 | #define _752x416 10 |
okini3939 | 0:8558bdecb0fa | 19 | #define _800x448 11 |
okini3939 | 0:8558bdecb0fa | 20 | #define _800x600 12 |
okini3939 | 0:8558bdecb0fa | 21 | |
okini3939 | 0:8558bdecb0fa | 22 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
okini3939 | 0:8558bdecb0fa | 23 | |
okini3939 | 0:8558bdecb0fa | 24 | struct CamInfo { |
okini3939 | 0:8558bdecb0fa | 25 | uint16_t vid; |
okini3939 | 0:8558bdecb0fa | 26 | uint16_t pid; |
okini3939 | 0:8558bdecb0fa | 27 | uint8_t size; |
okini3939 | 0:8558bdecb0fa | 28 | uint8_t option; |
okini3939 | 0:8558bdecb0fa | 29 | // |
okini3939 | 0:8558bdecb0fa | 30 | const char* name; |
okini3939 | 0:8558bdecb0fa | 31 | uint8_t formatIndex; |
okini3939 | 0:8558bdecb0fa | 32 | uint8_t frameIndex; |
okini3939 | 0:8558bdecb0fa | 33 | uint32_t interval; |
okini3939 | 0:8558bdecb0fa | 34 | uint8_t en; |
okini3939 | 0:8558bdecb0fa | 35 | uint8_t mps; |
okini3939 | 0:8558bdecb0fa | 36 | uint8_t if_alt; |
okini3939 | 0:8558bdecb0fa | 37 | uint8_t frameCount; // ITD frame count 1-8 |
okini3939 | 0:8558bdecb0fa | 38 | uint8_t queueLimit; // ITD queue limit 1-3 |
okini3939 | 0:8558bdecb0fa | 39 | }; |
okini3939 | 0:8558bdecb0fa | 40 | |
okini3939 | 0:8558bdecb0fa | 41 | /** |
okini3939 | 0:8558bdecb0fa | 42 | * A class to communicate a Cam |
okini3939 | 0:8558bdecb0fa | 43 | */ |
okini3939 | 0:8558bdecb0fa | 44 | class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { |
okini3939 | 0:8558bdecb0fa | 45 | public: |
okini3939 | 0:8558bdecb0fa | 46 | /** |
okini3939 | 0:8558bdecb0fa | 47 | * Constructor |
okini3939 | 0:8558bdecb0fa | 48 | * |
okini3939 | 0:8558bdecb0fa | 49 | */ |
okini3939 | 0:8558bdecb0fa | 50 | USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); |
okini3939 | 0:8558bdecb0fa | 51 | |
okini3939 | 0:8558bdecb0fa | 52 | /** |
okini3939 | 0:8558bdecb0fa | 53 | * Check if a Cam device is connected |
okini3939 | 0:8558bdecb0fa | 54 | * |
okini3939 | 0:8558bdecb0fa | 55 | * @return true if a Cam device is connected |
okini3939 | 0:8558bdecb0fa | 56 | */ |
okini3939 | 0:8558bdecb0fa | 57 | bool connected(); |
okini3939 | 0:8558bdecb0fa | 58 | |
okini3939 | 0:8558bdecb0fa | 59 | /** |
okini3939 | 0:8558bdecb0fa | 60 | * Try to connect to a Cam device |
okini3939 | 0:8558bdecb0fa | 61 | * |
okini3939 | 0:8558bdecb0fa | 62 | * @return true if connection was successful |
okini3939 | 0:8558bdecb0fa | 63 | */ |
okini3939 | 0:8558bdecb0fa | 64 | bool connect(); |
okini3939 | 0:8558bdecb0fa | 65 | |
okini3939 | 0:8558bdecb0fa | 66 | /** |
okini3939 | 0:8558bdecb0fa | 67 | * read jpeg image |
okini3939 | 0:8558bdecb0fa | 68 | * |
okini3939 | 0:8558bdecb0fa | 69 | * @param buf read buffer |
okini3939 | 0:8558bdecb0fa | 70 | * @param size buffer size |
okini3939 | 0:8558bdecb0fa | 71 | * @param timeout_ms timeout default 15sec |
okini3939 | 0:8558bdecb0fa | 72 | * @return jpeg size if read success else -1 |
okini3939 | 0:8558bdecb0fa | 73 | */ |
okini3939 | 0:8558bdecb0fa | 74 | int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); |
okini3939 | 0:8558bdecb0fa | 75 | |
okini3939 | 0:8558bdecb0fa | 76 | protected: |
okini3939 | 0:8558bdecb0fa | 77 | //From IUSBEnumerator |
okini3939 | 0:8558bdecb0fa | 78 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
okini3939 | 0:8558bdecb0fa | 79 | 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 |
okini3939 | 0:8558bdecb0fa | 80 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
okini3939 | 0:8558bdecb0fa | 81 | |
okini3939 | 0:8558bdecb0fa | 82 | private: |
okini3939 | 0:8558bdecb0fa | 83 | bool dev_connected; |
okini3939 | 0:8558bdecb0fa | 84 | |
okini3939 | 0:8558bdecb0fa | 85 | int cam_intf; |
okini3939 | 0:8558bdecb0fa | 86 | bool device_found; |
okini3939 | 0:8558bdecb0fa | 87 | bool caminfo_found; |
okini3939 | 0:8558bdecb0fa | 88 | uint8_t _seq; |
okini3939 | 0:8558bdecb0fa | 89 | uint8_t* _buf; |
okini3939 | 0:8558bdecb0fa | 90 | int _pos; |
okini3939 | 0:8558bdecb0fa | 91 | int _size; |
okini3939 | 0:8558bdecb0fa | 92 | CamInfo* CamInfoList; |
okini3939 | 0:8558bdecb0fa | 93 | CamInfo* caminfo; |
okini3939 | 0:8558bdecb0fa | 94 | uint8_t _caminfo_size; |
okini3939 | 0:8558bdecb0fa | 95 | uint8_t _caminfo_option; |
okini3939 | 0:8558bdecb0fa | 96 | |
okini3939 | 0:8558bdecb0fa | 97 | virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG |
okini3939 | 0:8558bdecb0fa | 98 | void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); |
okini3939 | 0:8558bdecb0fa | 99 | void init(); |
okini3939 | 0:8558bdecb0fa | 100 | void onDisconnect(); |
okini3939 | 0:8558bdecb0fa | 101 | }; |