1 / 16

Intro to the External Accessory Framework

Intro to the External Accessory Framework. Andrew Craze @ AndrewCr acraze at dxysolutions.com. Agenda. What is the EA Framework useful for? What hardware can I talk to? How do I use the EA Framework? Why/how do I get more info from Apple under the MFi NDA?.

platt
Download Presentation

Intro to the External Accessory Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to the External Accessory Framework Andrew Craze @AndrewCr acraze at dxysolutions.com

  2. Agenda What is the EA Framework useful for? What hardware can I talk to? How do I use the EA Framework? Why/how do I get more info from Apple under the MFi NDA?

  3. What can I do with EAAccessory? Application [not accessory] -side code Enumerate connected accessories Open a serial session with an accessory Communicate via streams and get notifications

  4. What can’t I do with EAAccessory? Pair or make the connection with a BlueTooth device Use (any) BlueTooth profiles

  5. Hardware Options • Consumer-ready (pre-built cables) • Like RedPark’s • Build-your-own, with 3rd-party firmware • Like BlueGiga’s • Build-your-own, with DIY firmware • Join the MFi program for Docs

  6. Easier Hardware(Examples, probably not the only options) RedPack’s Serial Cable BlueGiga’siWrap Firmware

  7. Application Checklist • Link with ExternalAccessory.framework • Add protocol(s) to info.plist • Use EAAccessoryManager to find your device • Add a delegate (EAAccessoryDelegate) to your accessory’s object • Connect with your chosen protocol • Manage the I/O stream data

  8. Link with ExternalAccessory.framework

  9. Add protocol(s) to info.plist

  10. Use EAAccessoryManager to find your device [[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(_accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil]; [[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(_accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil]; [[EAAccessoryManagersharedAccessoryManager] registerForLocalNotifications]; _accessoryList = [[NSMutableArrayalloc] initWithArray:[[EAAccessoryManagersharedAccessoryManager] connectedAccessories]];

  11. Add delegate to your accessory’s object, connect to streams [_accessorysetDelegate:self]; _session = [[EASessionalloc] initWithAccessory:_accessoryforProtocol:_protocolString]; if (_session) { [[_sessioninputStream] setDelegate:self]; [[_sessioninputStream] scheduleInRunLoop:[NSRunLoopcurrentRunLoop] forMode:NSDefaultRunLoopMode]; [[_sessioninputStream] open]; [[_sessionoutputStream] setDelegate:self]; [[_sessionoutputStream] scheduleInRunLoop:[NSRunLoopcurrentRunLoop] forMode:NSDefaultRunLoopMode]; [[_sessionoutputStream] open]; } else { NSLog(@"creating session failed"); }

  12. Manage the I/O stream data, part 1 - (void)stream:(NSStream *)aStreamhandleEvent:(NSStreamEvent)eventCode { switch (eventCode) { caseNSStreamEventNone: break; caseNSStreamEventOpenCompleted: break; caseNSStreamEventHasBytesAvailable: [self_readData]; break; caseNSStreamEventHasSpaceAvailable: [self_writeData]; break; caseNSStreamEventErrorOccurred: break; caseNSStreamEventEndEncountered: break; default: break; } }

  13. Manage the I/O stream data, part 2 - (void)_readData { #define EAD_INPUT_BUFFER_SIZE 128 uint8_tbuf[EAD_INPUT_BUFFER_SIZE]; while ([[_sessioninputStream] hasBytesAvailable]) { NSIntegerbytesRead = [[_sessioninputStream] read:buf maxLength:EAD_INPUT_BUFFER_SIZE]; if (_readData == nil) { _readData = [[NSMutableDataalloc] init]; } [_readDataappendBytes:(void *)buflength:bytesRead]; //NSLog(@"read %d bytes from input stream", bytesRead); } [[NSNotificationCenterdefaultCenter] postNotificationName:EADSessionDataReceivedNotification object:self userInfo:nil]; } - (NSData *)readData:(NSUInteger)bytesToRead { NSData *data = nil; if ([_readDatalength] >= bytesToRead) { NSRange range = NSMakeRange(0, bytesToRead); data = [_readDatasubdataWithRange:range]; [_readDatareplaceBytesInRange:rangewithBytes:NULLlength:0]; } return data; }

  14. The MFi Program Separate NDA, over-and-above the iOS developer program Free, but you must be a bona-fide company (and prove it!) Plan on a month to get fully-approved Docs on everything you need to know for accessory-side development

  15. Handy reference links (No endorsement expressed or implied. So there.) External Accessory Framework Reference (from Apple)http://developer.apple.com/library/ios/#documentation/ExternalAccessory/Reference/ExternalAccessoryFrameworkReference/_index.html#//apple_ref/doc/uid/TP40008235 Apple’s EADemo sample codehttp://developer.apple.com/library/ios/#samplecode/EADemo/Introduction/Intro.html Apple MFi pagehttps://developer.apple.com/programs/mfi/ Redpark Serial Cablehttp://redpark.com/c2db9.html BlueGiga’siWrap firmware (for their BlueTooth modules)http://www.bluegiga.com/iWRAP_module_firmware

  16. Questions, Maybe Answers Andrew Craze @AndrewCr http://blog.andrewcraze.com acrazeat dxysolutions.com

More Related