Skip to content

Latest commit

 

History

History
210 lines (146 loc) · 5.66 KB

File metadata and controls

210 lines (146 loc) · 5.66 KB

Functionality of Wearables

Wearable functionality in the Open Earable Flutter package is modular and extensible through the use of capabilities. Capabilities are abstract interfaces that define specific features (like sensor access, battery info, button interaction, etc.). Each Wearable can implement any combination of these capabilities depending on its hardware and firmware support.

This guide outlines the most common capabilities and how to use them with the new capability lookup helpers.

Use hasCapability<T>() to check support and getCapability<T>() or requireCapability<T>() to fetch an instance:

if (wearable.hasCapability<SensorManager>()) {
  final sensorManager = wearable.requireCapability<SensorManager>();
  final sensors = sensorManager.sensors;
}

The difference between getCapability<T>() and requireCapability<T>() is that the latter throws an exception if the capability is not supported, while the former returns null.

Warning

The old way of checking capabilities using is <Capability> is deprecated. Please use hasCapability<T>() instead.


Popular Capabilities

Some of the most commonly used capabilities include:

SensorManager

Enables access to available sensors on the wearable.

final sensorManager = wearable.getCapability<SensorManager>();
if (sensorManager != null) {
  List<Sensor> sensors = sensorManager.sensors;
}

SensorConfigurationManager

Allows configuration of the wearable’s sensors, including setting sampling rates or modes.

final configurationManager = wearable.getCapability<SensorConfigurationManager>();
if (configurationManager != null) {
  List<SensorConfiguration> configurations = configurationManager.sensorConfigurations;
}

🔋 Battery Capabilities

BatteryEnergyStatusService

Provides access to battery energy data.

final energyStatusService = wearable.getCapability<BatteryEnergyStatusService>();
if (energyStatusService != null) {
  BatteryEnergyStatus status = await energyStatusService.readEnergyStatus();
}

BatteryHealthStatusService

Reads battery health and performance metrics.

final healthStatusService = wearable.getCapability<BatteryHealthStatusService>();
if (healthStatusService != null) {
  BatteryHealthStatus healthStatus = await healthStatusService.readHealthStatus();
}

BatteryLevelStatusService

Gives the current battery level as a percentage or unit.

final levelStatusService = wearable.getCapability<BatteryLevelStatusService>();
if (levelStatusService != null) {
  BatteryPowerStatus levelStatus = await levelStatusService.readPowerStatus();
}

🔘 ButtonManager

Enables listening to hardware button events on the wearable.

final buttonManager = wearable.getCapability<ButtonManager>();
if (buttonManager != null) {
  buttonManager.buttonEvents.listen((buttonEvent) {
    // Handle button events
  });
}

💾 EdgeRecorderManager

Controls on-device recording. You can specify filename prefixes or manage session behaviors.

final edgeRecorder = wearable.getCapability<EdgeRecorderManager>();
if (edgeRecorder != null) {
  edgeRecorder.setFilePrefix("my_recording");
}

🎤 MicrophoneManager

Lets you select the active microphone (if the device has multiple).

final microphoneManager = wearable.getCapability<MicrophoneManager>();
if (microphoneManager != null) {
  List<Microphone> microphones = microphoneManager.availableMicrophones;
  microphoneManager.setMicrophone(microphones.first);
}

🔈 AudioModeManager

Allows switching between different audio modes (e.g., mono, stereo, streaming).

final audioModeManager = wearable.getCapability<AudioModeManager>();
if (audioModeManager != null) {
  List<AudioMode> audioModes = audioModeManager.availableAudioModes;
  audioModeManager.setAudioMode(audioModes.first);
}

ℹ️ Device Information Capabilities

DeviceFirmwareVersion

Reads the current firmware version of the device.

final firmwareVersionService = wearable.getCapability<DeviceFirmwareVersion>();
if (firmwareVersionService != null) {
  String firmwareVersion = await firmwareVersionService.readDeviceFirmwareVersion();
}

DeviceHardwareVersion

Reads the hardware version of the device.

final hardwareVersionService = wearable.getCapability<DeviceHardwareVersion>();
if (hardwareVersionService != null) {
  String hardwareVersion = await hardwareVersionService.readDeviceHardwareVersion();
}

DeviceIdentifier

Retrieves the device’s unique ID.

final deviceIdentifierService = wearable.getCapability<DeviceIdentifier>();
if (deviceIdentifierService != null) {
  String deviceId = await deviceIdentifierService.readDeviceIdentifier();
}

FotaCapability

Provides the device-level abstraction for firmware update operations.

final fota = wearable.getCapability<FotaCapability>();
if (fota != null) {
  final request = fota.createFirmwareUpdateRequest(selectedFirmware);
}

Use createFirmwareUpdateRequest(...) to build a wearable-specific update request without depending on the underlying FOTA backend.

FotaSlotInfoCapability

Provides firmware slot or image-table state for FOTA backends that expose it.

final slotInfo = wearable.getCapability<FotaSlotInfoCapability>();
if (slotInfo != null) {
  final slots = await slotInfo.readFirmwareSlots();
}

Summary

Capabilities are the building blocks of wearable functionality. Use hasCapability<T>() to check support and getCapability<T>() to access a capability instance. This enables modular development and ensures your app only uses features supported by the connected device.