-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from PhilipsHue/null-safety
Null safety integration
- Loading branch information
Showing
70 changed files
with
2,527 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; | ||
|
||
class BleDeviceInteractor { | ||
BleDeviceInteractor({ | ||
required Future<List<DiscoveredService>> Function(String deviceId) | ||
bleDiscoverServices, | ||
required Future<List<int>> Function(QualifiedCharacteristic characteristic) | ||
readCharacteristic, | ||
required Future<void> Function(QualifiedCharacteristic characteristic, | ||
{required List<int> value}) | ||
writeWithResponse, | ||
required Future<void> Function(QualifiedCharacteristic characteristic, | ||
{required List<int> value}) | ||
writeWithOutResponse, | ||
required void Function(String message) logMessage, | ||
required Stream<List<int>> Function(QualifiedCharacteristic characteristic) | ||
subscribeToCharacteristic, | ||
}) : _bleDiscoverServices = bleDiscoverServices, | ||
_readCharacteristic = readCharacteristic, | ||
_writeWithResponse = writeWithResponse, | ||
_writeWithoutResponse = writeWithOutResponse, | ||
_subScribeToCharacteristic = subscribeToCharacteristic, | ||
_logMessage = logMessage; | ||
|
||
final Future<List<DiscoveredService>> Function(String deviceId) | ||
_bleDiscoverServices; | ||
|
||
final Future<List<int>> Function(QualifiedCharacteristic characteristic) | ||
_readCharacteristic; | ||
|
||
final Future<void> Function(QualifiedCharacteristic characteristic, | ||
{required List<int> value}) _writeWithResponse; | ||
|
||
final Future<void> Function(QualifiedCharacteristic characteristic, | ||
{required List<int> value}) _writeWithoutResponse; | ||
|
||
final Stream<List<int>> Function(QualifiedCharacteristic characteristic) | ||
_subScribeToCharacteristic; | ||
|
||
final void Function(String message) _logMessage; | ||
|
||
Future<List<DiscoveredService>> discoverServices(String deviceId) async { | ||
try { | ||
_logMessage('Start discovering services for: $deviceId'); | ||
final result = await _bleDiscoverServices(deviceId); | ||
_logMessage('Discovering services finished'); | ||
return result; | ||
} on Error catch (e) { | ||
_logMessage('Error occured when discovering services: $e'); | ||
throw e; | ||
} | ||
} | ||
|
||
Future<List<int>> readCharacteristic( | ||
QualifiedCharacteristic characteristic) async { | ||
try { | ||
final result = await _readCharacteristic(characteristic); | ||
|
||
_logMessage('Read ${characteristic.characteristicId}: value = $result'); | ||
return result; | ||
} on Error catch (e, s) { | ||
_logMessage( | ||
'Error occured when reading ${characteristic.characteristicId} : $e', | ||
); | ||
print(s); | ||
throw e; | ||
} | ||
} | ||
|
||
Future<void> writeCharacterisiticWithResponse( | ||
QualifiedCharacteristic characteristic, List<int> value) async { | ||
try { | ||
_logMessage( | ||
'Write with response value : $value to ${characteristic.characteristicId}'); | ||
await _writeWithResponse(characteristic, value: value); | ||
} on Error catch (e, s) { | ||
_logMessage( | ||
'Error occured when writing ${characteristic.characteristicId} : $e', | ||
); | ||
print(s); | ||
throw e; | ||
} | ||
} | ||
|
||
Future<void> writeCharacterisiticWithoutResponse( | ||
QualifiedCharacteristic characteristic, List<int> value) async { | ||
try { | ||
await _writeWithoutResponse(characteristic, value: value); | ||
_logMessage( | ||
'Write without response value: $value to ${characteristic.characteristicId}'); | ||
} on Error catch (e, s) { | ||
_logMessage( | ||
'Error occured when writing ${characteristic.characteristicId} : $e', | ||
); | ||
print(s); | ||
throw e; | ||
} | ||
} | ||
|
||
Stream<List<int>> subScribeToCharacteristic( | ||
QualifiedCharacteristic characteristic) { | ||
_logMessage('Subscribing to: ${characteristic.characteristicId} '); | ||
return _subScribeToCharacteristic(characteristic); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
class BleLogger { | ||
final List<String> _logMessages = []; | ||
final DateFormat formatter = DateFormat('HH:mm:ss.SSS'); | ||
|
||
List<String> get messages => _logMessages; | ||
|
||
void addToLog(String message) { | ||
final now = DateTime.now(); | ||
_logMessages.add('${formatter.format(now)} - $message'); | ||
} | ||
|
||
void clearLogs() => _logMessages.clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.