Skip to content

Commit

Permalink
Tidy up #5
Browse files Browse the repository at this point in the history
Splitting glove_measurements.dart into multiple files.
  • Loading branch information
DariusIMP committed Mar 24, 2022
1 parent 1675bcd commit 2414371
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 150 deletions.
1 change: 1 addition & 0 deletions lib/datacollection/storage.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:convert';
import 'package:lsa_gloves/model/finger.dart';
import 'package:lsa_gloves/model/glove_measurement.dart';
import 'package:lsa_gloves/edgeimpulse/api_client.dart';
import 'package:path_provider/path_provider.dart';
Expand Down
29 changes: 29 additions & 0 deletions lib/model/acceleration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import 'package:lsa_gloves/model/vector3.dart';

/// Class to encapsulate the acceleration values received from the glove.
class Acceleration with Vector3 {
final double x;
final double y;
final double z;

Acceleration(this.x, this.y, this.z);

Acceleration.fromJson(Map<String, dynamic> json)
: x = json['x'], y = json['y'], z = json['z'];

Map<String, dynamic> toJson() => {
'x': x,
'y': y,
'z': z,
};

@override
double getX() => x;

@override
double getY() => y;

@override
double getZ() => z;
}
59 changes: 59 additions & 0 deletions lib/model/finger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'sensor_value.dart';
import 'vector3.dart';
import 'acceleration.dart';
import 'gyro.dart';

/// Enumeration for each of the hand's fingers.
enum FingerValue {
Pinky,
Ring,
Middle,
Index,
Thumb
}

extension FingerValueTranslation on FingerValue {
String spanishName() {
switch (this) {
case FingerValue.Pinky:
return "Meñique";
case FingerValue.Ring:
return "Anular";
case FingerValue.Middle:
return "Medio";
case FingerValue.Index:
return "Índice";
case FingerValue.Thumb:
return "Pulgar";
}
}
}

/// Class to handle the sensor measurements from a finger's mpu6050.
class Finger {
final Acceleration acc;
final Gyro gyro;

Finger(this.acc, this.gyro);

Finger.fromJson(Map<String, dynamic> json)
: acc = Acceleration.fromJson(json['acc'] as Map<String, dynamic>),
gyro = Gyro.fromJson(json['gyro'] as Map<String, dynamic>);
Map<String, dynamic> toJson() => {
'acc': acc.toJson(),
'gyro': gyro.toJson(),
};

Finger.fromList(List<double> m):
acc = Acceleration(m[0],m[1], m[2]),
gyro = Gyro(m[3],m[4], m[5]);

Vector3 getSensorValues(SensorValue sensorName) {
switch (sensorName) {
case SensorValue.Acceleration:
return acc;
case SensorValue.Gyroscope:
return gyro;
}
}
}
152 changes: 2 additions & 150 deletions lib/model/glove_measurement.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import 'finger.dart';

enum FingerValue {
Pinky,
Ring,
Middle,
Index,
Thumb
}

extension FingerValueTranslation on FingerValue {
String spanishName() {
switch (this) {
case FingerValue.Pinky:
return "Meñique";
case FingerValue.Ring:
return "Anular";
case FingerValue.Middle:
return "Medio";
case FingerValue.Index:
return "Índice";
case FingerValue.Thumb:
return "Pulgar";
}
}
}

/// Class to represent a glove measurement.
class GloveMeasurement {
static const int measurementsNumber = 6;
static const String pinkyLetter = "P";
Expand Down Expand Up @@ -99,129 +76,4 @@ class GloveMeasurement {
}
}

enum SensorValue {
Acceleration,
Gyroscope
}

extension SensorValueExtension on SensorValue {
String spanishName() {
switch (this) {
case SensorValue.Acceleration:
return "Acelerómetro";
case SensorValue.Gyroscope:
return "Giroscopio";
}
}

String getXLabel() {
switch (this) {
case SensorValue.Acceleration:
return "x (m/s²)";
case SensorValue.Gyroscope:
return "x (º/s)";
}
}
String getYLabel() {
switch (this) {
case SensorValue.Acceleration:
return "y (m/s²)";
case SensorValue.Gyroscope:
return "y (º/s)";
}
}
String getZLabel() {
switch (this) {
case SensorValue.Acceleration:
return "z (m/s²)";
case SensorValue.Gyroscope:
return "z (º/s)";
}
}
}

