From d56218159d27c8b992079f6fc5e3cee0c7ecd572 Mon Sep 17 00:00:00 2001 From: Yuuki Nishiyama Date: Tue, 20 Nov 2018 13:45:18 +0200 Subject: [PATCH] first commit --- .gitignore | 5 +- Example/Tests/Tests.swift | 2 +- .../project.pbxproj | 27 ++- .../ViewController.swift | 14 ++ LICENSE | 20 +- README.md | 40 +++- ...wareframework.ios.sensor.barometer.podspec | 15 +- .../Classes/BarometerSensor.swift | 186 ++++++++++++++++++ .../Classes/ReplaceMe.swift | 0 .../Classes/model/BarometerData.swift | 24 +++ 10 files changed, 299 insertions(+), 34 deletions(-) create mode 100644 com.awareframework.ios.sensor.barometer/Classes/BarometerSensor.swift delete mode 100644 com.awareframework.ios.sensor.barometer/Classes/ReplaceMe.swift create mode 100644 com.awareframework.ios.sensor.barometer/Classes/model/BarometerData.swift diff --git a/.gitignore b/.gitignore index 93c86d3..63830da 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ Carthage/Build # Note: if you ignore the Pods directory, make sure to uncomment # `pod install` in .travis.yml # -# Pods/ +Pods/ +Example/Podfile.lock +Example/Pods/ +Example/com.awareframework.ios.sensor.barometer.xcworkspace/ diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index 4d0374a..097d5ef 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -1,5 +1,5 @@ import XCTest -import com.awareframework.ios.sensor.barometer +import com_awareframework_ios_sensor_barometer class Tests: XCTestCase { diff --git a/Example/com.awareframework.ios.sensor.barometer.xcodeproj/project.pbxproj b/Example/com.awareframework.ios.sensor.barometer.xcodeproj/project.pbxproj index 0f3b38a..b468cba 100644 --- a/Example/com.awareframework.ios.sensor.barometer.xcodeproj/project.pbxproj +++ b/Example/com.awareframework.ios.sensor.barometer.xcodeproj/project.pbxproj @@ -28,9 +28,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 10AB74A1213BEE5344477911 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; + 10AB74A1213BEE5344477911 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 29B9CA1E73AFE8484109BF32 /* Pods-com.awareframework.ios.sensor.barometer_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.barometer_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.barometer_Tests/Pods-com.awareframework.ios.sensor.barometer_Tests.debug.xcconfig"; sourceTree = ""; }; - 2BE994CD2CBD0D76AD48E42E /* com.awareframework.ios.sensor.barometer.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = com.awareframework.ios.sensor.barometer.podspec; path = ../com.awareframework.ios.sensor.barometer.podspec; sourceTree = ""; }; + 2BE994CD2CBD0D76AD48E42E /* com.awareframework.ios.sensor.barometer.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = com.awareframework.ios.sensor.barometer.podspec; path = ../com.awareframework.ios.sensor.barometer.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 39AF8FB81557506307C26D5D /* Pods-com.awareframework.ios.sensor.barometer_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.barometer_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.barometer_Example/Pods-com.awareframework.ios.sensor.barometer_Example.debug.xcconfig"; sourceTree = ""; }; 607FACD01AFB9204008FA782 /* com.awareframework.ios.sensor.barometer_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = com.awareframework.ios.sensor.barometer_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -45,7 +45,7 @@ 6ECE96EFAE60FAAC4A3BA207 /* Pods-com.awareframework.ios.sensor.barometer_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.barometer_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.barometer_Tests/Pods-com.awareframework.ios.sensor.barometer_Tests.release.xcconfig"; sourceTree = ""; }; 8CAE2DF306B474EC9671B005 /* Pods-com.awareframework.ios.sensor.barometer_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.barometer_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.barometer_Example/Pods-com.awareframework.ios.sensor.barometer_Example.release.xcconfig"; sourceTree = ""; }; A6CBF099021A8798EF97EC93 /* Pods_com_awareframework_ios_sensor_barometer_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_com_awareframework_ios_sensor_barometer_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - C671B77C1C1433EA8BEDE5DC /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = ""; }; + C671B77C1C1433EA8BEDE5DC /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; DB54A3F7CA8CC4082657D0C1 /* Pods_com_awareframework_ios_sensor_barometer_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_com_awareframework_ios_sensor_barometer_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -212,6 +212,7 @@ TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = FH352PYMNC; LastSwiftMigration = 0900; }; 607FACE41AFB9204008FA782 = { @@ -292,13 +293,25 @@ ); inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-com.awareframework.ios.sensor.barometer_Example/Pods-com.awareframework.ios.sensor.barometer_Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Networking/Networking.framework", + "${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework", + "${BUILT_PRODUCTS_DIR}/Realm/Realm.framework", + "${BUILT_PRODUCTS_DIR}/RealmSwift/RealmSwift.framework", + "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework", "${BUILT_PRODUCTS_DIR}/com.awareframework.ios.sensor.barometer/com_awareframework_ios_sensor_barometer.framework", + "${BUILT_PRODUCTS_DIR}/com.awareframework.ios.sensor.core/com_awareframework_ios_sensor_core.framework", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( ); outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Networking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RealmSwift.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/com_awareframework_ios_sensor_barometer.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/com_awareframework_ios_sensor_core.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -422,7 +435,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -468,7 +481,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -481,7 +494,9 @@ baseConfigurationReference = 39AF8FB81557506307C26D5D /* Pods-com.awareframework.ios.sensor.barometer_Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FH352PYMNC; INFOPLIST_FILE = com.awareframework.ios.sensor.barometer/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; @@ -496,7 +511,9 @@ baseConfigurationReference = 8CAE2DF306B474EC9671B005 /* Pods-com.awareframework.ios.sensor.barometer_Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FH352PYMNC; INFOPLIST_FILE = com.awareframework.ios.sensor.barometer/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; diff --git a/Example/com.awareframework.ios.sensor.barometer/ViewController.swift b/Example/com.awareframework.ios.sensor.barometer/ViewController.swift index 3df88d2..f6a1845 100644 --- a/Example/com.awareframework.ios.sensor.barometer/ViewController.swift +++ b/Example/com.awareframework.ios.sensor.barometer/ViewController.swift @@ -7,14 +7,28 @@ // import UIKit +import com_awareframework_ios_sensor_barometer class ViewController: UIViewController { + var sensor:BarometerSensor? + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. + sensor = BarometerSensor.init(BarometerSensor.Config().apply{config in + config.debug = true + config.sensorObserver = Observer() + }) + sensor?.start() } + class Observer:BarometerObserver { + func onDataChanged(data: BarometerData) { + print(data) + } + } + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. diff --git a/LICENSE b/LICENSE index 9d90e14..baafd0f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,19 +1,5 @@ -Copyright (c) 2018 tetujin +Copyright (c) 2018 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/README.md b/README.md index 2714b66..2f24c1b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# com.awareframework.ios.sensor.barometer +# Aware Barometer [![CI Status](https://img.shields.io/travis/tetujin/com.awareframework.ios.sensor.barometer.svg?style=flat)](https://travis-ci.org/tetujin/com.awareframework.ios.sensor.barometer) [![Version](https://img.shields.io/cocoapods/v/com.awareframework.ios.sensor.barometer.svg?style=flat)](https://cocoapods.org/pods/com.awareframework.ios.sensor.barometer) @@ -10,20 +10,50 @@ To run the example project, clone the repo, and run `pod install` from the Example directory first. ## Requirements +iOS 10 or later ## Installation -com.awareframework.ios.sensor.barometer is available through [CocoaPods](https://cocoapods.org). To install -it, simply add the following line to your Podfile: +com.awareframework.ios.sensor.barometer is available through [CocoaPods](https://cocoapods.org). + +1. To install it, simply add the following line to your Podfile: ```ruby pod 'com.awareframework.ios.sensor.barometer' ``` +2. Import com.awareframework.ios.sensor.barometer library into your source code. +```swift +import com_awareframework_ios_sensor_barometer +``` + +## Example usage +```swift +var barometerSensor = BarometerSensor.init(BarometerSensor.Config().apply{config in + config.sensorObserver = Observer() + config.debug = true + config.dbType = .REALM +}) +barometerSensor?.start() +barometerSensor?.stop() +``` + +```swift +class Observer:BarometerObserver{ + func onDataChanged(data: BarometerData) { + // Your code here.. + } +} +``` + ## Author -tetujin, tetujin@ht.sfc.keio.ac.jp +Yuuki Nishiyama, tetujin@ht.sfc.keio.ac.jp ## License -com.awareframework.ios.sensor.barometer is available under the MIT license. See the LICENSE file for more info. +Copyright (c) 2018 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com) + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/com.awareframework.ios.sensor.barometer.podspec b/com.awareframework.ios.sensor.barometer.podspec index 22a3fa3..5ba2e18 100644 --- a/com.awareframework.ios.sensor.barometer.podspec +++ b/com.awareframework.ios.sensor.barometer.podspec @@ -21,14 +21,16 @@ Pod::Spec.new do |s| TODO: Add long description of the pod here. DESC - s.homepage = 'https://github.com/tetujin/com.awareframework.ios.sensor.barometer' + s.homepage = 'https://github.com/awareframework/com.awareframework.ios.sensor.barometer' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' - s.license = { :type => 'MIT', :file => 'LICENSE' } + s.license = { :type => 'Apache2', :file => 'LICENSE' } s.author = { 'tetujin' => 'tetujin@ht.sfc.keio.ac.jp' } - s.source = { :git => 'https://github.com/tetujin/com.awareframework.ios.sensor.barometer.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/awareframework/com.awareframework.ios.sensor.barometer.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '10.0' + + s.swift_version = '4.0' s.source_files = 'com.awareframework.ios.sensor.barometer/Classes/**/*' @@ -37,6 +39,9 @@ TODO: Add long description of the pod here. # } # s.public_header_files = 'Pod/Classes/**/*.h' - # s.frameworks = 'UIKit', 'MapKit' + s.frameworks = 'CoreMotion' #'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' + + s.dependency 'com.awareframework.ios.sensor.core' + end diff --git a/com.awareframework.ios.sensor.barometer/Classes/BarometerSensor.swift b/com.awareframework.ios.sensor.barometer/Classes/BarometerSensor.swift new file mode 100644 index 0000000..405e5c3 --- /dev/null +++ b/com.awareframework.ios.sensor.barometer/Classes/BarometerSensor.swift @@ -0,0 +1,186 @@ +// +// BarometerSensor.swift +// com.aware.ios.sensor.barometer +// +// Created by Yuuki Nishiyama on 2018/10/25. +// + +import UIKit +import CoreMotion +import SwiftyJSON +import com_awareframework_ios_sensor_core + +extension Notification.Name{ + public static let actionAwareBarometer = Notification.Name(BarometerSensor.ACTION_AWARE_BAROMETER) + public static let actionAwareBarometerStart = Notification.Name(BarometerSensor.ACTION_AWARE_BAROMETER_START) + public static let actionAwareBarometerStop = Notification.Name(BarometerSensor.ACTION_AWARE_BAROMETER_STOP) + public static let actionAwareBarometerSync = Notification.Name(BarometerSensor.ACTION_AWARE_BAROMETER_SYNC) + public static let actionAwareBarometerSetLabel = Notification.Name(BarometerSensor.ACTION_AWARE_BAROMETER_SET_LABEL) +} + +public protocol BarometerObserver{ + func onDataChanged(data: BarometerData) +} + +public class BarometerSensor: AwareSensor { + + public static let TAG = "AWARE::Barometer" + + public static let ACTION_AWARE_BAROMETER = "ACTION_AWARE_BAROMETER" + + public static let ACTION_AWARE_BAROMETER_START = "com.awareframework.android.sensor.barometer.SENSOR_START" + public static let ACTION_AWARE_BAROMETER_STOP = "com.awareframework.android.sensor.barometer.SENSOR_STOP" + + public static let ACTION_AWARE_BAROMETER_SET_LABEL = "com.awareframework.android.sensor.barometer.ACTION_AWARE_BAROMETER_SET_LABEL" + public static let EXTRA_LABEL = "label" + + public static let ACTION_AWARE_BAROMETER_SYNC = "com.awareframework.android.sensor.barometer.SENSOR_SYNC" + + var CONFIG = Config() + + var timer:Timer? = nil + + public class Config:SensorConfig{ + /** + * For real-time observation of the sensor data collection. + */ + public var sensorObserver: BarometerObserver? = nil + + /** + * Barometer interval in hertz per second: e.g. + * 0 - fastest + * 1 - sample per second + * 5 - sample per second + * 20 - sample per second + * The maximum interval is 1 on iOS. + */ + public var interval: Double = 5 + + /** + * Period to save data in minutes. (optional) + */ + public var period: Double = 1 + + /** + * Barometer threshold (double). Do not record consecutive points if + * change in value is less than the set value. + */ + public var threshold: Double = 0.0 + + public override init(){ + super.init() + dbPath = "aware_barometer" + } + + public convenience init(_ json:JSON){ + self.init() + } + + public func apply(closure:(_ config: BarometerSensor.Config ) -> Void ) -> Self{ + closure(self) + return self + } + } + + public override convenience init(){ + self.init(BarometerSensor.Config()) + } + + public init(_ config: BarometerSensor.Config){ + super.init() + CONFIG = config + initializeDbEngine(config: config) + } + + //////////////////////////////////// + var altimeter = CMAltimeter() + var lastSaveTime:Double = 0 + var lastEventTime:Double = 0 + var lastAltimeterData:CMAltitudeData? = nil + var currentAltimeterData:CMAltitudeData? = nil + var dataArray = Array() + + public override func start() { + // https://developer.apple.com/documentation/coremotion/cmaltimeter + if CMAltimeter.isRelativeAltitudeAvailable() { + altimeter.startRelativeAltitudeUpdates(to: OperationQueue.main) { (altimeterData, error) in + /** + * interval: Int: Data samples to collect per second. (default = 5) + * period: Float: Period to save data in minutes. (default = 1) + * threshold: Double: If set, do not record consecutive points if change in value is less than the set value. + */ + if let altData = altimeterData { + self.currentAltimeterData = altData + } + } + } + if self.timer == nil { + self.timer = Timer.scheduledTimer(withTimeInterval: 1.0/self.CONFIG.interval , repeats: true, block: { (timer) in + if let altData = self.currentAltimeterData { + let now = Date().timeIntervalSince1970 + + var isSkip = false + + /** threshold filter */ + if self.CONFIG.threshold != 0 { + if let lastAltData = self.lastAltimeterData { + let gap = abs(altData.pressure.doubleValue - lastAltData.pressure.doubleValue) + if gap < self.CONFIG.threshold { + if self.CONFIG.debug { print(BarometerSensor.TAG, "skip", "threshold", gap) } + isSkip = true + } + } + } + + if !isSkip { + let data = BarometerData() + data.pressure = altData.pressure.doubleValue // TODO: check the data format + data.eventTimestamp = Int64(altData.timestamp * 1000) // TODO: check the data format + if let observer = self.CONFIG.sensorObserver{ + observer.onDataChanged(data: data) + } + self.notificationCenter.post(name: .actionAwareBarometer, object: nil) + self.dataArray.append(data) + + self.lastAltimeterData = altData + self.lastEventTime = now + } + + /** MEMO: Save dataArray if the "current time" is bigger than "last time" + "save period" */ + if (self.lastSaveTime + (self.CONFIG.period * 60.0) ) < now { + /// save data + if let engin = self.dbEngine { + if self.dataArray.count > 0 { + engin.save(self.dataArray, BarometerData.TABLE_NAME) + if self.CONFIG.debug { print(BarometerSensor.TAG, "save data") } + }else{ + if self.CONFIG.debug { print(BarometerSensor.TAG, "no data") } + } + } + self.lastSaveTime = now + } + self.notificationCenter.post(name: .actionAwareBarometerStart, object: nil) + } + }) + } + } + + public override func stop() { + altimeter.stopRelativeAltitudeUpdates() + if let t = self.timer{ + t.invalidate() + self.timer = nil + } + self.notificationCenter.post(name: .actionAwareBarometerStop, object: nil) + } + + public override func sync(force: Bool = false) { + if let engine = self.dbEngine{ + engine.startSync(BarometerData.TABLE_NAME, DbSyncConfig.init().apply{config in + config.debug = CONFIG.debug + }) + } + self.notificationCenter.post(name: .actionAwareBarometerSync, object: nil) + } + +} diff --git a/com.awareframework.ios.sensor.barometer/Classes/ReplaceMe.swift b/com.awareframework.ios.sensor.barometer/Classes/ReplaceMe.swift deleted file mode 100644 index e69de29..0000000 diff --git a/com.awareframework.ios.sensor.barometer/Classes/model/BarometerData.swift b/com.awareframework.ios.sensor.barometer/Classes/model/BarometerData.swift new file mode 100644 index 0000000..ddc1a74 --- /dev/null +++ b/com.awareframework.ios.sensor.barometer/Classes/model/BarometerData.swift @@ -0,0 +1,24 @@ +// +// BarometerData.swift +// com.aware.ios.sensor.barometer +// +// Created by Yuuki Nishiyama on 2018/10/25. +// + +import UIKit +import com_awareframework_ios_sensor_core + +public class BarometerData: AwareObject { + public static var TABLE_NAME = "barometerData" + @objc dynamic public var pressure:Double = 0 + @objc dynamic public var eventTimestamp:Int64 = 0 + @objc dynamic public var accuracy:Int = 0 + + public override func toDictionary() -> Dictionary { + var dict = super.toDictionary() + dict["pressure"] = pressure + dict["eventTimestamp"] = eventTimestamp + dict["accuracy"] = accuracy + return dict + } +}