├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── CHANGELOG.md ├── ESSEddystone ├── AUTHORS ├── CONTRIBUTORS ├── ESSBeaconScanner.h ├── ESSBeaconScanner.m ├── ESSEddystone.h ├── ESSEddystone.m ├── ESSTimer.h ├── ESSTimer.m └── LICENSE ├── LICENSE ├── README.md ├── SensingKit.podspec ├── SensingKit.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SensingKit ├── Info.plist ├── NSString+SensorType.h ├── NSString+SensorType.m ├── SKAbstractSensor.h ├── SKAbstractSensor.m ├── SKAccelerometer.h ├── SKAccelerometer.m ├── SKAccelerometerConfiguration.h ├── SKAccelerometerConfiguration.m ├── SKAccelerometerData.h ├── SKAccelerometerData.m ├── SKAltimeter.h ├── SKAltimeter.m ├── SKAltimeterConfiguration.h ├── SKAltimeterConfiguration.m ├── SKAltimeterData.h ├── SKAltimeterData.m ├── SKBattery.h ├── SKBattery.m ├── SKBatteryConfiguration.h ├── SKBatteryConfiguration.m ├── SKBatteryData.h ├── SKBatteryData.m ├── SKConfiguration.h ├── SKConfiguration.m ├── SKDeviceMotion.h ├── SKDeviceMotion.m ├── SKDeviceMotionConfiguration.h ├── SKDeviceMotionConfiguration.m ├── SKDeviceMotionData.h ├── SKDeviceMotionData.m ├── SKEddystoneProximity.h ├── SKEddystoneProximity.m ├── SKEddystoneProximityConfiguration.h ├── SKEddystoneProximityConfiguration.m ├── SKEddystoneProximityData.h ├── SKEddystoneProximityData.m ├── SKErrors.h ├── SKGyroscope.h ├── SKGyroscope.m ├── SKGyroscopeConfiguration.h ├── SKGyroscopeConfiguration.m ├── SKGyroscopeData.h ├── SKGyroscopeData.m ├── SKHeading.h ├── SKHeading.m ├── SKHeadingConfiguration.h ├── SKHeadingConfiguration.m ├── SKHeadingData.h ├── SKHeadingData.m ├── SKLocation.h ├── SKLocation.m ├── SKLocationConfiguration.h ├── SKLocationConfiguration.m ├── SKLocationData.h ├── SKLocationData.m ├── SKMagnetometer.h ├── SKMagnetometer.m ├── SKMagnetometerConfiguration.h ├── SKMagnetometerConfiguration.m ├── SKMagnetometerData.h ├── SKMagnetometerData.m ├── SKMicrophone.h ├── SKMicrophone.m ├── SKMicrophoneConfiguration.h ├── SKMicrophoneConfiguration.m ├── SKMicrophoneData.h ├── SKMicrophoneData.m ├── SKMotionActivity.h ├── SKMotionActivity.m ├── SKMotionActivityConfiguration.h ├── SKMotionActivityConfiguration.m ├── SKMotionActivityData.h ├── SKMotionActivityData.m ├── SKMotionManager.h ├── SKMotionManager.m ├── SKPedometer.h ├── SKPedometer.m ├── SKPedometerConfiguration.h ├── SKPedometerConfiguration.m ├── SKPedometerData.h ├── SKPedometerData.m ├── SKProximityData.h ├── SKProximityData.m ├── SKSampleRateConfiguration.h ├── SKSampleRateConfiguration.m ├── SKSensorData.h ├── SKSensorData.m ├── SKSensorDataHandler.h ├── SKSensorManager.h ├── SKSensorManager.m ├── SKSensorTimestamp.h ├── SKSensorTimestamp.m ├── SKSensorType.h ├── SKiBeaconDeviceData.h ├── SKiBeaconDeviceData.m ├── SKiBeaconProximity.h ├── SKiBeaconProximity.m ├── SKiBeaconProximityConfiguration.h ├── SKiBeaconProximityConfiguration.m ├── SensingKit.h ├── SensingKitLib.h └── SensingKitLib.m └── SensingKitTests ├── Info.plist └── SensingKitTests.m /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve SensingKit-iOS 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | A clear and concise description of the steps required to reproduce the behavior. 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Screenshots** 17 | If applicable, add screenshots to help explain your problem. 18 | 19 | **Smartphone (please complete the following information):** 20 | - Device: [e.g. iPhone X] 21 | - OS: iOS 22 | - Version [e.g. 12.0] 23 | 24 | **Additional context** 25 | Add any other context about the problem here. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | Documentation -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 0.5.1 (September 20, 2018) 4 | - Added support for Heading sensor. 5 | - Added support for iOS 12 and Xcode 10. 6 | - Changed the minimum supported platform to iOS 9. 7 | - Fixed a bug with incorrect timestamps reported for some sensors. 8 | 9 | ### 0.5.0 (March 2, 2017) 10 | - Added error handling support using NSError. 11 | - Updated Eddystone Scanner into latest version. 12 | - Changed library into a dynamic framework. 13 | - Added CocoaPod support. 14 | - Added support for iOS 10. 15 | - Improved SensingKit API. 16 | - Updated SensingKit Documentation. 17 | 18 | ### 0.4.2 (November 27, 2015) 19 | - Fixed a bug where sensor configuration was not updated. 20 | 21 | ### 0.4.1 (October 16, 2015) 22 | - Added a restriction of 4 hours when recording audio using Microphone sensor. 23 | 24 | ### 0.4.0 (October 11, 2015) 25 | - Added Documentation using appledoc generator. 26 | - Added support for iOS 9. 27 | - Added support for iOS 9 App Slicing. 28 | - Added support for Swift 2 language 29 | - Updated SensingKit-iOS API. 30 | - Added Configuration for all sensors. 31 | - Added support for Microphone sensor. 32 | - Added currentPace and currentCadence in PedometerData (iOS 9 only) 33 | - SensorModules have been renamed into Sensors. 34 | - Activity sensor has been renamed into MotionActivity. 35 | 36 | ### 0.3.0 (August 29, 2015) 37 | - Added support for Pedometer sensor. 38 | - Added support for Altimeter sensor. 39 | - Added isSensorModuleAvailable: method to check for the availability of the sensor in the device. 40 | - Added csvHeaderForSensorModule: method to get the headers of the csv format. 41 | - Improved csvString by providing the timestamp in both string and timeIntervalSince1970 format. 42 | - Added SKSensorTimestamp class for better managing sensor timestamps. 43 | - Improved dictionaryData, making it compatible with JSON format. 44 | 45 | ### 0.2.0 (August 23, 2015) 46 | - Added support for Eddystone™ Proximity sensor. 47 | - Added [start/stop]ContinuousSensingWithAllRegisteredSensors in SensingKit API. 48 | - Added dictionaryData method for returning all sensor data as an NSDictionary. 49 | - Added moduleType property in SKSensorData. 50 | - Renamed Proximity sensor into iBeaconProximity. 51 | - Added generic SKProximityData that encapsulates multiple SKBeaconDeviceData. 52 | - Further improvements in iBeacon™ Proximity sensor. 53 | 54 | ### 0.1.2 (August 15, 2015) 55 | - Fixed crash with error message “SensorModule is already registered”. 56 | 57 | ### 0.1.1 (July 19, 2015) 58 | - Supported csv format in sensor data. 59 | - Fixed crash when deregistering multiple sensor modules. 60 | 61 | ### 0.1.0 (July 13, 2015) 62 | - Initial Release. -------------------------------------------------------------------------------- /ESSEddystone/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Eddystone authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | 11 | -------------------------------------------------------------------------------- /ESSEddystone/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | 12 | Michael Ashbridge 13 | Marc Wandschneider 14 | Peet Sasaki 15 | Michal Mocny 16 | Roy Want 17 | Giovanni Ortuno 18 | Dave Smith 19 | Christopher Dro 20 | Shuichi Tsutsumi 21 | -------------------------------------------------------------------------------- /ESSEddystone/ESSBeaconScanner.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | @class ESSBeaconScanner; 18 | 19 | // Delegates to the ESSBeaconScanner should implement this protocol. 20 | @protocol ESSBeaconScannerDelegate 21 | 22 | @optional 23 | 24 | - (void)beaconScanner:(ESSBeaconScanner *)scanner 25 | didFindBeacon:(id)beaconInfo; 26 | - (void)beaconScanner:(ESSBeaconScanner *)scanner 27 | didLoseBeacon:(id)beaconInfo; 28 | 29 | - (void)beaconScanner:(ESSBeaconScanner *)scanner 30 | didUpdateBeacon:(id)beaconInfo; 31 | 32 | - (void)beaconScanner:(ESSBeaconScanner *)scanner 33 | didFindURL:(NSURL *)url; 34 | 35 | @end 36 | 37 | @interface ESSBeaconScanner : NSObject 38 | 39 | @property(nonatomic, weak) id delegate; 40 | 41 | @property(nonatomic, assign) NSTimeInterval onLostTimeout; 42 | 43 | - (void)startScanning; 44 | - (void)stopScanning; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /ESSEddystone/ESSTimer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | @class ESSTimer; 18 | 19 | typedef void(^ESSTimerBlock)(ESSTimer *timer); 20 | 21 | /** 22 | *=-----------------------------------------------------------------------------------------------= 23 | * ESSTimer 24 | *=-----------------------------------------------------------------------------------------------= 25 | * A Timer class, much like NSTimer, but implemented using dispatch queues and sources. 26 | */ 27 | @interface ESSTimer : NSObject 28 | 29 | @property(nonatomic, copy, readonly) ESSTimerBlock block; 30 | @property(nonatomic, strong, readonly) dispatch_queue_t queue; 31 | @property(nonatomic, assign, readonly) NSTimeInterval delay; 32 | 33 | - (ESSTimer *)initWithDelay:(NSTimeInterval)delay 34 | onQueue:(dispatch_queue_t)queue 35 | block:(ESSTimerBlock)block; 36 | 37 | + (ESSTimer *)timerWithDelay:(NSTimeInterval)delay 38 | onQueue:(dispatch_queue_t)queue 39 | block:(ESSTimerBlock)block; 40 | 41 | + (ESSTimer *)scheduledTimerWithDelay:(NSTimeInterval)delay 42 | onQueue:(dispatch_queue_t)queue 43 | block:(ESSTimerBlock)block; 44 | 45 | /** 46 | * Schedule this timer so that it will fire after the specified delay. 47 | */ 48 | - (void)schedule; 49 | 50 | /** 51 | * Reschedule the timer, so it will fire after the specified delay from the current time, rather 52 | * than from when it was initially scheduled or last rescheduled. 53 | * This should not be called before |schedule|, though it will have no effect. 54 | */ 55 | - (void)reschedule; 56 | 57 | /** 58 | * Suspend this timer, so that it will not fire unless and until it has been resumed. 59 | */ 60 | - (void)suspend; 61 | 62 | /** 63 | * Resume the timer to allow it to fire. 64 | */ 65 | - (void)resume; 66 | 67 | /** 68 | * Cancel the timer, preventing it from ever firing again. 69 | */ 70 | - (void)cancel; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /ESSEddystone/ESSTimer.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ESSTimer.h" 16 | 17 | /** 18 | *=-----------------------------------------------------------------------------------------------= 19 | * Private Additions to ESSTimer 20 | *=-----------------------------------------------------------------------------------------------= 21 | */ 22 | @interface ESSTimer () 23 | 24 | @property(nonatomic, copy, readwrite) ESSTimerBlock block; 25 | @property(nonatomic, copy, readwrite) void(^wrappedBlock)(); 26 | @property(nonatomic, strong, readwrite) dispatch_queue_t queue; 27 | @property(nonatomic, assign, readwrite) NSTimeInterval delay; 28 | 29 | // The dispatch source used for the timer. 30 | @property(nonatomic, strong, readwrite) dispatch_source_t source; 31 | 32 | @property(nonatomic, assign) BOOL suspended; 33 | 34 | @end 35 | 36 | /** 37 | *=-----------------------------------------------------------------------------------------------= 38 | * Implementation for ESSTimer 39 | *=-----------------------------------------------------------------------------------------------= 40 | */ 41 | @implementation ESSTimer 42 | 43 | - (ESSTimer *)initWithDelay:(NSTimeInterval)delay 44 | onQueue:(dispatch_queue_t)queue 45 | block:(ESSTimerBlock)block { 46 | self = [super init]; 47 | if (self) { 48 | _block = block; 49 | _queue = queue; 50 | _delay = delay; 51 | 52 | __block ESSTimer *blockSelf = self; 53 | 54 | _wrappedBlock = ^{ 55 | // This is a one-shot timer - ensure we don't call its block after it has been canceled. 56 | if (!dispatch_source_testcancel(blockSelf.source)) { 57 | dispatch_source_cancel(blockSelf.source); 58 | blockSelf.block(blockSelf); 59 | } 60 | }; 61 | 62 | _source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _queue); 63 | } 64 | return self; 65 | } 66 | 67 | + (ESSTimer *)timerWithDelay:(NSTimeInterval)delay 68 | onQueue:(dispatch_queue_t)queue 69 | block:(ESSTimerBlock)block { 70 | return [[self alloc] initWithDelay:delay onQueue:queue block:block]; 71 | 72 | } 73 | 74 | + (ESSTimer *)scheduledTimerWithDelay:(NSTimeInterval)delay 75 | onQueue:(dispatch_queue_t)queue 76 | block:(ESSTimerBlock)block { 77 | ESSTimer *timer = [self timerWithDelay:delay onQueue:queue block:block]; 78 | [timer schedule]; 79 | return timer; 80 | } 81 | 82 | - (void)schedule { 83 | [self reschedule]; 84 | dispatch_source_set_event_handler(_source, _wrappedBlock); 85 | dispatch_resume(_source); 86 | } 87 | 88 | - (void)reschedule { 89 | dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_delay * NSEC_PER_SEC)); 90 | // Leeway is 10% of timer delay 91 | dispatch_source_set_timer(_source, start, DISPATCH_TIME_FOREVER, 92 | (uint64_t)(_delay / 10) * NSEC_PER_SEC); 93 | } 94 | 95 | - (void)suspend { 96 | dispatch_suspend(_source); 97 | } 98 | 99 | - (void)resume { 100 | dispatch_resume(_source); 101 | } 102 | 103 | - (void)cancel { 104 | dispatch_source_cancel(_source); 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /SensingKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SensingKit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.5.1 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /SensingKit/NSString+SensorType.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+SKSensorType.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | #import 27 | 28 | #import "SKSensorType.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * NSString+SKSensorType is a category responsible for converting an SKSensorType enum into string. 34 | */ 35 | @interface NSString (SKSensorType) 36 | 37 | /** 38 | * Converts an SKSensorType enum into a string. 39 | * 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". 40 | * 41 | * @param sensorType The type of the sensor. 42 | * 43 | * @return A string with the sensor name. (e.g. "iBeacon™ Proximity"). 44 | */ 45 | + (NSString *)stringWithSensorType:(SKSensorType)sensorType; 46 | 47 | /** 48 | * Converts an SKSensorType enum into a non-spaced string that does not include special characters. 49 | * 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". 50 | * 51 | * @param sensorType The type of the sensor. 52 | * 53 | * @return A non-spaced string with the sensor name. (e.g. "iBeaconProximity"). 54 | */ 55 | + (NSString *)nonspacedStringWithSensorType:(SKSensorType)sensorType; 56 | 57 | @end 58 | 59 | NS_ASSUME_NONNULL_END 60 | -------------------------------------------------------------------------------- /SensingKit/NSString+SensorType.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+SensorType.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "NSString+SensorType.h" 26 | 27 | @implementation NSString (SensorType) 28 | 29 | static const NSString *SENSOR_STRINGS[] = { 30 | @"Accelerometer", 31 | @"Gyroscope", 32 | @"Magnetometer", 33 | @"Device Motion", 34 | @"Motion Activity", 35 | @"Pedometer", 36 | @"Altimeter", 37 | @"Battery", 38 | @"Location", 39 | @"Heading", 40 | @"iBeacon™ Proximity", 41 | @"Eddystone™ Proximity", 42 | @"Microphone" 43 | }; 44 | 45 | static const NSString *NONSPACED_SENSOR_STRINGS[] = { 46 | @"Accelerometer", 47 | @"Gyroscope", 48 | @"Magnetometer", 49 | @"DeviceMotion", 50 | @"MotionActivity", 51 | @"Pedometer", 52 | @"Altimeter", 53 | @"Battery", 54 | @"Location", 55 | @"Heading", 56 | @"iBeaconProximity", 57 | @"EddystoneProximity", 58 | @"Microphone" 59 | }; 60 | 61 | + (NSString *)stringWithSensorType:(SKSensorType)sensorType 62 | { 63 | return SENSOR_STRINGS[sensorType].copy; 64 | } 65 | 66 | + (NSString *)nonspacedStringWithSensorType:(SKSensorType)sensorType 67 | { 68 | return NONSPACED_SENSOR_STRINGS[sensorType].copy; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /SensingKit/SKAbstractSensor.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAbstractSensor.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorType.h" 28 | #import "SKSensorDataHandler.h" 29 | #import "SKConfiguration.h" 30 | #import "SKErrors.h" 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | @interface SKAbstractSensor : NSObject 35 | 36 | @property (nonatomic, copy) SKConfiguration *configuration; 37 | 38 | @property (nonatomic, readonly) SKSensorType sensorType; 39 | @property (nonatomic, readonly, getter=isSensing) BOOL sensing; 40 | 41 | @property (readonly) NSUInteger handlersCount; 42 | 43 | - (BOOL)subscribeHandler:(SKSensorDataHandler)handler 44 | error:(NSError * _Nullable * _Nullable)error; 45 | 46 | - (BOOL)unsubscribeHandler:(SKSensorDataHandler)handler 47 | error:(NSError * _Nullable * _Nullable)error; 48 | 49 | - (void)unsubscribeAllHandlers; 50 | 51 | - (BOOL)startSensing:(NSError * _Nullable * _Nullable)error; 52 | 53 | - (BOOL)stopSensing:(NSError * _Nullable * _Nullable)error; 54 | 55 | - (void)submitSensorData:(SKSensorData * __nullable)data 56 | error:(NSError * _Nullable)error; 57 | 58 | @end 59 | 60 | NS_ASSUME_NONNULL_END 61 | -------------------------------------------------------------------------------- /SensingKit/SKAccelerometer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAccelerometer.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKAccelerometerConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKAccelerometer : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKAccelerometerConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKAccelerometerConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAccelerometerConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSampleRateConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKAccelerometerConfiguration can be used to configure the Accelerometer sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKAccelerometerConfiguration : SKSampleRateConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKAccelerometerConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKAccelerometerConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKAccelerometerConfiguration.h" 26 | 27 | @implementation SKAccelerometerConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKAccelerometerConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Accelerometer; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /SensingKit/SKAccelerometerData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAccelerometerData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKAccelerometerData encapsulates measurements related to the Accelerometer sensor. 34 | */ 35 | @interface SKAccelerometerData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKAccelerometerData object, initialized with a CMAccelerometerData structure. 44 | * 45 | * @param accelerometerData A structure that contains 3-axis acceleration data. 46 | * 47 | * @return An SKAccelerometerData object. 48 | */ 49 | - (instancetype)initWithAccelerometerData:(CMAccelerometerData *)accelerometerData NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * A structure that contains 3-axes acceleration values. 53 | */ 54 | @property (nonatomic, readonly) CMAcceleration acceleration; 55 | 56 | /** 57 | * A string with a CSV formatted header that describes the data of the Accelerometer sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 58 | * 59 | * @return A string with a CSV header. 60 | */ 61 | + (NSString *)csvHeader; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /SensingKit/SKAccelerometerData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKAccelerometerData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKAccelerometerData.h" 26 | 27 | @implementation SKAccelerometerData 28 | 29 | - (instancetype)initWithAccelerometerData:(CMAccelerometerData *)accelerometerData 30 | { 31 | if (self = [super initWithSensorType:Accelerometer 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:accelerometerData.timestamp]]) 33 | { 34 | _acceleration = accelerometerData.acceleration; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,x,y,z"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%f,%f,%f", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | _acceleration.x, 50 | _acceleration.y, 51 | _acceleration.z]; 52 | } 53 | 54 | - (NSDictionary *)dictionaryData 55 | { 56 | return @{ 57 | @"sensorType": @(self.sensorType), 58 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 59 | @"timestamp": self.timestamp.timestampDictionary, 60 | @"acceleration": @{ 61 | @"x": @(_acceleration.x), 62 | @"y": @(_acceleration.y), 63 | @"z": @(_acceleration.z) 64 | } 65 | }; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeter.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKAltimeterConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKAltimeter : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKAltimeterConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeter.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeter.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKAltimeter.h" 26 | #import "SKAltimeterData.h" 27 | 28 | @import CoreMotion; 29 | 30 | 31 | @interface SKAltimeter () 32 | 33 | @property (nonatomic, strong) CMAltimeter *altemeter; 34 | 35 | @end 36 | 37 | 38 | @implementation SKAltimeter 39 | 40 | - (instancetype)initWithConfiguration:(SKAltimeterConfiguration *)configuration 41 | { 42 | if (self = [super init]) 43 | { 44 | self.altemeter = [[CMAltimeter alloc] init]; 45 | self.configuration = configuration; 46 | } 47 | return self; 48 | } 49 | 50 | 51 | #pragma mark Configuration 52 | 53 | - (void)setConfiguration:(SKConfiguration *)configuration 54 | { 55 | super.configuration = configuration; 56 | 57 | // Cast the configuration instance 58 | // SKAltimeterConfiguration *altimeterConfiguration = (SKAltimeterConfiguration *)configuration; 59 | 60 | // Make the required updates on the sensor 61 | // 62 | } 63 | 64 | 65 | #pragma mark Sensing 66 | 67 | + (BOOL)isSensorAvailable 68 | { 69 | return [CMAltimeter isRelativeAltitudeAvailable]; 70 | } 71 | 72 | - (BOOL)startSensing:(NSError **)error 73 | { 74 | if (![super startSensing:error]) { 75 | return NO; 76 | } 77 | 78 | if (![SKAltimeter isSensorAvailable]) 79 | { 80 | if (error) { 81 | 82 | NSDictionary *userInfo = @{ 83 | NSLocalizedDescriptionKey: NSLocalizedString(@"Altimeter sensor is not available.", nil), 84 | }; 85 | 86 | *error = [NSError errorWithDomain:SKErrorDomain 87 | code:SKSensorNotAvailableError 88 | userInfo:userInfo]; 89 | } 90 | return NO; 91 | } 92 | 93 | [self.altemeter startRelativeAltitudeUpdatesToQueue:[NSOperationQueue currentQueue] 94 | withHandler:^(CMAltitudeData *altitudeData, NSError *error) { 95 | 96 | if (error) { 97 | [self submitSensorData:nil error:error]; 98 | } 99 | else { 100 | SKAltimeterData *data = [[SKAltimeterData alloc] initWithAltitudeData:altitudeData]; 101 | [self submitSensorData:data error:NULL]; 102 | } 103 | 104 | }]; 105 | 106 | return YES; 107 | } 108 | 109 | - (BOOL)stopSensing:(NSError **)error 110 | { 111 | [self.altemeter stopRelativeAltitudeUpdates]; 112 | 113 | return [super stopSensing:error]; 114 | } 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeterConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeterConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKAltimeterConfiguration can be used to configure the Altimeter sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKAltimeterConfiguration : SKConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeterConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeterConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKAltimeterConfiguration.h" 26 | 27 | @implementation SKAltimeterConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKAltimeterConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Altimeter; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeterData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeterData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKAltimeterData encapsulates measurements related to the Altimeter sensor. 34 | */ 35 | @interface SKAltimeterData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKAltimeterData object, initialized with an instance of CMAltitudeData. 44 | * 45 | * @param altitudeData A CMAltitudeData object that contains data related to the Altimeter sensor. 46 | * 47 | * @return An SKAltimeter object. 48 | */ 49 | - (instancetype)initWithAltitudeData:(CMAltitudeData *)altitudeData NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * An instance of CMAltitudeData object contains data about changes to the relative altitude (not the actual). It also provides the recorded atmospheric pressure in kPa. 53 | */ 54 | @property (nonatomic, readonly, copy) CMAltitudeData *altitudeData; 55 | 56 | /** 57 | * A string with a CSV formatted header that describes the data of the Altimeter sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 58 | * 59 | * @return A string with a CSV header. 60 | */ 61 | + (NSString *)csvHeader; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /SensingKit/SKAltimeterData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKAltimeterData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKAltimeterData.h" 26 | 27 | @implementation SKAltimeterData 28 | 29 | - (instancetype)initWithAltitudeData:(CMAltitudeData *)altitudeData 30 | { 31 | if (self = [super initWithSensorType:Altimeter 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:altitudeData.timestamp]]) 33 | { 34 | _altitudeData = altitudeData; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,relativeAltitude,pressure"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%ld,%lu", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | (long)_altitudeData.relativeAltitude.integerValue, 50 | (unsigned long)_altitudeData.pressure.unsignedIntegerValue]; 51 | } 52 | 53 | - (NSDictionary *)dictionaryData 54 | { 55 | return @{ 56 | @"sensorType": @(self.sensorType), 57 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 58 | @"timestamp": self.timestamp.timestampDictionary, 59 | @"altitudeData": @{ 60 | @"relativeAltitude": _altitudeData.relativeAltitude, 61 | @"pressure": _altitudeData.pressure 62 | } 63 | }; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /SensingKit/SKBattery.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKBattery.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKBatteryConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKBattery : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKBatteryConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKBatteryConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKBatteryConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKBatteryConfiguration can be used to configure the Battery sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKBatteryConfiguration : SKConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKBatteryConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKBatteryConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKBatteryConfiguration.h" 26 | 27 | @implementation SKBatteryConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKBatteryConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Battery; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /SensingKit/SKBatteryData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKBatteryData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | #import 27 | 28 | #import "SKSensorData.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKBatteryData encapsulates measurements related to the Battery sensor. 34 | */ 35 | @interface SKBatteryData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKBatteryData object, initialized with measurements of the battery level, as well as the battery state. 44 | * 45 | * @param level A float number that indicates the current battery charge level. Value ranges from 0.0 (fully discharged) to 1.0 (fully charged). 46 | * @param state An enumerator that descrives the state of the battery, classified as Charging, Full, Unplugged or Unknown. 47 | * 48 | * @return An SKBatteryData object. 49 | */ 50 | - (instancetype)initWithLevel:(CGFloat)level withState:(UIDeviceBatteryState)state NS_DESIGNATED_INITIALIZER; 51 | 52 | /** 53 | * A float number that indicates the current battery charge level. Value ranges from 0.0 (fully discharged) to 1.0 (fully charged). 54 | */ 55 | @property (nonatomic, readonly) CGFloat level; 56 | 57 | /** 58 | * An enumerator that describes the state of the battery, classified as Charging, Full, Unplugged or Unknown. 59 | */ 60 | @property (nonatomic, readonly) UIDeviceBatteryState state; 61 | 62 | /** 63 | * A string value that describes the state of the battery, classified as Charging, Full, Unplugged or Unknown. 64 | */ 65 | @property (nonatomic, readonly, copy) NSString *stateString; 66 | 67 | /** 68 | * A string with a CSV formatted header that describes the data of the Battery sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 69 | * 70 | * @return A string with a CSV header. 71 | */ 72 | + (NSString *)csvHeader; 73 | 74 | @end 75 | 76 | NS_ASSUME_NONNULL_END 77 | -------------------------------------------------------------------------------- /SensingKit/SKBatteryData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKBatteryData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKBatteryData.h" 26 | 27 | @implementation SKBatteryData 28 | 29 | - (instancetype)initWithLevel:(CGFloat)level withState:(UIDeviceBatteryState)state 30 | { 31 | if (self = [super initWithSensorType:Battery 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:[NSProcessInfo processInfo].systemUptime]]) 33 | { 34 | _level = level; 35 | _state = state; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSString *)stateString 41 | { 42 | switch (_state) { 43 | case UIDeviceBatteryStateCharging: 44 | return @"Charging"; 45 | 46 | case UIDeviceBatteryStateFull: 47 | return @"Full"; 48 | 49 | case UIDeviceBatteryStateUnplugged: 50 | return @"Unplugged"; 51 | 52 | case UIDeviceBatteryStateUnknown: 53 | return @"Unknown"; 54 | 55 | default: 56 | NSLog(@"Warning: Unknown state: %d", (int)_state); 57 | return @"Unknown"; 58 | } 59 | } 60 | 61 | + (NSString *)csvHeader 62 | { 63 | return @"timestamp,timeIntervalSince1970,state,level"; 64 | } 65 | 66 | - (NSString *)csvString 67 | { 68 | return [NSString stringWithFormat:@"\"%@\",%f,%@,%f", 69 | self.timestamp.timestampString, 70 | self.timestamp.timeIntervalSince1970, 71 | self.stateString, 72 | _level]; 73 | } 74 | 75 | - (NSDictionary *)dictionaryData 76 | { 77 | return @{ 78 | @"sensorType": @(self.sensorType), 79 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 80 | @"timestamp": self.timestamp.timestampDictionary, 81 | @"battery": @{ 82 | @"level": @(_level), 83 | @"state": @(_state), 84 | @"stateString": self.stateString 85 | } 86 | }; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /SensingKit/SKConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | #import "SKSensorType.h" 27 | #import "SKErrors.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * This is the base class for all Sensor Configuration objects. 33 | */ 34 | @interface SKConfiguration : NSObject 35 | 36 | - (BOOL)isValidForSensor:(SKSensorType)sensorType; 37 | 38 | @end 39 | 40 | NS_ASSUME_NONNULL_END 41 | -------------------------------------------------------------------------------- /SensingKit/SKConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKConfiguration.h" 26 | 27 | @implementation SKConfiguration 28 | 29 | - (id)copyWithZone:(NSZone *)zone 30 | { 31 | SKConfiguration *configuration = [[[self class] alloc] init]; 32 | 33 | return configuration; 34 | } 35 | 36 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 37 | { 38 | // Internal Error. Should never happen. 39 | NSLog(@"Internal Error: isValidForSensor method is not implemented in the inherited SKConfiguration class."); 40 | abort(); 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /SensingKit/SKDeviceMotion.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKDeviceMotion.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKDeviceMotionConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKDeviceMotion : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKDeviceMotionConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKDeviceMotion.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKDeviceMotion.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKDeviceMotion.h" 26 | #import "SKMotionManager.h" 27 | #import "SKDeviceMotionData.h" 28 | 29 | 30 | @interface SKDeviceMotion () 31 | 32 | @property (nonatomic, strong) CMMotionManager *motionManager; 33 | 34 | @end 35 | 36 | 37 | @implementation SKDeviceMotion 38 | 39 | - (instancetype)initWithConfiguration:(SKDeviceMotionConfiguration *)configuration 40 | { 41 | if (self = [super init]) 42 | { 43 | self.motionManager = [SKMotionManager sharedMotionManager]; 44 | self.configuration = configuration; 45 | } 46 | return self; 47 | } 48 | 49 | 50 | #pragma mark Configuration 51 | 52 | - (void)setConfiguration:(SKConfiguration *)configuration 53 | { 54 | super.configuration = configuration; 55 | 56 | // Cast the configuration instance 57 | SKDeviceMotionConfiguration *deviceMotionConfiguration = (SKDeviceMotionConfiguration *)configuration; 58 | 59 | // Make the required updates on the sensor 60 | self.motionManager.deviceMotionUpdateInterval = 1.0 / deviceMotionConfiguration.sampleRate; // Convert Hz into interval 61 | } 62 | 63 | 64 | #pragma mark Sensing 65 | 66 | + (BOOL)isSensorAvailable 67 | { 68 | return [SKMotionManager sharedMotionManager].isDeviceMotionAvailable; 69 | } 70 | 71 | - (BOOL)startSensing:(NSError **)error 72 | { 73 | if (![super startSensing:error]) { 74 | return NO; 75 | } 76 | 77 | if (![SKDeviceMotion isSensorAvailable]) 78 | { 79 | if (error) { 80 | 81 | NSDictionary *userInfo = @{ 82 | NSLocalizedDescriptionKey: NSLocalizedString(@"Device Motion sensor is not available.", nil), 83 | }; 84 | 85 | *error = [NSError errorWithDomain:SKErrorDomain 86 | code:SKSensorNotAvailableError 87 | userInfo:userInfo]; 88 | } 89 | return NO; 90 | } 91 | 92 | [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] 93 | withHandler:^(CMDeviceMotion *motion, NSError *error) { 94 | 95 | if (error) { 96 | [self submitSensorData:nil error:error]; 97 | } else { 98 | SKDeviceMotionData *data = [[SKDeviceMotionData alloc] initWithDeviceMotion:motion]; 99 | [self submitSensorData:data error:NULL]; 100 | } 101 | 102 | }]; 103 | 104 | return YES; 105 | } 106 | 107 | - (BOOL)stopSensing:(NSError **)error 108 | { 109 | [self.motionManager stopDeviceMotionUpdates]; 110 | 111 | return [super stopSensing:error]; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /SensingKit/SKDeviceMotionConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKDeviceMotionConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSampleRateConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKDeviceMotionConfiguration can be used to configure the Device Motion sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKDeviceMotionConfiguration : SKSampleRateConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKDeviceMotionConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKDeviceMotionConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKDeviceMotionConfiguration.h" 26 | 27 | @implementation SKDeviceMotionConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKDeviceMotionConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == DeviceMotion; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /SensingKit/SKDeviceMotionData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKDeviceMotionData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKDeviceMotionData encapsulates measurements related to the Device Motion sensor. 34 | * The measurements include the device's Attitude, Magnetic Field, Rotation Rate and a separation of the User Acceleration and the Gravity. For more information, please refer to Apple's Core Motion Documentation. 35 | */ 36 | @interface SKDeviceMotionData : SKSensorData 37 | 38 | - (instancetype)init NS_UNAVAILABLE; 39 | 40 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 41 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 42 | 43 | /** 44 | * Returns an SKDeviceMotionData object, initialized with a CMDeviceMotion object. 45 | * 46 | * @param motion The original CMDeviceMotion object. 47 | * 48 | * @return An SKDeviceMotionData object. 49 | */ 50 | - (instancetype)initWithDeviceMotion:(CMDeviceMotion *)motion NS_DESIGNATED_INITIALIZER; 51 | 52 | /** 53 | * An attitude object is the orientation of a body relative to a given frame of reference. 54 | */ 55 | @property (nonatomic, readonly, copy) CMAttitude *attitude; 56 | 57 | /** 58 | * The calibrated Magnetic Field vector that contains the magnetic field vector without the device's bias. 59 | */ 60 | @property (nonatomic, readonly) CMCalibratedMagneticField magneticField; 61 | 62 | /** 63 | * A structure that contains the device's rotation rate in 3-axis, excluding the gyroscopes bias using sensor fusion techniques. 64 | */ 65 | @property (nonatomic, readonly) CMRotationRate rotationRate; 66 | 67 | /** 68 | * The devices 3-axes acceleration produced by the user, exluding the acceleration of the gravity. 69 | */ 70 | @property (nonatomic, readonly) CMAcceleration userAcceleration; 71 | 72 | /** 73 | * The gravities 3-axes acceleration, exluding the acceleration of the user. 74 | */ 75 | @property (nonatomic, readonly) CMAcceleration gravity; 76 | 77 | /** 78 | * A string with a CSV formatted header that describes the data of the Device Motion sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 79 | * 80 | * @return A string with a CSV header. 81 | */ 82 | + (NSString *)csvHeader; 83 | 84 | @end 85 | 86 | NS_ASSUME_NONNULL_END 87 | -------------------------------------------------------------------------------- /SensingKit/SKEddystoneProximity.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKEddystoneProximity.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKEddystoneProximityConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKEddystoneProximity : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKEddystoneProximityConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKEddystoneProximityConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKEddystoneProximityConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | /** 30 | * These constants indicate the mode of the Eddystone™ Proximity sensor. At this moment, only Scan mode is supported. 31 | */ 32 | typedef NS_ENUM(NSUInteger, SKEddystoneProximityMode){ 33 | /** 34 | * Scan only mode ranges for other Eddystone™ beacons existing in range. 35 | */ 36 | SKEddystoneProximityModeScanOnly = 0 37 | }; 38 | 39 | NS_ASSUME_NONNULL_BEGIN 40 | 41 | /** 42 | * An instance of SKEddystoneProximityConfiguration can be used to configure the Eddystone™ Proximity sensor. 43 | */ 44 | @interface SKEddystoneProximityConfiguration : SKConfiguration 45 | 46 | /** 47 | * Mode of the Eddystone™ Proximity sensor. At this moment, only Scan mode is supported. 48 | */ 49 | @property (nonatomic) SKEddystoneProximityMode mode; 50 | 51 | /** 52 | * A 10-byte (80 bit) identifier that can used to group a particular set of beacons. This value should be in Hexadecimal format, with a maximum character length of 20 characters. 53 | */ 54 | @property (nonatomic, copy, nullable, readonly) NSString *namespaceFilter; 55 | 56 | - (BOOL)setNamespaceFilter:(NSString * _Nullable)namespaceFilter error:(NSError * _Nullable * _Nullable)error; 57 | 58 | @end 59 | 60 | NS_ASSUME_NONNULL_END 61 | -------------------------------------------------------------------------------- /SensingKit/SKEddystoneProximityConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKEddystoneProximityConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKEddystoneProximityConfiguration.h" 26 | 27 | @implementation SKEddystoneProximityConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | _mode = SKEddystoneProximityModeScanOnly; 35 | _namespaceFilter = nil; // All Eddystones available 36 | } 37 | return self; 38 | } 39 | 40 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 41 | { 42 | return sensorType == EddystoneProximity; 43 | } 44 | 45 | - (BOOL)setNamespaceFilter:(NSString *)namespaceFilter error:(NSError **)error 46 | { 47 | if (![SKEddystoneProximityConfiguration isNamespaceValid:namespaceFilter]) 48 | { 49 | if (error) { 50 | 51 | NSDictionary *userInfo = @{ 52 | NSLocalizedDescriptionKey: NSLocalizedString(@"Eddystone Proximity Namespace filter is not valid.", nil), 53 | NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"Namespace should be formatted as a 10-byte hexadecimal string.", nil) 54 | }; 55 | 56 | *error = [NSError errorWithDomain:SKErrorDomain 57 | code:SKConfigurationEddystoneProximityNamespaceNotValid 58 | userInfo:userInfo]; 59 | } 60 | return NO; 61 | } 62 | 63 | if (namespaceFilter.length == 0) { 64 | _namespaceFilter = nil; 65 | } 66 | else { 67 | _namespaceFilter = namespaceFilter.lowercaseString; 68 | } 69 | 70 | return YES; 71 | } 72 | 73 | - (id)copyWithZone:(NSZone *)zone 74 | { 75 | SKEddystoneProximityConfiguration *configuration = [super copyWithZone:zone]; 76 | configuration.mode = _mode; 77 | [configuration setNamespaceFilter:_namespaceFilter error:NULL]; 78 | 79 | return configuration; 80 | } 81 | 82 | + (BOOL)isNamespaceValid:(NSString *)string 83 | { 84 | if (!string || string.length == 0) 85 | { 86 | // Nil is valid 87 | return YES; 88 | } 89 | if (string.length > 20) 90 | { 91 | return NO; 92 | } 93 | else 94 | { 95 | NSCharacterSet *validCharacters = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFabcdef"].invertedSet; 96 | return ([string rangeOfCharacterFromSet:validCharacters].location == NSNotFound); 97 | } 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /SensingKit/SKEddystoneProximityData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKEddystoneProximityData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKEddystoneProximityData encapsulates measurements related to the Eddystone™ Proximity sensor. 33 | */ 34 | @interface SKEddystoneProximityData : SKSensorData 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 39 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 40 | 41 | /** 42 | * Returns an SKEddystoneProximityData object, initialized with the time the data log was captured, its namespace and instance identifiers, as well as its rssi and txPower. 43 | * 44 | * @param timestamp The time that this data log was captured. 45 | * @param namespaceId A 10-byte (80 bit) identifier that can used to group a particular set of beacons. This value should be in Hexadecimal format, with a maximum character length of 20 characters. 46 | * @param instanceId A 6-byte (48 bit) unsigned integer that is used to identify individual devices inside the namespace group. It ranges between 0 and 281474976710655. 47 | * @param rssi The strength of the signal (Received Signal Strength Indication). 48 | * @param txPower The strength of the signal measured at a distance of 1 meter. 49 | * 50 | * @return An SKEddystoneProximityData object. 51 | */ 52 | - (instancetype)initWithTimestamp:(NSDate *)timestamp 53 | withNamespaceId:(NSString * _Nullable)namespaceId 54 | withInstanceId:(NSUInteger)instanceId 55 | withRssi:(NSInteger)rssi 56 | withTxPower:(NSInteger)txPower NS_DESIGNATED_INITIALIZER; 57 | 58 | /** 59 | * A 10-byte (80 bit) identifier that can used to group a particular set of beacons. This value should be in Hexadecimal format, with a maximum character length of 20 characters. 60 | */ 61 | @property (nonatomic, readonly, copy, nullable) NSString *namespaceId; 62 | 63 | /** 64 | * A 6-byte (48 bit) unsigned integer that is used to identify individual devices inside the namespace group. It ranges between 0 and 281474976710655. 65 | */ 66 | @property (nonatomic, readonly) NSUInteger instanceId; 67 | 68 | /** 69 | * The strength of the signal (Received Signal Strength Indication). 70 | */ 71 | @property (nonatomic, readonly) NSInteger rssi; 72 | 73 | /** 74 | * The strength of the signal measured at a distance of 1 meter. 75 | */ 76 | @property (nonatomic, readonly) NSInteger txPower; 77 | 78 | /** 79 | * A string with a CSV formatted header that describes the data of the Eddystone™ Proximity sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 80 | * 81 | * @return A string with a CSV header. 82 | */ 83 | + (NSString *)csvHeader; 84 | 85 | @end 86 | 87 | NS_ASSUME_NONNULL_END 88 | -------------------------------------------------------------------------------- /SensingKit/SKEddystoneProximityData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKEddystoneProximityData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKEddystoneProximityData.h" 26 | 27 | @implementation SKEddystoneProximityData 28 | 29 | - (instancetype)initWithTimestamp:(NSDate *)timestamp 30 | withNamespaceId:(NSString *)namespaceId 31 | withInstanceId:(NSUInteger)instanceId 32 | withRssi:(NSInteger)rssi 33 | withTxPower:(NSInteger)txPower 34 | { 35 | if (self = [super initWithSensorType:EddystoneProximity 36 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:timestamp]]) 37 | { 38 | _namespaceId = namespaceId.lowercaseString; 39 | _instanceId = instanceId; 40 | _rssi = rssi; 41 | _txPower = txPower; 42 | } 43 | return self; 44 | } 45 | 46 | + (NSString *)csvHeader 47 | { 48 | return @"timestamp,timeIntervalSince1970,namespaceID,instanceID,rssi,txPower"; 49 | } 50 | 51 | - (NSString *)csvString 52 | { 53 | return [NSString stringWithFormat:@"\"%@\",%f,%@,%lu,%ld,%ld", 54 | self.timestamp.timestampString, 55 | self.timestamp.timeIntervalSince1970, 56 | _namespaceId, 57 | (unsigned long)_instanceId, 58 | (long)_rssi, 59 | (long)_txPower]; 60 | } 61 | 62 | - (NSDictionary *)dictionaryData 63 | { 64 | return @{ 65 | @"sensorType": @(self.sensorType), 66 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 67 | @"timestamp": self.timestamp.timestampDictionary, 68 | @"Eddystone": @{ 69 | @"namespace": _namespaceId, 70 | @"instanceId": @(_instanceId), 71 | @"rssi": @(_rssi), 72 | @"txPower": @(_txPower) 73 | } 74 | }; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /SensingKit/SKErrors.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKErrors.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | static NSString *const SKErrorDomain = @"org.sensingkit.SensingKit-iOS.ErrorDomain"; 28 | 29 | 30 | /** 31 | NSError codes in SKErrorDomain. 32 | */ 33 | typedef NS_ENUM(NSInteger, SKSensorError) { 34 | 35 | /** Sensor Availibility */ 36 | 37 | /** 38 | * Sensor is not available. 39 | */ 40 | SKSensorNotAvailableError = 0, 41 | 42 | 43 | 44 | /** Sensor Registration */ 45 | 46 | /** 47 | * Sensor is already registered. 48 | */ 49 | SKSensorAlreadyRegisteredError = 10, 50 | 51 | /** 52 | * Sensor is not registered. 53 | */ 54 | SKSensorNotRegisteredError = 11, 55 | 56 | 57 | 58 | /** Sensor Sensing */ 59 | 60 | /** 61 | * Sensor is currently sensing. 62 | */ 63 | SKSensorCurrentlySensingError = 20, 64 | 65 | /** 66 | * Sensor is currently not sensing. 67 | */ 68 | SKSensorCurrentlyNotSensingError = 21, 69 | 70 | 71 | 72 | /** Sensor Data Handlers */ 73 | 74 | /** 75 | * Sensor Data Handler is already registered. 76 | */ 77 | SKDataHandlerAlreadyRegistered = 30, 78 | 79 | /** 80 | * Sensor Data Handler is not registered 81 | */ 82 | SKDataHandlerNotRegistered = 31, 83 | 84 | 85 | 86 | /** Sensor Configuration */ 87 | 88 | /** 89 | * Configuration is not compatible with the registered sensor. 90 | */ 91 | SKConfigurationNotValid = 40, 92 | 93 | /** 94 | * Eddystone Proximity Namespace is not valid. 95 | */ 96 | SKConfigurationEddystoneProximityNamespaceNotValid = 41, 97 | 98 | 99 | }; 100 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscope.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscope.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKGyroscopeConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKGyroscope : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKGyroscopeConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscope.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscope.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKGyroscope.h" 26 | #import "SKMotionManager.h" 27 | #import "SKGyroscopeData.h" 28 | 29 | 30 | @interface SKGyroscope () 31 | 32 | @property (nonatomic, strong) CMMotionManager *motionManager; 33 | 34 | @end 35 | 36 | 37 | @implementation SKGyroscope 38 | 39 | - (instancetype)initWithConfiguration:(SKGyroscopeConfiguration *)configuration 40 | { 41 | if (self = [super init]) 42 | { 43 | self.motionManager = [SKMotionManager sharedMotionManager]; 44 | self.configuration = configuration; 45 | } 46 | return self; 47 | } 48 | 49 | 50 | #pragma mark Configuration 51 | 52 | - (void)setConfiguration:(SKConfiguration *)configuration 53 | { 54 | super.configuration = configuration; 55 | 56 | // Cast the configuration instance 57 | SKGyroscopeConfiguration *gyroscopeConfiguration = (SKGyroscopeConfiguration *)configuration; 58 | 59 | // Make the required updates on the sensor 60 | self.motionManager.gyroUpdateInterval = 1.0 / gyroscopeConfiguration.sampleRate; // Convert Hz into interval 61 | } 62 | 63 | 64 | #pragma mark Sensing 65 | 66 | + (BOOL)isSensorAvailable 67 | { 68 | return [SKMotionManager sharedMotionManager].isGyroAvailable; 69 | } 70 | 71 | - (BOOL)startSensing:(NSError **)error 72 | { 73 | if (![super startSensing:error]) { 74 | return NO; 75 | } 76 | 77 | if (![SKGyroscope isSensorAvailable]) 78 | { 79 | if (error) { 80 | 81 | NSDictionary *userInfo = @{ 82 | NSLocalizedDescriptionKey: NSLocalizedString(@"Gyroscope sensor is not available.", nil), 83 | }; 84 | 85 | *error = [NSError errorWithDomain:SKErrorDomain 86 | code:SKSensorNotAvailableError 87 | userInfo:userInfo]; 88 | } 89 | return NO; 90 | } 91 | 92 | [self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] 93 | withHandler:^(CMGyroData *gyroData, NSError *error) { 94 | 95 | if (error) { 96 | [self submitSensorData:nil error:error]; 97 | } else { 98 | SKGyroscopeData *data = [[SKGyroscopeData alloc] initWithGyroData:gyroData]; 99 | [self submitSensorData:data error:NULL]; 100 | } 101 | 102 | }]; 103 | 104 | return YES; 105 | } 106 | 107 | - (BOOL)stopSensing:(NSError **)error 108 | { 109 | [self.motionManager stopGyroUpdates]; 110 | 111 | return [super stopSensing:error]; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscopeConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscopeConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSampleRateConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKGyroscopeConfiguration can be used to configure the Gyroscope sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKGyroscopeConfiguration : SKSampleRateConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscopeConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscopeConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKGyroscopeConfiguration.h" 26 | 27 | @implementation SKGyroscopeConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKGyroscopeConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Gyroscope; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscopeData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscopeData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKGyroscopeData encapsulates measurements related to the Gyroscope sensor. 34 | */ 35 | @interface SKGyroscopeData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKGyroscopeData object, initialized with a CMRotationRate structure. 44 | * 45 | * @param gyroData A structure that contains 3-axis rotation rate data. 46 | * 47 | * @return An SKGyroscopeData object 48 | */ 49 | - (instancetype)initWithGyroData:(CMGyroData *)gyroData NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * A structure that contains 3-axis rotation rate data. 53 | */ 54 | @property (nonatomic, readonly) CMRotationRate rotationRate; 55 | 56 | /** 57 | * A string with a CSV formatted header that describes the data of the Gyroscope sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 58 | * 59 | * @return A string with a CSV header. 60 | */ 61 | + (NSString *)csvHeader; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /SensingKit/SKGyroscopeData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKGyroscopeData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKGyroscopeData.h" 26 | 27 | @implementation SKGyroscopeData 28 | 29 | - (instancetype)initWithGyroData:(CMGyroData *)gyroData 30 | { 31 | if (self = [super initWithSensorType:Gyroscope 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:gyroData.timestamp]]) 33 | { 34 | _rotationRate = gyroData.rotationRate; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,x,y,z"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%f,%f,%f", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | _rotationRate.x, 50 | _rotationRate.y, 51 | _rotationRate.z]; 52 | } 53 | 54 | - (NSDictionary *)dictionaryData 55 | { 56 | return @{ 57 | @"sensorType": @(self.sensorType), 58 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 59 | @"timestamp": self.timestamp.timestampDictionary, 60 | @"rotationRate": @{ 61 | @"x": @(_rotationRate.x), 62 | @"y": @(_rotationRate.y), 63 | @"z": @(_rotationRate.z) 64 | } 65 | }; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /SensingKit/SKHeading.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeading.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKHeadingConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKHeading : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKHeadingConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKHeading.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeading.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKHeading.h" 26 | #import "SKHeadingData.h" 27 | 28 | @import CoreLocation; 29 | 30 | 31 | @interface SKHeading () 32 | 33 | @property (nonatomic, strong) CLLocationManager *locationManager; 34 | 35 | @end 36 | 37 | 38 | @implementation SKHeading 39 | 40 | - (instancetype)initWithConfiguration:(SKHeadingConfiguration *)configuration 41 | { 42 | if (self = [super init]) 43 | { 44 | self.locationManager = [[CLLocationManager alloc] init]; 45 | self.locationManager.delegate = self; 46 | self.configuration = configuration; 47 | } 48 | return self; 49 | } 50 | 51 | #pragma mark Configuration 52 | 53 | - (void)setConfiguration:(SKConfiguration *)configuration 54 | { 55 | super.configuration = configuration; 56 | 57 | // Cast the configuration instance 58 | SKHeadingConfiguration *headingConfiguration = (SKHeadingConfiguration *)configuration; 59 | 60 | // Make the required updates on the sensor 61 | self.locationManager.headingFilter = headingConfiguration.headingFilter; 62 | self.locationManager.headingOrientation = headingConfiguration.headingOrientation; 63 | } 64 | 65 | #pragma mark Sensing 66 | 67 | + (BOOL)isSensorAvailable 68 | { 69 | return [CLLocationManager headingAvailable]; 70 | } 71 | 72 | - (BOOL)startSensing:(NSError **)error 73 | { 74 | if (![super startSensing:error]) { 75 | return NO; 76 | } 77 | 78 | if (![SKHeading isSensorAvailable]) 79 | { 80 | if (error) { 81 | 82 | NSDictionary *userInfo = @{ 83 | NSLocalizedDescriptionKey: NSLocalizedString(@"Heading sensor is not available.", nil), 84 | }; 85 | 86 | *error = [NSError errorWithDomain:SKErrorDomain 87 | code:SKSensorNotAvailableError 88 | userInfo:userInfo]; 89 | } 90 | return NO; 91 | } 92 | 93 | [self.locationManager startUpdatingHeading]; 94 | 95 | return YES; 96 | } 97 | 98 | - (BOOL)stopSensing:(NSError **)error 99 | { 100 | [self.locationManager stopUpdatingHeading]; 101 | 102 | return [super stopSensing:error]; 103 | } 104 | 105 | - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(nonnull CLHeading *)newHeading 106 | { 107 | // Ignore data if not accurate 108 | if (newHeading.headingAccuracy < 0) 109 | return; 110 | 111 | SKHeadingData *data = [[SKHeadingData alloc] initWithHeading:newHeading]; 112 | [self submitSensorData:data error:NULL]; 113 | } 114 | 115 | - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 116 | { 117 | [self submitSensorData:nil error:error]; 118 | } 119 | 120 | - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager 121 | { 122 | SKHeadingConfiguration *headingConfiguration = (SKHeadingConfiguration *)self.configuration; 123 | return headingConfiguration.displayHeadingCalibration; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /SensingKit/SKHeadingConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeadingConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | @import CoreLocation; 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | /** 34 | * An instance of SKHeadingConfiguration can be used to configure the Heading sensor. 35 | */ 36 | @interface SKHeadingConfiguration : SKConfiguration 37 | 38 | /** 39 | * The minimum angular change (measured in degrees) required to report new heading sensor data. 40 | */ 41 | @property (nonatomic) CLLocationDegrees headingFilter; 42 | 43 | /** 44 | * The physical orientation of the device, used to compute the heading values more accurately. 45 | */ 46 | @property (nonatomic) CLDeviceOrientation headingOrientation; 47 | 48 | /** 49 | * Allow the heading calibration alert to be displayed in the device's screen or not. 50 | */ 51 | @property (nonatomic) BOOL displayHeadingCalibration; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /SensingKit/SKHeadingConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeadingConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKHeadingConfiguration.h" 26 | 27 | @implementation SKHeadingConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | _headingFilter = 1; 35 | _headingOrientation = CLDeviceOrientationPortrait; 36 | _displayHeadingCalibration = NO; 37 | } 38 | return self; 39 | } 40 | 41 | - (id)copyWithZone:(NSZone *)zone 42 | { 43 | SKHeadingConfiguration *configuration = [super copyWithZone:zone]; 44 | configuration.headingFilter = _headingFilter; 45 | configuration.headingOrientation = _headingOrientation; 46 | configuration.displayHeadingCalibration = _displayHeadingCalibration; 47 | 48 | return configuration; 49 | } 50 | 51 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 52 | { 53 | return sensorType == Heading; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /SensingKit/SKHeadingData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeadingData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | /** 30 | * An instance of SKHeadingData encapsulates measurements related to the Heading sensor. 31 | */ 32 | @interface SKHeadingData : SKSensorData 33 | 34 | - (instancetype)init NS_UNAVAILABLE; 35 | 36 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 37 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 38 | 39 | /** 40 | * Returns an SKHeadingData object, initialized with an instance of CLHeading. 41 | * 42 | * @param heading A CLHeading object that contains Heading related data. 43 | * 44 | * @return An SKHeadingData object. 45 | */ 46 | - (instancetype)initWithHeading:(CLHeading *)heading NS_DESIGNATED_INITIALIZER; 47 | 48 | /** 49 | * A CLHeading object contains data about the device's orientation relative to magnetic and true north. 50 | */ 51 | @property (nonatomic, readonly, copy) CLHeading *heading; 52 | 53 | /** 54 | * A string with a CSV formatted header that describes the data of the Heading sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 55 | * 56 | * @return A string with a CSV header. 57 | */ 58 | + (NSString *)csvHeader; 59 | 60 | @end 61 | 62 | NS_ASSUME_NONNULL_END 63 | -------------------------------------------------------------------------------- /SensingKit/SKHeadingData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKHeadingData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2017. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKHeadingData.h" 26 | 27 | @implementation SKHeadingData 28 | 29 | - (instancetype)initWithHeading:(CLHeading *)heading 30 | { 31 | if (self = [super initWithSensorType:Heading 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:heading.timestamp]]) 33 | { 34 | _heading = heading; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,magneticHeading,trueHeading,headingAccuracy,x,y,z"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%f,%f,%f,%f,%f,%f", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | _heading.magneticHeading, 50 | _heading.trueHeading, 51 | _heading.headingAccuracy, 52 | _heading.x, 53 | _heading.y, 54 | _heading.z 55 | ]; 56 | } 57 | 58 | - (NSDictionary *)dictionaryData 59 | { 60 | return @{ 61 | @"sensorType": @(self.sensorType), 62 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 63 | @"timestamp": self.timestamp.timestampDictionary, 64 | @"heading": @{ 65 | @"magneticHeading": @(_heading.magneticHeading), 66 | @"trueHeading": @(_heading.trueHeading), 67 | @"headingAccuracy": @(_heading.headingAccuracy), 68 | @"x": @(_heading.x), 69 | @"y": @(_heading.y), 70 | @"z": @(_heading.z) 71 | } 72 | }; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /SensingKit/SKLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKLocation.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKLocationConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKLocation : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKLocationConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKLocationConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKLocationConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | /** 30 | * These constants indicate the accuracy of the Location sensor. 31 | */ 32 | typedef NS_ENUM(NSUInteger, SKLocationAccuracy){ 33 | /** 34 | * Highest accuracy possible, combined with other sensor data. This accuracy is ideal for Navigation applications were the device can be plagged in a power source. 35 | */ 36 | SKLocationAccuracyBestForNavigation = 0, 37 | /** 38 | * Highest accuracy possible. 39 | */ 40 | SKLocationAccuracyBest, 41 | /** 42 | * Ten meters accuracy. 43 | */ 44 | SKLocationAccuracyNearestTenMeters, 45 | /** 46 | * One hundred meters accuracy. 47 | */ 48 | SKLocationAccuracyHundredMeters, 49 | /** 50 | * One kilometer accuracy. 51 | */ 52 | SKLocationAccuracyKilometer, 53 | /** 54 | * Three kilometers accuracy. 55 | */ 56 | SKLocationAccuracyThreeKilometers 57 | }; 58 | 59 | /** 60 | * These constants indicate the authorization of the Location sensor. 61 | */ 62 | typedef NS_ENUM(NSUInteger, SKLocationAuthorization){ 63 | /** 64 | * Location can be acquired only when the app is running in the foreground. 65 | */ 66 | SKLocationAuthorizationWhenInUse, 67 | /** 68 | * Location can be acquired even when the app is running in the background. 69 | */ 70 | SKLocationAuthorizationAlways 71 | }; 72 | 73 | NS_ASSUME_NONNULL_BEGIN 74 | 75 | /** 76 | * An instance of SKLocationConfiguration can be used to configure the Location sensor. 77 | */ 78 | @interface SKLocationConfiguration : SKConfiguration 79 | 80 | /** 81 | * Accuracy of the Location sensor, expressed as an SKLocationAccuracy enumerator. 82 | */ 83 | @property (nonatomic) SKLocationAccuracy locationAccuracy; 84 | 85 | /** 86 | * Authrorization of the Location sensor, expressed as an SKLocationAuthorization enumerator. 87 | * Value can either be When In Use (indicating that sensor will only be active while the app runs in the foreground) or Always (allowing the sensor to be active even when the app runs in the background). 88 | */ 89 | @property (nonatomic) SKLocationAuthorization locationAuthorization; 90 | 91 | /** 92 | * The minimum distance in meters that the device needs to move horizontally before the SKSensorDataHandler attached with an SKLocationData object is being called. 93 | */ 94 | @property (nonatomic) double distanceFilter; 95 | 96 | @end 97 | 98 | NS_ASSUME_NONNULL_END 99 | -------------------------------------------------------------------------------- /SensingKit/SKLocationConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKLocationConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKLocationConfiguration.h" 26 | 27 | @import CoreLocation; 28 | 29 | @implementation SKLocationConfiguration 30 | 31 | - (instancetype)init 32 | { 33 | if (self = [super init]) 34 | { 35 | // Set default values 36 | _locationAccuracy = SKLocationAccuracyBest; 37 | _locationAuthorization = SKLocationAuthorizationWhenInUse; 38 | _distanceFilter = kCLDistanceFilterNone; 39 | } 40 | return self; 41 | } 42 | 43 | - (id)copyWithZone:(NSZone *)zone 44 | { 45 | SKLocationConfiguration *configuration = [super copyWithZone:zone]; 46 | configuration.locationAccuracy = _locationAccuracy; 47 | configuration.locationAuthorization = _locationAuthorization; 48 | configuration.distanceFilter = _distanceFilter; 49 | 50 | return configuration; 51 | } 52 | 53 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 54 | { 55 | return sensorType == Location; 56 | } 57 | 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /SensingKit/SKLocationData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKLocationData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreLocation; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKLocationData encapsulates measurements related to the Location sensor. 34 | */ 35 | @interface SKLocationData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKLocationData object, initialized with an instance of CLLocation. 44 | * 45 | * @param location A CLLocation object that contains Location related data. 46 | * 47 | * @return An SKLocationData object. 48 | */ 49 | - (instancetype)initWithLocation:(CLLocation *)location NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * A CLLocation object contains data related to the location of the device, as well as the accuracy of the measurements. More specifically it provides location coordinates, altitude and the logical floor of the building that the user is located. It also provides the instantaneous speed and the course of the device when the user is moving. For more information, please refer to Apple's Core Location documentation. 53 | */ 54 | @property (nonatomic, readonly, copy) CLLocation *location; 55 | 56 | /** 57 | * A string with a CSV formatted header that describes the data of the Location sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 58 | * 59 | * @return A string with a CSV header. 60 | */ 61 | + (NSString *)csvHeader; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /SensingKit/SKLocationData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKLocationData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKLocationData.h" 26 | 27 | @implementation SKLocationData 28 | 29 | - (instancetype)initWithLocation:(CLLocation *)location 30 | { 31 | if (self = [super initWithSensorType:Location 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:location.timestamp]]) 33 | { 34 | _location = location; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,latitude,longitude,altitude,horizontalAccuracy,verticalAccuracy,speed,course"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%f,%f,%f,%f,%f,%f,%f", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | _location.coordinate.latitude, 50 | _location.coordinate.longitude, 51 | _location.altitude, 52 | _location.horizontalAccuracy, 53 | _location.verticalAccuracy, 54 | _location.speed, 55 | _location.course]; 56 | } 57 | 58 | - (NSDictionary *)dictionaryData 59 | { 60 | return @{ 61 | @"sensorType": @(self.sensorType), 62 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 63 | @"timestamp": self.timestamp.timestampDictionary, 64 | @"location": @{ 65 | @"coordinate": @{ 66 | @"latitude": @(_location.coordinate.latitude), 67 | @"longitude": @(_location.coordinate.longitude) 68 | }, 69 | @"altitude": @(_location.altitude), 70 | @"horizontalAccuracy": @(_location.horizontalAccuracy), 71 | @"verticalAccuracy": @(_location.verticalAccuracy), 72 | @"speed": @(_location.speed), 73 | @"course": @(_location.course) 74 | } 75 | }; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometer.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKMagnetometerConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKMagnetometer : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKMagnetometerConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometer.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometer.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMagnetometer.h" 26 | #import "SKMotionManager.h" 27 | #import "SKMagnetometerData.h" 28 | 29 | 30 | @interface SKMagnetometer () 31 | 32 | @property (nonatomic, strong) CMMotionManager *motionManager; 33 | 34 | @end 35 | 36 | 37 | @implementation SKMagnetometer 38 | 39 | - (instancetype)initWithConfiguration:(SKMagnetometerConfiguration *)configuration 40 | { 41 | if (self = [super init]) 42 | { 43 | self.motionManager = [SKMotionManager sharedMotionManager]; 44 | self.configuration = configuration; 45 | } 46 | return self; 47 | } 48 | 49 | 50 | #pragma mark Configuration 51 | 52 | - (void)setConfiguration:(SKConfiguration *)configuration 53 | { 54 | super.configuration = configuration; 55 | 56 | // Cast the configuration instance 57 | SKMagnetometerConfiguration *magnetometerConfiguration = (SKMagnetometerConfiguration *)configuration; 58 | 59 | // Make the required updates on the sensor 60 | self.motionManager.magnetometerUpdateInterval = 1.0 / magnetometerConfiguration.sampleRate; // Convert Hz into interval 61 | } 62 | 63 | 64 | #pragma mark Sensing 65 | 66 | + (BOOL)isSensorAvailable 67 | { 68 | return [SKMotionManager sharedMotionManager].isMagnetometerAvailable; 69 | } 70 | 71 | - (BOOL)startSensing:(NSError **)error 72 | { 73 | if (![super startSensing:error]) { 74 | return NO; 75 | } 76 | 77 | if (![SKMagnetometer isSensorAvailable]) 78 | { 79 | if (error) { 80 | 81 | NSDictionary *userInfo = @{ 82 | NSLocalizedDescriptionKey: NSLocalizedString(@"Magnetometer sensor is not available.", nil), 83 | }; 84 | 85 | *error = [NSError errorWithDomain:SKErrorDomain 86 | code:SKSensorNotAvailableError 87 | userInfo:userInfo]; 88 | } 89 | return NO; 90 | } 91 | 92 | [self.motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue currentQueue] 93 | withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) { 94 | 95 | if (error) { 96 | [self submitSensorData:nil error:error]; 97 | } else { 98 | SKMagnetometerData *data = [[SKMagnetometerData alloc] initWithMagnetometerData:magnetometerData]; 99 | [self submitSensorData:data error:NULL]; 100 | } 101 | 102 | }]; 103 | 104 | return YES; 105 | } 106 | 107 | - (BOOL)stopSensing:(NSError **)error 108 | { 109 | [self.motionManager stopMagnetometerUpdates]; 110 | 111 | return [super stopSensing:error]; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometerConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometerConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSampleRateConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKMagnetometerConfiguration can be used to configure the Magnetometer sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKMagnetometerConfiguration : SKSampleRateConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometerConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometerConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMagnetometerConfiguration.h" 26 | 27 | @implementation SKMagnetometerConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKMagnetometerConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Magnetometer; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometerData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometerData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKMagnetometerData encapsulates measurements related to the Magnetometer sensor. 34 | */ 35 | @interface SKMagnetometerData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKMagnetometerData object, initialized with a CMMagnetometerData structure. 44 | * 45 | * @param magnetometerData A structure that contains 3-axis magnetometer data. 46 | * 47 | * @return An SKMagnetometerData object. 48 | */ 49 | - (instancetype)initWithMagnetometerData:(CMMagnetometerData *)magnetometerData NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * A structure that contains 3-axis magnetometer data. 53 | */ 54 | @property (nonatomic, readonly) CMMagneticField magneticField; 55 | 56 | /** 57 | * A string with a CSV formatted header that describes the data of the Magnetometer sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 58 | * 59 | * @return A string with a CSV header. 60 | */ 61 | + (NSString *)csvHeader; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /SensingKit/SKMagnetometerData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMagnetometerData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMagnetometerData.h" 26 | 27 | @implementation SKMagnetometerData 28 | 29 | - (instancetype)initWithMagnetometerData:(CMMagnetometerData *)magnetometerData 30 | { 31 | if (self = [super initWithSensorType:Magnetometer 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:magnetometerData.timestamp]]) 33 | { 34 | _magneticField = magnetometerData.magneticField; 35 | } 36 | return self; 37 | } 38 | 39 | + (NSString *)csvHeader 40 | { 41 | return @"timestamp,timeIntervalSince1970,x,y,z"; 42 | } 43 | 44 | - (NSString *)csvString 45 | { 46 | return [NSString stringWithFormat:@"\"%@\",%f,%f,%f,%f", 47 | self.timestamp.timestampString, 48 | self.timestamp.timeIntervalSince1970, 49 | _magneticField.x, 50 | _magneticField.y, 51 | _magneticField.z]; 52 | } 53 | 54 | - (NSDictionary *)dictionaryData 55 | { 56 | return @{ 57 | @"sensorType": @(self.sensorType), 58 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 59 | @"timestamp": self.timestamp.timestampDictionary, 60 | @"magneticField": @{ 61 | @"x": @(_magneticField.x), 62 | @"y": @(_magneticField.y), 63 | @"z": @(_magneticField.z) 64 | } 65 | }; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /SensingKit/SKMicrophone.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMicrophone.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKMicrophoneConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKMicrophone : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKMicrophoneConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKMicrophoneConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMicrophoneConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMicrophoneConfiguration.h" 26 | 27 | @implementation SKMicrophoneConfiguration 28 | 29 | - (nonnull instancetype)initWithOutputDirectory:(nonnull NSURL *)outputDirectory withFilename:(nonnull NSString *)filename 30 | { 31 | if (self = [super init]) 32 | { 33 | _outputDirectory = outputDirectory; 34 | _filename = filename; 35 | 36 | // Set default values 37 | _recordingFormat = SKMicrophoneRecordingFormatMPEG4AAC; 38 | _recordingQuality = SKMicrophoneRecordingQualityMedium; 39 | _sampleRate = 44100.0; 40 | } 41 | return self; 42 | } 43 | 44 | - (id)copyWithZone:(NSZone *)zone 45 | { 46 | SKMicrophoneConfiguration *configuration = [super copyWithZone:zone]; 47 | configuration.outputDirectory = _outputDirectory; 48 | configuration.filename = _filename; 49 | configuration.recordingFormat = _recordingFormat; 50 | configuration.recordingQuality = _recordingQuality; 51 | configuration.sampleRate = _sampleRate; 52 | 53 | return configuration; 54 | } 55 | 56 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 57 | { 58 | return sensorType == Microphone; 59 | } 60 | 61 | + (NSString *)extensionForRecordingFormat:(SKMicrophoneRecordingFormat)recordingFormat 62 | { 63 | switch (recordingFormat) 64 | { 65 | case SKMicrophoneRecordingFormatLinearPCM: 66 | return @"caf"; 67 | 68 | case SKMicrophoneRecordingFormatMPEG4AAC: 69 | return @"m4a"; 70 | 71 | // Don't forget to break! 72 | 73 | default: 74 | // Internal Error. Should never happen. 75 | NSLog(@"Unknown SKMicrophoneRecordingFormat: %lu", (unsigned long)recordingFormat); 76 | abort(); 77 | } 78 | } 79 | 80 | - (NSURL *)recordingPath 81 | { 82 | NSString *extension = [SKMicrophoneConfiguration extensionForRecordingFormat:self.recordingFormat]; 83 | return [self.outputDirectory URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", self.filename, extension]]; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /SensingKit/SKMicrophoneData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMicrophoneData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKMicrophoneData encapsulates measurements related to the Microphone sensor. Since Microphone sensor records audio from the environment directly into the device's memory, an SKSensorData object represent a change in the state of the Microphone sensor (e.g. Started or Stopped). 33 | */ 34 | @interface SKMicrophoneData : SKSensorData 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 39 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 40 | 41 | /** 42 | * Returns an SKMicrophoneData object, initialized with the current state of the sensor and the timestamp. 43 | * 44 | * @param state Microphone sensor state. 45 | * @param timeInterval Time that the state of the sensor changed. 46 | * 47 | * @return An SKMicrophoneData object. 48 | */ 49 | - (instancetype)initWithState:(NSString *)state 50 | withTimeInterval:(NSTimeInterval)timeInterval NS_DESIGNATED_INITIALIZER; 51 | 52 | /** 53 | * A string with the state of Microphone sensor (e.g. Started or Stopped). 54 | */ 55 | @property (nonatomic, readonly, copy) NSString *state; 56 | 57 | /** 58 | * A string with a CSV formatted header that describes the data of the Microphone sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 59 | * 60 | * @return A string with a CSV header. 61 | */ 62 | + (NSString *)csvHeader; 63 | 64 | @end 65 | 66 | NS_ASSUME_NONNULL_END 67 | -------------------------------------------------------------------------------- /SensingKit/SKMicrophoneData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMicrophoneData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMicrophoneData.h" 26 | 27 | @implementation SKMicrophoneData 28 | 29 | - (instancetype)initWithState:(NSString *)state 30 | withTimeInterval:(NSTimeInterval)timeInterval 31 | { 32 | if (self = [super initWithSensorType:Microphone 33 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:timeInterval]]) 34 | { 35 | _state = state; 36 | } 37 | return self; 38 | } 39 | 40 | + (NSString *)csvHeader 41 | { 42 | return @"timestamp,timeIntervalSince1970,state"; 43 | } 44 | 45 | - (NSString *)csvString 46 | { 47 | return [NSString stringWithFormat:@"\"%@\",%f,%@", 48 | self.timestamp.timestampString, 49 | self.timestamp.timeIntervalSince1970, 50 | self.state]; 51 | } 52 | 53 | - (NSDictionary *)dictionaryData 54 | { 55 | return @{ 56 | @"sensorType": @(self.sensorType), 57 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 58 | @"timestamp": self.timestamp.timestampDictionary, 59 | @"microphone": @{ 60 | @"state": _state 61 | } 62 | }; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivity.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivity.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKMotionActivityConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKMotionActivity : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKMotionActivityConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivity.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivity.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMotionActivity.h" 26 | #import "SKMotionActivityData.h" 27 | 28 | @import CoreMotion; 29 | 30 | 31 | @interface SKMotionActivity () 32 | 33 | @property (nonatomic, strong) CMMotionActivityManager *motionActivityManager; 34 | 35 | @end 36 | 37 | 38 | @implementation SKMotionActivity 39 | 40 | - (instancetype)initWithConfiguration:(SKMotionActivityConfiguration *)configuration 41 | { 42 | if (self = [super init]) 43 | { 44 | self.motionActivityManager = [[CMMotionActivityManager alloc] init]; 45 | self.configuration = configuration; 46 | } 47 | return self; 48 | } 49 | 50 | 51 | #pragma mark Configuration 52 | 53 | - (void)setConfiguration:(SKConfiguration *)configuration 54 | { 55 | super.configuration = configuration; 56 | 57 | // Cast the configuration instance 58 | // SKMotionActivityConfiguration *motionActivityConfiguration = (SKMotionActivityConfiguration *)configuration; 59 | 60 | // Make the required updates on the sensor 61 | // 62 | } 63 | 64 | 65 | #pragma mark Sensing 66 | 67 | + (BOOL)isSensorAvailable 68 | { 69 | return [CMMotionActivityManager isActivityAvailable]; 70 | } 71 | 72 | - (BOOL)startSensing:(NSError **)error 73 | { 74 | if (![super startSensing:error]) { 75 | return NO; 76 | } 77 | 78 | if (![SKMotionActivity isSensorAvailable]) 79 | { 80 | if (error) { 81 | 82 | NSDictionary *userInfo = @{ 83 | NSLocalizedDescriptionKey: NSLocalizedString(@"SKMotionActivity sensor is not available.", nil), 84 | }; 85 | 86 | *error = [NSError errorWithDomain:SKErrorDomain 87 | code:SKSensorNotAvailableError 88 | userInfo:userInfo]; 89 | } 90 | return NO; 91 | } 92 | 93 | [self.motionActivityManager startActivityUpdatesToQueue:[NSOperationQueue currentQueue] 94 | withHandler:^(CMMotionActivity *activity) { 95 | SKMotionActivityData *data = [[SKMotionActivityData alloc] initWithMotionActivity:activity]; 96 | [self submitSensorData:data error:NULL]; 97 | }]; 98 | 99 | return YES; 100 | } 101 | 102 | - (BOOL)stopSensing:(NSError **)error 103 | { 104 | [self.motionActivityManager stopActivityUpdates]; 105 | 106 | return [super stopSensing:error]; 107 | } 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivityConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivityConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKMotionActivityConfiguration can be used to configure the Activity sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKMotionActivityConfiguration : SKConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivityConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivityConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMotionActivityConfiguration.h" 26 | 27 | @implementation SKMotionActivityConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKMotionActivityConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == MotionActivity; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivityData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivityData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKMotionActivityData encapsulates measurements related to the Motion Activity sensor. Activity is classified between Stationary, Walking, Running, Automotive, Cycling and Unknown. 34 | */ 35 | @interface SKMotionActivityData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKMotionActivityData object, initialized with an instance of CMMotionActivity. 44 | * 45 | * @param motionActivity A CMMotionActivity object that contains data related to the Motion Activity sensor. 46 | * 47 | * @return An SKMotionActivityData object. 48 | */ 49 | - (instancetype)initWithMotionActivity:(CMMotionActivity *)motionActivity NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * An instance of CMMotionActivity object contains data about the measured motion activity, classified between Stationary, Walking, Running, Automotive, Cycling and Unknown. 53 | */ 54 | @property (nonatomic, readonly, copy) CMMotionActivity *motionActivity; 55 | 56 | /** 57 | * Start date that the activity data are valid. 58 | */ 59 | @property (nonatomic, readonly, copy) SKSensorTimestamp *startDate; 60 | 61 | /** 62 | * A string with a CSV formatted header that describes the data of the Activity sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 63 | * 64 | * @return A string with a CSV header. 65 | */ 66 | + (NSString *)csvHeader; 67 | 68 | @end 69 | 70 | NS_ASSUME_NONNULL_END 71 | -------------------------------------------------------------------------------- /SensingKit/SKMotionActivityData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionActivityData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMotionActivityData.h" 26 | 27 | @implementation SKMotionActivityData 28 | 29 | - (instancetype)initWithMotionActivity:(CMMotionActivity *)motionActivity 30 | { 31 | if (self = [super initWithSensorType:MotionActivity 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromTimeInterval:motionActivity.timestamp]]) 33 | { 34 | _startDate = [SKSensorTimestamp sensorTimestampFromDate:motionActivity.startDate]; 35 | _motionActivity = motionActivity; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSString *)confidenceString 41 | { 42 | switch (_motionActivity.confidence) { 43 | case CMMotionActivityConfidenceHigh: 44 | return @"High"; 45 | 46 | case CMMotionActivityConfidenceMedium: 47 | return @"Medium"; 48 | 49 | case CMMotionActivityConfidenceLow: 50 | return @"Low"; 51 | 52 | default: 53 | NSLog(@"Warning: Unknown confidence: %d", (int)_motionActivity.confidence); 54 | return @"Unknown"; 55 | } 56 | } 57 | 58 | + (NSString *)csvHeader 59 | { 60 | return @"timestamp,timeIntervalSince1970,createDate,createDateSince1970,stationary,walking,running,automotive,cycling,unknown,confidence"; 61 | } 62 | 63 | - (NSString *)csvString 64 | { 65 | return [NSString stringWithFormat:@"\"%@\",%f,\"%@\",%f,%d,%d,%d,%d,%d,%d,%@", 66 | self.timestamp.timestampString, 67 | self.timestamp.timeIntervalSince1970, 68 | _startDate.timestampString, 69 | _startDate.timeIntervalSince1970, 70 | _motionActivity.stationary, 71 | _motionActivity.walking, 72 | _motionActivity.running, 73 | _motionActivity.automotive, 74 | _motionActivity.cycling, 75 | _motionActivity.unknown, 76 | [self confidenceString]]; 77 | } 78 | 79 | - (NSDictionary *)dictionaryData 80 | { 81 | return @{ 82 | @"sensorType": @(self.sensorType), 83 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 84 | @"timestamp": self.timestamp.timestampDictionary, 85 | @"startDate": self.startDate.timestampDictionary, 86 | @"activity": @{ 87 | @"stationary": @(_motionActivity.stationary), 88 | @"walking": @(_motionActivity.walking), 89 | @"running": @(_motionActivity.running), 90 | @"automotive": @(_motionActivity.automotive), 91 | @"cycling": @(_motionActivity.cycling), 92 | @"unknown": @(_motionActivity.unknown) 93 | } 94 | }; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /SensingKit/SKMotionManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionManager.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | @import CoreMotion; 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | @interface SKMotionManager : NSObject 32 | 33 | - (instancetype)init NS_UNAVAILABLE; 34 | 35 | + (CMMotionManager *)sharedMotionManager; 36 | 37 | @end 38 | 39 | NS_ASSUME_NONNULL_END -------------------------------------------------------------------------------- /SensingKit/SKMotionManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKMotionManager.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKMotionManager.h" 26 | 27 | 28 | @implementation SKMotionManager 29 | 30 | + (CMMotionManager *)sharedMotionManager 31 | { 32 | static CMMotionManager *sharedMotionManager; 33 | @synchronized(self) 34 | { 35 | if (!sharedMotionManager) 36 | { 37 | sharedMotionManager = [[CMMotionManager alloc] init]; 38 | } 39 | 40 | return sharedMotionManager; 41 | } 42 | return sharedMotionManager; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /SensingKit/SKPedometer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometer.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKPedometerConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKPedometer : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKPedometerConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKPedometer.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometer.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKPedometer.h" 26 | #import "SKPedometerData.h" 27 | 28 | @import CoreMotion; 29 | 30 | 31 | @interface SKPedometer () 32 | 33 | @property (nonatomic, strong) CMPedometer *pedometer; 34 | 35 | @end 36 | 37 | 38 | @implementation SKPedometer 39 | 40 | - (instancetype)initWithConfiguration:(SKPedometerConfiguration *)configuration 41 | { 42 | if (self = [super init]) 43 | { 44 | self.pedometer = [[CMPedometer alloc] init]; 45 | self.configuration = configuration; 46 | } 47 | return self; 48 | } 49 | 50 | 51 | #pragma mark Configuration 52 | 53 | - (void)setConfiguration:(SKConfiguration *)configuration 54 | { 55 | super.configuration = configuration; 56 | 57 | // Cast the configuration instance 58 | // SKPedometerConfiguration *pedometerConfiguration = (SKPedometerConfiguration *)configuration; 59 | 60 | // Make the required updates on the sensor 61 | // 62 | } 63 | 64 | 65 | #pragma mark Sensing 66 | 67 | + (BOOL)isSensorAvailable 68 | { 69 | return [CMPedometer isStepCountingAvailable]; 70 | } 71 | 72 | 73 | - (BOOL)startSensing:(NSError **)error 74 | { 75 | if (![super startSensing:error]) { 76 | return NO; 77 | } 78 | 79 | if (![SKPedometer isSensorAvailable]) 80 | { 81 | if (error) { 82 | 83 | NSDictionary *userInfo = @{ 84 | NSLocalizedDescriptionKey: NSLocalizedString(@"SKPedometer sensor is not available.", nil), 85 | }; 86 | 87 | *error = [NSError errorWithDomain:SKErrorDomain 88 | code:SKSensorNotAvailableError 89 | userInfo:userInfo]; 90 | } 91 | return NO; 92 | } 93 | 94 | [self.pedometer startPedometerUpdatesFromDate:[NSDate date] 95 | withHandler:^(CMPedometerData *pedometerData, NSError *error) { 96 | 97 | if (error) { 98 | [self submitSensorData:nil error:error]; 99 | } 100 | else { 101 | SKPedometerData *data = [[SKPedometerData alloc] initWithPedometerData:pedometerData]; 102 | [self submitSensorData:data error:NULL]; 103 | } 104 | }]; 105 | 106 | return YES; 107 | } 108 | 109 | - (BOOL)stopSensing:(NSError **)error 110 | { 111 | [self.pedometer stopPedometerUpdates]; 112 | 113 | return [super stopSensing:error]; 114 | } 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /SensingKit/SKPedometerConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometerConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKPedometerConfiguration can be used to configure the Pedometer sensor. No configuration is available at this moment. 33 | */ 34 | @interface SKPedometerConfiguration : SKConfiguration 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /SensingKit/SKPedometerConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometerConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKPedometerConfiguration.h" 26 | 27 | @implementation SKPedometerConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | } 35 | return self; 36 | } 37 | 38 | - (id)copyWithZone:(NSZone *)zone 39 | { 40 | SKPedometerConfiguration *configuration = [super copyWithZone:zone]; 41 | 42 | return configuration; 43 | } 44 | 45 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 46 | { 47 | return sensorType == Pedometer; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /SensingKit/SKPedometerData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometerData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | @import CoreMotion; 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * An instance of SKPedometerData encapsulates measurements related to the Pedometer sensor. 34 | */ 35 | @interface SKPedometerData : SKSensorData 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 40 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 41 | 42 | /** 43 | * Returns an SKPedometer object, initialized with an instance of CMPedometerData. 44 | * 45 | * @param pedometerData A CMPedometerData object that contains data related to the Pedometer sensor. 46 | * 47 | * @return An SKPedometer object. 48 | */ 49 | - (instancetype)initWithPedometerData:(CMPedometerData *)pedometerData NS_DESIGNATED_INITIALIZER; 50 | 51 | /** 52 | * An instance of CMPedometerData object contains data about the distance travelled the user by foot. 53 | */ 54 | @property (nonatomic, readonly, copy) CMPedometerData *pedometerData; 55 | 56 | /** 57 | * Start date that the pedometer data are valid. 58 | */ 59 | @property (nonatomic, readonly, copy) SKSensorTimestamp *startDate; 60 | 61 | /** 62 | * End date that the pedometer data are valid. 63 | */ 64 | @property (nonatomic, readonly, copy) SKSensorTimestamp *endDate; 65 | 66 | /** 67 | * A string with a CSV formatted header that describes the data of the Pedometer sensor. This method is useful in combination with the csvString instance method of an SKSensorData object. 68 | * 69 | * @return A string with a CSV header. 70 | */ 71 | + (NSString *)csvHeader; 72 | 73 | @end 74 | 75 | NS_ASSUME_NONNULL_END 76 | -------------------------------------------------------------------------------- /SensingKit/SKPedometerData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKPedometerData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKPedometerData.h" 26 | 27 | @implementation SKPedometerData 28 | 29 | - (instancetype)initWithPedometerData:(CMPedometerData *)pedometerData 30 | { 31 | if (self = [super initWithSensorType:Pedometer 32 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:pedometerData.startDate]]) 33 | { 34 | // No need to have two instances of the same timestamp. We point startDate to self.timestamp 35 | _startDate = self.timestamp; 36 | _endDate = [SKSensorTimestamp sensorTimestampFromDate:pedometerData.endDate]; 37 | _pedometerData = pedometerData; 38 | } 39 | return self; 40 | } 41 | 42 | + (NSString *)csvHeader 43 | { 44 | return @"startTimestamp,startTimeIntervalSince1970,endTimestamp,endTimeIntervalSince1970,numberOfSteps,distance,currentPace,currentCadence,floorsAscended,floorsDescended"; 45 | } 46 | 47 | - (NSString *)csvString 48 | { 49 | return [NSString stringWithFormat:@"\"%@\",%f,\"%@\",%f,%lu,%lu,%lu,%lu,%lu,%lu", 50 | self.startDate.timestampString, 51 | self.startDate.timeIntervalSince1970, 52 | self.endDate.timestampString, 53 | self.endDate.timeIntervalSince1970, 54 | (unsigned long)_pedometerData.numberOfSteps.unsignedIntegerValue, 55 | (unsigned long)_pedometerData.distance.unsignedIntegerValue, 56 | (unsigned long)_pedometerData.currentPace.unsignedIntegerValue, 57 | (unsigned long)_pedometerData.currentCadence.unsignedIntegerValue, 58 | (unsigned long)_pedometerData.floorsAscended.unsignedIntegerValue, 59 | (unsigned long)_pedometerData.floorsDescended.unsignedIntegerValue]; 60 | } 61 | 62 | - (NSDictionary *)dictionaryData 63 | { 64 | return @{ 65 | @"sensorType": @(self.sensorType), 66 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 67 | @"startDate": self.startDate.timestampDictionary, 68 | @"endDate": self.endDate.timestampDictionary, 69 | @"pedometerData": @{ 70 | @"numberOfSteps": _pedometerData.numberOfSteps, 71 | @"distance": _pedometerData.distance, 72 | @"currentPace": _pedometerData.currentPace, 73 | @"currentCadence": _pedometerData.currentCadence, 74 | @"floorsAscended": _pedometerData.floorsAscended, 75 | @"floorsDescended": _pedometerData.floorsDescended 76 | } 77 | }; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /SensingKit/SKProximityData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKProximityData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * An instance of SKProximityData encapsulates an array of Device Data (e.g. SKiBeaconDeviceData). 33 | */ 34 | @interface SKProximityData : SKSensorData 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 39 | withTimestamp:(SKSensorTimestamp *)timestamp NS_UNAVAILABLE; 40 | 41 | /** 42 | * Returns an SKProximityData object, initialized with an array of Device Data objects as well as the time that the scan was completed. 43 | * 44 | * @param sensorType The type of the sensor that produced this data object. 45 | * @param timestamp The time that this data log was captured. 46 | * @param devices An array that holds the Device Data objects. 47 | * 48 | * @return An SKProximityData object. 49 | */ 50 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 51 | withTimestamp:(NSDate *)timestamp 52 | withDevices:(NSArray *)devices NS_DESIGNATED_INITIALIZER; 53 | 54 | /** 55 | * An array that holds the Device Data objects. 56 | */ 57 | @property (nonatomic, readonly, copy) NSArray *devices; 58 | 59 | /** 60 | * As the CSV header depends on the encapsulated Device Data objects, this method always returns nil. 61 | * 62 | * @return Always nil. 63 | */ 64 | + (nullable NSString *)csvHeader; 65 | 66 | @end 67 | 68 | NS_ASSUME_NONNULL_END 69 | -------------------------------------------------------------------------------- /SensingKit/SKProximityData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKProximityData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKProximityData.h" 26 | 27 | @implementation SKProximityData 28 | 29 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 30 | withTimestamp:(NSDate *)timestamp 31 | withDevices:(NSArray *)devices 32 | { 33 | if (self = [super initWithSensorType:sensorType 34 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:timestamp]]) 35 | { 36 | _devices = devices; 37 | } 38 | return self; 39 | } 40 | 41 | + (NSString *)csvHeader 42 | { 43 | // csvHeader depends on the encapsulated Device Data objects. 44 | return @""; 45 | } 46 | 47 | - (NSString *)csvString 48 | { 49 | return [[self.devices valueForKey:@"description"] componentsJoinedByString:@"\n"]; 50 | } 51 | 52 | - (NSDictionary *)dictionaryData 53 | { 54 | // Get the dictionaries of all devices 55 | NSMutableArray *dictionaries = [[NSMutableArray alloc] initWithCapacity:self.devices.count]; 56 | 57 | for (SKSensorData *device in self.devices) { 58 | [dictionaries addObject:device.dictionaryData]; 59 | } 60 | 61 | return @{ 62 | @"sensorType": @(self.sensorType), 63 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 64 | @"timestamp": self.timestamp.timestampDictionary, 65 | @"devices": dictionaries 66 | }; 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /SensingKit/SKSampleRateConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSampleRateConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | /** 32 | * This is the base class for all motion sensors that require a sample rate configuration. These sensors are Accelerometer, Gyroscope, Magnetometer and Device Motion. 33 | */ 34 | @interface SKSampleRateConfiguration : SKConfiguration 35 | 36 | /** 37 | * The Sample Rate of the sensor in Hz. 38 | */ 39 | @property (nonatomic) NSUInteger sampleRate; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /SensingKit/SKSampleRateConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKSampleRateConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKSampleRateConfiguration.h" 26 | 27 | @implementation SKSampleRateConfiguration 28 | 29 | - (instancetype)init 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | _sampleRate = 100; // Hz 35 | } 36 | return self; 37 | } 38 | 39 | - (id)copyWithZone:(NSZone *)zone 40 | { 41 | SKSampleRateConfiguration *configuration = [super copyWithZone:zone]; 42 | configuration.sampleRate = _sampleRate; 43 | 44 | return configuration; 45 | } 46 | 47 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 48 | { 49 | // Internal Error. Should never happen. 50 | NSLog(@"Internal Error: isValidForSensor method is not implemented in the inherited SKSampleRateConfiguration class."); 51 | abort(); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /SensingKit/SKSensorData.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorData.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | #import "SKSensorType.h" 27 | #import "SKSensorTimestamp.h" 28 | #import "NSString+SensorType.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | * This is the base class for all Sensor Data objects. A subclass of SKSensorData object is delivered through the SKSensorDataHandler, combined with the related SKSensorType. 34 | */ 35 | @interface SKSensorData : NSObject 36 | 37 | - (instancetype)init NS_UNAVAILABLE; 38 | 39 | /** 40 | * Returns an SKSensorData object, initialized with the given SKSensorType and SKSensorTimestamp. 41 | * 42 | * @param sensorType The type of the sensor that produced this data object. 43 | * @param timestamp The time were this data log was captured. 44 | * 45 | * @return A new SKSensorData object. 46 | */ 47 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 48 | withTimestamp:(SKSensorTimestamp *)timestamp NS_DESIGNATED_INITIALIZER; 49 | 50 | /** 51 | * The type of the sensor that produced this data object. 52 | */ 53 | @property (nonatomic, readonly) SKSensorType sensorType; 54 | 55 | /** 56 | * The time were this data log was captured. 57 | */ 58 | @property (nonatomic, readonly, copy) SKSensorTimestamp *timestamp; 59 | 60 | /** 61 | * Returns a string with all the sensor data elements into CSV format. For a description of the element types, sensor class method csvHeader can be used. 62 | */ 63 | @property (nonatomic, readonly, copy) NSString *csvString; 64 | 65 | /** 66 | * Returns a dictionary that encapsulates all the sensor data elements. 67 | */ 68 | @property (nonatomic, readonly, copy) NSDictionary *dictionaryData; 69 | 70 | @end 71 | 72 | NS_ASSUME_NONNULL_END -------------------------------------------------------------------------------- /SensingKit/SKSensorData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKSensorData.h" 26 | 27 | @implementation SKSensorData 28 | 29 | - (instancetype)initWithSensorType:(SKSensorType)sensorType 30 | withTimestamp:(SKSensorTimestamp *)timestamp 31 | { 32 | if (self = [super init]) 33 | { 34 | _sensorType = sensorType; 35 | _timestamp = timestamp; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSString *)csvString 41 | { 42 | // Internal Error. Should never happen. 43 | NSLog(@"Internal Error: csvString method is not implemented in the inherited SKSensorData class."); 44 | abort(); 45 | } 46 | 47 | - (NSDictionary *)dictionaryData 48 | { 49 | // Internal Error. Should never happen. 50 | NSLog(@"Internal Error: dictionaryData method is not implemented in the inherited SKSensorData class."); 51 | abort(); 52 | } 53 | 54 | - (NSString *)description 55 | { 56 | return self.csvString; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /SensingKit/SKSensorDataHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorDataHandler.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorData.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | 32 | /** 33 | Βlock to be invoked when new sensor data is available. You can cast the sensorData object into the actual sensor data (e.g. SKAccelerometerData), based on the reported sensorType. 34 | 35 | @param sensorType The type of the sensor producing the SKSensorData object. 36 | @param sensorData The new sensor data produced by the SKSensorType sensor. 37 | @param error This pointer is NULL if an error has occured and sensor data is not available. 38 | */ 39 | typedef void (^SKSensorDataHandler)(SKSensorType sensorType, SKSensorData * __nullable sensorData, NSError * __nullable error); 40 | 41 | NS_ASSUME_NONNULL_END 42 | -------------------------------------------------------------------------------- /SensingKit/SKSensorManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorManager.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKSensorType.h" 28 | #import "SKSensorDataHandler.h" 29 | #import "SKConfiguration.h" 30 | 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | @interface SKSensorManager : NSObject 35 | 36 | /** @name Sensor Status */ 37 | 38 | + (BOOL)isSensorAvailable:(SKSensorType)sensorType; 39 | 40 | - (BOOL)isSensorRegistered:(SKSensorType)sensorType; 41 | 42 | - (BOOL)isSensorSensing:(SKSensorType)sensorType; 43 | 44 | 45 | /** @name Sensor Registration and Configuration */ 46 | 47 | - (BOOL)registerSensor:(SKSensorType)sensorType 48 | withConfiguration:(nullable SKConfiguration *)configuration 49 | error:(NSError * _Nullable * _Nullable)error; 50 | 51 | - (BOOL)deregisterSensor:(SKSensorType)sensorType 52 | error:(NSError * _Nullable * _Nullable)error; 53 | 54 | - (BOOL)setConfiguration:(nullable SKConfiguration *)configuration 55 | toSensor:(SKSensorType)sensorType 56 | error:(NSError * _Nullable * _Nullable)error; 57 | 58 | - (nullable SKConfiguration *)getConfigurationFromSensor:(SKSensorType)sensorType 59 | error:(NSError * _Nullable * _Nullable)error; 60 | 61 | 62 | /** @name Sensor Subscription and Unsubscription */ 63 | 64 | - (BOOL)subscribeToSensor:(SKSensorType)sensorType 65 | withHandler:(SKSensorDataHandler)handler 66 | error:(NSError * _Nullable * _Nullable)error; 67 | 68 | - (BOOL)unsubscribeAllHandlersFromSensor:(SKSensorType)sensorType 69 | error:(NSError * _Nullable * _Nullable)error; 70 | 71 | + (NSString *)csvHeaderForSensor:(SKSensorType)sensorType; 72 | 73 | 74 | /** @name Continuous Sensing */ 75 | 76 | - (BOOL)startContinuousSensingWithSensor:(SKSensorType)sensorType 77 | error:(NSError * _Nullable * _Nullable)error; 78 | 79 | - (BOOL)stopContinuousSensingWithSensor:(SKSensorType)sensorType 80 | error:(NSError * _Nullable * _Nullable)error; 81 | 82 | - (BOOL)startContinuousSensingWithAllRegisteredSensors:(NSError * _Nullable * _Nullable)error; 83 | 84 | - (BOOL)stopContinuousSensingWithAllRegisteredSensors:(NSError * _Nullable * _Nullable)error; 85 | 86 | @end 87 | 88 | NS_ASSUME_NONNULL_END 89 | -------------------------------------------------------------------------------- /SensingKit/SKSensorTimestamp.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorTimestamp.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | /** 30 | * SKSensorTimestamp object represent a single point in time. 31 | */ 32 | @interface SKSensorTimestamp : NSObject 33 | 34 | - (instancetype)init NS_UNAVAILABLE; 35 | 36 | /** 37 | * Creates and returns a new SKSensorTimestamp from an NSDate object. If the sensor does not provide an NSDate object, [NSDate date] can be used. 38 | * 39 | * @param date The absolute date that this SKSensorTimestamp object should be initialized with. 40 | * 41 | * @return A new SKSensorTimestamp object initialized with the (NSDate *)date parameter. 42 | */ 43 | + (instancetype)sensorTimestampFromDate:(NSDate *)date; 44 | 45 | /** 46 | * Creates and returns a new SKSensorTimestamp from a NSTimeInterval object. The time interval should be relative to the last time the device was boot. If the sensor does not provide this value, [NSProcessInfo processInfo].systemUptime can be used. 47 | * 48 | * @param timeInterval The number of seconds since the last time the device was boot. 49 | * 50 | * @return A new SKSensorTimestamp object initialized relative to the timeInterval parameter. 51 | */ 52 | + (instancetype)sensorTimestampFromTimeInterval:(NSTimeInterval)timeInterval; 53 | 54 | /** 55 | * Returns an NSDate object of the sensor timestamp. 56 | */ 57 | @property (nonatomic, readonly, copy) NSDate *timestamp; 58 | 59 | /** 60 | * Returns the interval between the timestamp and the last time the device was boot. 61 | */ 62 | @property (nonatomic, readonly) NSTimeInterval timeIntervalSinceLastBoot; 63 | 64 | /** 65 | * Returns a dictionary that encapsulates the timestamp as a string, the interval since 1970, and the interval since the device was boot. 66 | */ 67 | @property (nonatomic, readonly, copy) NSDictionary *timestampDictionary; 68 | 69 | /** 70 | * Returns a string representation of the timestamp. The format of the string is "yyyy-MM-dd HH:mm:ss.SSS ZZZ". 71 | */ 72 | @property (nonatomic, readonly, copy) NSString *timestampString; 73 | 74 | /** 75 | * Returns the interval between the timestamp and 00:00:00 UTC on 1 January 1970. 76 | */ 77 | @property (nonatomic, readonly) NSTimeInterval timeIntervalSince1970; 78 | 79 | @end 80 | 81 | NS_ASSUME_NONNULL_END -------------------------------------------------------------------------------- /SensingKit/SKSensorTimestamp.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorTimestamp.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKSensorTimestamp.h" 26 | #include 27 | 28 | @implementation SKSensorTimestamp 29 | 30 | + (instancetype)sensorTimestampFromDate:(NSDate *)date 31 | { 32 | return [[SKSensorTimestamp alloc] initWithDate:date withTimeInterval:date.timeIntervalSince1970]; 33 | } 34 | 35 | + (instancetype)sensorTimestampFromTimeInterval:(NSTimeInterval)timeInterval 36 | { 37 | NSTimeInterval timestampOffset = [SKSensorTimestamp timestampOffset]; 38 | NSTimeInterval fixedInterval = timeInterval + timestampOffset; 39 | NSDate *date = [NSDate dateWithTimeIntervalSince1970:fixedInterval]; 40 | return [[SKSensorTimestamp alloc] initWithDate:date withTimeInterval:fixedInterval]; 41 | } 42 | 43 | - (instancetype)initWithDate:(NSDate *)date 44 | withTimeInterval:(NSTimeInterval)timeInterval 45 | { 46 | if (self = [super init]) 47 | { 48 | _timestamp = date; 49 | _timeIntervalSinceLastBoot = timeInterval; 50 | } 51 | return self; 52 | } 53 | 54 | + (NSTimeInterval)timestampOffset 55 | { 56 | NSTimeInterval upTime = [NSProcessInfo processInfo].systemUptime; 57 | NSTimeInterval nowTimeIntervalSince1970 = [[NSDate date] timeIntervalSince1970]; 58 | return nowTimeIntervalSince1970 - upTime; 59 | } 60 | 61 | - (id)copyWithZone:(NSZone *)zone 62 | { 63 | SKSensorTimestamp *sensorTimestamp = [[[self class] alloc] initWithDate:_timestamp 64 | withTimeInterval:_timeIntervalSinceLastBoot]; 65 | 66 | return sensorTimestamp; 67 | } 68 | 69 | + (NSDateFormatter *)dateFormatter 70 | { 71 | static NSDateFormatter *dateFormatter; 72 | 73 | if (!dateFormatter) 74 | { 75 | dateFormatter = [[NSDateFormatter alloc] init]; 76 | dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; 77 | dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0.0]; 78 | dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS ZZZ"; 79 | } 80 | return dateFormatter; 81 | } 82 | 83 | - (NSDictionary *)timestampDictionary 84 | { 85 | return @{ 86 | @"timestamp": self.timestampString, 87 | @"timeIntervalSince1970": @(self.timeIntervalSince1970), 88 | @"timeIntervalSinceLastBoot": @(self.timeIntervalSinceLastBoot) 89 | }; 90 | } 91 | 92 | - (NSString *)timestampString 93 | { 94 | return [[SKSensorTimestamp dateFormatter] stringFromDate:_timestamp]; 95 | } 96 | 97 | - (NSTimeInterval)timeIntervalSince1970 98 | { 99 | return _timestamp.timeIntervalSince1970; 100 | } 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /SensingKit/SKiBeaconDeviceData.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKiBeaconDeviceData.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKiBeaconDeviceData.h" 26 | 27 | @implementation SKiBeaconDeviceData 28 | 29 | - (instancetype)initWithTimestamp:(NSDate *)timestamp 30 | withMajor:(uint16_t)major 31 | withMinor:(uint16_t)minor 32 | withAccuracy:(CLLocationAccuracy)accuracy 33 | withProximity:(CLProximity)proximity 34 | withRssi:(NSInteger)rssi 35 | { 36 | if (self = [super initWithSensorType:iBeaconProximity 37 | withTimestamp:[SKSensorTimestamp sensorTimestampFromDate:timestamp]]) 38 | { 39 | _major = major; 40 | _minor = minor; 41 | _accuracy = accuracy; 42 | _proximity = proximity; 43 | _rssi = rssi; 44 | } 45 | return self; 46 | } 47 | 48 | - (NSString *)proximityString 49 | { 50 | switch (_proximity) { 51 | case CLProximityImmediate: 52 | return @"Immediate"; 53 | 54 | case CLProximityNear: 55 | return @"Near"; 56 | 57 | case CLProximityFar: 58 | return @"Far"; 59 | 60 | case CLProximityUnknown: 61 | return @"Unknown"; 62 | 63 | default: 64 | NSLog(@"Warning: Unknown proximity: %d", (int)_proximity); 65 | return @"Unknown"; 66 | } 67 | } 68 | 69 | + (NSString *)csvHeader 70 | { 71 | return @"timestamp,timeIntervalSince1970,major,minor,accuracy,proximity,rssi"; 72 | } 73 | 74 | - (NSString *)csvString 75 | { 76 | return [NSString stringWithFormat:@"\"%@\",%f,%lu,%lu,%f,%@,%ld", 77 | self.timestamp.timestampString, 78 | self.timestamp.timeIntervalSince1970, 79 | (unsigned long)_major, 80 | (unsigned long)_minor, 81 | _accuracy, 82 | self.proximityString, 83 | (long)_rssi]; 84 | } 85 | 86 | - (NSDictionary *)dictionaryData 87 | { 88 | return @{ 89 | @"sensorType": @(self.sensorType), 90 | @"sensorTypeString": [NSString stringWithSensorType:self.sensorType], 91 | @"timestamp": self.timestamp.timestampDictionary, 92 | @"iBeacon": @{ 93 | @"major": @(_major), 94 | @"minor": @(_minor), 95 | @"accuracy": @(_accuracy), 96 | @"proximity": @(_proximity), 97 | @"proximityString": self.proximityString, 98 | @"rssi": @(_rssi) 99 | } 100 | }; 101 | } 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /SensingKit/SKiBeaconProximity.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKiBeaconProximity.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKAbstractSensor.h" 28 | #import "SKiBeaconProximityConfiguration.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface SKiBeaconProximity : SKAbstractSensor 33 | 34 | + (BOOL)isSensorAvailable; 35 | 36 | - (instancetype)init NS_UNAVAILABLE; 37 | 38 | - (instancetype)initWithConfiguration:(SKiBeaconProximityConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /SensingKit/SKiBeaconProximityConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKiBeaconProximityConfiguration.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | #import "SKConfiguration.h" 28 | 29 | /** 30 | * These constants indicate the mode of the iBeacon™ Proximity sensor. 31 | */ 32 | typedef NS_ENUM(NSUInteger, SKiBeaconProximityMode){ 33 | /** 34 | * Scan only mode ranges for other iBeacons registered to the same UUID that exist in range. 35 | */ 36 | SKiBeaconProximityModeScanOnly = 0, 37 | /** 38 | * Broadcast only mode broadcasts an iBeacon™ signal to nearby devices. 39 | */ 40 | SKiBeaconProximityModeBroadcastOnly, 41 | /** 42 | * This mode both ranges and broadcasts an iBeacon™ signal at the same time. 43 | */ 44 | SKiBeaconProximityModeScanAndBroadcast 45 | }; 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | /** 50 | * An instance of SKiBeaconProximityConfiguration can be used to configure the iBeacon™ Proximity sensor. 51 | */ 52 | @interface SKiBeaconProximityConfiguration : SKConfiguration 53 | 54 | - (instancetype)init NS_UNAVAILABLE; 55 | 56 | /** 57 | * Returns an SKiBeaconProximityConfiguration object, initialized with the UUID . 58 | * 59 | * @param UUID The Universally Unique Identifiers (UUID) that will be used to distinguish the iBeacon™ devices of this application with other devices. Only iBeacons with the same UUID will be identified. 60 | * 61 | * @return A new SKiBeaconProximityConfiguration object. 62 | */ 63 | - (instancetype)initWithUUID:(NSUUID *)UUID NS_DESIGNATED_INITIALIZER; 64 | 65 | /** 66 | * The Universally Unique Identifiers (UUID) that will be used to distinguish the iBeacon™ devices of this application with other devices. Only iBeacons with the same UUID will be identified. 67 | */ 68 | @property (nonatomic, copy) NSUUID *UUID; 69 | 70 | /** 71 | * Mode of the iBeacon™ Proximity sensor. It can Scan for other iBeacon™ devices in range, Broadcast an iBeacon™ signal to other devices, or both Scan and Broadcast simultaneously. 72 | */ 73 | @property (nonatomic) SKiBeaconProximityMode mode; 74 | 75 | /** 76 | * A 16-bit unsigned integer identifier used to identify each device uniquelly. It ranges between 0 and 65535. This identifier can be used in combination with the minor identifier. 77 | */ 78 | @property (nonatomic) uint16_t major; 79 | 80 | /** 81 | * A 16-bit unsigned integer identifier used to identify each device uniquelly. It ranges between 0 and 65535. This identifier can be used in combination with the major identifier. 82 | */ 83 | @property (nonatomic) uint16_t minor; 84 | 85 | /** 86 | * The strength of the signal measured at a distance of 1 meter. 87 | */ 88 | @property (nonatomic, copy) NSNumber * _Nullable measuredPower; 89 | 90 | @end 91 | 92 | NS_ASSUME_NONNULL_END 93 | -------------------------------------------------------------------------------- /SensingKit/SKiBeaconProximityConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // SKiBeaconProximityConfiguration.m 3 | // SensingKit 4 | // 5 | // Copyright (c) 2014. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import "SKiBeaconProximityConfiguration.h" 26 | 27 | @implementation SKiBeaconProximityConfiguration 28 | 29 | - (nonnull instancetype)initWithUUID:(nonnull NSUUID *)UUID 30 | { 31 | if (self = [super init]) 32 | { 33 | // Set default values 34 | _UUID = UUID; 35 | _mode = SKiBeaconProximityModeScanOnly; 36 | _major = 0; 37 | _minor = 0; 38 | _measuredPower = nil; // default 39 | } 40 | return self; 41 | } 42 | 43 | - (id)copyWithZone:(NSZone *)zone 44 | { 45 | SKiBeaconProximityConfiguration *configuration = [super copyWithZone:zone]; 46 | configuration.UUID = _UUID; 47 | configuration.mode = _mode; 48 | configuration.major = _major; 49 | configuration.minor = _minor; 50 | configuration.measuredPower = _measuredPower; 51 | 52 | return configuration; 53 | } 54 | 55 | - (BOOL)isValidForSensor:(SKSensorType)sensorType 56 | { 57 | return sensorType == iBeaconProximity; 58 | } 59 | 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /SensingKit/SensingKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // SKSensorManager.h 3 | // SensingKit 4 | // 5 | // Copyright (c) 2016. Kleomenis Katevas 6 | // Kleomenis Katevas, k.katevas@imperial.ac.uk 7 | // 8 | // This file is part of SensingKit-iOS library. 9 | // For more information, please visit https://www.sensingkit.org 10 | // 11 | // SensingKit-iOS is free software: you can redistribute it and/or modify 12 | // it under the terms of the GNU Lesser General Public License as published by 13 | // the Free Software Foundation, either version 3 of the License, or 14 | // (at your option) any later version. 15 | // 16 | // SensingKit-iOS is distributed in the hope that it will be useful, 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | // GNU Lesser General Public License for more details. 20 | // 21 | // You should have received a copy of the GNU Lesser General Public License 22 | // along with SensingKit-iOS. If not, see . 23 | // 24 | 25 | #import 26 | 27 | //! Project version number for SensingKit. 28 | FOUNDATION_EXPORT double SensingKitVersionNumber; 29 | 30 | //! Project version string for SensingKit. 31 | FOUNDATION_EXPORT const unsigned char SensingKitVersionString[]; 32 | 33 | // In this header, you should import all the public headers of your framework using statements like #import 34 | 35 | #import 36 | 37 | #import 38 | #import 39 | #import 40 | #import 41 | 42 | // Sensor Data 43 | #import 44 | #import 45 | #import 46 | #import 47 | #import 48 | #import 49 | #import 50 | #import 51 | #import 52 | #import 53 | #import 54 | #import 55 | #import 56 | #import 57 | 58 | // Sensor Configuration 59 | #import 60 | #import 61 | #import 62 | #import 63 | #import 64 | #import 65 | #import 66 | #import 67 | #import 68 | #import 69 | #import 70 | #import 71 | #import 72 | -------------------------------------------------------------------------------- /SensingKitTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | --------------------------------------------------------------------------------