Skip to content

Commit

Permalink
Merge pull request #4 from SensingKit/next
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
minoskt committed Oct 11, 2015
2 parents 73f0b3d + 22233a2 commit a3f2742
Show file tree
Hide file tree
Showing 102 changed files with 4,465 additions and 1,012 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ profile
*.moved-aside
DerivedData
.idea/
Documentation
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

### 0.4.0 (October 11, 2015)
- Added Documentation using appledoc generator.
- Added support for iOS 9.
- Added support for iOS 9 App Slicing.
- Added support for Swift 2 language
- Updated SensingKit-iOS API.
- Added Configuration for all sensors.
- Added support for Microphone sensor.
- Added currentPace and currentCadence in PedometerData (iOS 9 only)
- SensorModules have been renamed into Sensors.
- Activity sensor has been renamed into MotionActivity.

### 0.3.0 (August 29, 2015)
- Added support for Pedometer sensor.
- Added support for Altimeter sensor.
Expand Down
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ An iOS library that provides Continuous Sensing functionality to your applicatio

## Supported Sensors

The following sensor modules are currently supported in SensingKit-Android, (listed in [SKSensorModuleType](SensingKit/SKSensorModuleType.h) enum):
The following mobile sensors are currently supported in SensingKit-iOS, (listed in [SKSensorType](SensingKit/SKSensorType.h) enum):

- Accelerometer
- Gyroscope
- Magnetometer
- Device Motion (senses Attitude, Gravity, User Acceleration, Magnetic Field, Rotation)
- Activity
- Motion Activity
- Pedometer
- Altimeter
- Battery
- Location
- iBeacon™ Proximity
- Eddystone™ Proximity
- Microphone


## Configuring the Library

