76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using Assets.Scripts.Devices.Ant;
|
|
using Assets.Scripts.Devices.Ble;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Devices
|
|
{
|
|
public sealed class MainDeviceAdapter : IDisposable
|
|
{
|
|
private List<DeviceAdapter> adapters = new List<DeviceAdapter>();
|
|
public MainDeviceAdapter()
|
|
{
|
|
this.CreateAntAdapter();
|
|
this.CreateBleAdapter();
|
|
}
|
|
|
|
private void CreateAntAdapter()
|
|
{
|
|
adapters.Add(new AntDeviceAdapter());
|
|
}
|
|
|
|
private void CreateBleAdapter()
|
|
{
|
|
adapters.Add(new BleDeviceAdapter());
|
|
}
|
|
|
|
public void StartScan()
|
|
{
|
|
adapters.ForEach(item =>
|
|
{
|
|
item.StartScan();
|
|
});
|
|
}
|
|
|
|
public void StopScan()
|
|
{
|
|
|
|
}
|
|
|
|
public DeviceAdapterState GetState(ConnectionInterface connectionInterface)
|
|
{
|
|
var adapter = adapters.FirstOrDefault(a => a.Interface == connectionInterface);
|
|
if(adapter != null)
|
|
{
|
|
Debug.Log("bbbbbb " + (adapter.GetState().ToString()));
|
|
return adapter.GetState();
|
|
}
|
|
return DeviceAdapterState.Unavailable;
|
|
}
|
|
|
|
public IEnumerable<AbstractDevice> GetDevices()
|
|
{
|
|
var result = new List<AbstractDevice>();
|
|
foreach (var item in adapters)
|
|
{
|
|
result.AddRange(item.GetDevices());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
//throw new NotImplementedException();
|
|
foreach (var item in adapters)
|
|
{
|
|
item.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|