Skip to content

Commit

Permalink
Displaying accelerometer values along with the interpretations
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIMP committed Nov 7, 2021
1 parent 27a08e4 commit f9a39d7
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/pages/interpretation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class _InterpretationsPanelState extends State<InterpretationsPanel> {
key: Key(entry.key.id.id),
device: entry.key,
interpretationCharacteristic: entry.value,
measurementsCharacteristic:
backend.dataCollectionCharacteristics[entry.key]!,
));
}
return Column(
Expand All @@ -87,24 +89,28 @@ class _InterpretationsPanelState extends State<InterpretationsPanel> {
class InterpretationWidget extends StatefulWidget {
final BluetoothDevice device;
final BluetoothCharacteristic interpretationCharacteristic;
final BluetoothCharacteristic measurementsCharacteristic;

const InterpretationWidget(
{Key? key,
required this.device,
required this.interpretationCharacteristic})
required this.interpretationCharacteristic,
required this.measurementsCharacteristic})
: super(key: key);

@override
_InterpretationWidgetState createState() =>
_InterpretationWidgetState(device, interpretationCharacteristic);
_InterpretationWidgetState createState() => _InterpretationWidgetState(
device, interpretationCharacteristic, measurementsCharacteristic);
}

class _InterpretationWidgetState extends State<InterpretationWidget> {
static final String TAG = "InterpretationWidget";
final BluetoothDevice device;
final BluetoothCharacteristic interpretationCharacteristic;
final BluetoothCharacteristic dcCharacteristic;

_InterpretationWidgetState(this.device, this.interpretationCharacteristic);
_InterpretationWidgetState(
this.device, this.interpretationCharacteristic, this.dcCharacteristic);

@override
void dispose() {
Expand All @@ -130,7 +136,22 @@ class _InterpretationWidgetState extends State<InterpretationWidget> {
alignment: Alignment.topCenter,
color: Theme.of(context).backgroundColor,
child: Text("Mac addr: ${device.id.id}")),
displayStats()
displayStats(),
StreamBuilder<List<int>>(
stream: dcCharacteristic.value,
initialData: [],
builder: (c, measurements) {
String msg = "";
if (measurements.hasData) {
msg = new String.fromCharCodes(measurements.data!);
}
return Container(
width: double.infinity,
height: 80,
alignment: Alignment.center,
color: Theme.of(c).backgroundColor,
child: Text(msg));
})
],
));
}
Expand Down

0 comments on commit f9a39d7

Please sign in to comment.