适配c2;新版设计稿;对战切换手势;主逻辑接通;使用think的阻力值,修改影子模式船位置

This commit is contained in:
Caiyanpeng committed 2022-03-25 18:02:34 +08:00
1 parent e6f3e2ecfa
commit ab653b994f
82 files changed
+25241 -8988

No files matched your search

+103 -22
View File
@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
@@ -16,9 +17,12 @@ namespace Assets.Scripts.Devices.Ble.Devices
private FtmsRowerData _rowerData;
public FtmsRowerData rowerData { get => _rowerData; }
C2RowerData _c2RowerData;
public C2RowerData c2RowerData { get => _c2RowerData; }
private List<BleServiceInfo> Services;
private BleCharacteristicInfo controlPointCharacteristic;
private BleCharacteristicInfo c2Control;
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
{
Debug.Log(24);
@@ -26,34 +30,50 @@ namespace Assets.Scripts.Devices.Ble.Devices
//划船机
this._rowerData = new FtmsRowerData();
base.Characteristics.Add(rowerData);
this._c2RowerData = new C2RowerData();
base.Characteristics.Add(c2RowerData);
bleWinHwInterface.CharacteristicReadEvent -= CharacteristicReadMainCallback;
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
}
protected override void CreateServices(List<BleServiceInfo> discoveredServices)
{
this.Services = discoveredServices;
Debug.Log("服务+" + string.Join(",", Services.Select(x => x.Id.ToString())));
foreach (var service in this.Services)
{
hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) =>
{
foreach (var character in response.Data)
{
//Debug.Log(character.Id.ToString());
if (character.MatchGuid(ServiceUuids.Characteristics.FitnessMachineControlPoint))
{
Debug.Log("中控台获取");
this.controlPointCharacteristic = character;
}
}
else if (character.MatchGuid(ServiceUuids.Characteristics.RowerData))
{
Debug.Log("划船机");
this.hwInterface.SubscribeCharacteristic(character, (hw, cha, res) =>
{
//Debug.Log("1111111111111111111111");
//Debug.WriteLine(res.ToString());
var res1 = (res as BleResponse<byte[]>);
Debug.Log("收到消息划船机:" + string.Join(",", res1));
});
Debug.Log("ftms划船机" + service.Id);
this.hwInterface.SubscribeCharacteristic(character, null);
}
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData))
{
Debug.Log("c2划船机基本数据" + service.Id);
//C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null);
}
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData1))
{
Debug.Log("c2划船机拉力数据" + service.Id);
//C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null);
}
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl))
{
Debug.Log("c2划船机控制台");
this.c2Control = character;
}
}
});
@@ -62,26 +82,87 @@ namespace Assets.Scripts.Devices.Ble.Devices
private void CharacteristicReadMainCallback(IBleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
{
foreach (var item in base.Characteristics)
//var tc = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData);
//tc.HandleAttributeReceived(new byte[] { 61, 89, 0, 0, 0, 33, 0, 33, 0, 46, 0, 46, 0, 53, 0, 60, 0, 60, 0, 68, 0, 68, 0, 0, 0 });
//tc.HandleAttributeReceived(new byte[] { 53, 223, 211, 0, 162, 57, 0, 82, 62, 96, 0, 94, 2, 183, 3, 125, 2, 208, 7, 203, 0 });
if (characteristic.MatchGuid(ServiceUuids.Characteristics.RowerData))
{
if (characteristic.MatchGuid(item.Uuid))
{
//Debug.Log(string.Join(",", response.Data));
item.HandleAttributeReceived(response.Data);
}
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData);
c.HandleAttributeReceived(response.Data);
}
else
{
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData);
var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray();
c.HandleAttributeReceived(data);
}
//foreach (var item in base.Characteristics)
//{
// if (characteristic.MatchGuid(item.Uuid) || characteristic.Id == ServiceUuids.Characteristics.C2RowerData1)
// {
// if (item.Uuid == ServiceUuids.Characteristics.C2RowerData1)
// {
// Debug.Log("c2");
// var data = new byte[] { item.Uuid.ToByteArray()[0] }.Concat(response.Data).ToArray();
// item.HandleAttributeReceived(data);
// }
// else if (item.Uuid == ServiceUuids.Characteristics.RowerData)
// {
// Debug.Log("ftms");
// item.HandleAttributeReceived(response.Data);
// }
// }
//}
}
public void Reset()
{
Debug.Log("发送重置命令"+this.controlPointCharacteristic.ToString());
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, new byte[] { 0x01 });
if (C2RowerData.IsEnabled == true)
{
//等对csafe协议研究透彻后写
//if (this.c2Control != null)
//{
// Debug.Log("发送重置命令" + this.c2Control.ToString());
// hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x86, 0x87, 0x01, 0xF2 });
// //hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x81, 0x81, 0xF2 });
//}
}
else
{
if (this.controlPointCharacteristic != null)
{
Debug.Log("发送重置命令" + this.controlPointCharacteristic.ToString());
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, new byte[] { 0x01 });
}
}
}
public void SetResistanceLevel(ushort v)
{
var r = new byte[] { 0x04 }.Concat(BitConverter.GetBytes(v)).ToArray();
Debug.Log($"设置阻力{v}, {string.Join(",", r)}");
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, r);
if (C2RowerData.IsEnabled == true)
{
//等对csafe协议研究透彻后写
//if (this.c2Control != null)
//{
// var data = new byte[] { 0x29 }.Concat(BitConverter.GetBytes(v)).ToArray();
// byte checksum = (byte)((byte)(data[0] ^ data[1]) ^ data[2]);
// var r = new byte[] { 0xF1 }.Concat(data).Concat(new byte[] { checksum, 0xf2 }) .ToArray();
// Debug.Log($"设置阻力{v}, {string.Join(",", r)}");
// hwInterface.WriteCharacteristic(this.c2Control, r);
//}
}
else
{
if (this.controlPointCharacteristic != null)
{
//特注:81是think专有指令,后期可能需要兼容其他设备
var r = new byte[] { 0x81 }.Concat(BitConverter.GetBytes((ushort)(50 + v))).ToArray();
Debug.Log($"设置阻力{v}, {string.Join(",", r)}");
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, r);
}
}
}
}
}