Ejemplo n.º 1
0
        public MainPageViewModel()
        {
            if (App.Current.Properties.ContainsKey("defaultPrinter"))
            {
                string guidName = App.Current.Properties["defaultPrinter"].ToString();
                _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult =>
                {
                    scanResult.ToList().ForEach(
                        item =>
                    {
                        if (!string.IsNullOrEmpty(item.Name) && item.Name == guidName)
                        {
                            Peripherals.Add(item);
                            _centralManager.StopScan();
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                await App.Current.MainPage.Navigation.PushAsync(new PrintPage(item));
                                SelectedPeripheral = null;
                            });

                            _scanDisposable?.Dispose();
                            IsScanning = _centralManager.IsScanning;
                        }
                    });

                    _connectedDisposable?.Dispose();
                });

                if (_centralManager.IsScanning)
                {
                    _centralManager.StopScan();
                }
                if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning)
                {
                    _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult =>
                    {
                        if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult))
                        {
                            Peripherals.Add(scanResult);
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                await App.Current.MainPage.Navigation.PushAsync(new PrintPage(scanResult));
                                SelectedPeripheral = null;
                            });
                        }
                    });
                }
            }
            else
            {
                GetDeviceListCommand    = new Command(GetDeviceList);
                SetAdapterCommand       = new Command(async() => await SetAdapter());
                CheckPermissionsCommand = new Command(async() => await CheckPermissions());
                CheckPermissionsCommand.Execute(null);
            }
        }
 public void ConnectPeripheral(Peripheral peripheral)
 {
     if (Connectors == null || Connectors.GetType() != t)
     {
         throw new Exception("No available connectors of the connection-type of the peripheral!");
     }
     else
     {
         Peripherals.Add(peripheral);
     }
 }
Ejemplo n.º 3
0
            private void ScanPeripheral(XElement node, RegisterSettings defaultRegisterSettings)
            {
                var name = GetMandatoryField(node, "name");
                var newRegisterSettings = GetRegisterSettings(node, defaultRegisterSettings);
                var peripheral = new SVDPeripheral(name, this);
                Peripherals.Add(peripheral);

                var registersElement = node.Element("registers");
                if(registersElement != null)
                {
                    ScanRegistersAndClusters(registersElement, newRegisterSettings, peripheral);
                }
            }
Ejemplo n.º 4
0
        void GetConnectedDevices()
        {
            _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult =>
            {
                scanResult.ToList().ForEach(
                    item =>
                {
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        Peripherals.Add(item);
                    }
                });

                _connectedDisposable?.Dispose();
            });

            if (_centralManager.IsScanning)
            {
                _centralManager.StopScan();
            }
        }
Ejemplo n.º 5
0
 void GetDeviceList()
 {
     if (_centralManager.IsScanning)
     {
         _scanDisposable?.Dispose();
     }
     else
     {
         if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning)
         {
             _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult =>
             {
                 if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult))
                 {
                     Peripherals.Add(scanResult);
                 }
             });
         }
     }
     IsScanning = _centralManager.IsScanning;
 }