Skip to content

Commit

Permalink
Initial pass at documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kroo committed Jun 15, 2014
1 parent 072bf1f commit dd09f5a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 17 deletions.
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control?
#
# Pods/

Blueforce.xcodeproj/xcuserdata
8 changes: 5 additions & 3 deletions Blueforce/BlueforceConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

-(BlueforceConnection *)initWithPeripheral:(CBPeripheral *)peripheral;

-(void) connected;


-(BOOL) canLockUnlock;
-(void) lock;
-(void) unlock;


// called by BlueforceConnectionManager to notify the connection that it is now active.
-(void) blueforceConnectionManagerConnected;

@end
4 changes: 3 additions & 1 deletion Blueforce/BlueforceConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ -(BlueforceConnection *)initWithPeripheral:(CBPeripheral *)peripheral {
return self;
}

-(void)connected {
-(void) blueforceConnectionManagerConnected {
// scan for all available services on the peripheral
[self.peripheral discoverServices:nil];
}

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
// only one service is likely published on the peripheral
[peripheral discoverCharacteristics:nil forService: [peripheral.services objectAtIndex:0]];
}

Expand Down
1 change: 0 additions & 1 deletion Blueforce/BlueforceConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@interface BlueforceConnectionManager : NSObject <CBCentralManagerDelegate>

@property CBCentralManager *cm;
@property BOOL acceptNewFobs;
@property id<BlueforceConnectionManagerDelegate> delegate;

+(BlueforceConnectionManager *)sharedConnectionManager;
Expand Down
10 changes: 7 additions & 3 deletions Blueforce/BlueforceConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ -(void)startScan {
}

-(void)centralManagerDidUpdateState:(CBCentralManager *)central {
if (!self.delegate) {
return;
}

if ([central state] == CBCentralManagerStatePoweredOn) {
[self.delegate isBluetoothEnabled:YES];
} else {
[self.delegate isBluetoothEnabled:NO];
}
}

- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSArray *serviceData = [advertisementData objectForKey:@"kCBAdvDataServiceUUIDs"];
if (!serviceData || (![serviceData containsObject: [CBUUID UUIDWithString: kBlueforceUUID]])) {
Expand All @@ -57,9 +61,9 @@ - (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPer
}
}

- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
BlueforceConnection *connection = [BlueforceConnection connectionWithId:peripheral.name];
[connection connected];
[connection blueforceConnectionManagerConnected];
if (self.delegate) {
[self.delegate didDiscoverConnection:connection];
}
Expand Down
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,103 @@
Blueforce
=========

Getaround Mobile API for blueforce
Getting Started
---------------

To add the Getaround Blueforce library to your iOS project, drag the repo into your projects, and add the two headers `BlueforceConnectionManager.h` and `BlueforceConnection.h` to your project's include path. The simplest way to do this is just to drag these to files into your project, and uncheck 'copy items into destination group's folder'.

![](http://cl.ly/image/3F3g1M3f1v06/Screen%20Shot%202014-06-14%20at%207.20.36%20PM.png)

Usage
-----

Create a class that implements the `BlueforceConnectionManagerDelegate` protocol, then construct a `BlueforceConnectionManager`. You will receive an initial callback when bluetooth is enabled, then additional callbacks as Getaround Connect devices are discovered.

```objective-c
@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Initializes a connection manager instance for this view controller
self.cm = [[BlueforceConnectionManager alloc] initWithDelegate:self];
}

#pragma mark - BlueforceConnectionManagerDelegate callbacks
// Called once after instantiation of the Connection Manager
- (void) isBluetoothEnabled:(bool)enabled {
self.label.text = enabled ? @"Scanning" : @"Bluetooth Off";

if (enabled) {
[self.cm startScan];
}
}

// Called each time a new BlueforceConnection is discovered
- (void) didDiscoverConnection:(BlueforceConnection *)connection {
self.label.text = @"Connected";
self.conn = connection;
[self.lock setHidden:NO];
[self.unlock setHidden:NO];
}

#pragma mark - Getaround Connnect IBActions
- (IBAction) lock:(id)sender {
if (self.conn && [self.conn canLockUnlock]) {
[self.conn lock];
}
}

- (IBAction) unlock:(id)sender {
if (self.conn && [self.conn canLockUnlock]) {
[self.conn unlock];
}
}

@end
```
### BlueforceConnectionManagerDelegate Protocol
#### - (void) isBluetoothEnabled:(bool) enabled
A callback you will receive as soon as a `BlueforceConnectionManager` is constructed. Note that Blueforce requires bluetooth LE, which is available only on iPhone 4s's and newer devices.
#### - (void) didDiscoverConnection:(BlueforceConnection*) connection
A callback you will receive each time a Getaround Connect is discovered in range. Note you will not receive these callbacks until `startScan` is called.
### BlueforceConnectionManager API
#### -(BlueforceConnectionManager *)initWithDelegate:(id<BlueforceConnectionManagerDelegate>)delegate
Construct a new `BlueforceConnectionManager` with a specified delegate. `delegate` can be nil, though no updates will be sent until a delegate is attached.
```
self.cm = [[BlueforceDelegateManager alloc] initWithDelegate: self];
```
#### -(void)startScan
Begins scanning for new `BlueforceConnection`s. This should be called only after a delegate object is attached to the connection manager.
```
[self.cm startScan];
```
### BlueforceConnection API
#### -(BOOL) canLockUnlock
Provides a convenient way to check wether this blueforce connection is active and ready to send commands.
#### -(void) lock
Sends a lock command to the device.
#### -(void) unlock
Sends an unlock command to the device.

0 comments on commit dd09f5a

Please sign in to comment.