Skip to content

Commit

Permalink
add edge impulse api
Browse files Browse the repository at this point in the history
  • Loading branch information
jazminsofiaf committed Oct 5, 2021
1 parent fa8800e commit bef490b
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 117 deletions.
3 changes: 2 additions & 1 deletion assets/secrets.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"api_key": "ei_7223fabc8d9843d8fff520e22a5b6fc5578444d02ea8b610398089e6cbc175ea"
"RightGloveLSA-ApiKey": "ei_0b21c715bb1b1ecc4a69812a38314280e2f3351eadf562fe",
"LeftGloveLSA-ApiKey": "ei_a6aa9ff39eb518436474eb402235f3babb298fe6ce0e637f"
}
10 changes: 6 additions & 4 deletions lib/connection/ble/bluetooth_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class BluetoothBackend {
sendCommandToConnectedDevice(device, BluetoothSpecification.CALIBRATE);
}

static void sendStopCommand(List<BluetoothDevice> connectedDevices) async {
sendCommandToConnectedDevices(
static Future sendStopCommand(List<BluetoothDevice> connectedDevices) async {
await sendCommandToConnectedDevices(
connectedDevices, BluetoothSpecification.STOP_ONGOING_TASK);
}

Expand All @@ -58,7 +58,7 @@ class BluetoothBackend {
///
/// This method is expected to be used to start and stop the measurement
/// readings from the glove as well as the interpretations.
static void sendCommandToConnectedDevices(
static Future sendCommandToConnectedDevices(
List<BluetoothDevice> connectedDevices, String command) async {
List<BluetoothCharacteristic> characteristics =
await getDevicesControllerCharacteristics(connectedDevices);
Expand Down Expand Up @@ -153,8 +153,10 @@ class BluetoothBackend {
/// Retrieve the deviceName in spanish
static String getSpanishGloveName(String deviceName) {
switch (deviceName) {
case (BluetoothSpecification.deviceName):
case (BluetoothSpecification.RIGHT_GLOVE_NAME):
return RightGlove;
case (BluetoothSpecification.LEFT_GLOVE_NAME):
return LeftGlove;
default:
return deviceName;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/connection/ble/bluetooth_specification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/// the service and characteristic UUIDs.
class BluetoothSpecification {
/// Identifier of the glove.
static const String deviceName = "RightHandSmartGlove";
static const String RIGHT_GLOVE_NAME = "RightHandSmartGlove";
static const String LEFT_GLOVE_NAME = "LeftHandSmartGlove";

/// Service for reading measurements or retrieving interpretations from the gloves.
static const String LSA_GLOVE_SERVICE_UUID = "7056f14b-02df-4dd8-86fd-0261c7b15c86";
Expand Down
3 changes: 2 additions & 1 deletion lib/connection/wifi/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:developer' as developer;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:lsa_gloves/connection/ble/bluetooth_specification.dart';
import 'package:lsa_gloves/datacollection/storage.dart';
import 'package:lsa_gloves/model/glove_measurement.dart';
import 'package:lsa_gloves/widgets/Dialog.dart';
Expand Down Expand Up @@ -218,7 +219,7 @@ class _MovementRecorderWidget extends State<MovementRecorderWidget> {
Dialogs.showLoadingDialog(context, _keyLoader, "Guardando...");
var word = fileName;
var deviceId = gloveMeasurement.first.deviceId;
var measurementFile = await DeviceMeasurementsFile.create(deviceId, word);
var measurementFile = await DeviceMeasurementsFile.create(BluetoothSpecification.RIGHT_GLOVE_NAME, deviceId, word);
for (int i = 0; i < gloveMeasurement.length; i++) {
developer.log('saving in file -> ${gloveMeasurement[i].toJson().toString()}');
measurementFile.add(gloveMeasurement[i]);
Expand Down
7 changes: 4 additions & 3 deletions lib/datacollection/measurements_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import 'package:lsa_gloves/model/glove_measurement.dart';
class MeasurementsCollector {
final GlobalKey<State> _keyLoader = new GlobalKey<State>();
static const String TAG = "MeasurementsCollector";
String _deviceName;
String _deviceId;
BluetoothCharacteristic _characteristic;
List<GloveMeasurement> _items;
StreamSubscription<List<int>>? _subscription;

MeasurementsCollector(this._deviceId, this._characteristic)
MeasurementsCollector(this._deviceName,this._deviceId, this._characteristic)
: _items = [];

void readMeasurements(BuildContext context) async {
Expand Down Expand Up @@ -96,9 +97,9 @@ class MeasurementsCollector {
}
//open pop up loading
Dialogs.showLoadingDialog(context, _keyLoader, "Guardando...");
var deviceId = gloveMeasurements.first.deviceId;

var measurementFile =
await DeviceMeasurementsFile.create(deviceId, selectedGesture);
await DeviceMeasurementsFile.create(this._deviceName, this._deviceId, selectedGesture);
for (int i = 0; i < gloveMeasurements.length; i++) {
developer
.log('saving in file -> ${gloveMeasurements[i].toJson().toString()}');
Expand Down
11 changes: 7 additions & 4 deletions lib/datacollection/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class DeviceMeasurementsFile {
this.lastModificationDate,
this.fileContent);

static Future<DeviceMeasurementsFile> create(String deviceId, String word) async {
static Future<DeviceMeasurementsFile> create(String deviceName, String deviceId, String word) async {
var creationDate = DateTime.now();
var values = <List<double>>[];
SensorMeasurements json = new SensorMeasurements(deviceId, word, values);
SensorMeasurements json = new SensorMeasurements(deviceName, deviceId, word, values);
String datetimeStr = format(creationDate);
var filename = "${word}_$datetimeStr";
var file = await new GloveEventsStorage().createFile(filename);
Expand Down Expand Up @@ -127,7 +127,7 @@ class DeviceMeasurementsFile {

Future<void> upload() async {
SensorMeasurements measurementsJson = await readJsonContent();
uploadFile(measurementsJson, lastModificationDate);
EdgeImpulseApiClient.uploadFile(measurementsJson, lastModificationDate);
}

static String format(DateTime date) {
Expand All @@ -141,11 +141,12 @@ class DeviceMeasurementsFile {
}

class SensorMeasurements {
final String deviceName;
final String deviceId;
final String word;
final List<List<double>> values;

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

bool add(GloveMeasurement gloveMeasurement) {
if(gloveMeasurement.deviceId != this.deviceId){
Expand Down Expand Up @@ -186,6 +187,7 @@ class SensorMeasurements {
}).toList();
}
return SensorMeasurements(
json['device_name'] as String,
json['device_id'] as String,
json['word'] as String,
_values,
Expand All @@ -194,6 +196,7 @@ class SensorMeasurements {

Map<String, dynamic> toJson() {
return <String, dynamic>{
'device_name': deviceName,
'device_id': deviceId,
'word': word,
'values': values,
Expand Down
Loading

0 comments on commit bef490b

Please sign in to comment.