Esempio n. 1
0
        public async Task UpdatePairedBluetoothDevicesAsync(CancellationToken cancellationToken = default)
        {
            await setDotNetRefAsync(cancellationToken);

            var module    = await _moduleTask.Value;
            var jsDevices = await module.InvokeAsync <Device[]>("WebBluetoothFunctions.GetPairedBluetoothDevices", cancellationToken);

            // Remove disconnected devices
            for (int i = connectedDevices.Count - 1; i >= 0; i--)
            {
                if (!jsDevices.Select(d => d.Id).Contains(connectedDevices[i].Id))
                {
                    OnDeviceDisconnected?.Invoke(connectedDevices[i]);
                    connectedDevices.RemoveAt(i);
                }
            }

            // Add connected Devices
            foreach (var newDevice in jsDevices)
            {
                if (!connectedDevices.Select(d => d.Id).Contains(newDevice.Id))
                {
                    connectedDevices.Add(newDevice);
                    OnDeviceConnected?.Invoke(newDevice);
                }
            }
        }
Esempio n. 2
0
        public void JsOnDisconnect(Device device)
        {
            var deviceObj = connectedDevices.SingleOrDefault(d => d.Id == device.Id);

            if (deviceObj != null)
            {
                OnDeviceDisconnected?.Invoke(deviceObj);
                connectedDevices.Remove(deviceObj);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        /// <returns><c>true</c> if successfully, <c>false</c> otherwise.</returns>
        public bool LidarStop()
        {
            if (!IsRunning ||
                IsDisposed)
            {
                return(false);
            }

            _TokenSource?.Cancel();

            try
            {
                _Task?.Wait(_Token);
            }
            catch (OperationCanceledException)
            {
            }
            catch (AggregateException e)
            {
                foreach (var v in e.InnerExceptions)
                {
                    Console.WriteLine(v);
                }
            }
            finally
            {
                _TokenSource?.Dispose();
            }

            try
            {
                // Stop device and dispose driver
                RpLidarInterface.LidarDisposeDriver();

                if (RpLidarInterface.LidarIsConnected() != 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                if (RpLidarInterface.LidarIsConnected() != 1)
                {
                    OnDeviceDisconnected?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Esempio n. 4
0
 protected void NotifyDeviceDisconnected()
 {
     Task.Run(() =>
     {
         try
         {
             OnDeviceDisconnected?.Invoke();
         }
         catch (Exception e)
         {
             Logger.GetInstance(typeof(UsbWatcher)).Error(e.ToString());
         }
     });
 }
Esempio n. 5
0
    private void OnDeviceChange(InputDevice device, InputDeviceChange inputDeviceChange)
    {
        deviceEventArgs.device = device;

        switch (inputDeviceChange)
        {
        case InputDeviceChange.Added:
            Debug.Log($"{device} was added.");
            OnDeviceConnected?.Invoke(this, deviceEventArgs);
            break;

        case InputDeviceChange.Removed:
            Debug.Log($"{device} was removed.");
            OnDeviceDisconnected?.Invoke(this, deviceEventArgs);
            break;

        default:
            break;
        }
    }
Esempio n. 6
0
        public void StartScrcpyServer(UsbDeviceEventArgs dev)
        {
            Task <int> task = new Task <int>(() =>
            {
                try
                {
                    OnVideoDataArrived cb = OnMirrorImageArrive;
                    RegistVideoCB(cb);
                    GC.KeepAlive(cb);
                    OnScrcpyLog cb2 = OnScrcpyLog1;
                    RegistScrcpyLogCB(cb2);
                    GC.KeepAlive(cb);
                    SetADBFolderPath(Marshal.StringToHGlobalAnsi(adb_path_)
                                     , Marshal.StringToHGlobalAnsi(adb_svr_path_));
                    IntPtr[] sbs = GetCommand($"-s {dev.GetSerial()} -m {Display_height} -b 2M");
                    var ret      = RunScrcpy(sbs.Length, sbs);

                    return(ret);
                }
                catch (Exception e)
                {
                    log_.Error($"StartScrcpyServer {e.ToString()}");
                }
                finally
                {
                    OnDeviceDisconnected?.Invoke(this, dev);
                    if (!adb_server_.GetStatus().IsRunning)
                    {
                        adb_server_.RestartServer();
                    }
                }
                return(-1);
            });

            task.Start();
        }
 public static extern StatusCode SetOnDeviceDisconnected(OnDeviceDisconnected func);
Esempio n. 8
0
 private void OnDeviceDisconnectedNotify(object sender, DeviceDataEventArgs e)
 {
     log_.Debug($"OnDeviceDisconnected {e.Device.Name}");
     OnDeviceDisconnected?.Invoke(this, new UsbDeviceEventArgs(e.Device));
 }
Esempio n. 9
0
 public void DisconnectDevice(IDevice device)
 {
     devices.Remove(device);
     OnDeviceDisconnected.Raise(device);
 }
Esempio n. 10
0
 private void RaiseDeviceDisconnectedEvent()
 {
     OnDeviceDisconnected?.Invoke();
 }
Esempio n. 11
0
 extern public static int BS2_SetDeviceEventListener(IntPtr context, OnDeviceFound cbOnDeviceFound, OnDeviceAccepted cbOnDeviceAccepted, OnDeviceConnected cbOnDeviceConnected, OnDeviceDisconnected cbOnDeviceDisconnected);