You can always skip this step by downloading the released version of SensingKit-iOS from [here](https://github.com/SensingKit/SensingKit-iOS/releases).

In case you want to build the library yourself:

- Open SensingKit project in Xcode and build SensingKit library using Product -> Build.

- Choose the ‘Framework’ scheme from the top toolbar (or using Product -> Scheme -> Framework) and build the framework. SensingKit.framework file should be available in your desktop.

- Move the generated SensingKit.framework file into your new Xcode project.

## Using the Library

- First, you need to move the generated SensingKit.framework file into your new Xcode project.

## How to Use this Library
- Since SensingKit-iOS uses Categories internally, you need to add the ’-ObjC’ flag into your project build settings. Open your project, select your project from the Project Navigator on the left and click on the app’s target. Select the Build Settings tab on the top of the screen and search for “Other Linker Flags”. Finally, click the + button and add ‘-ObjC’ as a new property on the list.

- Import and init SensingKit into your Activity class as shown bellow:
- Import and init SensingKit as shown bellow:

```objectivec
#import <SensingKit/SensingKitLib.h>
Expand All @@ -46,18 +53,27 @@ The following sensor modules are currently supported in SensingKit-Android, (lis
```


- Register a sensor module (e.g. a Battery sensor) as shown bellow:
- Check if a sensor is available in the device:

```objectivec
if ([self.sensingKit isSensorAvailable:Battery]) {
// You can access the sensor
}
```
- Register a sensor (e.g. a Battery sensor) as shown bellow:
```objectivec
[self.sensingKit registerSensorModule:Battery];
[self.sensingKit registerSensor:Battery];
```


- Subscribe a sensor data listener. You can cast the data object into the actual sensor data object in order to access all the sensor data properties:
- Subscribe a sensor data handler. You can cast the data object into the actual sensor data object in order to access all the sensor data properties:

```objectivec
[self.sensingKit subscribeSensorDataListenerToSensor:Battery
withHandler:^(SKSensorModuleType moduleType, SKSensorData *sensorData) {
[self.sensingKit subscribeToSensor:Battery
withHandler:^(SKSensorType sensorType, SKSensorData *sensorData) {

SKBatteryData *batteryData = (SKBatteryData *)sensorData;
NSLog(@“Battery Level: %f”, batteryData.level);
Expand Down
313 changes: 255 additions & 58 deletions SensingKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions SensingKit/NSString+SensorType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// NSString+SKSensorType.h
// SensingKit
//
// Copyright (c) 2014. Queen Mary University of London
// Kleomenis Katevas, k.katevas@qmul.ac.uk
//
// This file is part of SensingKit-iOS library.
// For more information, please visit http://www.sensingkit.org
//
// SensingKit-iOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SensingKit-iOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SensingKit-iOS. If not, see <http://www.gnu.org/licenses/>.
//

#import <Foundation/Foundation.h>
#import "SKSensorType.h"

NS_ASSUME_NONNULL_BEGIN

/**
* NSString+SKSensorType is a category responsible for converting an SKSensorType enum into string.
*/
@interface NSString (SKSensorType)

/**
* Converts an SKSensorType enum into a string.
* This method is useful when you want to use the sensor name in the application's User Interface. The returned string might contain spaces or special characters (such as '™'). For example, iBeacon™ Proximity sensor (enum iBeaconProximity) will be returned as "iBeacon™ Proximity".
*
* @param sensorType The type of the sensor.
*
* @return A string with the sensor name. (e.g. "iBeacon™ Proximity").
*/
+ (NSString *)stringWithSensorType:(SKSensorType)sensorType;

/**
* Converts an SKSensorType enum into a non-spaced string that does not include special characters.
* This method is useful when you want to use the sensor name in file or directory names. The returned string does not contain spaces or any special character (such as '™'). For example, iBeacon™ Proximity sensor (enum iBeaconProximity) will be returned as "iBeaconProximity".
*
* @param sensorType The type of the sensor.
*
* @return A non-spaced string with the sensor name. (e.g. "iBeaconProximity").
*/
+ (NSString *)nonspacedStringWithSensorType:(SKSensorType)sensorType;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SKBeaconDeviceData.h
// NSString+SensorType.h
// SensingKit
//
// Copyright (c) 2014. Queen Mary University of London
Expand All @@ -22,27 +22,48 @@
// along with SensingKit-iOS. If not, see <http://www.gnu.org/licenses/>.
//

#import <Foundation/Foundation.h>
#import "SKSensorData.h"
@import CoreLocation;
#import "NSString+SensorType.h"

@interface SKBeaconDeviceData : SKSensorData
@implementation NSString (SensorType)

@property (nonatomic, readonly) NSUInteger major;
@property (nonatomic, readonly) NSUInteger minor;
@property (nonatomic, readonly) CLLocationAccuracy accuracy;
@property (nonatomic, readonly) CLProximity proximity;
@property (nonatomic, readonly) NSInteger rssi;
static const NSString *SENSOR_STRINGS[] = {
@"Accelerometer",
@"Gyroscope",
@"Magnetometer",
@"Device Motion",
@"Motion Activity",
@"Pedometer",
@"Altimeter",
@"Battery",
@"Location",
@"iBeacon™ Proximity",
@"Eddystone™ Proximity",
@"Microphone"
};

- (instancetype)initWithTimestamp:(NSDate *)timestamp
withMajor:(NSUInteger)major
withMinor:(NSUInteger)minor
withAccuracy:(CLLocationAccuracy)accuracy
withProximity:(CLProximity)proximity
withRssi:(NSInteger)rssi;
static const NSString *NONSPACED_SENSOR_STRINGS[] = {
@"Accelerometer",
@"Gyroscope",
@"Magnetometer",
@"DeviceMotion",
@"MotionActivity",
@"Pedometer",
@"Altimeter",
@"Battery",
@"Location",
@"iBeaconProximity",
@"EddystoneProximity",
@"Microphone"
};

+ (NSString *)csvHeader;
+ (NSString *)stringWithSensorType:(SKSensorType)sensorType
{
return SENSOR_STRINGS[sensorType].copy;
}

- (NSString *)proximityString;
+ (NSString *)nonspacedStringWithSensorType:(SKSensorType)sensorType
{
return NONSPACED_SENSOR_STRINGS[sensorType].copy;
}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SKAbstractSensorModule.h
// SKAbstractSensor.h
// SensingKit
//
// Copyright (c) 2014. Queen Mary University of London
Expand All @@ -23,19 +23,24 @@
//

#import <Foundation/Foundation.h>
#import "SKSensorModuleType.h"
#import "SKSensorDataListener.h"
#import "SKSensorType.h"
#import "SKSensorDataHandler.h"
#import "SKConfiguration.h"

@interface SKAbstractSensorModule : NSObject
NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, readonly) SKSensorModuleType moduleType;
@interface SKAbstractSensor : NSObject

@property (nonatomic, copy) SKConfiguration *configuration;

@property (nonatomic, readonly) SKSensorType sensorType;
@property (nonatomic, readonly, getter=isSensing) BOOL sensing;

- (void)subscribeSensorDataListener:(SKSensorDataHandler)handler;
- (void)subscribeHandler:(SKSensorDataHandler)handler;

- (void)unsubscribeSensorDataListener:(SKSensorDataHandler)handler;
- (void)unsubscribeHandler:(SKSensorDataHandler)handler;

- (void)unsubscribeAllSensorDataListeners;
- (void)unsubscribeAllHandlers;

- (void)startSensing;

Expand All @@ -44,3 +49,5 @@
- (void)submitSensorData:(SKSensorData *)data;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SKAbstractSensorModule.m
// SKAbstractSensor.m
// SensingKit
//
// Copyright (c) 2014. Queen Mary University of London
Expand All @@ -21,17 +21,19 @@
// You should have received a copy of the GNU Lesser General Public License
// along with SensingKit-iOS. If not, see <http://www.gnu.org/licenses/>.
//
#import "SKAbstractSensorModule.h"
#import "SKAbstractSensor.h"

@interface SKAbstractSensorModule()

@interface SKAbstractSensor()

@property (nonatomic, strong) NSMutableArray *sensorDataListeners;

@end

@implementation SKAbstractSensorModule

- (void)subscribeSensorDataListener:(SKSensorDataHandler)handler
@implementation SKAbstractSensor

- (void)subscribeHandler:(SKSensorDataHandler)handler
{
// Register the callback
if ([self.sensorDataListeners containsObject:handler]) {
Expand All @@ -41,7 +43,7 @@ - (void)subscribeSensorDataListener:(SKSensorDataHandler)handler
[self.sensorDataListeners addObject:handler];
}

- (void)unsubscribeSensorDataListener:(SKSensorDataHandler)handler
- (void)unsubscribeHandler:(SKSensorDataHandler)handler
{
// Unregister the callback
if (![self.sensorDataListeners containsObject:handler]) {
Expand All @@ -51,7 +53,7 @@ - (void)unsubscribeSensorDataListener:(SKSensorDataHandler)handler
[self.sensorDataListeners removeObject:handler];
}

- (void)unsubscribeAllSensorDataListeners
- (void)unsubscribeAllHandlers
{
[self.sensorDataListeners removeAllObjects];
}
Expand Down Expand Up @@ -84,11 +86,11 @@ - (void)submitSensorData:(SKSensorData *)data
{
if ([self shouldPostSensorData:data]) {

if ([self.sensorDataListeners count]) {
if (self.sensorDataListeners.count) {

// CallBack with data as parameter
for (SKSensorDataHandler handler in self.sensorDataListeners) {
handler(self.moduleType, data);
handler(self.sensorType, data);
}

}
Expand Down
15 changes: 12 additions & 3 deletions SensingKit/SKAccelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@
// along with SensingKit-iOS. If not, see <http://www.gnu.org/licenses/>.
//

#import "SKAbstractSensorModule.h"
#import "SKAbstractSensor.h"
#import "SKAccelerometerConfiguration.h"

@interface SKAccelerometer : SKAbstractSensorModule
NS_ASSUME_NONNULL_BEGIN

+ (BOOL)isSensorModuleAvailable;
@interface SKAccelerometer : SKAbstractSensor

+ (BOOL)isSensorAvailable;

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithConfiguration:(SKAccelerometerConfiguration *)configuration NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit a3f2742

Please sign in to comment.