Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
probstlukas committed Dec 26, 2023
1 parent bd24516 commit 1dec4d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions open_earable/lib/apps/jump_height_test/jump_height_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ class _JumpHeightChartState extends State<JumpHeightChart> {
/// Calculates the height of the jump.
DataValue _calculateHeightData(XYZValue accValue) {
// Subtract gravity to get acceleration due to movement.
double currentAcc = accValue._z * cos(_pitch) + accValue._x * sin(_pitch) - _gravity;;
double currentAcc = accValue._z * cos(_pitch) + accValue._x * sin(_pitch) - _gravity;

double threshold = 0.3;
double accMagnitude = sqrt(accValue._x * accValue._x + accValue._y * accValue._y + accValue._z * accValue._z);
bool isStationary = (accMagnitude > _gravity - threshold) && (accMagnitude < _gravity + threshold);
/// Checks if the device is stationary based on acceleration magnitude.
// Checks if the device is stationary based on acceleration magnitude.
if (isStationary) {
_velocity = 0.0;
_height = 0.0;
} else {
// Integrate acceleration to get velocity.
_velocity += currentAcc * _timeSlice;
Expand Down
5 changes: 3 additions & 2 deletions open_earable/lib/apps/jump_height_test/jump_height_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class _JumpHeightTestState extends State<JumpHeightTest>
setState(() {
if (_deviceIsStationary(0.3)) {
_velocity = 0.0;
_height = 0.0;
} else {
// Integrate acceleration to get velocity.
_velocity += currentAcc * _timeSlice;
Expand Down Expand Up @@ -231,8 +232,6 @@ class _JumpHeightTestState extends State<JumpHeightTest>
),
SizedBox(height: 20), // Margin between chart and button
_buildButtons(),
SizedBox(height: 20), // Margin between button and text
_buildText(),
Visibility(
// Show error message if no OpenEarable device is connected.
visible: !_earableConnected,
Expand All @@ -246,6 +245,8 @@ class _JumpHeightTestState extends State<JumpHeightTest>
),
),
),
SizedBox(height: 20), // Margin between button and text
_buildText()
],
),
);
Expand Down

0 comments on commit 1dec4d2

Please sign in to comment.