Fixed version check for AOA 2.0
Fork of AndroidAccessory by
AndroidAccessory.h@0:1151e4446dbc, 2011-08-01 (annotated)
- Committer:
- p07gbar
- Date:
- Mon Aug 01 09:51:55 2011 +0000
- Revision:
- 0:1151e4446dbc
- Child:
- 1:0d5fc52b4dcd
First publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p07gbar | 0:1151e4446dbc | 1 | |
p07gbar | 0:1151e4446dbc | 2 | #ifndef ADK_H_INCLUDED |
p07gbar | 0:1151e4446dbc | 3 | #define ADK_H_INCLUDED |
p07gbar | 0:1151e4446dbc | 4 | |
p07gbar | 0:1151e4446dbc | 5 | #include "mbed.h" |
p07gbar | 0:1151e4446dbc | 6 | #include "USBHost.h" |
p07gbar | 0:1151e4446dbc | 7 | |
p07gbar | 0:1151e4446dbc | 8 | |
p07gbar | 0:1151e4446dbc | 9 | //#define ADKLOG 1 |
p07gbar | 0:1151e4446dbc | 10 | #if ADKLOG |
p07gbar | 0:1151e4446dbc | 11 | #define LOG(...) printf(__VA_ARGS__) |
p07gbar | 0:1151e4446dbc | 12 | #define Log(...) printf(__VA_ARGS__) |
p07gbar | 0:1151e4446dbc | 13 | #define log(...) printf(__VA_ARGS__) |
p07gbar | 0:1151e4446dbc | 14 | |
p07gbar | 0:1151e4446dbc | 15 | #else |
p07gbar | 0:1151e4446dbc | 16 | #define LOG(...) do {} while(0) |
p07gbar | 0:1151e4446dbc | 17 | #define Log(...) do {} while(0) |
p07gbar | 0:1151e4446dbc | 18 | #define log(...) do {} while(0) |
p07gbar | 0:1151e4446dbc | 19 | |
p07gbar | 0:1151e4446dbc | 20 | #endif |
p07gbar | 0:1151e4446dbc | 21 | |
p07gbar | 0:1151e4446dbc | 22 | #define ACCESSORY_STRING_MANUFACTURER 0 |
p07gbar | 0:1151e4446dbc | 23 | #define ACCESSORY_STRING_MODEL 1 |
p07gbar | 0:1151e4446dbc | 24 | #define ACCESSORY_STRING_DESCRIPTION 2 |
p07gbar | 0:1151e4446dbc | 25 | #define ACCESSORY_STRING_VERSION 3 |
p07gbar | 0:1151e4446dbc | 26 | #define ACCESSORY_STRING_URI 4 |
p07gbar | 0:1151e4446dbc | 27 | #define ACCESSORY_STRING_SERIAL 5 |
p07gbar | 0:1151e4446dbc | 28 | |
p07gbar | 0:1151e4446dbc | 29 | #define ACCESSORY_GET_PROTOCOL 51 |
p07gbar | 0:1151e4446dbc | 30 | #define ACCESSORY_SEND_STRING 52 |
p07gbar | 0:1151e4446dbc | 31 | #define ACCESSORY_START 53 |
p07gbar | 0:1151e4446dbc | 32 | |
p07gbar | 0:1151e4446dbc | 33 | |
p07gbar | 0:1151e4446dbc | 34 | bool switchDevice(int device); |
p07gbar | 0:1151e4446dbc | 35 | |
p07gbar | 0:1151e4446dbc | 36 | class AndroidAccessory { |
p07gbar | 0:1151e4446dbc | 37 | public: |
p07gbar | 0:1151e4446dbc | 38 | |
p07gbar | 0:1151e4446dbc | 39 | AndroidAccessory(int rbuffsize,int wbuffsize, |
p07gbar | 0:1151e4446dbc | 40 | const char* manufacturer, |
p07gbar | 0:1151e4446dbc | 41 | const char *model, |
p07gbar | 0:1151e4446dbc | 42 | const char *description, |
p07gbar | 0:1151e4446dbc | 43 | const char *version, |
p07gbar | 0:1151e4446dbc | 44 | const char *uri, |
p07gbar | 0:1151e4446dbc | 45 | const char *serial |
p07gbar | 0:1151e4446dbc | 46 | ); |
p07gbar | 0:1151e4446dbc | 47 | virtual void init(int device, int configuration, int interfaceNumber); |
p07gbar | 0:1151e4446dbc | 48 | |
p07gbar | 0:1151e4446dbc | 49 | virtual void resetDevice()=0; |
p07gbar | 0:1151e4446dbc | 50 | virtual void setupDevice()=0; |
p07gbar | 0:1151e4446dbc | 51 | virtual int callbackRead(u8 *buff, int len)=0; |
p07gbar | 0:1151e4446dbc | 52 | virtual int callbackWrite()=0; |
p07gbar | 0:1151e4446dbc | 53 | int write(u8 *buff, int len); |
p07gbar | 0:1151e4446dbc | 54 | int write() { |
p07gbar | 0:1151e4446dbc | 55 | return write(_writebuff,_writebuffsize); |
p07gbar | 0:1151e4446dbc | 56 | } |
p07gbar | 0:1151e4446dbc | 57 | int writeNC(u8 *buff, int len); |
p07gbar | 0:1151e4446dbc | 58 | int writeNC() { |
p07gbar | 0:1151e4446dbc | 59 | return writeNC(_writebuff,_writebuffsize); |
p07gbar | 0:1151e4446dbc | 60 | } |
p07gbar | 0:1151e4446dbc | 61 | |
p07gbar | 0:1151e4446dbc | 62 | int read(u8 *buff, int len); |
p07gbar | 0:1151e4446dbc | 63 | |
p07gbar | 0:1151e4446dbc | 64 | |
p07gbar | 0:1151e4446dbc | 65 | void adkEnd() { |
p07gbar | 0:1151e4446dbc | 66 | // _initok=false; |
p07gbar | 0:1151e4446dbc | 67 | resetDevice(); |
p07gbar | 0:1151e4446dbc | 68 | }; //if connection close |
p07gbar | 0:1151e4446dbc | 69 | bool switchDevice(int device); |
p07gbar | 0:1151e4446dbc | 70 | |
p07gbar | 0:1151e4446dbc | 71 | //buffer |
p07gbar | 0:1151e4446dbc | 72 | u8* _readbuff; |
p07gbar | 0:1151e4446dbc | 73 | int _readbuffsize; |
p07gbar | 0:1151e4446dbc | 74 | u8* _writebuff; |
p07gbar | 0:1151e4446dbc | 75 | int _writebuffsize; |
p07gbar | 0:1151e4446dbc | 76 | u8* _strbuff;//255bytes; |
p07gbar | 0:1151e4446dbc | 77 | void sendString(const char *str); |
p07gbar | 0:1151e4446dbc | 78 | |
p07gbar | 0:1151e4446dbc | 79 | private: |
p07gbar | 0:1151e4446dbc | 80 | |
p07gbar | 0:1151e4446dbc | 81 | void sendString(int device, int index, const char *str); |
p07gbar | 0:1151e4446dbc | 82 | int getProtocol(int device); |
p07gbar | 0:1151e4446dbc | 83 | |
p07gbar | 0:1151e4446dbc | 84 | const char *manufacturer; |
p07gbar | 0:1151e4446dbc | 85 | const char *model; |
p07gbar | 0:1151e4446dbc | 86 | const char *description; |
p07gbar | 0:1151e4446dbc | 87 | const char *version; |
p07gbar | 0:1151e4446dbc | 88 | const char *uri; |
p07gbar | 0:1151e4446dbc | 89 | const char *serial; |
p07gbar | 0:1151e4446dbc | 90 | |
p07gbar | 0:1151e4446dbc | 91 | //endpoints |
p07gbar | 0:1151e4446dbc | 92 | int input_ep; |
p07gbar | 0:1151e4446dbc | 93 | int output_ep; |
p07gbar | 0:1151e4446dbc | 94 | |
p07gbar | 0:1151e4446dbc | 95 | int _device; |
p07gbar | 0:1151e4446dbc | 96 | int _configuration; |
p07gbar | 0:1151e4446dbc | 97 | int _interfaceNumber; |
p07gbar | 0:1151e4446dbc | 98 | |
p07gbar | 0:1151e4446dbc | 99 | //bool _initok; |
p07gbar | 0:1151e4446dbc | 100 | |
p07gbar | 0:1151e4446dbc | 101 | }; |
p07gbar | 0:1151e4446dbc | 102 | |
p07gbar | 0:1151e4446dbc | 103 | extern AndroidAccessory* _adk; |
p07gbar | 0:1151e4446dbc | 104 | |
p07gbar | 0:1151e4446dbc | 105 | |
p07gbar | 0:1151e4446dbc | 106 | #endif |