This library allows us to use eSense (earable computing platform) on iOS easily. This library is inspired by eSense library for Android which is developed by Pervasive Systems team at Nokia Bell Labs Cambridge.
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 10 or later
ESense is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ESense'
- Import the library in your iOS project
import ESense
- Implement
ESenseConnectionListener
on your class
extension YOUR_CLASS:ESenseConnectionListener{
func onDeviceFound(_ manager: ESenseManager) {
// YOUR CODE HERE
}
func onDeviceNotFound(_ manager: ESenseManager) {
// YOUR CODE HERE
}
func onConnected(_ manager: ESenseManager) {
manager.setDeviceReadyHandler { device in
manager.removeDeviceReadyHandler()
// YOUR CODE HERE
}
}
func onDisconnected(_ manager: ESenseManager) {
// YOUR CODE HERE
}
}
- Create the ESenseManager instance
Prepare a variable for ESenseManager
as a class or static variable.
var manager:ESenseManager? = nil
Initialize an ESenseManager
class using a target device name and a class which is implemented the ESenseConnectionListener
.
manager = ESenseManager(deviceName: "YOUR_ESENSE_NAME", listener: YOUR_CLASS)
- Scan and connect an eSense device
For scanning an eSense device, you can use scan(timeout)
method. If ESenseManager
finds an eSense device, onDeviceFind(manager)
method on ESenseConnectionListener
is called.
manager.scan(timeout: SECOND)
- Handling sensor update events
After connecting the device, you can listen the sensor change events via ESenseSensrListener
. Please implement ESenseSensorListener in your class just like below.
extension YOUR_CLASS:ESenseSensorListener{
func onSensorChanged(_ evt: ESenseEvent) {
// YOUR CODE HERE
}
}
Finally, you can set the ESenseSensorListener
into your ESenseManager
with a sampling late (hz
).
manager.registerSensorListener(YOUR_CLASS, hz: 10)
- Handling eSense device events
In addition, you can handle eSense other events (battery, button, and config related events) using ESenseEventListener
. Please implement ESenseEventListener
on your class.
extension YOUR_CLASS:ESenseEventListener{
func onBatteryRead(_ voltage: Double) {
// YOUR CODE HERE
}
func onButtonEventChanged(_ pressed: Bool) {
// YOUR CODE HERE
}
func onAdvertisementAndConnectionIntervalRead(_ minAdvertisementInterval: Int, _ maxAdvertisementInterval: Int, _ minConnectionInterval: Int, _ maxConnectionInterval: Int) {
// YOUR CODE HERE
}
func onDeviceNameRead(_ deviceName: String) {
// YOUR CODE HERE
}
func onSensorConfigRead(_ config: ESenseConfig) {
// YOUR CODE HERE
}
func onAccelerometerOffsetRead(_ offsetX: Int, _ offsetY: Int, _ offsetZ: Int) {
// YOUR CODE HERE
}
}
Also, you can registe the implement listener by registerEventListener(ESenseEventListener)
method on ESenseManager
class.
manager.registerEventListener(self)
Executing read operations will trigger events on ESenseEventListener
.
manager.getBatteryVoltage()
manager.getAccelerometerOffset()
manager.getDeviceName()
manager.getSensorConfig()
manager.getAdvertisementAndConnectionInterval()
eSense Library for iOS is developed by Yuuki Nishiyama (The University of Tokyo, Japan) yuukin@iis.u-tokyo.ac.jp.
ESense is available under the MIT license. See the LICENSE file for more info.