解决蓝牙卡顿问题
This commit is contained in:
1 parent
432e02e3de
commit
aa75bb281f
14 files changed
+409
-319
No files matched your search
@@ -13,7 +13,7 @@ namespace Assets.Scripts.UI.Prefab.Device
|
||||
{
|
||||
public class DeviceCache
|
||||
{
|
||||
private static Dictionary<string, ushort> dict = null;
|
||||
private static Dictionary<string, string> dict = null;
|
||||
private static string _dataPath;
|
||||
public static void Init(string dataPath) {
|
||||
if(dict != null)
|
||||
@@ -24,23 +24,23 @@ namespace Assets.Scripts.UI.Prefab.Device
|
||||
|
||||
if(!System.IO.File.Exists(_dataPath + "/Devices.txt"))
|
||||
{
|
||||
dict = new Dictionary<string, ushort>();
|
||||
dict = new Dictionary<string, string>();
|
||||
return;
|
||||
}
|
||||
//var str = PlayerPrefs.GetString("DeviceCache", "");
|
||||
var str = System.IO.File.ReadAllText(_dataPath + "/Devices.txt", Encoding.UTF8);
|
||||
if (!string.IsNullOrWhiteSpace(str)) {
|
||||
dict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, ushort>>(str);
|
||||
dict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
|
||||
}
|
||||
else {
|
||||
dict = new Dictionary<string, ushort>();
|
||||
dict = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Add(AbstractDevice antDevice)
|
||||
{
|
||||
|
||||
Debug.Log("添加设备" + antDevice.DeviceNumber);
|
||||
//Debug.Log("添加设备" + antDevice.DeviceNumber);
|
||||
//new System.Collections.Concurrent.ConcurrentDictionary<string, string>().AddOrUpdate
|
||||
//dict.AddOrUpdate(antDevice.Sensor.ToString(), antDevice.DeviceNumber, (key, oldValue)=> {
|
||||
|
||||
@@ -49,16 +49,16 @@ namespace Assets.Scripts.UI.Prefab.Device
|
||||
// return antDevice.DeviceNumber;
|
||||
//});
|
||||
|
||||
dict[antDevice.Sensor.ToString()] = antDevice.DeviceNumber;
|
||||
dict[antDevice.Sensor.ToString()] = antDevice.Id;
|
||||
Write();
|
||||
}
|
||||
|
||||
public static bool Exist(AbstractDevice antDevice)
|
||||
{
|
||||
ushort a;
|
||||
string a;
|
||||
if(dict.TryGetValue(antDevice.Sensor.ToString(), out a))
|
||||
{
|
||||
return a == antDevice.DeviceNumber;
|
||||
return a == antDevice.Id;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -72,7 +72,7 @@ namespace Assets.Scripts.UI.Prefab.Device
|
||||
}
|
||||
if (dict.ContainsKey(antDevice.Sensor.ToString()))
|
||||
{
|
||||
if(dict[antDevice.Sensor.ToString()] == antDevice.DeviceNumber)
|
||||
if(dict[antDevice.Sensor.ToString()] == antDevice.Id)
|
||||
{
|
||||
dict.Remove(antDevice.Sensor.ToString());
|
||||
Write();
|
||||
|
||||
@@ -199,9 +199,13 @@ public class DeviceView : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//if(SensorType != SensorType.Trainer)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
{
|
||||
Main();
|
||||
|
||||
timer = 1.0f;
|
||||
@@ -232,6 +236,8 @@ public class DeviceView : MonoBehaviour
|
||||
mSearchButton.SetActive(false);
|
||||
mPairButton.SetActive(true);
|
||||
logo.sprite = sprite1;
|
||||
|
||||
//App.MainDeviceAdapter.GetDevices().First(d => d.Sensor == SensorType).Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -280,7 +286,9 @@ public class DeviceView : MonoBehaviour
|
||||
{
|
||||
powerValue.text = GetValue(connectedDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType)));
|
||||
}
|
||||
|
||||
string GetTitle()
|
||||
|
||||
Reference in new issue
Block a user