接入蓝牙基本结构
This commit is contained in:
1 parent
84e8b50bbf
commit
2f84f70a5f
152 files changed
+6426
-56
No files matched your search
@@ -12,16 +12,12 @@ namespace Assets.Scripts.Devices.Ant
|
||||
{
|
||||
public abstract class AbstractAntDevice : DataSourceBase
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
|
||||
public AntChannelProfile searchProfile;
|
||||
public bool isInitialized = false;
|
||||
private DeviceState state;
|
||||
public DeviceState State
|
||||
public override DeviceState State
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -37,7 +33,7 @@ namespace Assets.Scripts.Devices.Ant
|
||||
StateChange?.Invoke(state);
|
||||
}
|
||||
}
|
||||
public SensorType Sensor { get; private set; }
|
||||
|
||||
|
||||
private int _ManufacturerId;
|
||||
/// <summary>
|
||||
@@ -56,7 +52,7 @@ namespace Assets.Scripts.Devices.Ant
|
||||
}
|
||||
|
||||
private ushort _DeviceNumber;
|
||||
public ushort DeviceNumber
|
||||
public override ushort DeviceNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -92,10 +88,6 @@ namespace Assets.Scripts.Devices.Ant
|
||||
public bool pairingEnabled;
|
||||
}
|
||||
|
||||
public virtual int Priority
|
||||
{
|
||||
get; protected set;
|
||||
}
|
||||
|
||||
//private readonly Rhino.PowerFun.Services.DeviceService deviceService;
|
||||
//private readonly DeviceDetailService _deviceDetailService;
|
||||
@@ -174,7 +166,7 @@ namespace Assets.Scripts.Devices.Ant
|
||||
// base.reset();
|
||||
//}
|
||||
|
||||
public void Connect()
|
||||
public override void Connect()
|
||||
{
|
||||
if (State == DeviceState.Connected || State == DeviceState.Connecting)
|
||||
return;
|
||||
@@ -182,7 +174,7 @@ namespace Assets.Scripts.Devices.Ant
|
||||
AntConnector.Instance().ConnectDevice(this);
|
||||
}
|
||||
|
||||
public void Disconnect(bool save = true)
|
||||
public override void Disconnect(bool save = true)
|
||||
{
|
||||
if (State == DeviceState.Disconnected || State == DeviceState.Disconnecting)
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da476d42626b4894c80f0fc0b46709ad
|
||||
guid: aa2b23675a0486a40881d44a57de8d73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant
|
||||
{
|
||||
public abstract class DataSourceBase
|
||||
public abstract class DataSourceBase : AbstractDevice
|
||||
{
|
||||
//double distanceTravelled = 0;
|
||||
//DataSourcePacket lastPacketRcvd = null;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant
|
||||
{
|
||||
public enum DeviceState
|
||||
{
|
||||
Connecting,
|
||||
Connected,
|
||||
Interrupted,
|
||||
Disconnecting,
|
||||
Disconnected,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user