UVC host library
Dependents: LifeCam WebcamServer
uvc/uvc.h@0:b0f04c137829, 2012-07-31 (annotated)
- Committer:
- va009039
- Date:
- Tue Jul 31 13:58:03 2012 +0000
- Revision:
- 0:b0f04c137829
fix probe commit control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:b0f04c137829 | 1 | #ifndef UVC_H |
va009039 | 0:b0f04c137829 | 2 | #define UVC_H |
va009039 | 0:b0f04c137829 | 3 | #include "UsbBaseClass.h" |
va009039 | 0:b0f04c137829 | 4 | #include "usb_mem.h" |
va009039 | 0:b0f04c137829 | 5 | #include "usb_mjpeg.h" |
va009039 | 0:b0f04c137829 | 6 | |
va009039 | 0:b0f04c137829 | 7 | #define CLASS_VIDEO 0x0E |
va009039 | 0:b0f04c137829 | 8 | |
va009039 | 0:b0f04c137829 | 9 | #define SET_CUR 0x01 |
va009039 | 0:b0f04c137829 | 10 | #define GET_CUR 0x81 |
va009039 | 0:b0f04c137829 | 11 | #define GET_MIN 0x82 |
va009039 | 0:b0f04c137829 | 12 | #define GET_MAX 0x83 |
va009039 | 0:b0f04c137829 | 13 | #define GET_RES 0x84 |
va009039 | 0:b0f04c137829 | 14 | #define GET_LEN 0x85 |
va009039 | 0:b0f04c137829 | 15 | #define GET_INFO 0x86 |
va009039 | 0:b0f04c137829 | 16 | #define GET_DEF 0x87 |
va009039 | 0:b0f04c137829 | 17 | |
va009039 | 0:b0f04c137829 | 18 | #define VS_PROBE_CONTROL 0x01 |
va009039 | 0:b0f04c137829 | 19 | #define VS_COMMIT_CONTROL 0x02 |
va009039 | 0:b0f04c137829 | 20 | |
va009039 | 0:b0f04c137829 | 21 | #define PAYLOAD_UNDEF 0 |
va009039 | 0:b0f04c137829 | 22 | #define PAYLOAD_MJPEG 1 |
va009039 | 0:b0f04c137829 | 23 | #define PAYLOAD_YUY2 2 |
va009039 | 0:b0f04c137829 | 24 | |
va009039 | 0:b0f04c137829 | 25 | class uvc : public UsbBaseClass { |
va009039 | 0:b0f04c137829 | 26 | public: |
va009039 | 0:b0f04c137829 | 27 | uvc(int cam = 0); |
va009039 | 0:b0f04c137829 | 28 | ~uvc(); |
va009039 | 0:b0f04c137829 | 29 | int setup(); |
va009039 | 0:b0f04c137829 | 30 | int get_jpeg(const char* path); |
va009039 | 0:b0f04c137829 | 31 | int get_jpeg(uint8_t* buf, int size); |
va009039 | 0:b0f04c137829 | 32 | bool interrupt(); |
va009039 | 0:b0f04c137829 | 33 | int isochronous(); |
va009039 | 0:b0f04c137829 | 34 | void attach(usb_stream* stream); |
va009039 | 0:b0f04c137829 | 35 | void detach(); |
va009039 | 0:b0f04c137829 | 36 | ///set format index |
va009039 | 0:b0f04c137829 | 37 | void SetFormatIndex(int index = 1); |
va009039 | 0:b0f04c137829 | 38 | ///set frame index |
va009039 | 0:b0f04c137829 | 39 | void SetFrameIndex(int index = 1); |
va009039 | 0:b0f04c137829 | 40 | ///set frame interval |
va009039 | 0:b0f04c137829 | 41 | void SetFrameInterval(int val = 2000000); |
va009039 | 0:b0f04c137829 | 42 | ///set packet size |
va009039 | 0:b0f04c137829 | 43 | void SetPacketSize(int size = 128); |
va009039 | 0:b0f04c137829 | 44 | ///set image size |
va009039 | 0:b0f04c137829 | 45 | void SetImageSize(int width = 160, int height = 120); |
va009039 | 0:b0f04c137829 | 46 | ///set payload MJPEG or YUY2 |
va009039 | 0:b0f04c137829 | 47 | void SetPayload(int payload); // MJPEG,YUV422(YUY2) |
va009039 | 0:b0f04c137829 | 48 | UsbErr Control(int req, int cs, int index, uint8_t* buf, int size); |
va009039 | 0:b0f04c137829 | 49 | ///Setups the result callback |
va009039 | 0:b0f04c137829 | 50 | /** |
va009039 | 0:b0f04c137829 | 51 | @param pMethod : callback function |
va009039 | 0:b0f04c137829 | 52 | */ |
va009039 | 0:b0f04c137829 | 53 | void setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) ); |
va009039 | 0:b0f04c137829 | 54 | |
va009039 | 0:b0f04c137829 | 55 | ///Setups the result callback |
va009039 | 0:b0f04c137829 | 56 | /** |
va009039 | 0:b0f04c137829 | 57 | @param pItem : instance of class on which to execute the callback method |
va009039 | 0:b0f04c137829 | 58 | @param pMethod : callback method |
va009039 | 0:b0f04c137829 | 59 | */ |
va009039 | 0:b0f04c137829 | 60 | class CDummy; |
va009039 | 0:b0f04c137829 | 61 | template<class T> |
va009039 | 0:b0f04c137829 | 62 | void setOnResult( T* pItem, void (T::*pMethod)(uint16_t, uint8_t*, int) ) |
va009039 | 0:b0f04c137829 | 63 | { |
va009039 | 0:b0f04c137829 | 64 | m_pCb = NULL; |
va009039 | 0:b0f04c137829 | 65 | m_pCbItem = (CDummy*) pItem; |
va009039 | 0:b0f04c137829 | 66 | m_pCbMeth = (void (CDummy::*)(uint16_t, uint8_t*, int)) pMethod; |
va009039 | 0:b0f04c137829 | 67 | } |
va009039 | 0:b0f04c137829 | 68 | void clearOnResult(); |
va009039 | 0:b0f04c137829 | 69 | |
va009039 | 0:b0f04c137829 | 70 | void poll(); |
va009039 | 0:b0f04c137829 | 71 | void wait(float s); |
va009039 | 0:b0f04c137829 | 72 | void wait_ms(int ms); |
va009039 | 0:b0f04c137829 | 73 | uint16_t ReportConditionCode[16]; |
va009039 | 0:b0f04c137829 | 74 | protected: |
va009039 | 0:b0f04c137829 | 75 | int _init(); |
va009039 | 0:b0f04c137829 | 76 | void _config(struct stcamcfg* cfg); |
va009039 | 0:b0f04c137829 | 77 | void probe_commit_control(struct stcamcfg* cfg); |
va009039 | 0:b0f04c137829 | 78 | void onResult(uint16_t frame, uint8_t* buf, int len); |
va009039 | 0:b0f04c137829 | 79 | bool m_connect; |
va009039 | 0:b0f04c137829 | 80 | bool m_init; |
va009039 | 0:b0f04c137829 | 81 | int m_cam; |
va009039 | 0:b0f04c137829 | 82 | UsbDevice* m_pDev; |
va009039 | 0:b0f04c137829 | 83 | UsbEndpoint* m_pEpIntIn; |
va009039 | 0:b0f04c137829 | 84 | UsbEndpoint* m_pEpIsoIn; |
va009039 | 0:b0f04c137829 | 85 | int m_width; |
va009039 | 0:b0f04c137829 | 86 | int m_height; |
va009039 | 0:b0f04c137829 | 87 | int m_payload; |
va009039 | 0:b0f04c137829 | 88 | int m_FormatIndex; |
va009039 | 0:b0f04c137829 | 89 | int m_FrameIndex; |
va009039 | 0:b0f04c137829 | 90 | int m_FrameInterval; |
va009039 | 0:b0f04c137829 | 91 | int m_PacketSize; |
va009039 | 0:b0f04c137829 | 92 | int m_FrameCount; // 1-8 |
va009039 | 0:b0f04c137829 | 93 | int m_itdCount; |
va009039 | 0:b0f04c137829 | 94 | uint8_t m_int_buf[16]; |
va009039 | 0:b0f04c137829 | 95 | int m_int_seq; |
va009039 | 0:b0f04c137829 | 96 | int m_iso_seq; |
va009039 | 0:b0f04c137829 | 97 | uint16_t m_iso_frame; |
va009039 | 0:b0f04c137829 | 98 | usb_stream* m_stream; |
va009039 | 0:b0f04c137829 | 99 | CDummy* m_pCbItem; |
va009039 | 0:b0f04c137829 | 100 | void (CDummy::*m_pCbMeth)(uint16_t, uint8_t*, int); |
va009039 | 0:b0f04c137829 | 101 | void (*m_pCb)(uint16_t, uint8_t*, int); |
va009039 | 0:b0f04c137829 | 102 | }; |
va009039 | 0:b0f04c137829 | 103 | #endif //UVC_H |