diff --git a/lib/open_earable_flutter.dart b/lib/open_earable_flutter.dart index ed336b7..9e4b340 100644 --- a/lib/open_earable_flutter.dart +++ b/lib/open_earable_flutter.dart @@ -31,7 +31,7 @@ export 'src/models/capabilities/storage_path_audio_player.dart'; part 'src/constants.dart'; -Logger _logger = Logger(); +Logger logger = Logger(); class WearableManager { static final WearableManager _instance = WearableManager._internal(); @@ -70,12 +70,12 @@ class WearableManager { for (WearableFactory wearableFactory in _wearableFactories) { wearableFactory.bleManager = _bleManager; wearableFactory.disconnectNotifier = disconnectNotifier; - _logger.t("checking factory: $wearableFactory"); + logger.t("checking factory: $wearableFactory"); if (await wearableFactory.matches(device, connectionResult.$2)) { Wearable wearable = await wearableFactory.createFromDevice(device); return wearable; } else { - _logger.d("'$wearableFactory' does not support '$device'"); + logger.d("'$wearableFactory' does not support '$device'"); } } throw Exception('Device is currently not supported'); diff --git a/lib/src/models/devices/open_earable_factory.dart b/lib/src/models/devices/open_earable_factory.dart index 6cec224..29b85e9 100644 --- a/lib/src/models/devices/open_earable_factory.dart +++ b/lib/src/models/devices/open_earable_factory.dart @@ -18,7 +18,6 @@ const String _deviceParseInfoServiceUuid = const String _deviceParseInfoCharacteristicUuid = "caa25cb8-7e1b-44f2-adc9-e8c06c9ced43"; -Logger _logger = Logger(); class OpenEarableFactory extends WearableFactory { final _v1Regex = RegExp(r'^1\.\d+\.\d+$'); @@ -27,13 +26,13 @@ class OpenEarableFactory extends WearableFactory { @override Future matches(DiscoveredDevice device, List services) async { if (!services.any((service) => service.uuid == _deviceInfoServiceUuid)) { - _logger.d("'$device' has no service matching '$_deviceInfoServiceUuid'"); + logger.d("'$device' has no service matching '$_deviceInfoServiceUuid'"); return false; } String firmwareVersion = await _getFirmwareVersion(device); - _logger.d("Firmware Version: '$firmwareVersion'"); + logger.d("Firmware Version: '$firmwareVersion'"); - _logger.t("matches V2: ${_v2Regex.hasMatch(firmwareVersion)}"); + logger.t("matches V2: ${_v2Regex.hasMatch(firmwareVersion)}"); return _v1Regex.hasMatch(firmwareVersion) || _v2Regex.hasMatch(firmwareVersion); } @@ -77,7 +76,7 @@ class OpenEarableFactory extends WearableFactory { serviceId: _deviceInfoServiceUuid, characteristicId: _deviceFirmwareVersionCharacteristicUuid, ); - _logger.d("Raw Firmware Version: $softwareGenerationBytes"); + logger.d("Raw Firmware Version: $softwareGenerationBytes"); int firstZeroIndex = softwareGenerationBytes.indexOf(0); if (firstZeroIndex != -1) { softwareGenerationBytes = softwareGenerationBytes.sublist(0, firstZeroIndex); @@ -94,9 +93,9 @@ class OpenEarableFactory extends WearableFactory { serviceId: _deviceParseInfoServiceUuid, characteristicId: _deviceParseInfoCharacteristicUuid, ); - _logger.d("Read raw parse info: $sensorParseSchemeData"); + logger.d("Read raw parse info: $sensorParseSchemeData"); Map parseInfo = _parseSchemeCharacteristic(sensorParseSchemeData); - _logger.i("Found the following info about parsing: $parseInfo"); + logger.i("Found the following info about parsing: $parseInfo"); OpenEarableSensorManager sensorManager = OpenEarableSensorManager( bleManager: bleManager!, @@ -105,10 +104,10 @@ class OpenEarableFactory extends WearableFactory { for (String sensorName in parseInfo.keys) { Map sensorDetail = parseInfo[sensorName] as Map; - _logger.t("sensor detail: $sensorDetail"); + logger.t("sensor detail: $sensorDetail"); Map componentsMap = sensorDetail['Components'] as Map; - _logger.t("components: $componentsMap"); + logger.t("components: $componentsMap"); sensorConfigurations.add( _OpenEarableSensorConfiguration( @@ -121,7 +120,7 @@ class OpenEarableFactory extends WearableFactory { for (String groupName in componentsMap.keys) { Map groupDetail = componentsMap[groupName] as Map; - _logger.t("group detail: $groupDetail"); + logger.t("group detail: $groupDetail"); List<(String, String)> axisDetails = groupDetail.entries.map((axis) { Map v = axis.value as Map; return (axis.key, v['unit'] as String); @@ -141,8 +140,8 @@ class OpenEarableFactory extends WearableFactory { } } - _logger.d("Created sensors: $sensors"); - _logger.d("Created sensor configurations: $sensorConfigurations"); + logger.d("Created sensors: $sensors"); + logger.d("Created sensor configurations: $sensorConfigurations"); return (sensors, sensorConfigurations); } @@ -290,9 +289,9 @@ class _OpenEarableSensor extends Sensor { _dataSubscription?.cancel(); _dataSubscription = _sensorManager.subscribeToSensorData(_sensorId).listen((data) { int timestamp = data["timestamp"]; - _logger.t("SensorData: $data"); + logger.t("SensorData: $data"); - _logger.t("componentData of $componentName: ${data[componentName]}"); + logger.t("componentData of $componentName: ${data[componentName]}"); List values = []; for (var entry in (data[componentName] as Map).entries) { diff --git a/lib/src/models/devices/open_earable_v2.dart b/lib/src/models/devices/open_earable_v2.dart index 47c1e70..d24b9c1 100644 --- a/lib/src/models/devices/open_earable_v2.dart +++ b/lib/src/models/devices/open_earable_v2.dart @@ -2,21 +2,8 @@ import 'dart:async'; import 'dart:math'; import 'dart:typed_data'; -import 'package:logger/logger.dart'; -import 'package:open_earable_flutter/src/models/capabilities/battery_service.dart'; -import 'package:open_earable_flutter/src/models/capabilities/status_led.dart'; - -import '../capabilities/device_firmware_version.dart'; -import '../capabilities/device_hardware_version.dart'; -import '../capabilities/device_identifier.dart'; -import '../capabilities/rgb_led.dart'; -import '../capabilities/sensor.dart'; -import '../capabilities/sensor_configuration.dart'; -import '../capabilities/sensor_configuration_manager.dart'; -import '../capabilities/sensor_manager.dart'; +import 'package:open_earable_flutter/open_earable_flutter.dart'; import '../../managers/ble_manager.dart'; -import 'discovered_device.dart'; -import 'wearable.dart'; const String _batteryServiceUuid = "180F"; const String _batteryLevelCharacteristicUuid = "2A19"; @@ -38,8 +25,6 @@ const String _deviceFirmwareVersionCharacteristicUuid = const String _deviceHardwareVersionCharacteristicUuid = "45622513-6468-465a-b141-0b9b0f96b468"; -Logger _logger = Logger(); - class OpenEarableV2 extends Wearable implements SensorManager, @@ -162,7 +147,7 @@ class OpenEarableV2 extends Wearable characteristicId: _batteryLevelCharacteristicUuid, ); - _logger.t("Battery level bytes: $batteryLevelList"); + logger.t("Battery level bytes: $batteryLevelList"); if (batteryLevelList.length != 1) { throw StateError('Battery level characteristic expected 1 value, but got ${batteryLevelList.length}'); @@ -179,7 +164,7 @@ class OpenEarableV2 extends Wearable characteristicId: _batteryEnergyStatusCharacteristicUuid, ); - _logger.t("Battery energy status bytes: $energyStatusList"); + logger.t("Battery energy status bytes: $energyStatusList"); if (energyStatusList.length != 7) { throw StateError('Battery energy status characteristic expected 7 values, but got ${energyStatusList.length}'); @@ -200,7 +185,7 @@ class OpenEarableV2 extends Wearable chargeRate: chargeRate, ); - _logger.d('Battery energy status: $batteryEnergyStatus'); + logger.d('Battery energy status: $batteryEnergyStatus'); return batteryEnergyStatus; } @@ -212,7 +197,7 @@ class OpenEarableV2 extends Wearable if (mantissa >= 0x800) { mantissa = -((0x1000) - mantissa); } - _logger.t("Exponent: $exponent, Mantissa: $mantissa"); + logger.t("Exponent: $exponent, Mantissa: $mantissa"); double result = mantissa.toDouble() * pow(10.0, exponent.toDouble()); return result; } @@ -225,7 +210,7 @@ class OpenEarableV2 extends Wearable characteristicId: _batteryHealthStatusCharacteristicUuid, ); - _logger.t("Battery health status bytes: $healthStatusList"); + logger.t("Battery health status bytes: $healthStatusList"); if (healthStatusList.length != 5) { throw StateError('Battery health status characteristic expected 5 values, but got ${healthStatusList.length}'); @@ -241,7 +226,7 @@ class OpenEarableV2 extends Wearable currentTemperature: currentTemperature, ); - _logger.d('Battery health status: $batteryHealthStatus'); + logger.d('Battery health status: $batteryHealthStatus'); return batteryHealthStatus; } @@ -255,7 +240,7 @@ class OpenEarableV2 extends Wearable ); int powerState = (powerStateList[1] << 8) | powerStateList[2]; - _logger.d("Battery power status bits: ${powerState.toRadixString(2)}"); + logger.d("Battery power status bits: ${powerState.toRadixString(2)}"); bool batteryPresent = powerState >> 15 & 0x1 != 0; @@ -298,7 +283,7 @@ class OpenEarableV2 extends Wearable chargingFaultReason: chargingFaultReason, ); - _logger.d('Battery power status: $batteryPowerStatus'); + logger.d('Battery power status: $batteryPowerStatus'); return batteryPowerStatus; } @@ -317,7 +302,7 @@ class OpenEarableV2 extends Wearable try { yield await readPowerStatus(); } catch (e) { - _logger.e('Error reading power status: $e'); + logger.e('Error reading power status: $e'); } await Future.delayed(const Duration(seconds: 5)); } @@ -329,7 +314,7 @@ class OpenEarableV2 extends Wearable try { yield await readEnergyStatus(); } catch (e) { - _logger.e('Error reading energy status: $e'); + logger.e('Error reading energy status: $e'); } await Future.delayed(const Duration(seconds: 5)); } @@ -341,7 +326,7 @@ class OpenEarableV2 extends Wearable try { yield await readHealthStatus(); } catch (e) { - _logger.e('Error reading health status: $e'); + logger.e('Error reading health status: $e'); } await Future.delayed(const Duration(seconds: 5)); }