ESense 0.1.1

ESense 0.1.1

Maintained by tetujin.



ESense 0.1.1

  • By
  • Yuuki Nishiyama

eSense iOS Library

CI Status Version License Platform

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.

Yuuki Nishiyama,

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 10 or later

Installation

ESense is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ESense'

Use eSense Library

  1. Import the library in your iOS project
import ESense
  1. 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
    }
}
  1. 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)
  1. 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)
  1. Handling sensor update events After connecing the device, you listen the sensor change events via ESenseSensrListener. Please implement ESenseSensorListener on your class just like below.
extension YOUR_CLASS:ESenseSensorListener{
    func onSensorChanged(_ evt: ESenseEvent) {
        // YOUR CODE HERE
    }
}

Finally, you can set the ESenseSensorListener to your ESenseManager with a sampling late (hz).

manager.registerSensorListener(YOUR_CLASS, hz: 10)
  1. 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()

Author

eSense Library for iOS is developed by Yuuki Nishiyama (The University of Tokyo, Japan) [email protected].

License

ESense is available under the MIT license. See the LICENSE file for more info.