Skip to content

Commit

Permalink
Merge pull request #1 from Gloveland/test_socket
Browse files Browse the repository at this point in the history
Test socket
  • Loading branch information
jazminsofiaf authored Jul 27, 2021
2 parents c56f3a3 + a8fa984 commit 46fe991
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 32 deletions.
22 changes: 19 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import 'dart:convert';

import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:flutter/material.dart';
import 'package:lsa_gloves/screens/connection/find_connection.dart';
import 'package:lsa_gloves/screens/connection/ble/find_connection.dart';
import 'package:lsa_gloves/screens/connection/wifi/socket.dart';
import 'package:lsa_gloves/screens/files/file_content.dart';
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 Expand Up @@ -137,10 +142,21 @@ class _MyHomePageState extends State<MyHomePage> {
builder: (context) => GloveConnectionPage()
))
},
heroTag: 'Guante',
tooltip: 'Guante',

heroTag: 'Ble',
tooltip: 'Ble',
child: Icon(Icons.bluetooth),
),
FloatingActionButton(
onPressed: () =>{
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => WifiPage()
))
},
heroTag: 'Wifi',
tooltip: 'Wifi',
child: Icon(Icons.wifi),
),
FloatingActionButton(
onPressed: () => {
Navigator.of(context).push(MaterialPageRoute(
Expand Down
108 changes: 108 additions & 0 deletions lib/model/movement.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
class Movement {
final String deviceId;
final int eventNum;
final Hand hand;

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

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

Map<String, dynamic> toJson() => {
'device_id': deviceId,
'event_num': eventNum,
'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,
};

}


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:lsa_gloves/screens/files/storage.dart';
import 'package:lsa_gloves/screens/connection/bluetooth_widgets.dart';
import 'package:lsa_gloves/screens/connection/ble/bluetooth_widgets.dart';

class DeviceScreen extends StatefulWidget {
const DeviceScreen({Key? key, required this.device}) : super(key: key);
Expand Down Expand Up @@ -32,24 +32,9 @@ class _DeviceScreenState extends State<DeviceScreen> {
var word = 'HOLA';
var deviceId = "ac:87:a3:0a:2d:1b";
var measurementFile = await DeviceMeasurementsFile.create(deviceId, word);
while(true) {
for(int i = 0; i < 100; i++) {
String valueRead = await characteristic.read().then((value) => new String.fromCharCodes(value));
print("READING.... $valueRead");
if(!valueRead.contains("ack")){
setState(() {
_ack = (_ack + 1) > 9? 1: (_ack + 1);
});
}
print("SENDING.... ${_ack}ack");
await characteristic.write(utf8.encode("${_ack}ack"));
if(valueRead.contains("end")){
measurementFile.save();
return;
}
if(!valueRead.contains("start")){
var jsonList = "[$valueRead]";
measurementFile.add(jsonList);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class BluetoothOffScreen extends StatelessWidget {
}

class FindDevicesScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -72,8 +71,7 @@ class FindDevicesScreen extends StatelessWidget {
.asyncMap((_) => FlutterBlue.instance.connectedDevices),
initialData: [],
builder: (c, snapshot) => Column(
children: snapshot.data!
.map((d) => ListTile(
children: snapshot.data!.map((d) => ListTile(
title: Text(d.name),
subtitle: Text(d.id.toString()),
trailing: StreamBuilder<BluetoothDeviceState>(
Expand Down
Loading

0 comments on commit 46fe991

Please sign in to comment.