/** Search for the TrueTouch device. */
 private void handleBleScanning()
 {
     BleApi.DeviceUpdate device = new BleApi.DeviceUpdate();
     BleApi.ScanStatus   status;
     do
     {
         status = BleApi.PollDevice(ref device, false);
         if (status == BleApi.ScanStatus.AVAILABLE)
         {
             Debug.Log("Found device: " + device.name + " | " + device.id);
             if (device.name.Equals(DEVICE_NAME, StringComparison.OrdinalIgnoreCase))
             {
                 /* TrueTouch found, scan for the desired service UUID */
                 BleApi.StopDeviceScan();
                 truetouchDevice = device;
                 BleApi.ScanServices(truetouchDevice.id);
                 state = BleState.CONNECTING;
                 Debug.Log("Scanning TrueTouch's services");
                 return;
             }
         }
         else if (status == BleApi.ScanStatus.FINISHED)
         {
             /* Ran out of devices without finding target device */
             errorString = "Could not find TrueTouch";
             state       = BleState.ERROR;
         }
     } while (status == BleApi.ScanStatus.AVAILABLE);
 }
Example #2
0
 public void StartStopDeviceScan()
 {
     if (!isScanningDevices)
     {
         // start new scan
         for (int i = scanResultRoot.childCount - 1; i >= 0; i--)
         {
             Destroy(scanResultRoot.GetChild(i).gameObject);
         }
         BleApi.StartDeviceScan();
         isScanningDevices         = true;
         deviceScanButtonText.text = "Stop scan";
         deviceScanStatusText.text = "scanning";
     }
     else
     {
         // stop scan
         isScanningDevices = false;
         BleApi.StopDeviceScan();
         deviceScanButtonText.text = "Start scan";
         deviceScanStatusText.text = "stopped";
     }
 }