划船机优化

This commit is contained in:
lishuo committed 2022-06-10 19:31:07 +08:00
1 parent 2f64aa494f
commit 87a0e7fb6d
8 files changed
+109 -80

No files matched your search

@@ -37,74 +37,14 @@ namespace Assets.Scripts.Devices.Ble
}
WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOff;
internal BleMobileThread() {
var self = this;
//初始蓝牙
BluetoothLEHardwareInterface.Initialize(true, false, () => {
statusEnum = WclBleManagerStatus.RadioOn;
managerInitialized?.Invoke(self);
},
(error) => {
statusEnum = WclBleManagerStatus.RadioOff;
BluetoothLEHardwareInterface.Log("Error: " + error);
if (error.Contains("Bluetooth LE Not Enabled"))
BluetoothLEHardwareInterface.BluetoothEnable(true);
}, (status) => {
statusEnum = WclBleManagerStatus.RadioOn;
switch (status)
{
case 13:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 11:
statusEnum = WclBleManagerStatus.RadioOn;
break;
}
if (managerStatusChanged != null)
{
managerStatusChanged.Invoke(self, statusEnum);
}
});
Initialize();//初始蓝牙
}
public void StartWatcher() {
var self = this;
if (statusEnum == WclBleManagerStatus.RadioOff)
{
BluetoothLEHardwareInterface.BluetoothEnable(true);
BluetoothLEHardwareInterface.Initialize(true, false, () =>
{
statusEnum = WclBleManagerStatus.RadioOn;
managerInitialized?.Invoke(self);
BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(ServiceUuids.GetServiceUuidList().ToArray(), null, (address, name, rssi, bytes) =>
{
ScanInfoReceived?.Invoke(self, address, name, rssi, bytes);
}, true);
},
(error) =>
{
statusEnum = WclBleManagerStatus.RadioOff;
BluetoothLEHardwareInterface.Log("Error: " + error);
if (error.Contains("Bluetooth LE Not Enabled"))
BluetoothLEHardwareInterface.BluetoothEnable(true);
}, (status) =>
{
statusEnum = WclBleManagerStatus.RadioOn;
switch (status)
{
case 13:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 11:
statusEnum = WclBleManagerStatus.RadioOn;
break;
}
if (managerStatusChanged != null)
{
managerStatusChanged.Invoke(self, statusEnum);
}
});
Initialize();
}
else
{
@@ -114,6 +54,52 @@ namespace Assets.Scripts.Devices.Ble
}, true);
}
}
public void Initialize()
{
var self = this;
BluetoothLEHardwareInterface.BluetoothEnable(true);
BluetoothLEHardwareInterface.Initialize(true, false, () =>
{
statusEnum = WclBleManagerStatus.RadioOn;
managerInitialized?.Invoke(self);
BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(ServiceUuids.GetServiceUuidList().ToArray(), null, (address, name, rssi, bytes) =>
{
ScanInfoReceived?.Invoke(self, address, name, rssi, bytes);
}, true);
},
(error) =>
{
statusEnum = WclBleManagerStatus.RadioOff;
BluetoothLEHardwareInterface.Log("Error: " + error);
if (error.Contains("Bluetooth LE Not Enabled"))
BluetoothLEHardwareInterface.BluetoothEnable(true);
}, (status) =>
{
statusEnum = WclBleManagerStatus.RadioOn;
switch (status)
{
case 10:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 13:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 11:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 12:
statusEnum = WclBleManagerStatus.RadioOn;
break;
default:
statusEnum = WclBleManagerStatus.RadioOff;
break;
}
if (managerStatusChanged != null)
{
managerStatusChanged.Invoke(self, statusEnum);
}
});
}
public void Stop()
{