Skip to content

ESenseDeviceManager

The DeviceManager for an ESenseDevice.

Connects to the earable, sets its sampling rate, and gives the eSense probes access to the device through manager.

Key points:

  • eSense uses the bleName (and not the BLE address) for connecting. It is typically of the form eSense-xxxx. canConnect is false until bleName is set.
  • connect returns while connecting; the status follows the device's connection events.
  • While connected, it reads the battery voltage every 2 minutes and emits an estimated level on batteryEvents.
Inheritance

Constructors

ESenseDeviceManager

ESenseDeviceManager(
  1. String type, {
  2. ESenseDevice? configuration,
})

Creates a manager for an eSense device of the given device type.

Properties

batteryEvents

Stream<int> get batteryEvents
override

The stream of battery level events (0-100) from this hardware device.

batteryLevel

int? get batteryLevel
override

An estimate of the battery level of the eSense device.

It assumes a linear relationship based on a regression on these measures of battery and voltage levels:

  B  |  V
 ----+------
 1.0	| 4.1
 0.8	| 3.9
 0.6	| 3.8
 0.4	| 3.7
 0.2	| 3.4
 0.0  | 3.1

which gives B = 1.19V - 3.91. The level is a percentage, or null if no voltage has been read yet.

See e.g. https://en.wikipedia.org/wiki/State_of_charge#Voltage_method

bleAddress

  1. @Deprecated('Use bleName instead')
  2. @override
String? get bleAddress
override
  1. @Deprecated('Use bleName instead')
  2. @override
set bleAddress (String? address)
override

The BLE address of this device.

The format of the BLE address is platform-specific. On Android, it is typically a MAC address of the form 00:04:79:00:0F:4D. On iOS, it is typically be a UUID string on the form E2C56DB5-DFFB-48D2-B060-D0F5A71096E0.

Returns null if unknown. Typically, the BLE address is only known after pairing with a specific BLE device.

canConnect

bool get canConnect
override

Determines whether a connection can be made at this point in time to the device.

displayName

String? get displayName
override

Default display name for a BLE device is its BLE name or address.

manager

ESenseManager? get manager

The esense_flutter ESenseManager that talks to the device. Null until bleName has been set.

Methods

createRegistration

BLEDeviceRegistration createRegistration()
override

Create a device registration which can be used to configure this device for deployment.

This method is used when a device is connected and a registration for this device is needed in the deployment and hence in the deployment service. The registration is typically created from the device information of the real device, e.g., the ID, name, and BLE address of the smartphone or a connected Bluetooth device.

onConnect

Future<DeviceStatus> onConnect()
override

Callback on connect. Returns the DeviceStatus of the device.

Can be overridden for device-specific connection handling.

onDisconnect

Future<bool> onDisconnect()
override

Callback on disconnect.

This method is called after all sampling on this device has been stopped, and the device manager is trying to disconnect from the real device.

Is to be overridden in sub-classes and implement device-specific disconnection.