Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
omergul committed Feb 10, 2015
0 parents commit db55e68
Show file tree
Hide file tree
Showing 41 changed files with 2,487 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
# Pods - for those of you who use CocoaPods
Pods
23 changes: 23 additions & 0 deletions Discovery.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Pod::Spec.new do |s|
s.name = "Discovery"
s.version = "1.0.0"
s.summary = "Discovery: A simple library to discover and retrieve data from nearby devices."
s.description = <<-DESC
Discovery is a very simple but useful library for discovering nearby devices with BLE and to exchange a value (kind of ID or username determined by you on the running app on peer device) wheather the app on peer device is working at foregorund or background state.
Discovery:
* lets you easily discover nearby devices
* retrieve their id(assigned by you) wheather the app works on foreground or background state
* hides the nitty gritty details of BLE calls and delegates from the developer
* determines the proximity of the peer device
DESC

s.homepage = "https://github.com/omergul123/Discovery”
s.license = { :type => 'APACHE', :file => 'LICENSE' }
s.author = { "Ömer Faruk Gül" => "omer.gul@louvredigital.com" }
s.platform = :ios,'7.0'
s.source = { :git => "https://github.com/omergul123/Discovery.git", :tag => "v1.0.0" }
s.source_files = 'Discovery/*.{h,m}'
s.requires_arc = true
s.framework = 'CoreBluetooth', 'CoreLocation'
end
22 changes: 22 additions & 0 deletions Discovery/BLEUser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// BLEUser.h
// Discover
//
// Created by Ömer Faruk Gül on 1/23/14.
// Copyright (c) 2014 Louvre Digital. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreLocation/CoreLocation.h>
#import "EasedValue.h"

@interface BLEUser : NSObject
@property (strong, nonatomic) NSString *peripheralId;
@property (strong, nonatomic) NSString *name;
@property (nonatomic) float rssi;
@property (nonatomic) NSInteger proximity;
@property (strong, nonatomic) EasedValue *easedProximity;
@property (nonatomic) double updateTime;
@property (strong, nonatomic) CBPeripheral *peripheral;
@end
37 changes: 37 additions & 0 deletions Discovery/BLEUser.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// BLEUser.m
// Discover
//
// Created by Ömer Faruk Gül on 1/23/14.
// Copyright (c) 2014 Louvre Digital. All rights reserved.
//

#import "BLEUser.h"


@implementation BLEUser

- (id)init {
self = [super init];
if(self) {
self.easedProximity = [[EasedValue alloc] init];
}

return self;
}

- (void)setRssi:(float)rssi {
_rssi = rssi;
_proximity = [self convertRSSItoProximity:rssi];
}

- (NSInteger)convertRSSItoProximity:(NSInteger)rssi {
// eased value doesn't support negative values
self.easedProximity.value = fabsf(rssi);
[self.easedProximity update];
NSInteger proximity = self.easedProximity.value * -1.0f;

return proximity;
}

@end
18 changes: 18 additions & 0 deletions Discovery/Discovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Discovery.h
// DiscoveryExample
//
// Created by Ömer Faruk Gül on 08/02/15.
// Copyright (c) 2015 Ömer Faruk Gül. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreLocation/CoreLocation.h>

@interface Discovery : NSObject

@property (strong, nonatomic, readonly) CBUUID *uuid;

-(instancetype)initWithUUID:(CBUUID*)uuid;
@end
20 changes: 20 additions & 0 deletions Discovery/Discovery.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Discovery.m
// DiscoveryExample
//
// Created by Ömer Faruk Gül on 08/02/15.
// Copyright (c) 2015 Ömer Faruk Gül. All rights reserved.
//

#import "Discovery.h"

@implementation Discovery
-(instancetype)initWithUUID:(CBUUID *)uuid {
self = [super init];
if(self) {
_uuid = uuid;
}

return self;
}
@end
37 changes: 37 additions & 0 deletions Discovery/EasedValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// EasedValue.h
//
//
// Created by Ben Purdy on 1/31/13.
// Copyright (c) 2013 Instrument. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

/**
Allows easing from start to end values.
The more times you call update the closer the output value will become to the input value.
Tutorial:
1) set the `value` property to desired value.
2) call `update` method repeatedly
3) read `value` property back to get the eased value
*/

@interface EasedValue : NSObject

@property (nonatomic, assign) CGFloat value;

/**
Causes the output of `value` to ease towards it's original input
*/
- (void)update;

/**
Causes the output of `value` to be equal to it's original input
*/
- (void)reset;
@end
63 changes: 63 additions & 0 deletions Discovery/EasedValue.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// EasedValue.m
//
//
// Created by Ben Purdy on 1/31/13.
// Copyright (c) 2013 Instrument. All rights reserved.
//

#import "EasedValue.h"

@implementation EasedValue
{
CGFloat velocity;
CGFloat targetValue;
CGFloat currentValue;
}

- (id)init
{
self = [super init];

velocity = 0.0f;
targetValue = 0.0f;
currentValue = 0.0f;

return self;
}

- (void)setValue:(CGFloat)value
{
targetValue = value;
}

- (CGFloat)value
{
return currentValue;
}

- (void)update
{
// determine speed at which the ease will happen
// this is based on difference between target and current value
velocity += (targetValue - currentValue) * 0.01f;
velocity *= 0.7f;

// ease the current value
currentValue += velocity;

// limit how small the ease can get
if(fabsf(targetValue - currentValue) < 0.001f){
currentValue = targetValue;
velocity = 0.0f;
}

// keep above zero
currentValue = MAX(0.0f, currentValue);
}

- (void)reset
{
currentValue = targetValue;
}
@end
Loading

0 comments on commit db55e68

Please sign in to comment.