class Finger {
final Acceleration acc;
final Gyro gyro;

Finger(this.acc, this.gyro);

Finger.fromJson(Map<String, dynamic> json)
: acc = Acceleration.fromJson(json['acc'] as Map<String, dynamic>),
gyro = Gyro.fromJson(json['gyro'] as Map<String, dynamic>);
Map<String, dynamic> toJson() => {
'acc': acc.toJson(),
'gyro': gyro.toJson(),
};

Finger.fromList(List<double> m):
acc = Acceleration(m[0],m[1], m[2]),
gyro = Gyro(m[3],m[4], m[5]);

Vector3 getSensorValues(SensorValue sensorName) {
switch (sensorName) {
case SensorValue.Acceleration:
return acc;
case SensorValue.Gyroscope:
return gyro;
}
}
}

class Acceleration with Vector3 {
final double x;
final double y;
final double z;

Acceleration(this.x, this.y, this.z);

Acceleration.fromJson(Map<String, dynamic> json)
: x = json['x'], y = json['y'], z = json['z'];

Map<String, dynamic> toJson() => {
'x': x,
'y': y,
'z': z,
};

@override
double getX() => x;

@override
double getY() => y;

@override
double getZ() => z;
}

class Gyro with Vector3 {
final double x;
final double y;
final double z;
Gyro (this.x, this.y, this.z);

Gyro .fromJson(Map<String, dynamic> json)
: x = json['x'], y = json['y'], z = json['z'];

Map<String, dynamic> toJson() => {
'x': x,
'y': y,
'z': z,
};

@override
double getX() => x;

@override
double getY() => y;

@override
double getZ() => z;
}

abstract class Vector3 {
double getX();
double getY();
double getZ();
}

28 changes: 28 additions & 0 deletions lib/model/gyro.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import 'package:lsa_gloves/model/vector3.dart';

/// Class to encapsulate the gyroscope values received from the glove.
class Gyro with Vector3 {
final double x;
final double y;
final double z;
Gyro (this.x, this.y, this.z);

Gyro .fromJson(Map<String, dynamic> json)
: x = json['x'], y = json['y'], z = json['z'];

Map<String, dynamic> toJson() => {
'x': x,
'y': y,
'z': z,
};

@override
double getX() => x;

@override
double getY() => y;

@override
double getZ() => z;
}
40 changes: 40 additions & 0 deletions lib/model/sensor_value.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
enum SensorValue {
Acceleration,
Gyroscope
}

extension SensorValueExtension on SensorValue {
String spanishName() {
switch (this) {
case SensorValue.Acceleration:
return "Acelerómetro";
case SensorValue.Gyroscope:
return "Giroscopio";
}
}

String getXLabel() {
switch (this) {
case SensorValue.Acceleration:
return "x (m/s²)";
case SensorValue.Gyroscope:
return "x (º/s)";
}
}
String getYLabel() {
switch (this) {
case SensorValue.Acceleration:
return "y (m/s²)";
case SensorValue.Gyroscope:
return "y (º/s)";
}
}
String getZLabel() {
switch (this) {
case SensorValue.Acceleration:
return "z (m/s²)";
case SensorValue.Gyroscope:
return "z (º/s)";
}
}
}
6 changes: 6 additions & 0 deletions lib/model/vector3.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// Helper class to contain the 3 axis values of the mpu6050 sensors.
abstract class Vector3 {
double getX();
double getY();
double getZ();
}
3 changes: 3 additions & 0 deletions lib/pages/data_visualization_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import 'package:intl/intl.dart';
import 'package:lsa_gloves/connection/ble/bluetooth_backend.dart';
import 'package:lsa_gloves/datacollection/measurements_collector.dart';
import 'package:lsa_gloves/datacollection/measurements_listener.dart';
import 'package:lsa_gloves/model/finger.dart';
import 'package:lsa_gloves/model/glove_measurement.dart';
import 'package:lsa_gloves/model/sensor_value.dart';
import 'package:lsa_gloves/model/vector3.dart';
import 'package:lsa_gloves/navigation/navigation_drawer.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/file_content_chart_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:lsa_gloves/connection/ble/bluetooth_backend.dart';
import 'package:lsa_gloves/datacollection/storage.dart';
import 'package:lsa_gloves/model/acceleration.dart';
import 'package:lsa_gloves/model/finger.dart';
import 'package:lsa_gloves/model/glove_measurement.dart';
import 'package:lsa_gloves/model/gyro.dart';
import 'package:lsa_gloves/model/sensor_value.dart';
import 'package:lsa_gloves/model/vector3.dart';
import 'package:lsa_gloves/navigation/navigation_drawer.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
Expand Down

0 comments on commit 2414371

Please sign in to comment.