Rich Bayliss / AndroidAccessory
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AndroidAccessory.h Source File

AndroidAccessory.h

00001 #ifndef ADK_H_INCLUDED
00002 #define ADK_H_INCLUDED
00003 
00004 #include "mbed.h"
00005 #include "USBHost.h"
00006 
00007 
00008 #define  ADKLOG 1
00009 #if ADKLOG
00010 #define  LOG(...)       printf(__VA_ARGS__)
00011 #define  Log(...)       printf(__VA_ARGS__)
00012 #define  log(...)       printf(__VA_ARGS__)
00013 
00014 #else
00015 #define  LOG(...)       do {} while(0)
00016 #define  Log(...)       do {} while(0)
00017 #define  log(...)       do {} while(0)
00018 
00019 #endif
00020 
00021 #define ACCESSORY_STRING_MANUFACTURER   0
00022 #define ACCESSORY_STRING_MODEL          1
00023 #define ACCESSORY_STRING_DESCRIPTION    2
00024 #define ACCESSORY_STRING_VERSION        3
00025 #define ACCESSORY_STRING_URI            4
00026 #define ACCESSORY_STRING_SERIAL         5
00027 
00028 #define ACCESSORY_GET_PROTOCOL          51
00029 #define ACCESSORY_SEND_STRING           52
00030 #define ACCESSORY_START                 53
00031 
00032 
00033 bool switchDevice(int device);
00034 
00035 /** Library to allow your mbed device to communicate with the Android ADK.
00036   *  
00037   * Information about the ADK here: http://accessories.android.com/
00038   * 
00039   * Example:
00040   * @code
00041   * class DemoKit : public AndroidAccessory
00042   * {
00043   *   public:
00044   *     DemoKit() : AndroidAccessory    ( 3,
00045   *                                       3,
00046   *                                      "Google, Inc.",
00047   *                                      "DemoKit",
00048   *                                      "DemoKit Arduino Board",
00049   *                                      "1.0",
00050   *                                      "http://www.android.com",
00051   *                                      "0000000012345678") {};
00052   *     virtual int  callbackRead(u8 *buff, int len);
00053   *     virtual void setupDevice();
00054   *     virtual void resetDevice();
00055   * }
00056   * @endcode
00057   */
00058 class AndroidAccessory {
00059 public:
00060 
00061     AndroidAccessory(int rbuffsize,int wbuffsize,
00062                      const char* manufacturer,
00063                      const char *model,
00064                      const char *description,
00065                      const char *version,
00066                      const char *uri,
00067                      const char *serial
00068                     );
00069     virtual void init(int device, int configuration, int interfaceNumber); 
00070 
00071     virtual void resetDevice()=0;
00072     virtual void setupDevice()=0;
00073     virtual int callbackRead(u8 *buff, int len)=0;
00074     int write(u8 *buff, int len);
00075     int write() {
00076         return write(_writebuff,_writebuffsize);
00077     }
00078     
00079     void Sleep() {
00080         USBLoop();
00081     }
00082 
00083     void adkEnd() {
00084        // _initok=false;
00085         resetDevice();
00086     }; //if connection close
00087     bool switchDevice(int device);
00088 
00089     //buffer
00090     u8* _readbuff;
00091     int _readbuffsize;
00092     u8* _writebuff;
00093     int _writebuffsize;
00094     u8* _strbuff;//255bytes;
00095 
00096 private:
00097 
00098     void sendString(int device, int index, const char *str);
00099     int getProtocol(int device);
00100 
00101     const char *manufacturer;
00102     const char *model;
00103     const char *description;
00104     const char *version;
00105     const char *uri;
00106     const char *serial;
00107 
00108     //endpoints
00109     int input_ep;
00110     int output_ep;
00111 
00112     int _device;
00113     int _configuration;
00114     int _interfaceNumber;
00115 
00116     //bool _initok;
00117 
00118 };
00119 
00120 extern AndroidAccessory* _adk;
00121 
00122 
00123 #endif