-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting glove_measurements.dart into multiple files.
- Loading branch information
Showing
9 changed files
with
173 additions
and
150 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
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; | ||
} |
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,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; | ||
} | ||
} | ||
} |
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,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; | ||
} |
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,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)"; | ||
} | ||
} | ||
} |
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,6 @@ | ||
/// Helper class to contain the 3 axis values of the mpu6050 sensors. | ||
abstract class Vector3 { | ||
double getX(); | ||
double getY(); | ||
double getZ(); | ||
} |
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