-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Services and characteristics list (#92)
Added displaying list of services and characteristics Co-authored-by: Tomasz Bogusz <[email protected]>
- Loading branch information
1 parent
c7c7477
commit f3f30be
Showing
14 changed files
with
481 additions
and
41 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
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,54 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter_ble_lib/flutter_ble_lib.dart'; | ||
|
||
class BleService extends Equatable { | ||
final String uuid; | ||
final List<BleCharacteristic> characteristics; | ||
|
||
BleService(this.uuid, this.characteristics); | ||
|
||
@override | ||
List<Object> get props => [uuid, characteristics]; | ||
} | ||
|
||
class BleCharacteristic extends Equatable { | ||
final String uuid; | ||
final Uint8List value; | ||
final bool isReadable; | ||
final bool isWritableWithResponse; | ||
final bool isWritableWithoutResponse; | ||
final bool isNotifiable; | ||
final bool isIndicatable; | ||
|
||
BleCharacteristic( | ||
this.uuid, | ||
this.value, | ||
this.isReadable, | ||
this.isWritableWithResponse, | ||
this.isWritableWithoutResponse, | ||
this.isNotifiable, | ||
this.isIndicatable, | ||
); | ||
|
||
@override | ||
List<Object> get props => [ | ||
uuid, | ||
value, | ||
isReadable, | ||
isWritableWithResponse, | ||
isWritableWithoutResponse, | ||
isNotifiable, | ||
isIndicatable | ||
]; | ||
|
||
BleCharacteristic.fromCharacteristic(Characteristic characteristic) | ||
: uuid = characteristic.uuid, | ||
value = null, | ||
isReadable = characteristic.isReadable, | ||
isWritableWithResponse = characteristic.isWritableWithResponse, | ||
isWritableWithoutResponse = characteristic.isWritableWithoutResponse, | ||
isNotifiable = characteristic.isNotifiable, | ||
isIndicatable = characteristic.isIndicatable; | ||
} |
50 changes: 50 additions & 0 deletions
50
example/lib/peripheral_details/components/characteristics_view.dart
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,50 @@ | ||
import 'package:blemulator_example/model/ble_service.dart'; | ||
import 'package:blemulator_example/styles/custom_text_style.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
class CharacteristicsView extends StatelessWidget { | ||
final BleCharacteristic _characteristic; | ||
|
||
CharacteristicsView(this._characteristic); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Card( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
Text( | ||
"UUID: ${_characteristic.uuid}", | ||
style: CustomTextStyle.characteristicsStyle, | ||
), | ||
Text( | ||
"Properties: ${_getCharacteristicProperties(_characteristic).toString()}", | ||
style: CustomTextStyle.characteristicsStyle, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
static List<String> _getCharacteristicProperties( | ||
BleCharacteristic characteristic) { | ||
List<String> properties = new List<String>(); | ||
|
||
if (characteristic.isWritableWithResponse || | ||
characteristic.isWritableWithoutResponse) { | ||
properties.add("write"); | ||
} | ||
if (characteristic.isReadable) { | ||
properties.add("read"); | ||
} | ||
if (characteristic.isIndicatable || characteristic.isNotifiable) { | ||
properties.add("notify"); | ||
} | ||
|
||
return properties; | ||
} | ||
} |
41 changes: 25 additions & 16 deletions
41
example/lib/peripheral_details/components/peripheral_details_view.dart
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.