Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosinuss one sensor #15

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/lib/widgets/rgb_led_control_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class _RgbLedControlWidgetState extends State<RgbLedControlWidget> {
ElevatedButton(
onPressed: () {
widget.rgbLed.writeLedColor(
r: _currentColor.red,
g: _currentColor.green,
b: _currentColor.blue,
r: (255 * _currentColor.r).round(),
g: (255 * _currentColor.g).round(),
b: (255 * _currentColor.b).round(),
);
},
child: const Text('Set'),
Expand Down
12 changes: 10 additions & 2 deletions lib/open_earable_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:universal_ble/universal_ble.dart';

import 'src/managers/ble_manager.dart';
import 'src/managers/notifier.dart';
import 'src/models/devices/cosinuss_one.dart';
import 'src/models/devices/discovered_device.dart';
import 'src/models/devices/wearable.dart';

Expand All @@ -25,8 +26,6 @@ export 'src/models/capabilities/jingle_player.dart';
export 'src/models/capabilities/audio_player_controls.dart';
export 'src/models/capabilities/storage_path_audio_player.dart';

part 'src/constants.dart';

class WearableManager {
static final WearableManager _instance = WearableManager._internal();

Expand Down Expand Up @@ -59,6 +58,15 @@ class WearableManager {
disconnectNotifier.notifyListeners,
);
if (connectionResult.$1) {
if (device.name == "earconnect") {
return CosinussOne(
name: device.name,
disconnectNotifier: disconnectNotifier,
bleManager: _bleManager,
discoveredDevice: device,
);
}

return OpenEarableV1(
name: device.name,
disconnectNotifier: disconnectNotifier,
Expand Down
34 changes: 13 additions & 21 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
part of open_earable_flutter;
import 'models/devices/cosinuss_one.dart';
import 'models/devices/open_earable_v1.dart';

const String sensorServiceUuid = "34c2e3bb-34aa-11eb-adc1-0242ac120002";
const String sensorConfigurationCharacteristicUuid =
Expand Down Expand Up @@ -34,24 +35,15 @@ const String ledServiceUuid = "81040a2e-4819-11ee-be56-0242ac120002";
const String ledSetStateCharacteristic = "81040e7a-4819-11ee-be56-0242ac120002";

// All UUIDs in a list for filters
List<String> allUuids = [
sensorServiceUuid,
sensorConfigurationCharacteristicUuid,
sensorDataCharacteristicUuid,
deviceInfoServiceUuid,
deviceIdentifierCharacteristicUuid,
deviceFirmwareVersionCharacteristicUuid,
deviceHardwareVersionCharacteristicUuid,
parseInfoServiceUuid,
schemeCharacteristicUuid,
sensorNamesCharacteristicUuid,
audioPlayerServiceUuid,
audioSourceCharacteristic,
audioStateCharacteristic,
batteryServiceUuid,
batteryLevelCharacteristicUuid,
buttonServiceUuid,
buttonStateCharacteristicUuid,
ledServiceUuid,
ledSetStateCharacteristic,
List<String> allServiceUuids = [
OpenEarableV1.ledServiceUuid,
OpenEarableV1.deviceInfoServiceUuid,
OpenEarableV1.audioPlayerServiceUuid,
OpenEarableV1.sensorServiceUuid,
OpenEarableV1.parseInfoServiceUuid,
OpenEarableV1.buttonServiceUuid,
OpenEarableV1.batteryServiceUuid,
CosinussOne.ppgAndAccServiceUuid,
CosinussOne.temperatureServiceUuid,
CosinussOne.heartRateServiceUuid,
];
3 changes: 2 additions & 1 deletion lib/src/managers/ble_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:universal_ble/universal_ble.dart';

import '../../open_earable_flutter.dart';
import '../constants.dart';

/// A class that establishes and manages Bluetooth Low Energy (BLE)
/// communication with OpenEarable devices.
Expand Down Expand Up @@ -131,7 +132,7 @@ class BleManager {
await UniversalBle.startScan(
scanFilter: ScanFilter(
// Needs to be passed for web, can be empty for the rest
withServices: kIsWeb ? allUuids : [],
withServices: kIsWeb ? allServiceUuids : [],
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/managers/open_earable_sensor_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:math';

import 'package:flutter/foundation.dart';

import '../../open_earable_flutter.dart';
import '../constants.dart';
import '../utils/mahony_ahrs.dart';
import 'ble_manager.dart';

Expand Down Expand Up @@ -31,6 +31,7 @@ class OpenEarableSensorManager {
Exception("Can't write sensor config. Earable not connected");
}
await _bleManager.write(
deviceId: deviceId,
serviceId: sensorServiceUuid,
characteristicId: sensorConfigurationCharacteristicUuid,
byteData: sensorConfig.byteList,
Expand Down
Loading
Loading