Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CoreBluetoothEditor
{
public class BuildPostProcessor : IPostprocessBuildWithReport
public class BuildPostprocessor : IPostprocessBuildWithReport
{
public int callbackOrder { get { return 1; } }

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

namespace CoreBluetoothSample
{
public class Sample_Central : MonoBehaviour, ICBCentralManagerDelegate, ICBPeripheralDelegate
public class SampleDebug_Central : MonoBehaviour, ICBCentralManagerDelegate, ICBPeripheralDelegate
{
CBCentralManager centralManager;

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
string serviceUUID = "068C47B7-FC04-4D47-975A-7952BE1A576F";
string characteristicUUID = "E3737B3F-A08D-405B-B32D-35A8F6C64C5D";
CBPeripheral peripheral;
CBCharacteristic remoteCharacteristic;
string _serviceUUID = "068C47B7-FC04-4D47-975A-7952BE1A576F";
string _characteristicUUID = "E3737B3F-A08D-405B-B32D-35A8F6C64C5D";

CBCentralManager _centralManager;
CBPeripheral _peripheral;
CBCharacteristic _remoteCharacteristic;

void Start()
{
centralManager = new CBCentralManager(this);
_centralManager = new CBCentralManager(this);
}

public void DidDiscoverPeripheral(CBCentralManager central, CBPeripheral peripheral, int rssi)
{
Debug.Log($"[DidDiscoverPeripheral] peripheral: {peripheral} rssi: {rssi}");
this.peripheral = peripheral;
_peripheral = peripheral;
peripheral.Delegate = this;
central.StopScan();
central.Connect(peripheral);
Expand All @@ -35,14 +35,14 @@ public void DidUpdateState(CBCentralManager central)
if (central.State == CBManagerState.PoweredOn)
{
Debug.Log($"[DidUpdateState] Start scanning for peripherals...");
central.ScanForPeripherals(new string[] { serviceUUID });
central.ScanForPeripherals(new string[] { _serviceUUID });
}
}

public void DidConnectPeripheral(CBCentralManager central, CBPeripheral peripheral)
{
Debug.Log($"[DidConnectPeripheral] peripheral: {peripheral}");
peripheral.DiscoverServices(new string[] { serviceUUID });
peripheral.DiscoverServices(new string[] { _serviceUUID });
}

public void DidDisconnectPeripheral(CBCentralManager central, CBPeripheral peripheral, CBError error)
Expand All @@ -67,7 +67,7 @@ public void DidDiscoverServices(CBPeripheral peripheral, CBError error)
foreach (var service in peripheral.Services)
{
Debug.Log($"[DidDiscoverServices] service: {service}, start discovering characteristics...");
peripheral.DiscoverCharacteristics(new string[] { characteristicUUID }, service);
peripheral.DiscoverCharacteristics(new string[] { _characteristicUUID }, service);
}
}

Expand All @@ -84,9 +84,9 @@ public void DidDiscoverCharacteristics(CBPeripheral peripheral, CBService servic
{
Debug.Log($"[DidDiscoverCharacteristics] characteristic: {characteristic}");

if (characteristic.UUID == characteristicUUID)
if (characteristic.UUID == _characteristicUUID)
{
remoteCharacteristic = characteristic;
_remoteCharacteristic = characteristic;
}

if (characteristic.Properties.HasFlag(CBCharacteristicProperties.Notify))
Expand Down Expand Up @@ -136,46 +136,46 @@ public void DidUpdateNotificationStateForCharacteristic(CBPeripheral peripheral,

public void OnClickWrite()
{
if (peripheral == null)
if (_peripheral == null)
{
Debug.Log("peripheral is null.");
return;
}

if (remoteCharacteristic == null)
if (_remoteCharacteristic == null)
{
Debug.Log("remoteCharacteristic is null.");
return;
}

var value = UnityEngine.Random.Range(100, 1000).ToString();
var data = Encoding.UTF8.GetBytes(value);
peripheral.WriteValue(data, remoteCharacteristic, CBCharacteristicWriteType.WithResponse);
_peripheral.WriteValue(data, _remoteCharacteristic, CBCharacteristicWriteType.WithResponse);
}

public void OnClickRead()
{
if (peripheral == null)
if (_peripheral == null)
{
Debug.Log("peripheral is null.");
return;
}

if (remoteCharacteristic == null)
if (_remoteCharacteristic == null)
{
Debug.Log("remoteCharacteristic is null.");
return;
}

peripheral.ReadValue(remoteCharacteristic);
_peripheral.ReadValue(_remoteCharacteristic);
}

void OnDestroy()
{
if (centralManager != null)
if (_centralManager != null)
{
centralManager.Dispose();
centralManager = null;
_centralManager.Dispose();
_centralManager = null;
}
}
}
Expand Down
Loading