This sensor module allows us to access the current Linear Accelerometer data. The acceleration that the user is giving to the device. The total acceleration of the device is equal to gravity plus the acceleration the user imparts to the device. The data is provided by CMDeviceMotion in Core Motion library. Please check the link below for details.
Apple | Getting Processed Device-Motion Data
Apple | CMDeviceMotion | gravity
iOS 10 or later
com.awareframework.ios.sensor.linearaccelerometer is available through CocoaPods.
- To install it, simply add the following line to your Podfile:
pod 'com.awareframework.ios.sensor.linearaccelerometer'
- Import com.awareframework.ios.sensor.linearaccelerometer library into your source code.
import com_awareframework_ios_sensor_linearaccelerometer
init(config:LinearAccelerometerSensor.Config?)
: Initializes the linear-accelerometer sensor with the optional configuration.start()
: Starts the linear-accelerometer sensor with the optional configuration.stop()
: Stops the service.
Class to hold the configuration of the sensor.
sensorObserver: LinearAccelerometerObserver
: Callback for live data updates.frequency: Int
: Data samples to collect per second (Hz). (default = 5)period: Double
: 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.enabled: Boolean
Sensor is enabled or not. (default =false
)debug: Boolean
enable/disable logging to Xcode console. (default =false
)label: String
Label for the data. (default = "")deviceId: String
Id of the device that will be associated with the events and the sensor. (default = "")dbEncryptionKey
Encryption key for the database. (default =null
)dbType: Engine
Which db engine to use for saving data. (default =Engine.DatabaseType.NONE
)dbPath: String
Path of the database. (default = "aware_linear_acceleromete")dbHost: String
Host for syncing the database. (default =null
)
LinearAccelerometerSensor.ACTION_AWARE_GYROSCOPE
fired when gyroscope saved data to db after the period ends.
LinearAccelerometerSensor.ACTION_AWARE_LINEAR_ACCELEROMETER_START
: received broadcast to start the sensor.LinearAccelerometerSensor.ACTION_AWARE_LINEAR_ACCELEROMETER_STOP
: received broadcast to stop the sensor.LinearAccelerometerSensor.ACTION_AWARE_LINEAR_ACCELEROMETER_SYNC
: received broadcast to send sync attempt to the host.LinearAccelerometerSensor.ACTION_AWARE_LINEAR_ACCELEROMETER_SET_LABEL
: received broadcast to set the data label. Label is expected in theLinearAccelerometerSensor.EXTRA_LABEL
field of the intent extras.
Contains the raw sensor data.
Field | Type | Description |
---|---|---|
x | Double | value of X axis |
y | Double | value of Y axis |
z | Double | value of Z axis |
label | String | Customizable label. Useful for data calibration or traceability |
deviceId | String | AWARE device UUID |
label | String | Customizable label. Useful for data calibration or traceability |
timestamp | Int64 | unixtime milliseconds since 1970 |
timezone | Int | Raw timezone offset of the device |
os | String | Operating system of the device (ex. ios) |
var linearAccSensor = LinearAccelerometerSensor.init(LinearAccelerometerSensor.Config().apply{config in
config.debug = true
config.dbType = .REALM
config.sensorObserver = Observer()
})
linearAccSensor.start()
class Observer:LinearAccelerometerObserver{
func onDataChanged(data: LinearAccelerometerData) {
// Your code here...
}
}
Yuuki Nishiyama, yuukin@iis.u-tokyo.ac.jp
Copyright (c) 2021 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.