parent
c0687819f2
commit
3e89a2d3fd
@ -1,16 +0,0 @@
|
||||
/*
|
||||
enum DeviceConnectionStatus { NOT_CONNECTED, CONNECTING, CONNECTED }
|
||||
enum DeviceConnectionStatus { NOT_CONNECTED, CONNECTING, CONNECTED }
|
||||
|
||||
extension DeviceConnectionStatusExtenstion on DeviceConnectionStatus {
|
||||
String get statusName {
|
||||
switch (this) {
|
||||
case DeviceConnectionStatus.NOT_CONNECTED:
|
||||
return "Not connected";
|
||||
case DeviceConnectionStatus.CONNECTING:
|
||||
return "Connecting";
|
||||
case DeviceConnectionStatus.CONNECTED:
|
||||
return "MDS connected";
|
||||
}
|
||||
}
|
||||
}*/
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mdsflutter/Mds.dart';
|
||||
|
||||
class DeviceModel extends ChangeNotifier {
|
||||
String? _serial;
|
||||
String? _info;
|
||||
|
||||
// ------------ //
|
||||
|
||||
String? get info => _info;
|
||||
|
||||
// ------------ //
|
||||
|
||||
void getInfo() {
|
||||
MdsAsync.get(Mds.createRequestUri(_serial!, "/Info"), "{}")
|
||||
.then((value) => {_info = value});
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
*/
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
import 'package:smartfit_app_mobile/Modele/Mds/DeviceConnectionStatus.dart';
|
||||
|
||||
class Device {
|
||||
String? _address;
|
||||
String? _name;
|
||||
String? _serial;
|
||||
DeviceConnectionStatus _connectionStatus =
|
||||
DeviceConnectionStatus.NOT_CONNECTED;
|
||||
|
||||
Device(String? name, String? address) {
|
||||
_name = name;
|
||||
_address = address;
|
||||
}
|
||||
|
||||
//String? get name => _name != null ? _name : "";
|
||||
String? get name {
|
||||
if (_name == null) {
|
||||
return "";
|
||||
}
|
||||
return _name;
|
||||
}
|
||||
|
||||
//String? get address => _address != null ? _address : "";
|
||||
String? get address {
|
||||
if (_address == null) {
|
||||
return "";
|
||||
}
|
||||
return _address;
|
||||
}
|
||||
|
||||
//String? get serial => _serial != null ? _serial : "";
|
||||
String? get serial {
|
||||
if (_serial == null) {
|
||||
return "";
|
||||
}
|
||||
return _serial;
|
||||
}
|
||||
|
||||
DeviceConnectionStatus get connectionStatus => _connectionStatus;
|
||||
|
||||
void onConnecting() => _connectionStatus = DeviceConnectionStatus.CONNECTING;
|
||||
void onMdsConnected(String serial) {
|
||||
_serial = serial;
|
||||
_connectionStatus = DeviceConnectionStatus.CONNECTED;
|
||||
}
|
||||
|
||||
void onDisconnected() =>
|
||||
_connectionStatus = DeviceConnectionStatus.NOT_CONNECTED;
|
||||
|
||||
bool operator ==(o) =>
|
||||
o is Device && o._address == _address && o._name == _name;
|
||||
int get hashCode => _address.hashCode * _name.hashCode;
|
||||
}
|
||||
*/
|
@ -1,101 +0,0 @@
|
||||
|
||||
/*
|
||||
import 'dart:collection';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mdsflutter/Mds.dart';
|
||||
import 'package:smartfit_app_mobile/Modele/Mds/DeviceConnectionStatus.dart';
|
||||
import 'package:smartfit_app_mobile/Modele/Mds/device.dart';
|
||||
|
||||
// Doc - https://pub.dev/packages/mdsflutter
|
||||
//https://github.com/petri-lipponen-movesense/mdsflutter/tree/master/example/lib
|
||||
|
||||
class ManagerStateWatch extends ChangeNotifier {
|
||||
final Set<Device> _deviceList = {};
|
||||
bool _scanning = false;
|
||||
// ------------------ //
|
||||
|
||||
bool get scanning => _scanning;
|
||||
UnmodifiableListView<Device> get deviceList =>
|
||||
UnmodifiableListView(_deviceList);
|
||||
|
||||
// ------------------ //
|
||||
|
||||
void startScan() {
|
||||
// On deconnecte les devices si ils sont connecté
|
||||
_deviceList.forEach((device) {
|
||||
if (device.connectionStatus == DeviceConnectionStatus.CONNECTED) {
|
||||
disconnect(device);
|
||||
}
|
||||
});
|
||||
|
||||
// On vide la liste
|
||||
_deviceList.clear();
|
||||
notifyListeners();
|
||||
|
||||
// On lance le scan
|
||||
try {
|
||||
Mds.startScan((name, address) {
|
||||
Device device = Device(name, address);
|
||||
if (!_deviceList.contains(device)) {
|
||||
_deviceList.add(device);
|
||||
notifyListeners();
|
||||
}
|
||||
});
|
||||
_scanning = true;
|
||||
notifyListeners();
|
||||
} on PlatformException {
|
||||
_scanning = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void stopScan() {
|
||||
Mds.stopScan();
|
||||
_scanning = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void disconnect(Device device) {
|
||||
// Deconnexion matérielle
|
||||
Mds.disconnect(device.address!);
|
||||
|
||||
disconnectOnModele(device.address);
|
||||
}
|
||||
|
||||
void disconnectOnModele(String? address) {
|
||||
// Deconnexion avec l'enum
|
||||
Device foundDevice =
|
||||
_deviceList.firstWhere((element) => element.address == address);
|
||||
foundDevice.onDisconnected();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void connectToDevice(Device device) {
|
||||
// Changement de l'enum (On connecting)
|
||||
device.onConnecting();
|
||||
// Connexion matérielle
|
||||
Mds.connect(
|
||||
device.address!,
|
||||
// Connexion établi
|
||||
(serial) => _onDeviceMdsConnected(device.address, serial),
|
||||
// Connexion coupé
|
||||
() => disconnectOnModele(device.address),
|
||||
// Erreur dans la connexion
|
||||
() => _onDeviceConnectError(device.address));
|
||||
}
|
||||
|
||||
// Appeller si la connexion à réussi
|
||||
void _onDeviceMdsConnected(String? address, String serial) {
|
||||
Device foundDevice =
|
||||
_deviceList.firstWhere((element) => element.address == address);
|
||||
// On save le serial + changer l'enum en connected
|
||||
foundDevice.onMdsConnected(serial);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Appeller si une erreur survient dans la connexion
|
||||
void _onDeviceConnectError(String? address) {
|
||||
disconnectOnModele(address);
|
||||
}
|
||||
}*/
|
Loading…
Reference in new issue