62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using Assets.Scripts.UI.Prefab.Device;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Devices.Ant
|
|
{
|
|
public class AntDeviceAdapter : DeviceAdapter
|
|
{
|
|
public override ConnectionInterface Interface => ConnectionInterface.ANT;
|
|
|
|
public AntDeviceAdapter()
|
|
{
|
|
AntConnector.Instance((device2) => {
|
|
if (device2.State == DeviceState.Disconnected)
|
|
{
|
|
//Debug.Log($"探索到新的设备{ device2.DeviceNumber }");
|
|
//自动连接
|
|
if (DeviceCache.Exist(device2))
|
|
{
|
|
//Debug.Log("自动连接" + device2.DeviceNumber);
|
|
device2.Connect();
|
|
}
|
|
}
|
|
}, Debug.Log);
|
|
}
|
|
|
|
public override DeviceAdapterState GetState()
|
|
{
|
|
if (AntConnector.Instance().IsAvailable)
|
|
{
|
|
return DeviceAdapterState.On;
|
|
}
|
|
return DeviceAdapterState.Unavailable;
|
|
}
|
|
|
|
public override IEnumerable<AbstractDevice> GetDevices()
|
|
{
|
|
return AntConnector.Instance().discoveredDevices;
|
|
}
|
|
|
|
public override void StartScan()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
|
|
public override void StopScan()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
AntConnector.Instance().Dispose();
|
|
base.Dispose();
|
|
}
|
|
}
|
|
}
|