Skip to content

Commit

Permalink
guardar archivo con nombre
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazmin Ferreiro authored and Jazmin Ferreiro committed Jul 19, 2021
1 parent 0262234 commit a8fa984
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 16 deletions.
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:flutter/material.dart';
import 'package:lsa_gloves/screens/connection/ble/find_connection.dart';
Expand All @@ -7,6 +9,8 @@ import 'package:lsa_gloves/screens/files/file_list.dart';
import 'dart:developer';
import 'package:lsa_gloves/screens/files/storage.dart';

import 'model/movement.dart';


void main() {
runApp(MyApp());
Expand Down
104 changes: 97 additions & 7 deletions lib/model/movement.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,108 @@
class Movement {
final String deviceId;
final int eventNum;
final double acc;
final double gyro;
Movement(this.deviceId, this.eventNum, this.acc, this.gyro);
final Hand hand;

Movement(this.deviceId, this.eventNum, this.hand);

Movement.fromJson(Map<String, dynamic> json)
: deviceId = json['device_id'], eventNum = json['event_num'],
acc = json['acc'], gyro = json['gyro'];
hand = Hand.fromJson(json['hand'] as Map<String, dynamic>);

Map<String, dynamic> toJson() => {
'device_id': deviceId,
'event_num': eventNum,
'acc': acc,
'gyro': gyro,
'hand': hand.toJson(),
};
}


class Hand {
final Finger thump;
/*
final Finger index;
final Finger middle;
final Finger ring;
final Finger pinky;
*/

Hand(this.thump);

Hand.fromJson(Map<String, dynamic> json)
: thump = Finger.fromJson(json['thump'] as Map<String, dynamic>);

Map<String, dynamic> toJson() => {
'thump': thump.toJson(),
};

}

class Finger {
final Acceleration acc;
final Gyro gyro;
final Inclination inclination;

Finger(this.acc, this.gyro, this.inclination);

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

}
class Acceleration {
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,
};
}

class Gyro {
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,
};
}
}

class Inclination {
final double roll;
final double pitch;
final double yaw;
Inclination(this.roll, this.pitch, this.yaw);

Inclination.fromJson(Map<String, dynamic> json)
: roll = json['roll'], pitch = json['pitch'], yaw = json['yaw'];

Map<String, dynamic> toJson() => {
'roll': roll,
'pitch': pitch,
'yaw': yaw,
};

}


6 changes: 3 additions & 3 deletions lib/screens/connection/wifi/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class _MovementRecorderWidget extends State<MovementRecorderWidget> {
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Desea guardar los movimientos medidos?'),
title: const Text('Guardar los movimientos?'),
content: TextField(
onChanged: (value) {
setState(() {
Expand All @@ -106,7 +106,7 @@ class _MovementRecorderWidget extends State<MovementRecorderWidget> {

},
controller: _fileNameFieldController,
decoration: InputDecoration(hintText: "Nombre"),
decoration: InputDecoration(hintText: "Nombre del archivo"),
),
actions: <Widget>[
TextButton(
Expand Down Expand Up @@ -195,7 +195,7 @@ class _MovementRecorderWidget extends State<MovementRecorderWidget> {
print('map to -> ${pkg.toJson().toString()}');
sc.add(pkg);
}catch(e){
print('cant parse : jsonString');
print('cant parse : ${list[i]}');
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions lib/screens/files/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class DeviceMeasurementsFile {
"${date.minute.toString()}:" +
"${date.second.toString()}";
}

}

class SensorMeasurements {
Expand All @@ -147,14 +146,22 @@ class SensorMeasurements {

SensorMeasurements(this.deviceId, this.word, this.values);

bool add(Movement measurement) {
if(measurement.deviceId != this.deviceId){
print("wrong deviceId $measurement.deviceId");
bool add(Movement mov) {
if(mov.deviceId != this.deviceId){
print("wrong deviceId $mov.deviceId");
return false;
}
List<double> measurementList = [];
measurementList.add(measurement.acc);
measurementList.add(measurement.gyro);
var thump = mov.hand.thump;
measurementList.add(thump.acc.x);
measurementList.add(thump.acc.y);
measurementList.add(thump.acc.z);
measurementList.add(thump.gyro.x);
measurementList.add(thump.gyro.y);
measurementList.add(thump.gyro.z);
measurementList.add(thump.inclination.yaw);
measurementList.add(thump.inclination.pitch);
measurementList.add(thump.inclination.roll);
this.values.add(measurementList);
return true;
}
Expand Down

0 comments on commit a8fa984

Please sign in to comment.