Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z revert by Axeda Corp

Committer:
AxedaCorp
Date:
Wed Jul 02 15:59:38 2014 +0000
Revision:
1:5ad12c581db4
Parent:
0:65004368569c
url ip switch
;

Who changed what in which revision?

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