Skip to content

Commit

Permalink
fix earable not connected warning in sensor data tab
Browse files Browse the repository at this point in the history
  • Loading branch information
o-bagge committed Feb 24, 2024
1 parent 0619fe8 commit b2ba7d7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 55 deletions.
100 changes: 54 additions & 46 deletions open_earable/lib/sensor_data_tab/earable_3d_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
import 'package:open_earable/ble_controller.dart';
import 'package:open_earable/widgets/earable_not_connected_warning.dart';
import 'package:provider/provider.dart';
import 'dart:async';
import 'package:three_dart/three_dart.dart' as three;
import 'package:three_dart_jsm/three_dart_jsm.dart' as three_jsm;
Expand Down Expand Up @@ -88,52 +91,57 @@ class _Earable3DModelState extends State<Earable3DModel> {

@override
Widget build(BuildContext context) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
// child: Text(title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
),
Expanded(child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
width = constraints.maxWidth;
height = constraints.maxHeight;
Color c = Theme.of(context).colorScheme.background;
_sceneBackground = three.Color.fromArray([c.red, c.green, c.blue]);
initSize(context);
return Column(
children: [
Stack(
children: [
Container(
width: width,
height: height,
color: Theme.of(context).colorScheme.background,
child: Builder(builder: (BuildContext context) {
if (kIsWeb) {
return three3dRender.isInitialized
? HtmlElementView(
viewType:
three3dRender.textureId!.toString())
: Container();
} else {
return three3dRender.isInitialized
? Texture(textureId: three3dRender.textureId!)
: Container();
}
})),
],
),
],
);
},
)),
Padding(
padding: EdgeInsets.only(bottom: 16),
child: Text(
"Yaw: ${(_yaw * 180 / pi).toStringAsFixed(1)}°\nPitch: ${(_pitch * 180 / pi).toStringAsFixed(1)}°\nRoll: ${(_roll * 180 / pi).toStringAsFixed(1)}°"))
],
);
if (!Provider.of<BluetoothController>(context).connected) {
return EarableNotConnectedWarning();
} else {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
// child: Text(title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
),
Expanded(child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
width = constraints.maxWidth;
height = constraints.maxHeight;
Color c = Theme.of(context).colorScheme.background;
_sceneBackground =
three.Color.fromArray([c.red, c.green, c.blue]);
initSize(context);
return Column(
children: [
Stack(
children: [
Container(
width: width,
height: height,
color: Theme.of(context).colorScheme.background,
child: Builder(builder: (BuildContext context) {
if (kIsWeb) {
return three3dRender.isInitialized
? HtmlElementView(
viewType:
three3dRender.textureId!.toString())
: Container();
} else {
return three3dRender.isInitialized
? Texture(textureId: three3dRender.textureId!)
: Container();
}
})),
],
),
],
);
},
)),
Padding(
padding: EdgeInsets.only(bottom: 16),
child: Text(
"Yaw: ${(_yaw * 180 / pi).toStringAsFixed(1)}°\nPitch: ${(_pitch * 180 / pi).toStringAsFixed(1)}°\nRoll: ${(_roll * 180 / pi).toStringAsFixed(1)}°"))
],
);
}
}

// Platform messages are asynchronous, so we initialize in an async method.
Expand Down
10 changes: 9 additions & 1 deletion open_earable/lib/sensor_data_tab/sensor_chart.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:async';

import 'package:flutter/scheduler.dart';
import 'package:open_earable/ble_controller.dart';
import 'package:open_earable/widgets/earable_not_connected_warning.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:provider/provider.dart';
import 'package:simple_kalman/simple_kalman.dart';
import 'package:collection/collection.dart';
import 'dart:math';
Expand Down Expand Up @@ -155,7 +158,9 @@ class _EarableDataChartState extends State<EarableDataChart> {
_minY = -25;
_maxY = 25;
}
_setupListeners();
if (_openEarable.bleManager.connected) {
_setupListeners();
}
}

@override
Expand All @@ -172,6 +177,9 @@ class _EarableDataChartState extends State<EarableDataChart> {

@override
Widget build(BuildContext context) {
if (!Provider.of<BluetoothController>(context).connected) {
return EarableNotConnectedWarning();
}
if (_title == 'Pressure' || _title == 'Temperature') {
seriesList = [
charts.Series<SensorData, int>(
Expand Down
10 changes: 2 additions & 8 deletions open_earable/lib/sensor_data_tab/sensor_data_tab.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:open_earable/ble_controller.dart';
import 'package:open_earable/sensor_data_tab/earable_3d_model.dart';
import 'package:open_earable/widgets/earable_not_connected_warning.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'package:open_earable/sensor_data_tab/sensor_chart.dart';
import 'package:provider/provider.dart';

class SensorDataTab extends StatefulWidget {
final OpenEarable _openEarable;
Expand Down Expand Up @@ -58,14 +60,6 @@ class _SensorDataTabState extends State<SensorDataTab>

@override
Widget build(BuildContext context) {
if (!_openEarable.bleManager.connected) {
return EarableNotConnectedWarning();
} else {
return _buildSensorDataTabs();
}
}

Widget _buildSensorDataTabs() {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
appBar: PreferredSize(
Expand Down

0 comments on commit b2ba7d7

Please sign in to comment.